:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #16202c;
  --muted: #5b6878;
  --border: #d9dfe7;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --ok: #15803d;
  --near: #b45309;
  --bad: #b91c1c;
  --overlay-line: #2dd4bf;
  --overlay-ok: #4ade80;
  --overlay-dot: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319;
    --surface: #161d26;
    --surface-2: #1f2833;
    --text: #e6edf3;
    --muted: #9aa7b5;
    --border: #2b3643;
    --accent: #2dd4bf;
    --accent-contrast: #062925;
    --ok: #4ade80;
    --near: #fbbf24;
    --bad: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 16px; top: 8px; z-index: 10; background: var(--surface); padding: 8px 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; }
.brand-mark { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tabs button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

.layout {
  display: grid; gap: 16px; padding: 16px; max-width: 1200px; margin: 0 auto;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  align-items: start;
}
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.stage { position: sticky; top: 16px; }
@media (max-width: 860px) { .stage { position: static; } }

.video-wrap {
  position: relative; aspect-ratio: 4 / 3; background: #0b0f14; border-radius: var(--radius); overflow: hidden;
}
.video-wrap video, .video-wrap canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1);
}
.video-placeholder {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: #cbd5e1; padding: 16px;
}
.video-placeholder p { margin: 4px 0; }
.video-placeholder .muted { color: #94a3b8; }
.video-placeholder[hidden] { display: none; }

.stage-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 12px; }
.status { color: var(--muted); font-size: 0.95rem; }

.panel { display: grid; gap: 16px; }
.panel[hidden] { display: none; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }

.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 8px 16px; border-radius: 8px; cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-small { padding: 4px 10px; font-size: 0.9rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.badge {
  display: inline-block; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.badge-ai { background: var(--accent); color: var(--accent-contrast); }

.detected-main { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 10px; }
.detected-title { font-size: 2.2rem; font-weight: 700; line-height: 1.1; }
.detected-title.tentative { color: var(--muted); }

.meter { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter-lg { height: 12px; }
.meter-fill { height: 100%; width: 0; background: var(--accent); transition: width 120ms linear; }

.alternatives { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.95rem; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); padding: 4px 12px; border-radius: 999px; cursor: pointer;
}
.chip:hover { border-color: var(--bad); }

.suggestions { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.suggestions li { display: flex; align-items: center; gap: 8px; font-size: 1.1rem; }
.suggestions li span:first-child { flex: 1; }
.suggestions li.muted { font-size: 1rem; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; cursor: pointer; }
.switch[hidden] { display: none; }

.muted { color: var(--muted); }
.fineprint { font-size: 0.85rem; color: var(--muted); margin: 10px 0 0; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; justify-self: start; }
.seg { border: 0; background: transparent; padding: 6px 16px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.progress-text { color: var(--muted); font-size: 0.9rem; }
.lesson-list { margin-top: 8px; }
.lesson-group { font-size: 0.95rem; margin: 14px 0 6px; }
.lesson-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.lesson-btn {
  border: 1px solid var(--border); background: var(--surface); padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.lesson-btn.learned { border-color: var(--ok); }
.lesson-btn.learned::after { content: " ✓"; color: var(--ok); }
.lesson-btn[aria-current="true"] { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

.lesson-title { margin: 0; font-size: 1.5rem; }
.lesson-body { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 16px; margin-bottom: 12px; }
@media (max-width: 480px) { .lesson-body { grid-template-columns: minmax(0, 1fr); } }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

.diagram { background: var(--surface-2); border-radius: 10px; aspect-ratio: 200 / 220; }
.diagram-small { max-width: 180px; margin-top: 12px; }
.diagram[hidden] { display: none; }
.diagram svg { width: 100%; height: 100%; display: block; }
.diagram-palm { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.diagram-finger { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.diagram-tip { fill: var(--surface); }
.diagram-motion path { fill: none; stroke: var(--near); stroke-width: 3; stroke-linecap: round; }

.checklist { list-style: none; margin: 8px 0 12px; padding: 0; display: grid; gap: 4px; }
.checklist li { padding-left: 26px; position: relative; }
.checklist li::before { position: absolute; left: 0; font-weight: 700; }
.checklist li.ok { color: var(--ok); }
.checklist li.ok::before { content: "✓"; }
.checklist li.near { color: var(--near); }
.checklist li.near::before { content: "~"; }
.checklist li.bad { color: var(--bad); }
.checklist li.bad::before { content: "✗"; }

.hold { margin-bottom: 12px; }
.hold-text { margin: 8px 0 0; color: var(--muted); }

.quiz-scores { display: flex; gap: 32px; margin-bottom: 8px; }
.quiz-scores strong { display: block; font-size: 1.8rem; }
.quiz-prompt { font-size: 1.3rem; font-weight: 600; }

.form-row { display: grid; gap: 4px; margin: 12px 0; }
.form-row[hidden] { display: none; }
.form-row select, .form-row input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-width: 320px;
}
.file-btn { position: relative; overflow: hidden; display: inline-block; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.samples { width: 100%; border-collapse: collapse; }
.samples th, .samples td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }

.footer { max-width: 1200px; margin: 0 auto; padding: 8px 16px 32px; font-size: 0.85rem; color: var(--muted); }
.footer a { color: var(--accent); }

@media (prefers-reduced-motion: reduce) { .meter-fill { transition: none; } }
