:root {
  --cream: #f7f2e9;
  --paper: #fffdf8;
  --ink: #31271f;
  --muted: #776b61;
  --brown: #6b4226;
  --gold: #d4a84b;
  --tile: #e8ded0;
  --tile-edge: #d8c9b5;
  --green: #3d8b5c;
  --red: #cf5a52;
  --blue: #4169e1;
  --line: #ded2c2;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html.worddash-dialog-open, body.worddash-dialog-open {
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  margin: 0;
  background:
    radial-gradient(circle at 50% -10%, rgba(212, 168, 75, .18), transparent 38%),
    var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; }

.game-shell {
  width: min(100%, 520px);
  min-height: calc(100dvh - 53px);
  margin: 0 auto;
  padding: clamp(18px, 4vh, 34px) 18px calc(24px + env(safe-area-inset-bottom));
  display: grid;
}

.screen {
  display: none;
  width: 100%;
  align-self: center;
  text-align: center;
  animation: screen-in .32s ease both;
}
.screen.active { display: block; }
.eyebrow {
  color: var(--brown);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
  margin-bottom: 12px;
}
h1 { font-size: clamp(38px, 12vw, 58px); line-height: .98; margin: 0 0 16px; letter-spacing: -.045em; }
.intro { max-width: 390px; margin: 0 auto 24px; color: var(--muted); font-size: clamp(18px, 5vw, 21px); line-height: 1.45; font-weight: 600; }

