  :root {
    --bg: #f5f5f7;
    --fg: #1d1d1f;
    --muted: #6e6e73;
    --border: #d2d2d7;
    --panel: #ffffff;
    --accent: #cbde67;
    --accent-soft: rgba(203, 222, 103, 0.20);
    --row-hover: rgba(0, 0, 0, 0.04);
    --row-active: rgba(203, 222, 103, 0.18);
    --good: #16a34a;
    --bad: #dc2626;
    --canvas-bg: #eceff3;
  }
  body.dark {
    --bg: #0a0a0f;
    --fg: #e0e0ec;
    --muted: #8888a0;
    --border: #2a2a3e;
    --panel: #12121a;
    --row-hover: rgba(255, 255, 255, 0.04);
    --row-active: rgba(203, 222, 103, 0.22);
    --canvas-bg: #0a0c10;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; overflow: hidden; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    transition: background 0.2s, color 0.2s;
    display: flex;
    flex-direction: column;
  }

  header {
    display: flex; align-items: center; flex-wrap: wrap;
    gap: 8px 12px; padding: 8px 16px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  header h1 { font-size: 14px; font-weight: 600; margin: 0; }
  .title-block { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
  .btn.nav-back { font-size: 13px; padding: 6px 12px; font-weight: 500; }
  .btn.nav-back:hover:not(:disabled) { filter: brightness(1.08); }
  .header-toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    flex: 1; min-width: 0; justify-content: center;
  }
  .header-controls { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
  /* Inline speed slider for the header — slimmer than the sidebar variant */
  .speed-inline {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 8px; border: 1px solid var(--border);
    border-radius: 6px; background: var(--bg);
    font-size: 11px; color: var(--muted);
  }
  .speed-inline input[type=range] { width: 80px; accent-color: var(--accent); }
  .speed-inline .speed-val {
    color: var(--fg); font-family: ui-monospace, monospace;
    min-width: 28px; text-align: right; font-size: 11px;
  }
  .toolbar-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-right: 2px; }
  .badge {
    font-size: 11px; color: var(--fg);
    background: var(--accent-soft); padding: 3px 9px; border-radius: 999px;
    font-variant-numeric: tabular-nums;
  }

  #app { display: flex; flex: 1; min-height: 0; }

  #sidebar {
    width: 320px; flex-shrink: 0;
    background: var(--panel); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden; transition: width 0.2s ease, border-right-width 0.2s ease;
  }
  #sidebar.collapsed { width: 0; border-right-width: 0; }
  .sidebar-scroll { flex: 1; overflow-y: auto; }

  .section {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }
  .section h2 {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.6px; color: var(--muted); margin: 0 0 8px;
  }
  .section .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
  .section .row + .row { margin-top: 6px; }
  .project-name {
    flex: 1;
    min-width: 0;
    padding: 5px 10px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-family: ui-monospace, monospace;
    color: var(--fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .btn {
    background: var(--panel);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    text-decoration: none;
    transition: all 0.15s;
  }
  .btn:hover:not(:disabled) { border-color: var(--muted); }
  .btn:disabled { opacity: 0.45; cursor: not-allowed; }
  .btn.active { background: var(--accent); color: #0a0d14; border-color: var(--accent); }
  .btn.primary { background: var(--accent); color: #0a0d14; border-color: var(--accent); }
  .btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
  .btn.small { padding: 3px 8px; font-size: 11px; }
  .btn.recording { background: #d33b3b; color: #fff; border-color: #d33b3b; opacity: 1 !important; cursor: default; }
  #captureStatus { background: #d33b3b; color: #fff; border-color: #d33b3b; }

  .seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
  .seg .btn { border: none; border-radius: 0; border-right: 1px solid var(--border); }
  .seg .btn:last-child { border-right: none; }

  select, input[type=text], input[type=number] {
    width: 100%;
    background: var(--bg); color: var(--fg);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 6px 8px; font-size: 12px; font-family: inherit;
    outline: none;
  }
  select:focus, input[type=text]:focus, input[type=number]:focus { border-color: var(--accent); }

  input[type=range] {
    flex: 1; min-width: 60px;
    accent-color: var(--accent);
  }
  input[type=range]:disabled { opacity: 0.4; }
  input[type=file] { display: none; }
  input[type=checkbox] { accent-color: var(--accent); }

  .layer-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px; align-items: center;
    padding: 4px 0;
    font-size: 12px;
  }
  .layer-row label { display: flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; }
  .layer-row .opacity-val { font-family: ui-monospace, monospace; font-size: 10px; color: var(--muted); min-width: 28px; text-align: right; }

  .speed-row {
    display: flex; gap: 6px; align-items: center;
    font-size: 11px; color: var(--muted);
    margin-top: 4px;
  }
  .speed-val { font-family: ui-monospace, monospace; color: var(--fg); min-width: 28px; text-align: right; }

  .scan-row {
    display: flex; flex-direction: column; gap: 2px;
    padding: 6px 14px; cursor: pointer;
    border-left: 2px solid transparent;
    font-size: 12px;
  }
  .scan-row:hover { background: var(--row-hover); }
  .scan-row.active { background: var(--row-active); border-left-color: var(--accent); }
  .scan-row .name { font-weight: 500; }
  .scan-row .meta { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
  .empty { padding: 12px 14px; font-size: 11px; color: var(--muted); }

  /* File inventory — one row per expected file, with a presence dot. */
  .file-inventory { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
  .file-inventory .file-row {
    display: grid;
    grid-template-columns: 10px 1fr auto;
    gap: 8px;
    align-items: center;
    font-size: 11px;
    line-height: 1.3;
    font-variant-numeric: tabular-nums;
  }
  .file-inventory .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: transparent;
    border: 1px solid var(--muted);
  }
  .file-inventory .dot.present {
    background: var(--good);
    border-color: var(--good);
  }
  .file-inventory .row-name { color: var(--fg); font-family: ui-monospace, monospace; }
  .file-inventory .row-meta { color: var(--muted); font-size: 10px; }
  .file-inventory .row-optional .row-name { color: var(--muted); }
  .file-inventory .empty { padding: 0; font-size: 11px; color: var(--muted); }

  /* ── Stage ──────────────────────────────────────────── */
  #stage { flex: 1; min-width: 0; min-height: 0; position: relative; background: var(--canvas-bg); }
  #canvas3d { width: 100%; height: 100%; display: block; }
  body.click-pivot #canvas3d { cursor: crosshair; }
  body.click-zoom  #canvas3d { cursor: zoom-in; }
  body.click-warp  #canvas3d { cursor: pointer; }
  body.click-off   #canvas3d { cursor: grab; }
  body.click-off   #canvas3d:active { cursor: grabbing; }

  #fadeOverlay {
    position: absolute; inset: 0;
    background: #000; opacity: 0; pointer-events: none; z-index: 5;
  }

  /* 9:16 framing guide for portrait capture — composing aid only, never in
     the recorded video (HTML overlay, not in the WebGL framebuffer). The
     box-shadow trick paints a dim "letterbox" around the central strip in a
     single rule. */
  #captureFrameGuide {
    position: absolute;
    top: 0; bottom: 0;
    left: 50%;
    height: 100%;
    aspect-ratio: 9 / 16;
    transform: translateX(-50%);
    border: 2px dashed #ffeb3b;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    z-index: 4;
    display: none;
  }
  #captureFrameGuide.active { display: block; }

  .loaded-summary {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    display: flex;
    gap: 8px;
    align-items: center;
  }
  .loaded-summary strong { color: var(--fg); font-weight: 600; }
  .loaded-summary .dot-sep { color: var(--border); }

  #help {
    position: absolute; bottom: 12px; right: 12px;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 6px; padding: 6px 10px;
    font-size: 10px; color: var(--muted);
    font-family: ui-monospace, monospace; line-height: 1.6;
    pointer-events: none; max-width: 320px; text-align: right;
  }
  #help kbd {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 3px; padding: 1px 4px; font-size: 9px; color: var(--fg);
  }

  #exitPanoBtn {
    position: absolute; top: 12px; right: 12px; display: none; z-index: 6;
  }
  #exitPanoBtn.visible { display: inline-flex; }

  #toast {
    position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 14px; font-size: 12px;
    color: var(--fg); opacity: 0; transition: opacity 0.2s;
    pointer-events: none; max-width: 80%; z-index: 7;
  }
  #toast.visible { opacity: 1; }
  #toast.error { border-color: var(--bad); color: var(--bad); }
