/* True Vision Camera — styles
   Token system follows the aesthetic research digest: one hue + one chroma drive a perceptual
   (oklch) scale; dark mode is its own token set (tinted base, surfaces rise in lightness,
   halation-safe text, lighter/lower-chroma accent); elevation on dark = light ring + ambient shadow;
   type on a 1.25 modular scale with optical sizing; motion 100–300 ms, ease-out in / ease-in out,
   transform + opacity only; few backdrop-filter surfaces. */
:root {
  /* scene-adaptive hue and chroma (set live from the camera by app.js) */
  --h: 80;            /* warm gold by default */
  --c: 0.09;
  --font-ui: "Inter", "SF Pro Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-brand: "Cormorant Garamond", "Didot", "Georgia", "Times New Roman", serif;
  /* type scale: major third (1.25) from a 14px base */
  --t-1: 0.8rem;  --t0: 0.875rem; --t1: 1.09rem; --t2: 1.37rem; --t3: 1.71rem;
  /* spacing primitives */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
  --r-sm: 10px; --r-md: 16px; --r-lg: 22px;
  /* motion tokens */
  --d-micro: 150ms; --d-std: 240ms; --d-large: 380ms;
  --e-out: cubic-bezier(0.22, 1, 0.36, 1);
  --e-in: cubic-bezier(0.55, 0, 1, 0.45);
  --e-spring: linear(0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017, 1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%, 1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%, 0.997 69.8%, 1.003 76.9%, 1);
  /* dark theme tokens (sRGB fallbacks first, oklch where supported) */
  --bg: #100d0a; --surface-1: #16120e; --surface-2: #1d1812; --surface-3: #27211a;
  --text: #ece6dc; --muted: #9c927f; --accent: #e3cf98; --on-accent: #1a1409; --accent-rgb: 227, 207, 152;
  --ring: rgba(255, 255, 255, 0.06);
  --shadow-ambient: 0 4px 20px rgba(0, 0, 0, 0.6);
  --shadow-key: 0 2px 4px -1px rgba(0,0,0,.2), 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12);
  --danger: #ff5a4d;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --scrim: rgba(12, 10, 8, 0.62);
}
@supports (color: oklch(0.5 0.1 80)) {
  :root {
    --bg: oklch(0.10 calc(var(--c) * 0.25) var(--h));
    --surface-1: oklch(0.12 calc(var(--c) * 0.22) var(--h));
    --surface-2: oklch(0.14 calc(var(--c) * 0.2) var(--h));
    --surface-3: oklch(0.19 calc(var(--c) * 0.12) var(--h));
    --text: oklch(0.92 0.008 var(--h));
    --muted: oklch(0.62 0.012 var(--h));
    --accent: oklch(0.80 min(var(--c), 0.12) var(--h));
    --on-accent: oklch(0.10 0.02 var(--h));
    --ring: oklch(1 0 0 / 0.06);
    --danger: oklch(0.68 0.2 28);
    --scrim: oklch(0.12 0.01 var(--h) / 0.64);
  }
}
:root[data-theme="light"] {
  --bg: #efe9df; --surface-1: #f4efe6; --surface-2: #f9f5ee; --surface-3: #ffffff;
  --text: #221c14; --muted: #6a5f50; --accent: #8c6f2a; --on-accent: #fffaf0; --accent-rgb: 140, 111, 42;
  --ring: rgba(40, 30, 10, 0.08);
  --shadow-ambient: 0 8px 28px rgba(60, 40, 10, 0.16);
  --glass: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(60, 40, 10, 0.12);
  --scrim: rgba(250, 246, 238, 0.72);
}
@supports (color: oklch(0.5 0.1 80)) {
  :root[data-theme="light"] {
    --bg: oklch(0.94 calc(var(--c) * 0.2) var(--h));
    --surface-1: oklch(0.96 calc(var(--c) * 0.15) var(--h));
    --surface-2: oklch(0.975 calc(var(--c) * 0.1) var(--h));
    --surface-3: oklch(0.99 0.004 var(--h));
    --text: oklch(0.22 0.02 var(--h));
    --muted: oklch(0.48 0.02 var(--h));
    --accent: oklch(0.55 min(var(--c), 0.12) var(--h));
    --on-accent: oklch(0.98 0.01 var(--h));
    --scrim: oklch(0.97 0.01 var(--h) / 0.74);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui); font-size: var(--t0); line-height: 1.45;
  font-optical-sizing: auto; font-feature-settings: "tnum" 1, "cv05" 1;
  color: var(--text); background: var(--bg); overflow: hidden; -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
hr { border: 0; border-top: 1px solid var(--glass-border); margin: var(--s4) 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Adaptive background: a blurred, low-res copy of the live frame (static filter, never animated) */
.ambient {
  position: fixed; inset: -12%; width: 124%; height: 124%;
  filter: blur(70px) saturate(1.2) brightness(0.5);
  z-index: 0; pointer-events: none; opacity: 0;
  transition: opacity var(--amb-period, 1600ms) linear; /* cross-fade exactly one sampling period */
  will-change: opacity;
}
.ambient.front { opacity: 1; }
:root[data-theme="light"] .ambient { filter: blur(70px) saturate(0.85) brightness(1.6) opacity(0.6); }
:root[data-theme="light"] .ambient.front { opacity: 0.6; }
body, .panel, .seg, .res select, .dock, .controls, .mode::before { transition-property: background-color, color, box-shadow; transition-duration: var(--amb-period, 1600ms); transition-timing-function: linear; }
.ambient-veil {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(1200px 700px at 60% 45%, rgba(var(--accent-rgb), 0.06), transparent 60%), linear-gradient(180deg, rgba(0,0,0,0.25), rgba(0,0,0,0.55));
}
:root[data-theme="light"] .ambient-veil { background: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0.55)); }

