/* Caustica — styles */

:root {
  --bg:          #ffffff;
  --bg-soft:     #f9fafb;
  --bg-soft2:    #f3f4f6;
  --fg:          #1f2937;
  --fg-soft:     #4b5563;
  --muted:       #6b7280;
  --hairline:    #e5e7eb;
  --accent:      #4a7fc8;
  --accent-soft: rgba(74, 127, 200, 0.12);
  --good:        #10b981;
  --warn:        #f59e0b;
  --bad:         #ef4444;

  /* Unified type colors: all lens planes share one color, all source planes another. */
  --lens-color:   #4a7fc8;
  --src-color:    #f59e0b;
  --hybrid-color: #9b7dd4;
}

html[data-theme="dark"] {
  --bg:          #0d1117;
  --bg-soft:     #161b22;
  --bg-soft2:    #1c2128;
  --fg:          #e6edf3;
  --fg-soft:     #c9d1d9;
  --muted:       #8b949e;
  --hairline:    #30363d;
  --accent:      #7bbfcc;
  --accent-soft: rgba(123, 191, 204, 0.16);
  --good:        #4ade80;
  --warn:        #fbbf24;
  --bad:         #f87171;

  --lens-color:   #7bbfcc;
  --src-color:    #fbbf24;
  --hybrid-color: #b09ac8;
}

/* ── Reset / base ─────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ────────────────────────────────────────────────────────────── */

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.app-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

/* Desktop 1.3× scale — same technique as chi-by-eye. */
@media (min-width: 721px) and (min-aspect-ratio: 1) {
  .app-inner {
    width: calc(100% / 1.3);
    height: calc(100% / 1.3);
    transform: scale(1.3);
    transform-origin: top left;
  }
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */

.sl-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 44px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
}

.sl-topbar h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg);
  flex: 1;
}

.sl-back-btn {
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--hairline);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.sl-back-btn:hover { color: var(--fg); border-color: var(--fg-soft); }

.sl-demo-btn {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 12px;
  border: 1px solid var(--hairline);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
  font-family: inherit;
  text-decoration: none;
}
.sl-demo-btn:hover { color: var(--fg); border-color: var(--fg-soft); }

/* Theme button — matches parent site .dark-toggle */
.sl-theme-btn {
  background: none;
  border: none;
  padding: 5px;
  cursor: pointer;
  color: #7a8288;
  border-radius: 4px;
  line-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* Icon visibility driven by CSS, not JS — correct on first paint */
.icon-sun  { display: none;  }
.icon-moon { display: block; }
html[data-theme="dark"] .icon-sun  { display: block; }
html[data-theme="dark"] .icon-moon { display: none;  }
.sl-theme-btn:hover { color: #313436; background: rgba(0,0,0,0.06); }
html[data-theme="dark"] .sl-theme-btn       { color: rgba(255,255,255,0.72); }
html[data-theme="dark"] .sl-theme-btn:hover { color: #fff; background: rgba(255,255,255,0.06); }

/* ── Body (upper + timeline) ──────────────────────────────────────────────── */

.sl-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Upper: image panel + sidebar ────────────────────────────────────────── */

/* ── Three-column flex layout — wraps when image would be smaller than min-basis ── */
/* Wide:         [image 1fr] [plane-controls 270px] [settings 270px]            */
/* Intermediate: [image full-width]                                              */
/*               [plane-controls 270px] [settings 270px]                         */
/* Thin:         [image full-width] [plane-controls] [settings] (all stacked)   */

.sl-upper {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 0;
}

/* Image: tries to fill remaining space but never shrinks below 320px.          */
/* When sidebars don't fit alongside it the image wraps to its own full row.    */
/* Controls group: right-justified within its flex area, inner items can grow */
.sl-upper .sl-controls-col {
  flex: 1 0 270px;         /* can grow beyond its min; wraps when image needs room */
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;  /* blank space opens on the LEFT */
  gap: 14px;
  align-items: flex-start;
  align-content: flex-start;
  min-width: 270px;
}

/* Inner panels: grow from 270px min, capped so they don't become excessively wide */
.sl-controls-col > .sl-param-col,
.sl-controls-col > .sl-sidebar {
  flex: 1 0 270px;
  max-width: 400px;
  min-width: 270px;
}

/* ── Image panel ─────────────────────────────────────────────────────────── */

.sl-image-wrap {
  touch-action: none; /* prevent page scroll / pull-to-refresh when dragging in the image */
  flex: 1 1 320px;   /* grow freely, wraps to own row if it would be < 320px */
  min-width: 0;
  /* max-width caps the flex main axis so aspect-ratio:1 derives height without overflow.
     Formula: (viewport_height / 1.3_scale) - topbar(44) - timeline(190) - padding(26)
     The 780px hard cap prevents excessive size on very tall monitors. */
  max-width: min(calc(100vh / 1.3 - 260px), 780px);
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  align-self: start;
}

/* WebGL canvas fills the wrapper. */
.sl-image-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* prevent page scroll/refresh when dragging on the canvas */
}

/* In light mode, invert the lensed image so background is bright and arcs are dark. */
html[data-theme="light"] #sl-gl-canvas { filter: invert(1); }

/* Overlay canvas for critical curves — sits on top, pointer-events off. */
.sl-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Empty-state hint shown before any sources are placed. */
.sl-image-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  pointer-events: none;
}

/* Critical-curve toggle chip — top-right of the image. */
.sl-crit-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--fg-soft);
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 3px 8px;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  opacity: 0.85;
}
.sl-crit-toggle:hover { opacity: 1; }
.sl-crit-toggle input { accent-color: var(--accent); }