.preview-grid, .progress-grid, .result-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  width: min(100%, 342px);
  margin: 0 auto;
}
.preview-grid i, .progress-cell, .result-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--tile);
  border: 1px solid rgba(107, 66, 38, .06);
}
.preview-grid i:nth-child(3n + 1) { background: #ded2c2; }
.preview-grid i:nth-child(5n) { background: #eadcbf; }

.rules {
  list-style: none;
  padding: 0;
  margin: 22px auto 24px;
  display: flex;
  justify-content: center;
  gap: 18px;
  color: var(--muted);
  font-size: 13px;
}
.rules strong { display: block; color: var(--ink); font-size: 22px; }
.primary-button, .secondary-button {
  min-height: 52px;
  border-radius: 999px;
  padding: 13px 30px;
  border: 0;
  cursor: pointer;
  font-weight: 800;
  font-size: 18px;
  transition: transform .08s ease, filter .15s ease;
}
.primary-button { color: #fff; background: var(--green); box-shadow: 0 9px 22px rgba(61, 139, 92, .24); }
.secondary-button { color: var(--brown); background: var(--paper); border: 2px solid var(--line); }
.primary-button:hover, .secondary-button:hover { filter: brightness(.97); }
.primary-button:active, .secondary-button:active { transform: scale(.98); }
.best-line { margin: 18px 0 0; color: var(--brown); font-weight: 700; }

.play-screen { align-self: stretch; }
.progress-grid { margin-bottom: 23px; gap: 6px; }
.progress-cell, .result-cell { border-radius: 6px; transition: background .2s, transform .2s; }
.progress-cell.correct, .result-cell.correct { background: var(--green); }
.progress-cell.missed, .result-cell.missed { background: var(--red); }
.progress-cell.current { outline: 3px solid rgba(212, 168, 75, .45); outline-offset: 2px; }
.progress-cell.pop { animation: pop .35s cubic-bezier(.2, 1.7, .5, 1); }
.progress-row { display: flex; justify-content: space-between; align-items: center; text-align: left; margin: 0 4px 14px; }
.word-number { font-size: 19px; font-weight: 850; }
.score-label { margin-top: 3px; color: var(--muted); font-size: 14px; }
.timer-wrap { display: flex; align-items: center; gap: 10px; }
.pause-button {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--paper); color: var(--brown); cursor: pointer; font-weight: 900;
}
.sound-button { font-size: 18px; }
.timer { color: var(--green); min-width: 72px; text-align: right; font-variant-numeric: tabular-nums; }
.timer span { font-size: 42px; line-height: 1; font-weight: 900; letter-spacing: -.06em; }
.timer small { font-size: 18px; margin-left: 2px; font-weight: 800; }
.timer.low { color: var(--red); animation: timer-pulse .8s ease-in-out infinite alternate; }

.answer {
  min-height: 64px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(3px, 1.2vw, 7px);
  margin: clamp(10px, 3vh, 24px) auto 8px;
}
.answer-slot {
  width: clamp(32px, 10vw, 48px);
  height: clamp(40px, 12vw, 56px);
  border-bottom: 4px solid var(--tile-edge);
  display: grid;
  place-items: center;
  font-size: clamp(22px, 7vw, 30px);
  font-weight: 900;
  text-transform: uppercase;
}
.answer.correct .answer-slot { color: var(--green); border-color: var(--green); }
.answer.missed .answer-slot { color: var(--red); border-color: var(--red); animation: pop .35s ease both; }
.answer.shake { animation: shake .36s ease; }
.message { min-height: 24px; color: var(--muted); font-size: 14px; font-weight: 700; margin-bottom: 16px; }
.message.success { color: var(--green); }
.message.error { color: var(--red); }
.letters {
  width: min(100%, 370px);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
}
.letter-tile {
  width: clamp(54px, 17vw, 70px);
  height: clamp(54px, 17vw, 70px);
  border: 0;
  border-bottom: 5px solid var(--tile-edge);
  border-radius: 14px;
  background: var(--tile);
  color: var(--ink);
  font-size: clamp(25px, 8vw, 31px);
  font-weight: 900;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease, border-color .12s ease;
}
.letter-tile:hover { transform: translateY(-2px); }
.letter-tile:active { transform: translateY(2px); border-bottom-width: 2px; }
.letter-tile.selected { opacity: .24; transform: scale(.88); pointer-events: none; }
.clear-button, .text-button { border: 0; background: transparent; color: var(--brown); text-decoration: underline; cursor: pointer; font-weight: 750; }
.clear-button { margin: 18px auto 0; min-height: 44px; padding: 8px 12px; }
.keyboard-help { margin: 8px 0 0; color: var(--muted); font-size: 12px; }

.result-screen { padding-top: 4px; }
.score-ring {
  width: 142px; height: 142px; margin: 0 auto 16px; border-radius: 50%;
  display: flex; align-items: baseline; justify-content: center;
  background: var(--paper); border: 9px solid var(--gold); box-shadow: 0 10px 28px rgba(81, 55, 34, .12);
  padding-top: 35px;
}
.score-ring strong { font-size: 54px; line-height: 1; letter-spacing: -.07em; }
.score-ring span { color: var(--muted); font-size: 18px; font-weight: 800; }
.result-message { color: var(--muted); font-size: 18px; font-weight: 650; margin: 0 auto 18px; }
.result-grid { margin-bottom: 15px; }
.best-result { min-height: 22px; color: var(--brown); font-weight: 800; }
.daily-rank { min-height: 20px; margin: -5px 0 10px; color: var(--green); font-size: 14px; font-weight: 800; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.prototype-note { color: var(--muted); font-size: 12px; margin: 18px 0 0; }
/* Direct child only — cuppa-cta.js repaints #join-cuppa with its own inline-styled
   signup button + a nested "Sign in" text link; a broad `#join-cuppa a` rule turned
   that text link into an invisible brown-on-brown button. */
#join-cuppa > a { display: inline-block; padding: 11px 24px; color: #fff; background: var(--brown); border-radius: 10px; text-decoration: none; font-weight: 700; }

.pause-overlay {
  position: fixed; inset: 0; z-index: 9998; padding: 20px;
  display: grid; place-items: center; background: rgba(49, 39, 31, .72); backdrop-filter: blur(4px);
  overflow-y: auto; overscroll-behavior: contain;
}
.pause-overlay[hidden] { display: none; }
.pause-card { width: min(100%, 360px); max-height: calc(100dvh - 40px); overflow-y: auto; background: var(--paper); border-radius: 24px; padding: 30px; text-align: center; box-shadow: 0 22px 60px rgba(0, 0, 0, .22); }
.pause-icon { font-size: 44px; }
.pause-card h2 { margin: 7px 0 5px; font-size: 26px; }
.pause-card p { margin: 0 0 22px; color: var(--muted); }
.pause-card .text-button { display: block; min-height: 44px; margin: 8px auto 0; padding: 10px 12px; }
.pause-card button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 14px); padding: 10px 17px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 700; opacity: 0; pointer-events: none; transition: .2s; z-index: 10000; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

body.cuppa-dark { --paper: #241f1b; --ink: #f2e9df; --muted: #b9aa9b; --tile: #3a3029; --tile-edge: #55463b; --line: #4a3d34; --brown: #ddbb91; background: #191512 !important; }
body.cuppa-dark .pause-card { background: var(--paper) !important; }
body.cuppa-dark .preview-grid i:nth-child(3n + 1), body.cuppa-dark .preview-grid i:nth-child(5n) { background: var(--tile-edge); }

@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { 50% { transform: scale(1.2); } }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
@keyframes timer-pulse { to { transform: scale(1.06); } }

@media (max-height: 700px) {
  .game-shell { padding-top: 14px; }
  .progress-grid { width: min(100%, 270px); margin-bottom: 12px; }
  .answer { margin-top: 4px; }
  .keyboard-help { display: none; }
  .result-screen h1 { font-size: 38px; }
  .score-ring { width: 112px; height: 112px; padding-top: 27px; }
  .score-ring strong { font-size: 43px; }
}
@media (max-width: 350px) {
  .rules { gap: 10px; }
  .letter-tile { width: 52px; height: 52px; }
  .keyboard-help { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