.app {
  position: relative; z-index: 1; height: 100vh; height: 100dvh;
  display: grid; grid-template-columns: 300px minmax(420px, 1fr) 340px; grid-template-rows: 64px 1fr;
  grid-template-areas: "top top top" "modes stage panel"; gap: 0 18px; padding: 0 18px 18px;
}

/* Top bar */
.topbar { grid-area: top; display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.brand { display: flex; align-items: center; gap: 14px; margin-top: 34px; }
.brand-ring { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--accent); box-shadow: 0 0 24px rgba(var(--accent-rgb), 0.22) inset; }
.brand-text h1 { font-family: var(--font-brand); font-weight: 500; letter-spacing: 0.28em; font-size: 20px; margin: 0; }
.brand-text p { margin: 2px 0 0; font-size: 10px; letter-spacing: 0.22em; color: var(--muted); }
.top-actions { display: flex; gap: var(--s2); }
.icon-btn { width: 40px; height: 40px; border-radius: var(--r-sm); display: grid; place-items: center; color: var(--muted); transition: color var(--d-micro) var(--e-out), transform var(--d-micro) var(--e-out); }
.icon-btn:hover { color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 18px; height: 18px; }

/* Modes */
.modes { grid-area: modes; display: flex; flex-direction: column; gap: var(--s2); padding-top: 70px; }
.mode {
  position: relative; display: grid; grid-template-columns: 118px 1fr; gap: 14px; align-items: center;
  padding: var(--s2); border-radius: var(--r-md); text-align: left; min-height: 44px;
  transition: transform var(--d-micro) var(--e-out);
}
.mode::before { /* elevation drawn as a layer whose opacity animates (never box-shadow) */
  content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none;
  background: var(--surface-3); box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.45), var(--shadow-ambient);
  transition: opacity var(--d-std) var(--e-out);
}
.mode:hover::before { opacity: 0.5; }
.mode.on::before { opacity: 1; }
.mode:active { transform: scale(0.985); }
.mode > * { position: relative; }
.mode-thumb { width: 118px; height: 124px; border-radius: var(--r-sm); background: var(--surface-3); box-shadow: 0 0 0 1px var(--ring); transition: box-shadow var(--d-std) var(--e-out); }
.mode.on .mode-thumb { box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.6); }
.mode-text strong { display: block; font-weight: 500; font-size: var(--t1); margin-bottom: 3px; letter-spacing: 0.01em; }
.mode-text small { display: block; font-size: var(--t-1); color: var(--muted); line-height: 1.35; letter-spacing: 0.01em; }