/* ── Right sidebar ────────────────────────────────────────────────────────── */

/* Default (narrow): single column, params first then settings. */
/* ── Tabbed sidebar ───────────────────────────────────────────────────────── */

.sl-sidebar {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.sl-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--hairline);
}

.sl-tab-btn {
  flex: 1;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s;
}
.sl-tab-btn:hover:not(.active) { color: var(--fg-soft); }
.sl-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.sl-tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Critical curves subsection header within the Settings panel */
.sl-subsection-header {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sl-subsection-header kbd {
  font-size: 10px;
  padding: 1px 4px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--bg-soft);
  color: var(--muted);
  font-family: inherit;
}

/* ── Object panel (bottom-right, lens/source params) ─────────────────────── */

/* Plane Controls column — mirrors the sidebar in size and style */
.sl-param-col {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 10px;   /* space between the .sl-tabs bar and sl-obj-panel */
}

#sl-obj-panel {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Static title row for Plane Controls — matches tab row height but neutral */
.sl-param-col-title {
  flex: 1;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-soft);
  text-align: center;
  cursor: default;
  user-select: none;
}

/* Shared grid on the panel so ALL rows share the same column widths.
   max-content on col 1 resolves to the WIDEST label, making all sliders equal length. */
#sl-obj-panel .sl-panel {
  display: grid;
  grid-template-columns: max-content 1fr 28px;
  column-gap: 8px;
  row-gap: 6px;
  align-items: center;
}
/* Title row, meta row, model select, and empty-msg span all 3 columns. */
#sl-obj-panel .sl-panel-title-row,
#sl-obj-panel .sl-params-meta-row,
#sl-obj-panel .sl-select,
#sl-obj-panel .sl-hybrid-section,
#sl-obj-panel .sl-empty-msg { grid-column: 1 / -1; }
/* Remove param-row's own box so its three children become direct grid items.
   Also suppress the margins that the parent row-gap now handles. */
#sl-obj-panel .sl-param-row { display: contents; }
#sl-obj-panel .sl-panel-title-row { margin-bottom: 0; }
#sl-obj-panel .sl-select { margin-bottom: 0; }
#sl-obj-panel .sl-param-row input[type="range"] { width: 100%; min-width: 0; }
#sl-obj-panel .sl-param-val { font-size: 11px; text-align: right; }

.sl-panel {
  border: 1px solid var(--hairline);
  border-radius: 6px;
  background: color-mix(in srgb, var(--bg-soft) 70%, transparent);
  padding: 12px;
}

