:root {
  --bg: #0b1016;
  --bg2: #141d28;
  --fg: #eef2f6;
  --muted: #93a3b3;
  --line: #24313f;
  --accent: #2ec4b6;
  --accent2: #ffd166;
  --warn: #ff9f1c;
  --bad: #ef476f;
  --pad: 10px;
  --radius: 12px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--pad);
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}
.title {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--muted);
}
.topbar-right { display: flex; align-items: center; gap: 6px; }
.timer, .score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.15rem;
  min-width: 4.2ch;
}
.timer.low { color: var(--bad); }
.score { color: var(--accent2); text-align: right; }
.score.bump { animation: bump 320ms ease-out; }
@keyframes bump { 50% { transform: scale(1.28); } }

/* -------------------------------------------------------------- stage */

.stage {
  position: relative;
  min-height: 0;
  background:
    radial-gradient(120% 90% at 50% 20%, #1a2735 0%, var(--bg) 62%, #05080c 100%);
  touch-action: none;
}
#board { display: block; width: 100%; height: 100%; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(6, 10, 14, .55);
  backdrop-filter: blur(2px);
  z-index: 3;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.overlay.hidden { display: none; }
#overlay-countdown span {
  font-size: clamp(4rem, 22vmin, 9rem);
  font-weight: 800;
  color: var(--fg);
  text-shadow: 0 0 40px rgba(46, 196, 182, .5);
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

.viewtools {
  position: absolute;
  left: 10px; bottom: 10px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 2;
  font-size: .78rem;
}
.tool-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tool, .icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(20, 29, 40, .82);
  color: var(--fg);
  border-radius: 999px;
  padding: 7px 11px;
  font: inherit;
  cursor: pointer;
  min-height: 34px;
}
.tool:hover, .icon-btn:hover { border-color: var(--accent); }
.tool[aria-pressed="true"] { background: var(--accent); color: #04231f; border-color: var(--accent); font-weight: 700; }
.rangetool { display: flex; flex-direction: column; gap: 2px; color: var(--muted); }
.rangetool input { width: 130px; accent-color: var(--accent); }

.hint-line {
  position: absolute;
  right: 10px; bottom: 12px;
  margin: 0;
  max-width: 45%;
  text-align: right;
  color: #5d6c7c;
  font-size: .72rem;
  pointer-events: none;
}

/* ----------------------------------------------------------- word bar */

.wordbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  background: var(--bg2);
}
.wordbar.shake { animation: shake 400ms cubic-bezier(.36,.07,.19,.97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.chips { display: flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; }
.chip {
  display: grid; place-content: center;
  min-width: 26px; height: 30px; padding: 0 5px;
  border-radius: 7px;
  background: #e9dcc3; color: #241f1b;
  font-weight: 800; letter-spacing: .02em;
}

.word-input {
  flex: 1;
  min-width: 4ch;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--line);
  color: var(--fg);
  font: 700 1.1rem/1 inherit;
  letter-spacing: .18em;
  text-transform: uppercase;
  padding: 6px 2px;
  outline: none;
}
.word-input:focus { border-bottom-color: var(--muted); }
.word-input.is-word { border-bottom-color: var(--accent); }
.word-input.is-path { border-bottom-color: var(--warn); }
.word-input.is-none { border-bottom-color: var(--bad); }

.icon-btn.ok { color: var(--accent); }
.icon-btn.no { color: var(--bad); }
.icon-btn.mic[data-state="listening"] { background: var(--bad); color: #fff; animation: pulse 1.1s ease-in-out infinite; }
.icon-btn.mic[data-state="error"] { opacity: .5; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(239, 71, 111, .22); } }

/* -------------------------------------------------------- found words */

.found { border-top: 1px solid var(--line); background: #0d141c; max-height: 26dvh; overflow: auto; }
.found-summary {
  width: 100%;
  text-align: left;
  background: none; border: none; color: var(--muted);
  font: 600 .78rem/1 inherit; letter-spacing: .1em; text-transform: uppercase;
  padding: 9px 12px; cursor: pointer;
}
.found-list {
  display: flex; flex-wrap: wrap; gap: 5px;
  margin: 0; padding: 0 10px 10px; list-style: none;
}
.found[data-collapsed="true"] .found-list { display: none; }
.found-list li button {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line); background: #14202b; color: var(--fg);
  border-radius: 999px; padding: 4px 9px; font: 600 .8rem inherit;
  letter-spacing: .06em;
}
.found-list li button:hover { border-color: var(--accent); }
.found-list li b { color: var(--accent2); margin-left: 5px; font-weight: 800; }
.found-list.missed li button { opacity: .8; }

/* ------------------------------------------------------------- toasts */

.toasts {
  position: fixed; left: 50%; bottom: 30dvh; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  z-index: 20; pointer-events: none;
}
.toast {
  padding: 7px 14px; border-radius: 999px;
  font: 800 .9rem inherit; letter-spacing: .1em; text-transform: uppercase;
  background: #1d2a37; color: var(--fg); border: 1px solid var(--line);
  animation: rise 1.6s ease-out forwards;
}
.toast.good { background: var(--accent); color: #04231f; border-color: transparent; }
.toast.warn { background: var(--warn); color: #2a1a00; border-color: transparent; }
.toast.grey { color: var(--muted); }
@keyframes rise {
  0% { opacity: 0; transform: translateY(10px) scale(.95); }
  15% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-18px); }
}

/* ------------------------------------------------------------ dialogs */

.sheet {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg2);
  color: var(--fg);
  padding: 18px;
  width: min(460px, 92vw);
  max-height: 88dvh;
  overflow: auto;
}
.sheet::backdrop { background: rgba(4, 7, 10, .68); backdrop-filter: blur(3px); }
.sheet h2 { margin: 0 0 4px; }
.sheet h3 { margin: 14px 0 6px; font-size: .82rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.sheet label { display: block; margin: 10px 0; color: var(--muted); font-size: .84rem; }
.sheet label.check { display: flex; align-items: center; gap: 8px; }
.sheet select, .sheet input[type="text"] {
  display: block; width: 100%; margin-top: 4px;
  background: #0d141c; color: var(--fg);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; font: inherit;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.row button {
  appearance: none; cursor: pointer; font: 700 .95rem inherit;
  border-radius: 999px; padding: 10px 16px;
  background: #1d2a37; color: var(--fg); border: 1px solid var(--line);
}
.row button.primary { background: var(--accent); color: #04231f; border-color: transparent; }
.row button.ghost { background: transparent; color: var(--muted); }
.muted { color: var(--muted); }
.res-score { font-size: 2.4rem; font-weight: 800; margin: 6px 0; color: var(--accent2); }
.res-score small { font-size: .8rem; color: var(--muted); font-weight: 600; }

/* -------------------------------------------------------- a11y / misc */

:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@media (min-width: 720px) {
  .title { font-size: 1.1rem; }
  .hint-line { font-size: .78rem; }
}