/* Stage */
.stage { grid-area: stage; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: 1fr 96px; gap: 14px; min-width: 0; }
.viewfinder { grid-column: 1; grid-row: 1; }
.focus-rail { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; gap: 10px; width: 176px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; animation: dlg-in var(--d-std) var(--e-out); }
.focus-rail::-webkit-scrollbar { display: none; }
.focus-rail[hidden] { display: none; }
.controls { grid-column: 1 / -1; grid-row: 2; }
.viewfinder { position: relative; border-radius: 20px; overflow: hidden; background: #000; box-shadow: 0 0 0 1px var(--ring), var(--shadow-ambient); min-height: 0; }
#view { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
/* overlays sit on an arbitrary live background: always on a scrim, never bare text */
.vf-top { position: absolute; inset: 14px 14px auto; display: flex; align-items: center; justify-content: center; z-index: 3; pointer-events: none; }
.vf-top > * { pointer-events: auto; }
.seg { display: flex; padding: 4px; border-radius: 999px; background: var(--scrim); box-shadow: 0 0 0 1px var(--glass-border); }
.seg button { padding: 8px 24px; min-height: 36px; border-radius: 999px; font-size: var(--t-1); letter-spacing: 0.12em; color: var(--muted); transition: color var(--d-micro) var(--e-out), background-color var(--d-micro) var(--e-out); }
.seg button.on { background: rgba(var(--accent-rgb), 0.2); color: var(--accent); box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.35) inset; }
.res { position: absolute; right: 0; top: 0; }
.res select {
  appearance: none; padding: 9px 32px 9px 14px; min-height: 36px; border-radius: 999px; font-size: var(--t-1);
  background: var(--scrim) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c8c0b2' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>") no-repeat right 10px center / 14px;
  border: 0; box-shadow: 0 0 0 1px var(--glass-border); color: var(--text);
}
.guide { position: absolute; left: 0; right: 0; bottom: 16px; text-align: center; z-index: 3; font-size: var(--t-1); letter-spacing: 0.04em; color: var(--text); pointer-events: none; }
.guide .pill { display: inline-block; padding: 7px 14px; border-radius: 999px; background: var(--scrim); box-shadow: 0 0 0 1px var(--glass-border); }
.guide .ok { color: oklch(0.85 0.12 140); }
.guide .warn { color: oklch(0.85 0.12 80); }
.guide-box { position: absolute; z-index: 2; pointer-events: none; border: 1px solid rgba(var(--accent-rgb), 0.7); border-radius: var(--r-sm); box-shadow: 0 0 0 1px rgba(0,0,0,0.4); transition: transform var(--d-micro) linear; }
.viewfinder.thirds::before {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background:
    linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255,255,255,0.25) calc(33.33% - .5px), rgba(255,255,255,0.25) calc(33.33% + .5px), transparent calc(33.33% + .5px)),
    linear-gradient(to right, transparent calc(66.66% - .5px), rgba(255,255,255,0.25) calc(66.66% - .5px), rgba(255,255,255,0.25) calc(66.66% + .5px), transparent calc(66.66% + .5px)),
    linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255,255,255,0.25) calc(33.33% - .5px), rgba(255,255,255,0.25) calc(33.33% + .5px), transparent calc(33.33% + .5px)),
    linear-gradient(to bottom, transparent calc(66.66% - .5px), rgba(255,255,255,0.25) calc(66.66% - .5px), rgba(255,255,255,0.25) calc(66.66% + .5px), transparent calc(66.66% + .5px));
}
.rec-badge { position: absolute; left: 16px; top: 48px; z-index: 3; display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--scrim); box-shadow: 0 0 0 1px var(--glass-border); font-size: var(--t-1); }
.rec-badge[hidden], .guide-box[hidden], #lastImg[hidden] { display: none; }
.rec-badge .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.status { position: absolute; inset: 0; display: grid; place-items: center; z-index: 4; background: rgba(10,8,6,0.78); color: var(--muted); font-size: var(--t1); text-align: center; padding: 24px; white-space: pre-line; }
.status[hidden] { display: none; }
.status .retry { margin-top: 14px; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 5; }
.flash.go { animation: flash 350ms var(--e-out); }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }
.viewfinder.compare::after { content: "ORIGINAL"; position: absolute; right: 16px; bottom: 16px; z-index: 3; font-size: 11px; letter-spacing: .2em; padding: 6px 10px; border-radius: 999px; background: var(--scrim); color: var(--accent); }

