/* Word Rush styles — "arcade ticket" identity.
 *
 * Deliberately NOT the dark-neon-gradient look: paper background with a
 * dot-grid print texture, ink-black borders, hard offset shadows, chunky
 * Arial Black headlines, typewriter Courier words, sticker stamps.
 * Everything offline-safe: system fonts only, zero CDN.
 */

:root {
  --paper: #f5eedc;
  --card: #fffdf4;
  --ink: #1b150c;
  --muted: #6f6350;
  --red: #d93a1e;
  --yellow: #ffc53d;
  --blue: #2743c7;
  --green: #1e8e4d;
  --orange: #b35400;
  --radius: 14px;
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 4px 4px 0 var(--ink);
  --font-display: "Arial Black", "Arial Bold", Arial, sans-serif;
  --font-ui: Arial, Helvetica, sans-serif;
  --font-word: "Courier New", Courier, monospace;
  --font-prose: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  min-height: 100vh;
  background-color: var(--paper);
  /* print dot-grid texture (flat pattern, not a glow) */
  background-image: radial-gradient(rgba(27, 21, 12, 0.13) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: var(--paper);
  padding: 8px 12px; z-index: 50; border-radius: 8px; font-weight: 700;
}
.skip-link:focus { left: 8px; top: 8px; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* hazard stripe up top, like arcade marquee trim */
.hazard {
  height: 12px;
  background: repeating-linear-gradient(-45deg, var(--ink) 0 16px, var(--yellow) 16px 32px);
  border-bottom: 3px solid var(--ink);
}

.app-header {
  max-width: 720px; margin: 0 auto; padding: 20px 16px 4px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  font-size: 1.5rem; line-height: 1;
  background: var(--red); color: #fff;
  border: 3px solid var(--ink); border-radius: 12px;
  padding: 8px 10px; transform: rotate(-6deg);
  box-shadow: var(--shadow-sm);
}
.brand h1 {
  margin: 0; font-family: var(--font-display);
  font-size: 1.7rem; letter-spacing: 0.5px; text-transform: uppercase;
  text-shadow: 3px 3px 0 var(--yellow);
}
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; font-family: var(--font-word); }
.header-actions { display: flex; align-items: center; gap: 10px; }
.burst {
  font-family: var(--font-display); font-size: 0.95rem; color: var(--ink);
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 50%;
  width: 58px; height: 58px; display: grid; place-items: center;
  transform: rotate(8deg); box-shadow: 3px 3px 0 var(--ink);
}

.container { max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }

.card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-top: 16px;
}
.kicker {
  display: inline-block; margin: 0 0 6px;
  font-family: var(--font-word); font-size: 0.8rem; font-weight: bold;
  text-transform: uppercase; letter-spacing: 2px;
  background: var(--ink); color: var(--paper);
  padding: 3px 10px; border-radius: 999px; transform: rotate(-1deg);
}
.card h2 { margin: 0 0 8px; font-family: var(--font-display); font-size: 1.6rem; text-transform: uppercase; }
.card h3 { font-family: var(--font-display); font-size: 1.05rem; text-transform: uppercase; margin: 0; }
.prose { font-family: var(--font-prose); line-height: 1.65; margin: 8px 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.rules { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.rules li {
  background: var(--paper); border: 2px dashed var(--ink);
  border-radius: 10px; padding: 8px 10px; font-size: 0.92rem;
}
.tag {
  display: inline-block; font-family: var(--font-word); font-size: 0.72rem; font-weight: bold;
  border: 2px solid var(--ink); border-radius: 6px; padding: 0 6px; margin-right: 6px;
  text-transform: uppercase;
}
.tag-good { background: #d9f2e3; }
.tag-bad { background: #ffd9d2; }
.tag-warn { background: var(--yellow); }
code, kbd { font-family: var(--font-word); }
kbd {
  background: var(--card); border: 2px solid var(--ink);
  border-bottom-width: 4px; border-radius: 6px; padding: 0 6px; font-size: 0.85em;
}

/* ---- buttons: chunky, pressable ---- */
.btn {
  font-family: var(--font-display); font-size: 1rem;
  border: 3px solid var(--ink); border-radius: 12px;
  padding: 12px 20px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn:focus-visible, input:focus-visible, .linklike:focus-visible {
  outline: 3px solid var(--blue); outline-offset: 2px;
}
.btn-primary { background: var(--red); color: #fff; text-transform: uppercase; letter-spacing: 0.5px; }
.btn-ghost { background: var(--card); color: var(--ink); }
.btn-small { font-size: 0.85rem; padding: 8px 14px; }
.setup-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.race-actions { display: flex; gap: 10px; margin-top: 14px; }

/* ---- main menu: game name + Play / Settings / About ---- */
.game-name {
  font-size: 2.2rem;
  text-shadow: 3px 3px 0 var(--yellow);
}
.menu-col { display: grid; gap: 10px; margin: 16px 0 6px; }
.menu-btn { width: 100%; }
.setting-group {
  border: 2px dashed var(--ink); border-radius: 10px;
  padding: 10px 12px; margin: 12px 0; background: var(--paper);
}
.setting-group legend {
  font-family: var(--font-word); font-weight: bold; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 1.5px;
  background: var(--ink); color: var(--paper);
  padding: 2px 10px; border-radius: 999px;
}
.radio-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 0.95rem; }
.radio-row input { width: 18px; height: 18px; accent-color: var(--red); }
.setting-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--paper); border: 2px dashed var(--ink);
  border-radius: 10px; padding: 8px 12px; margin: 10px 0;
}
/* motion-off: UI still flashes tiles, just without the jump/shake */
body.no-fx .shake, body.no-fx .word-display.pop .tile.hit, body.no-fx .combo-line.pop .combo-value { animation: none; }
.linklike {
  background: none; border: none; padding: 2px 4px; cursor: pointer;
  color: var(--blue); font-size: 0.85rem; text-decoration: underline;
}

/* ---- phase strip: restrained progress display, not buttons ---- */
.phase-strip { display: flex; gap: 6px; margin: 2px 0 10px; }
.phase-seg {
  flex: 1; min-width: 0; text-align: center;
  font-family: var(--font-word); font-size: 0.68rem; font-weight: bold;
  letter-spacing: 1px; padding: 4px 2px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  border: 2px solid var(--ink); border-radius: 8px;
  background: var(--paper); color: var(--muted); opacity: 0.7;
}
.phase-seg.is-done { background: var(--card); opacity: 0.9; }
.phase-seg.is-now { background: var(--ink); color: var(--paper); opacity: 1; }
.points-chip {
  font-family: var(--font-word); font-weight: bold; color: var(--green);
}
.stat-small { font-size: 1rem; }

/* ---- combo: visible but secondary to the word ---- */
.combo-line { text-align: center; margin: 2px 0 8px; min-height: 0; }
.combo-value {
  display: block; font-family: var(--font-display); font-size: 1.6rem;
  line-height: 1; color: var(--ink);
}
.combo-tag {
  font-family: var(--font-word); font-size: 0.7rem; font-weight: bold;
  letter-spacing: 4px; color: var(--muted);
}
.combo-line.pop .combo-value { animation: pop 0.18s ease-out; }

/* ---- rush: meter charges, badge shows only while active ---- */
.rush-meter {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 0 8px;
}
.rush-tag {
  font-family: var(--font-word); font-size: 0.7rem; font-weight: bold;
  letter-spacing: 2px; color: var(--muted);
}
.rush-meter.is-active .rush-tag { color: var(--red); }
.rush-track {
  flex: 1; height: 12px; border: 2px solid var(--ink); border-radius: 999px;
  overflow: hidden; background: var(--paper);
}
.rush-fill {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 10px, #eeb01e 10px 20px);
  transition: width 0.2s linear;
}
.rush-meter.is-active .rush-fill {
  background: repeating-linear-gradient(-45deg, var(--red) 0 10px, #a82a12 10px 20px);
}
.rush-badge {
  display: inline-block; font-family: var(--font-display); font-size: 1rem;
  background: var(--red); color: #fff; border: 3px solid var(--ink);
  border-radius: 10px; padding: 6px 14px; transform: rotate(-1.5deg);
  box-shadow: var(--shadow-sm); margin: 0 auto 8px; text-align: center;
}
/* earned power state (badge) vs current phase (strip): never the same look */
#screen-game.is-rush { background: #fff6dc; }
.best-banner {
  display: inline-block; font-family: var(--font-display); font-size: 0.95rem;
  background: var(--card); border: 3px solid var(--green); color: var(--green);
  border-radius: 10px; padding: 6px 14px; margin: 6px 6px 0 0;
}

/* ---- precision HUD: budget is information, not health ---- */
.prec-top {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 2px 0 4px;
}
.prec-mode {
  font-family: var(--font-word); font-size: 0.75rem; font-weight: bold;
  letter-spacing: 2px; background: var(--ink); color: var(--paper);
  padding: 3px 10px; border-radius: 999px;
}
.prec-progress {
  font-family: var(--font-display); font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}
.prec-budget { font-size: 0.85rem; margin: 0 0 10px; color: var(--muted); }
.prec-budget strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.prec-budget strong.danger { color: var(--red); }
.prec-foot {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 12px; font-size: 0.85rem; color: var(--muted);
}
.prec-foot strong { color: var(--ink); font-variant-numeric: tabular-nums; }
#precInput.input-bad { background: #ffe3de; }

/* ---- game HUD ---- */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.stat {
  background: var(--paper); border: 3px solid var(--ink);
  border-radius: 10px; padding: 6px 4px; text-align: center;
}
.stat-label {
  display: block; font-size: 0.66rem; font-weight: bold;
  text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted);
}
.stat-value { font-family: var(--font-display); font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat-value.danger { color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

.progress-track {
  height: 16px; border: 3px solid var(--ink); border-radius: 999px;
  overflow: hidden; background: var(--paper); margin-bottom: 10px;
}
.progress-fill {
  height: 100%; width: 100%;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 12px, #eeb01e 12px 24px);
  transition: width 0.2s linear;
}
.progress-fill.low {
  background: repeating-linear-gradient(-45deg, var(--red) 0 12px, #a82a12 12px 24px);
}

.deck-line { font-size: 0.9rem; margin: 4px 0 10px; }
/* tier stamp: rotated rubber-stamp label */
.stamp {
  display: inline-block; font-family: var(--font-word); font-weight: bold;
  text-transform: uppercase; font-size: 0.8rem; letter-spacing: 1px;
  border: 3px solid currentColor; border-radius: 6px;
  padding: 1px 10px; transform: rotate(-3deg);
}
.tier-easy { color: var(--green); background: #e2f4e9; }
.tier-medium { color: var(--blue); background: #e0e7ff; }
.tier-hard { color: var(--orange); background: #ffe9d2; }
.tier-intense { color: #fff; background: var(--red); border-color: var(--ink); }
.tier-fast { color: var(--yellow); background: var(--ink); border-color: var(--ink); }

/* ---- word as letterpress tiles ---- */
.word-display {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 5px;
  padding: 20px 12px; margin: 6px 0 14px;
  background: var(--paper);
  border: 3px solid var(--ink); border-radius: var(--radius);
  box-shadow: inset 4px 4px 0 rgba(27, 21, 12, 0.08);
  min-height: 84px;
}
.tile {
  display: inline-block; min-width: 1.05em;
  font-family: var(--font-word); font-weight: bold;
  font-size: clamp(1.5rem, 7vw, 2.2rem); line-height: 1.25; text-align: center;
  background: var(--card); border: 3px solid var(--ink); border-radius: 8px;
  padding: 0 4px;
}
.tile.hit { background: var(--green); border-color: var(--ink); color: #fff; }
.tile.miss { background: var(--red); border-color: var(--ink); color: #fff; }
.tile.next { box-shadow: inset 0 -7px 0 var(--yellow); }
.word-display.pop .tile.hit { animation: pop 0.18s ease-out; }
@keyframes pop { 40% { transform: translateY(-4px); } }
.shake { animation: shake 0.3s; }
@keyframes shake {
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

.input-label { display: block; margin-bottom: 6px; font-size: 0.85rem; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
#typingInput, #playerName {
  font-family: var(--font-word); font-weight: bold;
  border: 3px solid var(--ink); border-radius: 10px;
  background: var(--card); color: var(--ink);
}
#typingInput {
  width: 100%; font-size: 1.5rem; padding: 12px;
  text-align: center; letter-spacing: 2px;
}
#typingInput.input-bad { background: #ffe3de; }
#typingInput.input-good { background: #d9f2e3; }

/* ---- leaderboard: results sheet ---- */
.board-panel { margin-top: 18px; border-top: 3px dashed var(--ink); padding-top: 14px; }
.board-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
thead th {
  background: var(--ink); color: var(--paper);
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1.5px;
  padding: 8px 10px; text-align: left;
}
thead th:first-child { border-radius: 8px 0 0 0; }
thead th:last-child { border-radius: 0 8px 0 0; }
tbody td { padding: 8px 10px; border-bottom: 2px dashed rgba(27, 21, 12, 0.3); font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.is-new td { background: var(--yellow); font-weight: bold; }
.rank-chip {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--ink); font-weight: bold; font-size: 0.85rem; background: var(--card);
}
.rank-chip.r1 { background: var(--yellow); }
.rank-chip.r2 { background: #e8e4d8; }
.rank-chip.r3 { background: #f0b27a; }

.rank-banner {
  display: inline-block; font-family: var(--font-display); font-size: 1.05rem;
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 10px;
  padding: 8px 14px; transform: rotate(-1.5deg); box-shadow: var(--shadow-sm);
  margin: 6px 0 4px;
}
.save-box { margin: 12px 0 4px; }
.save-box label { font-weight: bold; font-size: 0.9rem; }
.save-row { display: flex; gap: 8px; margin-top: 6px; }
#playerName { flex: 1; min-width: 0; font-size: 1.1rem; padding: 8px 12px; text-transform: uppercase; }

.footer {
  max-width: 720px; margin: 0 auto; padding: 12px 16px 28px;
  display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-family: var(--font-word); font-size: 0.78rem;
}
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) rotate(-1deg);
  background: var(--ink); color: var(--paper);
  border: 3px solid var(--yellow);
  padding: 10px 18px; border-radius: 999px;
  font-family: var(--font-display); font-size: 0.9rem;
}

@media (max-width: 520px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .phase-seg { font-size: 0.56rem; letter-spacing: 0; }
  .card { padding: 16px; }
  #typingInput { font-size: 1.25rem; }
  .brand h1 { font-size: 1.3rem; }
  .burst { display: none; }
  table { font-size: 0.85rem; }
}

/* ── Word Rush refinement: clearer phase state, scoring feedback, word flow ── */
/* The current phase stands out as the active step, not just another box. */
.phase-seg.is-now {
  position: relative;
  box-shadow: inset 0 0 0 2px var(--yellow);
}
.phase-seg.is-now::after {
  content: "now";
  position: absolute;
  top: -10px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-word); font-size: 0.55rem; font-weight: bold;
  color: var(--ink); background: var(--yellow); border: 2px solid var(--ink);
  border-radius: 6px; padding: 0 5px; white-space: nowrap;
}

/* Scoring feedback: the last-word points chip reads like a ticket-stamp reward. */
.points-chip {
  font-family: var(--font-display); font-weight: bold; color: var(--green);
  border: 2px dashed var(--ink); border-radius: 8px; padding: 1px 8px;
  background: var(--card); display: inline-block;
}

/* The next letter to type is underlined so the eye never loses its place. */
.tile.next { position: relative; }
.tile.next::after {
  content: ""; position: absolute; left: 20%; right: 20%; bottom: 2px;
  height: 4px; background: var(--yellow); border-radius: 2px;
}

/* Progress track glows slightly as time runs low. */
.progress-fill.low { animation: none; }
.progress-track.low { border-color: var(--red); }
@keyframes trackPulse {
  0% { box-shadow: 0 0 0 0 rgba(217, 58, 30, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(217, 58, 30, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 58, 30, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .shake, .word-display.pop .tile.hit, .combo-line.pop .combo-value, .stat-value.danger { animation: none; }
  .progress-fill, .rush-fill { transition: none; }
}

/* ===== 1.2.0 — Practice mode (practice-ui.js) ===== */
.prac-focus { border: 3px solid var(--ink); border-radius: 12px; padding: 10px 14px 12px; margin: 12px 0; background: var(--card); }
.prac-focus legend { font-family: var(--font-display); padding: 0 6px; }
.prac-focus-list { display: grid; gap: 6px; }
.prac-option { display: flex; align-items: center; gap: 8px; font-family: var(--font-ui); font-size: 1rem; cursor: pointer; }
.prac-option input { width: 18px; height: 18px; accent-color: var(--blue); }
.prac-weak-now { font-family: var(--font-display); background: var(--yellow); border: 3px solid var(--ink); border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow-sm); }
.prac-sub { font-family: var(--font-display); margin: 18px 0 4px; }
.prac-keyboard { display: grid; gap: 6px; margin: 10px 0; overflow-x: auto; padding-bottom: 4px; }
.prac-krow { display: flex; gap: 6px; }
.prac-key {
  --miss: 0;
  flex: none; width: 2.4em; height: 2.4em; display: grid; place-items: center;
  font-family: var(--font-display); border: 2px solid var(--ink); border-radius: 8px;
  background: color-mix(in srgb, var(--red) calc(var(--miss) * 100%), var(--card));
  color: var(--ink);
}
.prac-key.unused { opacity: .45; border-style: dashed; }
@media (max-width: 420px) { .prac-key { width: 2em; height: 2em; font-size: .85rem; } .prac-krow { gap: 4px; } }
