:root {
  --bg: #0a0e14;
  --surface: #141b24;
  --border: #2a3441;
  --text: #e7edf4;
  --muted: #8b98a8;
  --accent: #22c55e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.bar {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.bar h1 { margin: 0.25rem 0 0; font-size: 1.15rem; }
.bar .ver { color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.bar .hint { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.85rem; }
.back { color: var(--accent); text-decoration: none; font-size: 0.9rem; }

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 86px);
}
.sidebar {
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow-y: auto;
  min-height: 0;
}
.step { display: grid; gap: 0.5rem; }
.step-title {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
label { display: grid; gap: 0.35rem; font-size: 0.8rem; color: var(--muted); }
select, input[type="range"] { width: 100%; }
.meta, .status, .value-label {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.35;
  word-break: break-word;
}
.step button, .link-btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  padding: 0.45rem 0.55rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  font-size: 0.8rem;
}
.step button:hover:not(:disabled), .link-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.step button:disabled { opacity: 0.45; cursor: not-allowed; }

.viewport-wrap {
  position: relative;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  touch-action: pan-y pinch-zoom;
}
#frame-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.viewport-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls-backdrop,
.controls-close-btn,
.mobile-chrome {
  display: none;
}

@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  body {
    height: 100dvh;
  }

  .bar {
    padding: 0.55rem 0.85rem;
    padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
  }

  .bar h1 {
    font-size: 0.95rem;
    margin: 0.1rem 0 0;
  }

  .bar .hint {
    display: none;
  }

  .layout {
    display: block;
    height: calc(100dvh - 52px);
    overflow: hidden;
  }

  .viewport-wrap {
    width: 100%;
    height: 100%;
  }

  #frame-img {
    object-fit: contain;
  }

  .mobile-chrome {
    display: grid;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    gap: 0.45rem;
    padding: 0.55rem 0.75rem;
    padding-bottom: calc(0.55rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, rgba(2, 6, 23, 0.92) 0%, rgba(2, 6, 23, 0.55) 70%, transparent 100%);
    pointer-events: none;
  }

  .mobile-chrome[hidden] {
    display: none !important;
  }

  body.controls-open .mobile-chrome {
    opacity: 0;
    pointer-events: none;
  }

  .mobile-frame-label {
    margin: 0;
    font-size: 0.72rem;
    color: #cbd5e1;
    text-align: center;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
  }

  .mobile-transport {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    pointer-events: auto;
  }

  .mobile-transport-btn,
  .mobile-play-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 999px;
    background: rgba(20, 27, 36, 0.88);
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }

  .mobile-play-btn {
    min-width: 52px;
    font-size: 1.1rem;
  }

  .mobile-play-btn:disabled,
  .mobile-transport-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  .mobile-frame-slider {
    width: 100%;
    margin: 0;
    pointer-events: auto;
    accent-color: var(--accent);
  }

  .mobile-controls-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: end;
    min-height: 40px;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(20, 27, 36, 0.92);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }

  .controls-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.5);
  }

  body.controls-open .controls-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    max-height: min(72dvh, 520px);
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 36px rgba(0, 0, 0, 0.42);
    transform: translateY(100%);
    transition: transform 0.22s ease;
    padding-top: 2.4rem;
    padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
  }

  body.controls-open .sidebar {
    transform: translateY(0);
  }

  .controls-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0.55rem;
    right: 0.75rem;
    min-height: 36px;
    padding: 0.35rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 0.78rem;
    cursor: pointer;
  }

  .step button,
  .link-btn {
    min-height: 44px;
  }

  .sidebar select,
  .sidebar input[type="range"] {
    min-height: 40px;
  }
}