/* Controls */
.controls { display: flex; align-items: center; justify-content: center; gap: 36px; }
.thumb { width: 84px; height: 84px; border-radius: var(--r-md); overflow: hidden; background: var(--surface-2); box-shadow: 0 0 0 1px var(--ring); display: grid; place-items: center; transition: transform var(--d-micro) var(--e-out); }
.thumb:active { transform: scale(0.95); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.round { width: 62px; height: 62px; border-radius: 50%; background: var(--surface-2); box-shadow: 0 0 0 1px var(--ring), var(--shadow-key); display: grid; place-items: center; color: var(--text); transition: transform var(--d-micro) var(--e-out), color var(--d-micro) var(--e-out); }
.round:hover { color: var(--accent); }
.round:active { transform: scale(0.93); }
.round svg { width: 24px; height: 24px; }
.round.on { color: var(--accent); box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.6), var(--shadow-key); }
.round:disabled { opacity: .4; cursor: default; }
.shutter { position: relative; width: 96px; height: 96px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.9); display: grid; place-items: center; transition: transform var(--d-micro) var(--e-spring); }
.shutter::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; box-shadow: 0 0 30px rgba(var(--accent-rgb), 0.3); opacity: 1; transition: opacity var(--d-std) var(--e-out); pointer-events: none; }
.shutter span { width: 78px; height: 78px; border-radius: 50%; background: #f7f1e3; transition: transform var(--d-std) var(--e-spring), border-radius var(--d-std) var(--e-out), background-color var(--d-std) var(--e-out); }
.shutter:hover span { transform: scale(1.03); }
.shutter:active { transform: scale(0.94); }
.shutter.video span { background: var(--danger); }
.shutter.video.rec span { transform: scale(0.46); border-radius: 22%; }
.shutter:disabled { opacity: .5; cursor: progress; }
.shutter:disabled::after { opacity: 0; }

/* Panel (one of only two backdrop-filter surfaces) */
.panel {
  grid-area: panel; margin-top: 50px; padding: 22px 22px 18px; border-radius: var(--r-lg); overflow-y: auto; overscroll-behavior: contain;
  background: var(--glass); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 0 0 1px var(--glass-border), var(--shadow-ambient);
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.panel-head h2 { font-weight: 400; font-size: var(--t3); margin: 0; letter-spacing: 0.005em; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: var(--t0); }
.panel h3 { font-weight: 500; font-size: var(--t1); margin: 6px 0 12px; }
.row { margin-bottom: 18px; }
.row-h { display: grid; grid-template-columns: 20px 1fr auto; gap: 12px; align-items: center; font-size: var(--t0); margin-bottom: 8px; min-height: 24px; }
.row-h svg { color: var(--muted); }
.row-h b { font-weight: 400; font-size: var(--t-1); color: var(--muted); }
.row small { display: block; color: var(--muted); font-size: var(--t-1); margin-left: 32px; margin-top: 6px; letter-spacing: 0.01em; }
.row.toggle .row-h { margin-bottom: 0; }
.row input[type="range"] { width: calc(100% - 32px); margin-left: 32px; display: block; }
.aura-body .row-h { grid-template-columns: 1fr auto; }
.aura-body .row input[type="range"], .aura-body .row small { margin-left: 0; width: 100%; }
.aura-body[hidden] { display: none; }
.aura-head small { margin-top: 2px; }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 28px; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: rgba(255,255,255,0.18); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 2px; background: rgba(255,255,255,0.18); border-radius: 2px; }
:root[data-theme="light"] input[type="range"]::-webkit-slider-runnable-track, :root[data-theme="light"] input[type="range"]::-moz-range-track { background: rgba(40,30,10,0.2); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); margin-top: -8px; box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.15); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(var(--accent-rgb), 0.15); }
.switch { position: relative; width: 44px; height: 26px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,0.15); transition: background-color var(--d-std) var(--e-out); }
:root[data-theme="light"] .switch i { background: rgba(40,30,10,0.2); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform var(--d-std) var(--e-spring); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 8px 14px; min-height: 36px; border-radius: 999px; font-size: var(--t-1); box-shadow: 0 0 0 1px var(--glass-border); color: var(--muted); background: var(--surface-2); transition: color var(--d-micro) var(--e-out), background-color var(--d-micro) var(--e-out); }
.chip.on { color: var(--accent); box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.55); background: rgba(var(--accent-rgb), 0.1); }
.aura-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s2); }
.preset { display: grid; gap: 8px; justify-items: center; font-size: var(--t-1); color: var(--muted); transition: transform var(--d-micro) var(--e-out), color var(--d-micro) var(--e-out); }
.preset:active { transform: scale(0.96); }
.preset canvas { width: 100%; aspect-ratio: 1; height: auto; border-radius: var(--r-sm); box-shadow: 0 0 0 1px var(--ring); background: var(--surface-3); transition: box-shadow var(--d-std) var(--e-out); }
.preset.on { color: var(--text); }
.preset.on canvas { box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.7); }
.muted { color: var(--muted); font-size: var(--t-1); }