/* z-value + delete button row under the panel title */
.sl-params-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.sl-params-z {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.sl-params-pos {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  flex: 1;
  min-width: 0;
}
.sl-obj-vis-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
  flex-shrink: 0;
}
.sl-obj-vis-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}
.sl-obj-vis-btn.sl-obj-hidden {
  color: var(--muted);
  opacity: 0.5;
}
.sl-delete-obj-btn {
  font-size: 11px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
  flex-shrink: 0;
}
.sl-delete-obj-btn:hover {
  color: var(--bad);
  border-color: var(--bad);
  background: color-mix(in srgb, var(--bad) 8%, transparent);
}

.sl-panel-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.sl-panel-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
}

/* ── Hybrid object panels ─────────────────────────────────────────────────── */

.sl-hybrid-section { border-top: 1px solid var(--hairline); padding-top: 4px; margin-top: 4px; }
.sl-hybrid-section:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.sl-hybrid-hdr {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 2px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  color: var(--fg);
  border-radius: 3px;
}
.sl-hybrid-hdr:hover { background: var(--bg-soft); }
.sl-hybrid-arrow {
  font-size: 16px;
  color: var(--muted);
  flex-shrink: 0;
  width: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}
.sl-hybrid-body {
  padding: 4px 2px 2px;
  display: grid;
  grid-template-columns: max-content 1fr 28px;
  column-gap: 8px;
  row-gap: 6px;
  align-items: center;
}
/* Full-width items inside hybrid body */
.sl-hybrid-body .sl-select,
.sl-hybrid-body .sl-shape-toggle,
.sl-hybrid-body .sl-checkbox-row { grid-column: 1 / -1; }
.sl-hybrid-body .sl-param-row { display: contents; }
.sl-hybrid-body input[type="range"] { width: 100%; min-width: 0; }
.sl-hybrid-body .sl-param-val { font-size: 11px; text-align: right; white-space: nowrap; }

/* ⓘ info toggle */
.sl-info-details { position: relative; }
.sl-info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  /* Hide the native <details> disclosure triangle */
  list-style: none;
  user-select: none;
  /* Custom circle */
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-style: italic;
  font-family: 'Times New Roman', serif;
  cursor: pointer;
  flex-shrink: 0;
}
.sl-info-btn::-webkit-details-marker { display: none; }
.sl-info-btn::marker              { display: none; }
.sl-info-btn:hover { color: var(--fg); border-color: var(--fg-soft); }
.sl-info-details[open] .sl-info-btn { color: var(--accent); border-color: var(--accent); }

.sl-info-content {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  width: 220px;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  font-size: 11.5px;
  color: var(--fg-soft);
  line-height: 1.55;
}

/* Unit label after number inputs */
.sl-unit { font-size: 12px; color: var(--muted); }

/* Parameter rows — label (flex:1) | short slider | value */
.sl-param-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
}
.sl-param-row:last-child { margin-bottom: 0; }

.sl-param-label {
  font-size: 12px;
  color: var(--fg-soft);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.sl-param-row input[type="range"] {
  /* Shrinks with the panel but never below 40px or above 70px */
  flex: 0 0 clamp(40px, 22%, 70px);
  accent-color: var(--accent);
  cursor: pointer;
}

.sl-param-val {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Checkbox row inside panels */
.sl-checkbox-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}
.sl-checkbox-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-soft);
  cursor: pointer;
}
.sl-checkbox-row input[type="checkbox"] { accent-color: var(--accent); }

/* Recording subsection label */
.sl-rec-subsection-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 7px;
}
.sl-rec-subsection-label:first-of-type { margin-top: 0; }

/* Format / FPS rows */
.sl-rec-setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}
.sl-rec-setting-label {
  color: var(--fg-soft);
  min-width: 68px;
  flex-shrink: 0;
}

