/* VERGE — stereo vision training
   Palette: neutral near-black stage (luminance control matters for fusion),
   dual functional accents = anaglyph heritage: OS (left eye) vermilion, OD (right eye) cyan. */

:root {
  --bg: #0a0b0e;
  --surface: #12151c;
  --surface-2: #1a1e27;
  --line: #262b36;
  --ink: #eaedf3;
  --muted: #8c94a4;
  --os: #ff7a66;   /* left eye  — oculus sinister */
  --od: #4fd8e8;   /* right eye — oculus dexter  */
  --warn: #ffc46b;

  --font-display: "Bricolage Grotesque", "Arial Black", sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Mono", monospace;
}

/* light theme: dark targets on a low-glare paper grey, gentler for astigmatism */
:root[data-theme="light"] {
  --bg: #e9e9e6;
  --surface: #f4f4f2;
  --surface-2: #eaeae7;
  --line: #d2d3ce;
  --ink: #1c1e24;
  --muted: #5a6070;
  --os: #cf3a22;
  --od: #0e7f8f;
  --warn: #9a6a00;
}
:root[data-theme="light"] .dot { mix-blend-mode: multiply; }
:root[data-theme="light"] .seg button.on,
:root[data-theme="light"] .wide-btn.accent {
  background: var(--ink);
  color: var(--surface);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }

#app {
  display: flex;
  height: 100%;
}

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

#panel {
  width: 304px;
  flex: 0 0 auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
#panel.collapsed { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.brand-mark { display: flex; }
.dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  display: inline-block;
  mix-blend-mode: screen;
}
.dot.os { background: var(--os); }
.dot.od { background: var(--od); margin-left: -7px; }
.dot.big { width: 26px; height: 26px; }
.dot.big.od { margin-left: -11px; }

.brand-word h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.06em;
  margin: 0;
  line-height: 1;
}
.brand-word p {
  margin: 3px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.icon-btn {
  margin-left: auto;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 28px; height: 28px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { color: var(--ink); }

#btn-expand {
  position: fixed;
  left: 10px; top: 14px;
  z-index: 20;
}

.ctl-group {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.ctl-group h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 12px;
}

/* segmented control */
.seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 7px;
  padding: 7px 4px;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
.seg button.on {
  background: var(--ink);
  color: var(--bg);
}

/* exercise grid */
.ex-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.ex-grid button {
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  padding: 9px 10px;
  cursor: pointer;
  font-family: var(--font-body);
}
.ex-grid button b {
  display: block;
  color: var(--ink);
  font-size: 13px;
  margin-bottom: 2px;
}
.ex-grid button span { font-size: 11px; line-height: 1.25; display: block; }
.ex-grid button.on {
  border-color: var(--ink);
  background: #20242f;
}

/* rows */
.row {
  display: block;
  margin: 12px 0 0;
}
.row > span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 5px;
}
.row > span em {
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.row > span small {
  color: var(--muted);
  font-size: 11px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.toggle-row > span { display: block; margin: 0; }

input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
  height: 20px;
}
input[type="checkbox"] {
  accent-color: var(--od);
  width: 17px; height: 17px;
  flex: 0 0 auto;
}

/* difficulty stepper */
.stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.stepper button {
  width: 28px; height: 28px;
  flex: 0 0 auto;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.stepper button:hover { background: var(--line); }
.lvl-bar {
  flex: 1;
  display: flex;
  gap: 3px;
  height: 10px;
}
.lvl-bar i {
  flex: 1;
  border-radius: 2px;
  background: var(--line);
}
.lvl-bar i.on { background: var(--od); }

#toast {
  position: absolute;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 700;
  z-index: 12;
  white-space: nowrap;
}

.hint {
  font-size: 11.5px;
  color: var(--muted);
  margin: 8px 0 0;
}
.hint-warn { color: var(--warn); }

.wide-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 9px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
}
.wide-btn:hover { background: #20242f; }
.wide-btn.accent {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.wide-btn.accent:hover { background: #fff; }

.panel-foot {
  padding: 14px 16px 20px;
  margin-top: auto;
}
.panel-foot p {
  font-size: 11px;
  color: var(--muted);
  margin: 0;
}

/* ─────────── stage ─────────── */

#stage {
  flex: 1;
  position: relative;
  min-width: 0;
}
#gpu-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#statusbar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.st-sep { opacity: 0.4; }
#st-mode { font-weight: 500; letter-spacing: 0.08em; }
.st-mode-cross { color: var(--os); }
.st-mode-parallel { color: var(--od); }
#st-disp { color: var(--ink); }
#statusbar button {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 0 0 0 2px;
}
#statusbar button:hover { color: var(--ink); }

/* on-stage fusion guide */
#guide {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 520px;
  width: calc(100% - 40px);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  z-index: 10;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.25);
}
#guide p {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--ink);
}
#guide p b { color: var(--od); }
#guide .wide-btn { margin-top: 10px; padding: 7px; }

#gpu-error {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: 46%;
  background: #3a1210;
  color: #ffb4a8;
  border: 1px solid #7c2f26;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 11px;
  z-index: 15;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─────────── overlays ─────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  overflow-y: auto;
  padding: 24px;
}

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  max-width: 640px;
  margin: auto;
}
.overlay-card h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  margin: 0 0 10px;
}
.overlay-card p { color: var(--muted); }
.overlay-card p b { color: var(--ink); }

.intro-card { max-width: 720px; }
.intro-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}
.intro-brand h2 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0.08em;
}
.lede {
  font-size: 16px;
  margin: 0 0 22px;
}

.technique-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.tech {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.tech h3 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 10px 0 6px;
  font-size: 17px;
}
.tech p { font-size: 12.5px; margin: 0; }
.tech svg { width: 100%; height: auto; display: block; }

.sv-img { fill: none; stroke-width: 2; }
.sv-img.os-s { stroke: var(--os); }
.sv-img.od-s { stroke: var(--od); }
.sv-eye { fill: var(--surface); stroke: var(--muted); stroke-width: 2; }
.sv-ray { stroke-width: 1.5; stroke-dasharray: 3 3; opacity: 0.8; }
.sv-ray.os-s { stroke: var(--os); }
.sv-ray.od-s { stroke: var(--od); }
.sv-fuse { fill: var(--ink); }

.intro-tips {
  margin: 22px 0 0;
  padding: 0 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}
.intro-tips li { margin-bottom: 6px; }
.intro-tips b { color: var(--warn); }

/* calibration */
#cal-card {
  height: 120px;
  border: 2px solid var(--od);
  border-radius: 10px;
  margin: 18px auto 14px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  width: 324px;
  max-width: 100%;
}
.cal-chip {
  position: absolute;
  left: 12%; top: 26%;
  width: 15%; height: 22%;
  border: 2px solid var(--muted);
  border-radius: 4px;
  opacity: 0.7;
}
.btn-row { display: flex; gap: 10px; }

/* break */
.break-card { text-align: center; }
.break-count {
  font-size: 72px;
  font-weight: 500;
  color: var(--od);
  margin: 12px 0;
}

/* focus visibility & motion */
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--od);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* small screens: panel becomes an overlay sheet */
@media (max-width: 760px) {
  #panel {
    position: fixed;
    z-index: 30;
    height: 100%;
    box-shadow: 0 0 40px rgb(0 0 0 / 0.6);
  }
  .technique-cols { grid-template-columns: 1fr; }
}