/* Dialogs */
.dlg { border: 0; border-radius: 20px; padding: 0; background: var(--surface-2); color: var(--text); width: min(520px, 92vw); box-shadow: 0 0 0 1px var(--glass-border), var(--shadow-ambient); }
.dlg.wide { width: min(760px, 94vw); }
.dlg::backdrop { background: rgba(0,0,0,0.6); }
.dlg[open] { animation: dlg-in var(--d-std) var(--e-out); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.dlg form { padding: 24px; max-height: 86vh; overflow: auto; }
.dlg h2 { margin: 0 0 14px; font-weight: 400; font-size: var(--t2); }
.dlg h3 { margin: 20px 0 6px; font-weight: 500; font-size: var(--t1); }
.dlg-grid { display: grid; gap: 12px; }
.dlg label { display: grid; gap: 6px; font-size: var(--t-1); color: var(--muted); }
.dlg label.chk { grid-template-columns: auto 1fr; align-items: center; min-height: 32px; }
.dlg input[type="text"], .dlg input[type="number"], .dlg select { padding: 9px 10px; min-height: 40px; border-radius: var(--r-sm); border: 0; box-shadow: 0 0 0 1px var(--glass-border); background: var(--surface-1); color: var(--text); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.ghost { padding: 10px 16px; min-height: 40px; border-radius: var(--r-sm); box-shadow: 0 0 0 1px var(--glass-border); color: var(--muted); background: var(--surface-2); transition: color var(--d-micro) var(--e-out), transform var(--d-micro) var(--e-out); }
.ghost:hover { color: var(--text); }
.ghost:active { transform: scale(0.97); }
.ghost.sm { padding: 8px 12px; min-height: 36px; font-size: var(--t-1); }
.ghost.active { color: var(--accent); box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.55); }
.primary { padding: 10px 18px; min-height: 40px; border-radius: var(--r-sm); background: var(--accent); color: var(--on-accent); font-weight: 500; transition: transform var(--d-micro) var(--e-out); }
.primary:active { transform: scale(0.97); }
.report { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: var(--t-1); }
.report div { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--glass-border); }
.report div span:last-child { color: var(--accent); text-align: right; }
.report .wide { grid-column: 1 / -1; }
.models { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.models div { padding: 10px 12px; border-radius: var(--r-sm); box-shadow: 0 0 0 1px var(--glass-border); background: var(--surface-1); font-size: var(--t-1); }
.models strong { display: block; font-weight: 500; margin-bottom: 3px; }
.models em { color: var(--accent); font-style: normal; }
.models p { margin: 4px 0 0; color: var(--muted); }


/* ---- Hiding panels: display none AND their drawing loops stop (see app.js) ---- */
.hide-x { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 4px 8px; border-radius: 999px; align-self: flex-end; }
.hide-x:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.modes .hide-x { margin: -56px 0 8px; }
.panel-head .hide-x { margin-right: 4px; }
.panel-head { align-items: center; }
.panel-head > div { flex: 1; }
body.hide-modes .modes, body.hide-panel .panel, body.hide-rail .focus-rail, body.hide-ambient .ambient, body.hide-ambient .ambient-veil, body.hide-overlay #overlay { display: none !important; }
body.hide-modes .app { grid-template-columns: minmax(420px, 1fr) 340px; grid-template-areas: "top top" "stage panel"; }
body.hide-panel .app { grid-template-columns: 300px minmax(420px, 1fr); grid-template-areas: "top top" "modes stage"; }
body.hide-modes.hide-panel .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "stage"; }
body.hide-ambient { background: var(--bg); }
body.hide-modes .brand { margin-top: 0; }
#hideBtn.on { color: var(--accent); }
@media (max-width: 1240px) { body.hide-modes .app, body.hide-panel .app, body.hide-modes.hide-panel .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "stage" "modes" "panel"; } .modes .hide-x { margin: 0; } }