/* Programmatic field rows — key | value (flex:1) | buttons */
.sl-rec-prog-field {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
}
.sl-rec-prog-key {
  color: var(--muted);
  flex-shrink: 0;
  min-width: 50px;
}
.sl-rec-prog-val {
  flex: 1;
  color: var(--fg-soft);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.sl-rec-prog-z {
  font-size: 12px;
  color: var(--fg-soft);
  margin-bottom: 7px;
}
.sl-muted-note { font-size: 11.5px; color: var(--muted); }

/* Small "Set" / "✕" buttons in programmatic rows */
.sl-rec-mini-btn {
  font-size: 11px;
  padding: 2px 7px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.1s, border-color 0.1s;
}
.sl-rec-mini-btn:hover { color: var(--fg); border-color: var(--fg-soft); }
.sl-rec-mini-clear { color: var(--bad); border-color: transparent; }
.sl-rec-mini-clear:hover { border-color: var(--bad); background: transparent; }

/* Program object list */
.sl-prog-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sl-prog-empty {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  padding: 4px 0;
}
.sl-prog-entry {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-soft);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 11px;
}
.sl-prog-entry-label {
  font-weight: 500;
  color: var(--fg-soft);
  flex-shrink: 0;
  margin-right: 2px;
}
.sl-prog-entry-path {
  flex: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10.5px;
}

/* Duration input inside programmatic row */
.sl-prog-dur-input {
  width: 48px;
  padding: 2px 5px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font-size: 12px;
  flex-shrink: 0;
}

/* Capture / record row */
.sl-capture-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.sl-capture-btn {
  font-size: 12px;
  padding: 4px 9px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}
.sl-capture-btn:hover { background: var(--bg-soft); }
.sl-capture-btn.recording {
  border-color: var(--bad);
  color: var(--bad);
}
.sl-capture-fps {
  font-size: 12px;
  padding: 3px 5px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
/* "Show shape" toggle — spans all grid columns */
.sl-shape-toggle {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  margin-top: 3px;
}
.sl-shape-toggle input { accent-color: var(--accent); flex-shrink: 0; }
.sl-shape-toggle:hover { color: var(--fg-soft); }

/* Color picker in source params — spans slider + value columns */
.sl-color-input {
  grid-column: 2 / -1;
  width: 100%;
  height: 26px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 2px 3px;
  cursor: pointer;
  background: transparent;
}

.sl-gif-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-soft);
  cursor: pointer;
  white-space: nowrap;
}
.sl-gif-label input { accent-color: var(--accent); }

/* Recording indicator dot */
.sl-rec-dot {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bad);
  animation: sl-rec-pulse 1s ease-in-out infinite;
  pointer-events: none;
}
@keyframes sl-rec-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.sl-how-link {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  text-decoration: none;
  padding: 10px 0 4px;
  text-align: right;
}
.sl-how-link:hover { color: var(--accent); }

.sl-perf-note {
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
  font-style: italic;
}

.sl-select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font-size: 12.5px;
  cursor: pointer;
  margin-bottom: 10px;
}

/* Empty-selection message in sidebar. */
.sl-empty-msg {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}

/* Global controls (FOV, z_max). */
.sl-global-input {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--fg-soft);
  margin-bottom: 8px;
}
.sl-global-input:last-child { margin-bottom: 0; }
.sl-global-input label { min-width: 62px; flex-shrink: 0; }
.sl-global-input select {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  font-size: 12px;
  padding: 2px 4px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
.sl-global-input input[type="number"] {
  width: 72px;
  padding: 4px 7px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font-size: 12.5px;
}
.sl-global-input input[type="range"] { flex: 1; min-width: 0; }
.sl-tone-param-val {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 28px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Timeline panel ───────────────────────────────────────────────────────── */

/* Visual divider inside the sidebar */
.sl-sidebar-divider {
  height: 1px;
  background: var(--hairline);
  flex-shrink: 0;
}

/* ── Timeline (bottom bar: z-axis + plane boxes) ─────────────────────────── */

.sl-timeline {
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  height: 190px;
  border-top: 1px solid var(--hairline);
  margin-top: 10px;
  background: var(--bg-soft);
  overflow: hidden;
}

/* Clickable z-axis strip. */
.sl-axis-wrap {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 220px;
  border-right: 1px solid var(--hairline);
  padding: 8px 0 0;
  position: relative;
  background: var(--bg);
}

.sl-axis-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: 0.05em;
}

.sl-axis-canvas {
  flex: 1;
  width: 100%;
  cursor: crosshair;
  display: block;
}

/* Scrollable plane-box area. */
.sl-planes-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: stretch;
}
.sl-planes {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 12px;
}
.sl-planes-arrow {
  display: none; /* shown only on mobile via media query */
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 28px;
  height: 44px;
  border: none;
  border-radius: 4px;
  background: color-mix(in srgb, var(--bg-soft) 90%, transparent);
  color: var(--fg-soft);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  line-height: 1;
  backdrop-filter: blur(4px);
}
.sl-planes-arrow:hover { background: var(--bg-soft2); }
.sl-planes-arrow-l { left: 0; }
.sl-planes-arrow-r { right: 0; }

