/* Word Sprint - styles.
   Theming is entirely CSS custom properties, so a theme is a palette swap and
   nothing else. Colours always travel with a shape, an icon or a word, never
   on their own, so colour-blind players get the same information. */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 18px;
  --radius-sm: 10px;
  --gap: 14px;
  --shadow: 0 10px 30px rgba(20, 30, 60, 0.12);
  --tile-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  --speed: 1;
}

/* ------------------------------------------------------------- palettes */
[data-theme="default"] {
  --bg: #eef4ff;
  /* Kept slightly off-white at the top: a pure white hotspot washes out the
     white tiles sitting in the middle of the page. */
  --bg-glow: radial-gradient(circle at 50% 0%, #f4f8ff 0%, #dfe9ff 45%, #cfe0ff 100%);
  --panel: #ffffff;
  --panel-2: #f4f8ff;
  --ink: #12203c;
  --ink-dim: #5a6a8c;
  --accent: #1e6fff;
  --accent-ink: #ffffff;
  --tile: #ffffff;
  --tile-ink: #12203c;
  --tile-edge: #c9d9ff;
  --ok: #12a150;
  --bad: #e5484d;
  --warn: #f5a524;
  --rare: #b8860b;
  --border: rgba(30, 111, 255, 0.18);
}
[data-theme="dark"] {
  --bg: #0d1117;
  --bg-glow: radial-gradient(circle at 50% 0%, #1b2432 0%, #0f141c 60%, #0a0e13 100%);
  --panel: #161d27;
  --panel-2: #1d2634;
  --ink: #e8eefc;
  --ink-dim: #93a3bd;
  --accent: #4c8dff;
  --accent-ink: #08101f;
  --tile: #212c3c;
  --tile-ink: #f2f6ff;
  --tile-edge: #32405a;
  --ok: #2ecc71;
  --bad: #ff5c5c;
  --warn: #ffb020;
  --rare: #ffd166;
  --border: rgba(255, 255, 255, 0.12);
}
[data-theme="neon"] {
  --bg: #07030f;
  --bg-glow: radial-gradient(circle at 50% 0%, #1a0b33 0%, #0b0518 55%, #05020c 100%);
  --panel: #120a24;
  --panel-2: #1a1033;
  --ink: #f5e9ff;
  --ink-dim: #a98fd6;
  --accent: #ff2fd0;
  --accent-ink: #16021a;
  --tile: #1b0f38;
  --tile-ink: #7dfcff;
  --tile-edge: #5222a8;
  --ok: #35ffa8;
  --bad: #ff3b6b;
  --warn: #ffd166;
  --rare: #7dfcff;
  --border: rgba(255, 47, 208, 0.35);
}
[data-theme="retro"] {
  --font: "Consolas", "SF Mono", "Menlo", "DejaVu Sans Mono", monospace;
  --bg: #06120b;
  --bg-glow: radial-gradient(circle at 50% 0%, #0d2a18 0%, #07160d 60%, #040d07 100%);
  --panel: #0c1f13;
  --panel-2: #102a1a;
  --ink: #b8ffcb;
  --ink-dim: #5fa878;
  --accent: #ffb000;
  --accent-ink: #101a08;
  --tile: #10301d;
  --tile-ink: #d6ffe3;
  --tile-edge: #2f7d4d;
  --ok: #64ff9b;
  --bad: #ff6b5e;
  --warn: #ffb000;
  --rare: #ffe066;
  --border: rgba(184, 255, 203, 0.22);
  --radius: 8px;
}
[data-theme="pastel"] {
  --bg: #fdf3f8;
  --bg-glow: radial-gradient(circle at 50% 0%, #fff7fb 0%, #ffeaf4 45%, #eef2ff 100%);
  --panel: #ffffff;
  --panel-2: #fff4fa;
  --ink: #4a3b52;
  --ink-dim: #8d7c95;
  --accent: #f189b8;
  --accent-ink: #ffffff;
  --tile: #ffffff;
  --tile-ink: #55405f;
  --tile-edge: #f7cfe3;
  --ok: #74c69d;
  --bad: #ef7d8b;
  --warn: #f2c14e;
  --rare: #b28dff;
  --border: rgba(241, 137, 184, 0.28);
}
[data-theme="candy"] {
  --bg: #2a1140;
  --bg-glow: radial-gradient(circle at 50% 0%, #59199a 0%, #341260 55%, #1e0b39 100%);
  --panel: #3a1660;
  --panel-2: #481c73;
  --ink: #fff1fb;
  --ink-dim: #d0a9ee;
  --accent: #ffd23f;
  --accent-ink: #3a1600;
  --tile: #5a2a8c;
  --tile-ink: #fff6fd;
  --tile-edge: #8d4fd0;
  --ok: #6ce5a0;
  --bad: #ff5d8f;
  --warn: #ffb703;
  --rare: #7ef9ff;
  --border: rgba(255, 210, 63, 0.3);
}

/* --------------------------------------------------------------- shell */

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  background-image: var(--bg-glow);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

/* Mobile browser chrome shrinks the visual viewport; dvh keeps the tiles and
   the controls on screen instead of sliding under the toolbars. */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(8px, 1.6vh, 18px) clamp(8px, 2vw, 20px);
  gap: clamp(6px, 1.2vh, 14px);
}

.app.is-shaking { animation: shake calc(260ms * var(--speed)) ease-in-out; }

/* ----------------------------------------------------------------- hud */

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.hud-left { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hud-right { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-dim);
  white-space: nowrap;
}
.chip b { color: var(--ink); }
.chip.is-final { background: var(--bad); color: #fff; border-color: transparent; }

.stat { text-align: right; line-height: 1.1; }
.stat-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.stat-value { font-size: clamp(20px, 3.4vh, 30px); font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-value.bump { animation: bump calc(240ms * var(--speed)) ease-out; }

/* --------------------------------------------------------------- timer */

.timer { text-align: center; min-width: 180px; }
.timer-num {
  font-size: clamp(30px, 6.6vh, 54px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: -0.02em;
}
.timer-unit { font-size: 0.44em; font-weight: 700; color: var(--ink-dim); margin-left: 2px; }
.timer-bar {
  height: 10px;
  margin-top: 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}
.timer-bar::after {
  /* Where a fresh run starts, so banked time is visible as a gain. */
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--start-mark, 75%);
  width: 1px;
  background: var(--ink);
  opacity: 0.22;
}
.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: background-color 200ms linear;
}
.timer.is-warn .timer-num { color: var(--warn); }
.timer.is-warn .timer-fill { background: var(--warn); }
.timer.is-danger .timer-num { color: var(--bad); animation: pulse calc(700ms * var(--speed)) infinite; }
.timer.is-danger .timer-fill { background: var(--bad); }
.timer.is-danger::after {
  content: "";
  position: absolute;
}
.app.is-danger { box-shadow: inset 0 0 0 3px var(--bad); }

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

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.4vh, 22px);
  min-height: 0;
  position: relative;
}

.word {
  display: flex;
  gap: 6px;
  min-height: clamp(34px, 6vh, 46px);
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.word-slot {
  min-width: 0.9em;
  padding: 2px 4px;
  text-align: center;
  font-size: clamp(20px, 3.6vh, 30px);
  font-weight: 800;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 3px solid var(--border);
}
.word.is-empty .word-placeholder {
  font-size: clamp(13px, 2vh, 16px);
  color: var(--ink-dim);
  font-weight: 600;
}

.tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(8px, 1.4vw, 14px);
  max-width: 100%;
}

.tile {
  position: relative;
  width: clamp(52px, 11vh, 96px);
  height: clamp(52px, 11vh, 96px);
  border-radius: var(--radius);
  background: var(--tile);
  color: var(--tile-ink);
  border: 2px solid var(--tile-edge);
  box-shadow: var(--tile-shadow);
  font-size: clamp(24px, 5.6vh, 46px);
  font-weight: 800;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 90ms ease, box-shadow 90ms ease, opacity 120ms ease;
  touch-action: manipulation;
  user-select: none;
}
.tile:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); }
.tile.is-used { opacity: 0.32; transform: translateY(6px) scale(0.96); box-shadow: none; }
.tile.is-rare { color: var(--rare); }
.tile.is-trap::after {
  content: "−1s";
  position: absolute;
  top: -9px;
  right: -6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: var(--bad);
  color: #fff;
  border-radius: 999px;
  padding: 2px 6px;
}
.tile.is-trap { border-color: var(--bad); }
.tile.is-pop { animation: pop calc(220ms * var(--speed)) ease-out; }

.feedback {
  min-height: clamp(26px, 4vh, 34px);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: clamp(14px, 2.2vh, 18px);
  letter-spacing: 0.02em;
}
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.feedback.neutral { color: var(--ink-dim); }
.feedback .detail { font-weight: 600; color: var(--ink-dim); font-size: 0.86em; }
.feedback.jump { animation: jump calc(260ms * var(--speed)) ease-out; }

/* ------------------------------------------------------------ controls */

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-weight: 800;
  font-size: clamp(13px, 1.8vh, 15px);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink);
  transition: transform 90ms ease, background-color 120ms ease;
  touch-action: manipulation;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--ink-dim); }