/* ---- Viewfinder overlays, dock, drawer, focus windows ---- */
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.focus-layer { display: none; }
.focus-win { flex: 0 0 auto; width: 176px; border-radius: 18px; overflow: hidden; background: var(--surface-1); box-shadow: 0 0 0 1px rgba(var(--accent-rgb), 0.55), var(--shadow-ambient); animation: dlg-in var(--d-std) var(--e-out); }
.focus-win canvas { display: block; width: 176px; height: 176px; image-rendering: auto; }
.focus-win[data-state="lost"] { box-shadow: 0 0 0 1px oklch(0.7 0.18 28 / 0.8), var(--shadow-ambient); }
.focus-win[data-state="predicting"], .focus-win[data-state="reacquiring"] { box-shadow: 0 0 0 1px oklch(0.8 0.12 80 / 0.8), var(--shadow-ambient); }
.fw-bar { display: flex; align-items: center; gap: 2px; padding: 4px 6px; font-size: 11px; color: var(--muted); background: var(--surface-2); }
.fw-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fw-btn { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; color: var(--muted); font-size: 13px; line-height: 1; }
.fw-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.fw-btn.on { color: var(--accent); }
.region-box { position: absolute; z-index: 3; pointer-events: none; border: 1.5px dashed rgba(var(--accent-rgb), 0.9); border-radius: 6px; background: rgba(var(--accent-rgb), 0.05); transition: background-color var(--d-std) var(--e-out); }
.region-box.active { background: rgba(255, 90, 77, 0.18); border-color: var(--danger); }
.viewfinder.region-mode { cursor: crosshair; }
.mode-label { position: absolute; left: 16px; top: 16px; z-index: 3; font-size: 11px; letter-spacing: 0.06em; padding: 6px 10px; border-radius: 999px; background: var(--scrim); color: var(--muted); max-width: 42%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 0 0 1px var(--glass-border); }
.mode-label.warn { color: oklch(0.85 0.12 80); }
.dock { position: absolute; right: 12px; top: 64px; z-index: 5; display: flex; flex-direction: column; gap: 4px; padding: 6px; border-radius: 14px; background: var(--scrim); box-shadow: 0 0 0 1px var(--glass-border); }
.dock-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); transition: color var(--d-micro) var(--e-out), background-color var(--d-micro) var(--e-out); }
.dock-btn svg { width: 18px; height: 18px; }
.dock-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.dock-btn.on { color: var(--accent); background: rgba(var(--accent-rgb), 0.16); }
.dock-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.drawer { position: absolute; left: 12px; right: 60px; bottom: 56px; max-height: 58%; z-index: 6; border-radius: var(--r-md); background: var(--surface-2); box-shadow: 0 0 0 1px var(--glass-border), var(--shadow-ambient); display: flex; flex-direction: column; animation: dlg-in var(--d-std) var(--e-out); }
.drawer[hidden] { display: none; }
.drawer header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 16px; }
.drawer-body { padding: 4px 16px 14px; overflow: auto; font-size: var(--t-1); }
.drawer-body[hidden] { display: none; }
.drawer-body .row { margin-bottom: 10px; }
.drawer-body .row-h { grid-template-columns: 1fr auto; }
.row-h.cols-2 { grid-template-columns: 1fr auto; }
.row-h.cols-1 { grid-template-columns: 1fr; }
.drawer-body .row input[type="range"], .drawer-body input[type="range"] { margin-left: 0; width: 100%; }
.drawer-body label.chk { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; min-height: 30px; color: var(--text); }
label.chk.inline { display: inline-grid; grid-template-columns: auto auto; gap: 6px; align-items: center; min-height: 0; }
.hist-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.hist-tools select { padding: 6px 8px; border-radius: 8px; border: 0; box-shadow: 0 0 0 1px var(--glass-border); background: var(--surface-1); color: var(--text); font-size: var(--t-1); }
.hist-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.hist-item { display: grid; grid-template-columns: 48px 1fr auto; gap: 10px; align-items: center; padding: 6px; border-radius: 10px; background: var(--surface-1); box-shadow: 0 0 0 1px var(--ring); }
.hist-item img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: #000; }
.hist-item strong { display: block; font-weight: 500; }
.hist-item small { color: var(--muted); }
.hist-acts { display: flex; gap: 4px; }
.freq-states { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; color: var(--muted); }
.tag { padding: 2px 8px; border-radius: 999px; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; }
.tag.measured { background: oklch(0.45 0.12 145 / 0.4); color: oklch(0.9 0.1 145); }
.tag.estimated { background: oklch(0.5 0.12 80 / 0.4); color: oklch(0.9 0.1 80); }
.tag.illustrative { background: oklch(0.5 0.1 300 / 0.4); color: oklch(0.9 0.08 300); }

