:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #5d6572;
  --line: #d9dde3;
  --accent: #2458d6;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --bad: #c0362c;
  --dot: #e0342a;
  --target: #1a1d23;
  --shadow: 0 8px 30px rgba(20, 24, 31, 0.12);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --text: #e8eaee;
    --muted: #9aa2ae;
    --line: #2d323b;
    --accent: #6d97ff;
    --accent-text: #0c1020;
    --ok: #4cc27f;
    --warn: #f0a93b;
    --bad: #ff6b5f;
    --dot: #ff5b4f;
    --target: #f2f3f5;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
a { color: var(--accent); }

button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: none; color: var(--muted); padding: 2px 0; text-decoration: underline; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.boot { max-width: 640px; margin: 15vh auto; padding: 0 16px; color: var(--muted); }

/* ---------------------------------------------------------------- top bar */
.bar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 8px 16px; background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.brand { font-weight: 650; white-space: nowrap; }
.tag { font-weight: 500; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted);
}
.chip[data-state="ok"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.chip[data-state="warn"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.chip[data-state="bad"] { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.eye { width: 14px; height: 9px; border-radius: 50%; border: 2px solid currentColor; display: inline-block; transition: height 60ms; }
.eye.closed { height: 2px; border-width: 1px; border-radius: 1px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-left: auto; }
.toggle, .select, .range { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
select { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; max-width: 220px; }
input[type="range"] { width: 90px; accent-color: var(--accent); }
input[type="number"] { font: inherit; font-size: 13px; width: 80px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }

/* ---------------------------------------------------------------- cards */
main { position: fixed; inset: 0; overflow: auto; padding: 72px 16px 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); padding: 22px 24px;
}
.intro, .results { max-width: 680px; margin: 4vh auto 0; }
h1 { font-size: 24px; margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 17px; margin: 0 0 8px; }
.privacy { border-left: 3px solid var(--ok); padding: 4px 0 4px 14px; margin: 16px 0; }
.privacy ul { margin: 0; padding-left: 18px; }
.privacy li { margin: 3px 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--muted); font-size: 13px; }
th:first-child { width: 34%; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.best td:first-child::after { content: " (auto)"; color: var(--ok); font-size: 12px; }
tr[data-method] { cursor: pointer; }
tr.chosen { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.alerts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 8px; width: min(560px, calc(100vw - 32px)); }
.alert { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 14px; }
.alert.bad { border-left-color: var(--bad); }
.alert.info { border-left-color: var(--accent); }
.alert strong { display: block; margin-bottom: 2px; }

/* ---------------------------------------------------------------- preview */
.preview {
  position: fixed; left: 16px; bottom: 16px; z-index: 15; width: 256px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; box-shadow: var(--shadow);
}
.cam { position: relative; width: 240px; aspect-ratio: 16 / 9; background: #000; border-radius: 8px; overflow: hidden; }
.cam video, .cam canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; transform: scaleX(-1); }
.patches { display: flex; gap: 8px; margin-top: 8px; }
.patches figure { margin: 0; flex: 1; }
.patches canvas { width: 100%; aspect-ratio: 60 / 36; image-rendering: pixelated; background: #000; border-radius: 4px; display: block; }
.patches figcaption { font-size: 11px; color: var(--muted); text-align: center; }
.debug { font-size: 10.5px; line-height: 1.35; margin: 6px 0 2px; white-space: pre-wrap; color: var(--muted); max-height: 180px; overflow: auto; }
.preview.collapsed .cam, .preview.collapsed .patches, .preview.collapsed .debug { display: none; }
.preview.collapsed { width: auto; }

/* ---------------------------------------------------------------- calibration */
.calib { position: fixed; inset: 0; z-index: 50; background: var(--bg); cursor: crosshair; }
.calib-card { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 32px)); cursor: default; }
.mode { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 12px 0 0; }
.mode legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.mode label { display: block; margin: 4px 0; }
.target {
  position: absolute; width: 36px; height: 36px; margin: -18px 0 0 -18px; padding: 0;
  border-radius: 50%; border: 3px solid var(--target); background: transparent; cursor: pointer;
  animation: pulse 1.1s ease-in-out infinite;
}
.target span { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--dot); }
.target.collect { animation: none; transform: scale(0.45); transition: transform 500ms ease-in; border-color: var(--dot); }
@keyframes pulse { 50% { transform: scale(1.18); } }
.calib-progress { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); color: var(--muted); font-size: 13px; text-align: center; max-width: calc(100vw - 32px); }
@media (prefers-reduced-motion: reduce) { .target { animation: none; } .target.collect { transition: none; } }

/* ---------------------------------------------------------------- gaze dot */
.gaze-dot, .raw-dot { position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none; border-radius: 50%; will-change: transform; }
.gaze-dot { width: 28px; height: 28px; margin: -14px 0 0 -14px; background: color-mix(in srgb, var(--dot) 55%, transparent); border: 2px solid var(--dot); }
.gaze-dot.frozen { background: transparent; border-style: dashed; }
.raw-dot { width: 8px; height: 8px; margin: -4px 0 0 -4px; background: var(--muted); opacity: 0.6; }

@media (max-width: 720px) {
  .actions { margin-left: 0; }
  .preview { width: 200px; }
  .cam { width: 184px; }
}