/* Individual plane box. */
.sl-plane-box {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 152px;
  border: 2px solid var(--plane-color, var(--hairline));
  border-radius: 6px;
  background: var(--bg);
  overflow: hidden;
}

.sl-plane-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg-soft);
}

/* Compact z label in plane header */
.sl-plane-z {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--fg-soft);
  flex: 1;
  white-space: nowrap;
}

/* Clear-plane button */
.sl-plane-clear {
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.sl-plane-clear:hover { color: var(--warn); }

/* ── Plane toolbar (left of .sl-planes, above on mobile) ────────────────── */
.sl-plane-toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 5px;
  border-right: 1px solid var(--hairline);
  background: var(--bg);
  flex-shrink: 0;
  width: 38px;
}
.sl-tool-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  flex-shrink: 0;
}
.sl-tool-btn:hover:not(.active) { color: var(--fg); border-color: var(--fg); }
.sl-tool-btn[data-mode="lens"].active   { background: var(--lens-color);   border-color: var(--lens-color);   color: #fff; }
.sl-tool-btn[data-mode="source"].active { background: var(--src-color);    border-color: var(--src-color);    color: #fff; }
.sl-tool-btn[data-mode="hybrid"].active { background: var(--hybrid-color); border-color: var(--hybrid-color); color: #fff; }
/* Short label shown on desktop (vertical column), long label on mobile (horizontal row) */
.sl-tool-s { display: inline; }
.sl-tool-l { display: none;   }
.sl-tool-del { margin-top: auto; } /* bottom-justify in the column */
.sl-tool-del:hover { color: var(--bad) !important; border-color: var(--bad) !important;
  background: color-mix(in srgb, var(--bad) 8%, transparent) !important; }
/* sep is a spacer that grows to push delete down */
.sl-tool-sep { flex: 1; width: 18px; min-height: 6px; }

/* Effective-type drives border and button active color via --plane-color */
.sl-plane-box[data-effective-type="lens"]   { --plane-color: var(--lens-color);   }
.sl-plane-box[data-effective-type="source"] { --plane-color: var(--src-color);    }
.sl-plane-box[data-effective-type="hybrid"] { --plane-color: var(--hybrid-color); }
.sl-plane-box[data-effective-type="empty"]  { --plane-color: var(--hairline);     }

.sl-plane-del {
  font-size: 13px;
  line-height: 1;
  padding: 1px 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.sl-plane-del:hover { color: var(--bad); }

.sl-axis-canvas  { cursor: crosshair; }
.sl-plane-canvas {
  display: block;
  width: 148px;
  height: 148px;
  cursor: crosshair;
  touch-action: none;
}
.sl-plane-canvas.has-selected { cursor: grab; }

/* Empty timeline prompt. */
.sl-timeline-hint {
  padding: 8px 16px;
  font-size: 12.5px;
  color: var(--muted);
  align-self: center;
}

/* Mobile tab bar — hidden on desktop */
.sl-mobile-tabs { display: none; }
.sl-plane-setup-bar { display: none; }

/* ── Narrow screens: tighter padding, sidebars wrap to full rows ───────────── */

@media (max-width: 600px) {
  .sl-upper { padding: 8px 8px 0; gap: 10px; }
  /* On very narrow screens controls group fills its row */
  .sl-upper .sl-controls-col { flex: 1 0 100%; min-width: 0; }
  .sl-controls-col > .sl-param-col,
  .sl-controls-col > .sl-sidebar { max-width: 100%; }
}

/* ── Mobile layout: single-column, plane setup in a slide-up drawer ───────── */

@media (max-width: 640px) {
  /* Make the body scroll; -webkit-overflow-scrolling:touch enables it inside
     position:fixed ancestors on iOS Safari. */
  .sl-body {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    /* Pad enough that the last element scrolls clear of the fixed bar +
       device safe-area (iPhone home indicator etc.) */
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  /* Stack image above controls, stretch children to full width */
  .sl-upper {
    flex-wrap: nowrap;
    flex-direction: column;
    align-items: stretch;
    padding: 8px 8px 0;
    gap: 0;
    flex: 0 0 auto;
    overflow: visible;
  }

  /* Image: full width, square */
  .sl-image-wrap {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 1;
    align-self: stretch;
  }

  /* Controls: full width below image, no internal scroll */
  .sl-upper .sl-controls-col {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
    align-self: stretch;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0;
    /* Pad bottom so content isn't hidden under the fixed Plane Setup bar */
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }
  .sl-controls-col > .sl-param-col,
  .sl-controls-col > .sl-sidebar {
    max-width: 100%;
    min-width: 0;
    width: 100%;
    overflow: visible;
    height: auto;
  }
  /* Panels expand to natural height — no internal scrollbars */
  #sl-obj-panel,
  .sl-tab-content {
    overflow: visible;
    height: auto;
    min-height: 0;
    flex: 0 0 auto;
  }
  .sl-sidebar { overflow: visible; height: auto; min-height: 0; flex: 0 0 auto; }
  .sl-param-col { overflow: visible; height: auto; min-height: 0; }

  /* Mobile tab bar — full width, equal thirds */
  .sl-mobile-tabs {
    display: flex;
    width: 100%;
    flex-shrink: 0;
    border-bottom: 1px solid var(--hairline);
    background: var(--bg-soft);
  }
  .sl-mobile-tab-btn {
    flex: 1;
    padding: 10px 4px;
    font-size: 12px;
    font-weight: 500;
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
  }
  .sl-mobile-tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  /* Object tab: show/hide param-col and sidebar based on data-mobile-tab */
  #sl-controls-col[data-mobile-tab="object"]    .sl-param-col { display: flex; }
  #sl-controls-col[data-mobile-tab="object"]    .sl-sidebar   { display: none; }
  #sl-controls-col[data-mobile-tab="settings"]  .sl-param-col { display: none; }
  #sl-controls-col[data-mobile-tab="settings"]  .sl-sidebar   { display: flex; }
  #sl-controls-col[data-mobile-tab="recording"] .sl-param-col { display: none; }
  #sl-controls-col[data-mobile-tab="recording"] .sl-sidebar   { display: flex; }

  /* Desktop tab header inside sidebar hidden — mobile tab bar takes over */
  .sl-sidebar #sl-tabs { display: none; }
  /* Object Controls title hidden — mobile tab bar already labels it */
  .sl-param-col-title { display: none; }
  /* Axis label hidden on mobile — canvas draws it inline with the hint text */
  .sl-timeline .sl-axis-label { display: none; }

  /* Timeline hidden in normal flow; becomes a slide-up drawer */
  .sl-timeline {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    flex-direction: column;
    height: auto;
    margin-top: 0;
    border-top: 1px solid var(--hairline);
    box-shadow: 0 -4px 16px rgba(0,0,0,0.25);
  }
  .sl-timeline.plane-setup-open { display: flex; }

  /* Toolbar: horizontal row above the planes, left-aligned */
  .sl-timeline .sl-plane-toolbar {
    order: 0;
    flex-direction: row;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--hairline);
    padding: 6px 8px;
    justify-content: flex-start;
    gap: 6px;
  }
  /* Show full labels in horizontal layout */
  .sl-timeline .sl-tool-s { display: none; }
  .sl-timeline .sl-tool-l { display: inline; }
  .sl-timeline .sl-tool-btn { width: auto; padding: 0 10px; font-size: 12px; }
  .sl-timeline .sl-tool-del { margin-top: 0; margin-left: auto; width: 32px; padding: 0; }
  .sl-timeline .sl-tool-sep { flex: 0; width: 1px; height: 18px; min-height: 0;
                               background: var(--hairline); align-self: center; }

  /* Show scroll arrows on mobile */
  .sl-planes-arrow { display: flex; }

  /* Inside the drawer: planes on top, axis below.
     flex: 0 0 auto on planes prevents them from filling max-height. */
  .sl-timeline .sl-planes-wrap { order: 1; flex: 0 0 auto; width: 100%; }
  .sl-timeline .sl-planes {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .sl-timeline .sl-axis-wrap {
    order: 2;
    width: 100%;
    height: auto;
    flex-shrink: 0;
    border-right: none;
    border-top: 1px solid var(--hairline);
  }
  /* Fixed canvas height ensures getBoundingClientRect() is reliable on mobile */
  .sl-timeline .sl-axis-canvas {
    flex: 0 0 64px;
    height: 64px;
  }

  /* Plane setup bar: fixed footer strip */
  .sl-plane-setup-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    right: 8px;
    left: auto;
    z-index: 201;
    height: auto;
    background: transparent;
    border: none;
    transition: bottom 0.2s ease;
  }
  .sl-plane-setup-btn {
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    color: var(--fg-soft);
    background: var(--bg-soft);
    border: 1px solid var(--hairline);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    box-shadow: -2px -2px 8px rgba(0,0,0,0.12);
    padding: 0 14px;
    white-space: nowrap;
  }
  .sl-plane-setup-btn:active { opacity: 0.75; }

  /* axis canvas: prevent scroll-hijack when dragging plane markers */
  .sl-axis-canvas { touch-action: none; }
}

/* ── Tour overlay (mirrors chi-by-eye tutorial styles) ───────────────────── */
.tutorial-backdrop {
  position: fixed; inset: 0; background: transparent;
  z-index: 200; pointer-events: auto;
}
.tutorial-spotlight {
  position: fixed; border: 2px solid var(--accent); border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.55), 0 0 0 5px var(--accent-soft);
  pointer-events: none; z-index: 201;
  transition: left 0.28s ease, top 0.28s ease, width 0.28s ease, height 0.28s ease;
}
.tutorial-spotlight.no-target { border: none; box-shadow: 0 0 0 9999px rgba(0,0,0,0.55); width:0; height:0; }
.tutorial-tooltip {
  position: fixed; background: var(--bg); border: 1px solid var(--hairline);
  border-radius: 10px; padding: 18px 20px 14px; z-index: 202;
  max-width: 380px; min-width: 260px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18); pointer-events: auto;
  transition: left 0.28s ease, top 0.28s ease;
}
@media (max-width: 640px) {
  .tutorial-tooltip {
    max-width: calc(100vw - 24px);
    min-width: 0;
    transition: none; /* avoid animating from off-screen on first show */
  }
}
html[data-theme="dark"] .tutorial-tooltip { box-shadow: 0 12px 32px rgba(0,0,0,0.6); }
.tutorial-tooltip .tt-step {
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.tutorial-tooltip .tt-body {
  font-size: 13.5px; line-height: 1.55; color: var(--fg); margin-bottom: 14px;
}
.tutorial-tooltip .tt-body kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; background: var(--bg-soft); padding: 1px 5px;
  border-radius: 3px; border: 1px solid var(--hairline);
}
.tutorial-tooltip .tt-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.tutorial-tooltip .tt-skip {
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); background: transparent; border: none; padding: 4px 6px; cursor: pointer;
}
.tutorial-tooltip .tt-skip:hover { color: var(--fg); }
.tutorial-tooltip .tt-next { font-size: 13px; padding: 7px 18px; border-radius: 6px; }
.tutorial-tooltip .tt-arrow {
  position: absolute; width: 12px; height: 12px; background: var(--bg);
  border: 1px solid var(--hairline); transform: rotate(45deg);
}
.tutorial-tooltip.below  .tt-arrow { top: -7px;    border-right: none; border-bottom: none; }
.tutorial-tooltip.above  .tt-arrow { bottom: -7px; border-left:  none; border-top: none; }
.tutorial-tooltip.right  .tt-arrow { left: -7px;   border-right: none; border-top: none; }
.tutorial-tooltip.left   .tt-arrow { right: -7px;  border-left:  none; border-bottom: none; }
.tutorial-quit {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 203; color: var(--muted); background: var(--bg); font-family: inherit;
  font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 5px 12px; border: 1px solid var(--hairline); border-radius: 5px; cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.tutorial-quit:hover { color: var(--fg); border-color: var(--fg); background: var(--bg-soft); }