/* ---- Workspace and screen recorder panels ---- */
.overlay-panel { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; padding: 18px; gap: 12px; overflow: auto; animation: dlg-in var(--d-std) var(--e-out); }
.overlay-panel[hidden] { display: none; }
.op-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.op-head h2 { margin: 0; font-weight: 400; font-size: var(--t3); }
.op-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.op-tools select { padding: 8px 10px; min-height: 36px; border-radius: var(--r-sm); border: 0; box-shadow: 0 0 0 1px var(--glass-border); background: var(--surface-2); color: var(--text); font-size: var(--t-1); max-width: 240px; }
.primary.sm { padding: 8px 14px; min-height: 36px; font-size: var(--t-1); }
.ws-grid { flex: 1; display: grid; gap: 10px; min-height: 0; grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(160px, 1fr); }
.ws-grid[data-layout="1x2"] { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; }
.ws-grid[data-layout="1x1"] { grid-template-columns: 1fr; }
.ws-grid:has(.ws-tile.max) .ws-tile:not(.max) { display: none; }
.ws-grid:has(.ws-tile.max) { grid-template-columns: 1fr; }
.ws-empty { grid-column: 1 / -1; align-self: center; text-align: center; }
.ws-tile { position: relative; border-radius: var(--r-md); overflow: hidden; background: #000; box-shadow: 0 0 0 1px var(--ring); cursor: grab; min-height: 160px; }
.ws-tile.over { box-shadow: 0 0 0 2px var(--accent); }
.ws-tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.ws-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--scrim); font-size: var(--t-1); }
.ws-name { font-weight: 500; }
.ws-kind { color: var(--muted); flex: 1; }
.sr-layout { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; min-height: 0; }
.sr-preview { position: relative; border-radius: var(--r-md); background: #000; box-shadow: 0 0 0 1px var(--ring); display: grid; place-items: center; overflow: hidden; min-height: 240px; }
.sr-preview canvas { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; touch-action: none; cursor: move; }
.sr-preview p { position: absolute; }
.sr-preview p[hidden] { display: none; }
.sr-controls { display: flex; flex-direction: column; gap: 8px; font-size: var(--t-1); overflow: auto; }
.sr-controls label.chk { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; min-height: 30px; }
.sr-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

/* ---- Settings: device cards and feature switches ---- */
.device-cards { display: grid; gap: 8px; }
.device-card { display: grid; gap: 4px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-1); box-shadow: 0 0 0 1px var(--ring); font-size: var(--t-1); }
.device-card .hist-acts { margin-top: 4px; }
.feature-list { display: grid; gap: 6px; }
.feature-domain { border-radius: var(--r-sm); background: var(--surface-1); box-shadow: 0 0 0 1px var(--ring); padding: 0 12px; }
.feature-domain summary { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; cursor: pointer; list-style: none; font-weight: 500; }
.feature-domain summary::-webkit-details-marker { display: none; }
.feature-domain > p { margin: 0 0 8px; }
.feature-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--glass-border); font-size: var(--t-1); }
.feature-row strong { display: block; font-weight: 500; color: var(--text); }
.feature-row small { color: var(--muted); }
.switch input:disabled + i { opacity: 0.4; }
@media (max-width: 760px) {
  .sr-layout { grid-template-columns: 1fr; }
  .drawer { left: 8px; right: 8px; bottom: 50px; max-height: 70%; }
  .dock { top: 56px; right: 8px; }
  .focus-win { width: 128px; } .focus-win canvas { width: 128px; height: 128px; }
  .focus-rail { gap: 8px; }
}

