:root {
  --bg: #f4f7f6;
  --card: #ffffff;
  --ink: #12201e;
  --muted: #5b6b68;
  --line: #dde6e3;
  --brand: #0f766e;
  --brand-soft: #d9f2ee;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(15 118 110 / 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1413;
    --card: #142120;
    --ink: #e7f1ef;
    --muted: #93a6a2;
    --line: #233533;
    --brand: #2dd4bf;
    --brand-soft: #123a36;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

button, select, input, .button {
  font: inherit;
  color: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 8px 14px;
}

button, .button { cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .primary { color: #04201d; } }
.ghost { background: transparent; }
.danger { color: var(--bad); }
.big { font-size: 18px; padding: 14px 26px; }
.muted { color: var(--muted); }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px max(16px, calc((100vw - 1200px) / 2));
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 22px; letter-spacing: -0.02em; }
.brand span { color: var(--muted); font-size: 14px; }
.controls { display: flex; gap: 10px; align-items: center; }
.studio-link { text-decoration: none; font-weight: 600; color: var(--brand); border-color: var(--brand); }
.controls label { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }

.stage { padding: 12px; align-self: start; }
.camera { position: relative; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: #0b1211; }
.camera video, .camera canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

.chip {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-size: 14px;
}
.chip:empty { display: none; }

.gate {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  padding: 16px;
  background: radial-gradient(circle at 50% 40%, #134e48, #0b1211 70%);
}
.gate .muted { color: #a8c7c1; max-width: 340px; }
.gate[hidden] { display: none; }

.hold { height: 8px; margin-top: 10px; border-radius: 99px; background: var(--brand-soft); overflow: hidden; }
.hold div { height: 100%; width: 0; background: var(--brand); transition: width 80ms linear; }

.panel { padding: 16px 20px 22px; min-height: 420px; }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 6px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

.eyebrow { margin: 0 0 6px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

.target {
  font-size: 120px;
  line-height: 1;
  font-weight: 800;
  text-align: center;
  padding: 12px 0 8px;
  color: var(--brand);
}
.target.small { font-size: 72px; padding: 0; min-width: 96px; }
.target.win { color: var(--good); animation: pop 320ms ease-out; }

@keyframes pop { 40% { transform: scale(1.18); } }
@media (prefers-reduced-motion: reduce) { .target.win { animation: none; } }

.meter { height: 10px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.meter div { height: 100%; width: 0; border-radius: 99px; background: var(--warn); transition: width 120ms ease, background 120ms; }
.meter div.good { background: var(--good); }

.advice { min-height: 48px; font-size: 18px; font-weight: 600; margin: 12px 0; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.row.live { align-items: stretch; flex-wrap: nowrap; }

.reference { margin: 0; text-align: center; }
.reference canvas { background: var(--bg); border-radius: 12px; width: 140px; height: 140px; }
.reference figcaption { font-size: 13px; color: var(--muted); }

.stats { display: grid; gap: 10px; margin: 0; }
.stats dt { font-size: 13px; color: var(--muted); }
.stats dd { margin: 0; font-size: 28px; font-weight: 700; }

.word { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 16px 0; }
.word span { font-size: 44px; font-weight: 800; min-width: 50px; text-align: center; padding: 4px 6px; border-bottom: 4px solid var(--line); color: var(--muted); }
.word span.done { color: var(--good); border-color: var(--good); }
.word span.now { color: var(--brand); border-color: var(--brand); }

.words, .letters { display: flex; flex-wrap: wrap; gap: 6px; }
.words button { padding: 4px 10px; font-size: 14px; }
.letters button { width: 52px; padding: 6px 0; display: grid; justify-items: center; line-height: 1.2; }
.letters button b { font-size: 20px; }
.letters button small { font-size: 11px; color: var(--muted); }
.letters button.has { background: var(--brand-soft); border-color: var(--brand); }
.letters button[aria-pressed="true"] { outline: 3px solid var(--brand); }

#spellInput { flex: 1; min-width: 0; text-transform: uppercase; }

.transcript {
  flex: 1;
  min-height: 96px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.04em;
  word-break: break-word;
}

.empty { text-align: center; padding: 48px 12px; }
.empty[hidden], .mode[hidden] { display: none; }