.btn.small { padding: 8px 14px; font-size: 12px; }
.btn.icon { padding: 8px 12px; line-height: 1; }
/* First tap arms the restart button, the second fires: a mis-tap should never
   cost a run. */
.btn.icon.is-armed {
  background: var(--bad);
  color: #fff;
  border-color: transparent;
  animation: pulse calc(600ms * var(--speed)) infinite;
}
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

.hint-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-wrap: wrap;
}
kbd {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--ink);
}

/* ------------------------------------------------------------ overlays */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(7px);
  z-index: 20;
  overflow-y: auto;
}
.overlay[hidden] { display: none; }
.overlay.enter { animation: fadeIn calc(180ms * var(--speed)) ease-out; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vh, 28px);
  width: min(560px, 100%);
  max-height: 92vh;
  overflow-y: auto;
}
.panel.wide { width: min(720px, 100%); }
.panel-title {
  margin: 0 0 4px;
  font-size: clamp(22px, 4vh, 32px);
  font-weight: 800;
  letter-spacing: -0.01em;
}
.panel-sub { margin: 0 0 16px; color: var(--ink-dim); font-size: 14px; line-height: 1.5; }

.hero-score {
  font-size: clamp(44px, 9vh, 76px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hero-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.new-best {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rows { display: grid; gap: 8px; margin: 18px 0; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 14px;
}
.row .k { color: var(--ink-dim); }
.row .v { font-weight: 800; font-variant-numeric: tabular-nums; }
.row.highlight { background: color-mix(in srgb, var(--accent) 16%, var(--panel-2)); }

.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.panel-actions .btn { flex: 1 1 auto; text-align: center; }

.menu-list { display: grid; gap: 10px; margin-bottom: 16px; }
.menu-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.menu-item:hover { border-color: var(--accent); }
.menu-item .name { font-weight: 800; font-size: 15px; }
.menu-item .hint { display: block; font-weight: 500; font-size: 12px; color: var(--ink-dim); margin-top: 2px; }
.menu-item .go { color: var(--accent); font-weight: 800; font-size: 12px; letter-spacing: 0.08em; }

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.setting:last-child { border-bottom: 0; }
.setting .label { font-weight: 700; }
.setting .note { display: block; font-size: 12px; color: var(--ink-dim); font-weight: 500; }

.switch {
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  position: relative;
  flex: 0 0 auto;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 140ms ease, background-color 140ms ease;
}
.switch[aria-checked="true"] { background: var(--accent); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(22px); background: #fff; }

.themes { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 2px solid var(--border);
  position: relative;
}
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent); }
.swatch[disabled] { opacity: 0.35; cursor: not-allowed; }
.swatch span {
  position: absolute;
  bottom: -16px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.swatch-wrap { position: relative; margin-bottom: 20px; }

.board { width: 100%; border-collapse: collapse; font-size: 14px; }
.board th, .board td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.board th { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-dim); }
.board td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.board tr.is-you td { background: color-mix(in srgb, var(--accent) 14%, transparent); }

.empty-note { color: var(--ink-dim); font-size: 13px; padding: 12px 0; }

.cols { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin: 14px 0; }
.cell {
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.cell .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.cell .k { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-dim); }

.credit { font-size: 12px; color: var(--ink-dim); line-height: 1.6; margin: 10px 0 0; }
.credit b { color: var(--ink); }

/* First-run tips: shown only until the first run has been played. */
.tips {
  list-style: none;
  margin: 4px 0 20px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}
.tips li {
  position: relative;
  padding: 10px 12px 10px 38px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-dim);
}
.tips li::before {
  content: "›";
  position: absolute;
  left: 14px;
  top: 8px;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
}
.tips b { color: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  z-index: 40;
  animation: fadeIn 160ms ease-out;
}

.float {
  position: fixed;
  pointer-events: none;
  font-weight: 800;
  font-size: 24px;
  color: var(--ok);
  z-index: 30;
  animation: floatUp calc(900ms * var(--speed)) ease-out forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
.float.time { color: var(--accent); }
.float.bad { color: var(--bad); }

.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;
}

/* ------------------------------------------------------------- small screens */

@media (max-width: 620px) {
  .hud { grid-template-columns: 1fr auto; grid-template-areas: "left right" "timer timer"; }
  .hud-left { grid-area: left; }
  .hud-right { grid-area: right; }
  .timer { grid-area: timer; min-width: 0; }
  .tile { width: clamp(46px, 13vw, 68px); height: clamp(46px, 13vw, 68px); }
  .hint-row { display: none; }
  .stat-value { font-size: 22px; }
}

@media (max-height: 560px) {
  .tile { width: clamp(40px, 9vh, 60px); height: clamp(40px, 9vh, 60px); font-size: clamp(20px, 4vh, 30px); }
  .timer-num { font-size: clamp(24px, 5vh, 34px); }
}

/* ---------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
[data-motion="calm"] * {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 1ms !important;
}

@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.14); } 100% { transform: scale(1); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes jump { 0% { transform: translateY(6px); opacity: 0.4; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes floatUp {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-70px); opacity: 0; }
}

/* ---------------------------------------------------- teaching.nz edition */
/* Lets the "All games" links wear the same shape as the buttons. */
a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.site-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
}
.site-link:hover { text-decoration: underline; }