/* Responsive — stacked layout below the three-column breakpoint */
@media (max-width: 1240px) {
  html, body { overflow: auto; height: auto; }
  .app {
    height: auto; min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr); grid-template-rows: 64px auto auto auto;
    grid-template-areas: "top" "stage" "modes" "panel";
    gap: 16px; padding: 0 16px 24px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  }
  .topbar { padding: 0; }
  .brand { margin-top: 0; gap: 10px; }
  .brand-ring { width: 32px; height: 32px; }
  .brand-text h1 { font-size: 16px; letter-spacing: 0.24em; }
  .brand-text p { font-size: 9px; letter-spacing: 0.18em; }
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; gap: 12px; }
  .viewfinder { grid-column: 1; grid-row: 1; }
  .focus-rail { grid-column: 1; grid-row: 2; width: auto; flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .controls { grid-column: 1; grid-row: 3; }
  .viewfinder { aspect-ratio: 4 / 3; max-height: 70dvh; }
  .modes { flex-direction: row; gap: 10px; padding: 4px 0 8px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .modes::-webkit-scrollbar { display: none; }
  .mode { grid-template-columns: 64px 1fr; gap: 10px; min-width: min(260px, 72vw); flex: 0 0 auto; scroll-snap-align: start; }
  .mode-thumb { width: 64px; height: 72px; }
  .mode-text strong { font-size: 16px; }
  .mode-text small { font-size: 12.5px; }
  .panel { margin-top: 0; overflow: visible; }
}
/* Phones: portrait viewfinder, shutter bar fixed in the thumb zone */
@media (max-width: 640px) {
  .mode-label { top: 54px; max-width: 70%; }
  .rec-badge { top: 86px; }
  .app { padding-bottom: calc(112px + env(safe-area-inset-bottom)); gap: 14px; }
  .topbar { grid-template-columns: 1fr auto; }
  .top-actions { gap: 4px; }
  .viewfinder { aspect-ratio: 3 / 4; max-height: 62dvh; border-radius: 18px; }
  .vf-top { inset: 10px 10px auto; }
  .seg button { padding: 7px 16px; font-size: 11px; }
  .res select { padding: 7px 28px 7px 12px; font-size: 12px; }
  .controls {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    gap: 22px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--scrim); -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 -1px 0 var(--ring);
  }
  .thumb { width: 52px; height: 52px; border-radius: 12px; }
  .round { width: 52px; height: 52px; }
  .round svg { width: 22px; height: 22px; }
  .shutter { width: 78px; height: 78px; }
  .shutter span { width: 62px; height: 62px; }
  .panel { padding: 18px 16px 14px; border-radius: 18px; }
  .panel-head h2 { font-size: 20px; }
  .row-h { font-size: 14px; }
  .presets { gap: 8px; }
  .dlg form { padding: 18px; }
  .report, .models { grid-template-columns: 1fr; }
}
/* Short landscape phones: keep the viewfinder visible without scrolling the controls away */
@media (max-height: 480px) and (orientation: landscape) and (max-width: 1240px) {
  .viewfinder { aspect-ratio: 16 / 9; max-height: 78dvh; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; } }
