:root {
  --ink: #2a0b4d;
  --ink-soft: #3d1566;
  --tile: #43106b;
  --tile-hi: #521c80;
  --tile-lip: #26063f;
  --mint: #52f2ab;
  --mint-hi: #8affcf;
  --mint-lip: #1fbf7d;
  --cyan: #a9f5fb;
  --cyan-lip: #5ccbe0;
  --yellow: #ffd84a;
  --yellow-lip: #d9a300;
  --red: #ff5a6e;
  --red-lip: #c22a45;
  --orange: #ffb13d;
  --white: #ffffff;
  --panel: rgba(255, 255, 255, 0.28);
  --panel-strong: rgba(255, 255, 255, 0.42);
  --font: 'Montserrat', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, #5ad3ff 0%, #4597ff 48%, #6a7bff 100%);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Post-game gradient fades in over the sky gradient. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #53c9ff 0%, #8c78ff 45%, #e16cf0 100%);
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
}
body.post::before { opacity: 1; }

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---------- floating background squares ---------- */
.bg-tiles {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.bg-tiles i {
  position: absolute;
  display: block;
  border-radius: 22%;
  background: rgba(255, 255, 255, 0.12);
  animation: drift linear infinite;
}
@keyframes drift {
  from { transform: translateY(110vh) rotate(0deg); }
  to { transform: translateY(-30vh) rotate(160deg); }
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  padding: calc(14px + var(--safe-top)) 14px calc(14px + var(--safe-bottom));
  gap: 14px;
  overflow-y: auto;
  z-index: 1;
}
.screen.active {
  display: flex;
  animation: screen-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes screen-in {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: none; }
}

.panel {
  background: var(--panel);
  border-radius: 26px;
  padding: 16px;
  width: 100%;
  max-width: 520px;
}

.screen-title {
  margin: 4px 0 0;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 900;
  color: var(--white);
  text-align: center;
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  letter-spacing: 0.5px;
}

/* ---------- buttons ---------- */
.big-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 68px;
  padding: 0 28px;
  border: 4px solid var(--ink);
  border-radius: 24px;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--ink);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.big-btn:hover { filter: brightness(1.05); }
.big-btn:active { transform: translateY(4px); }
.btn-green {
  background: var(--mint);
  box-shadow: inset 0 -8px 0 var(--mint-lip), 0 6px 0 var(--ink), 0 12px 18px rgba(30, 10, 90, 0.3);
}
.btn-green:active { box-shadow: inset 0 -5px 0 var(--mint-lip), 0 2px 0 var(--ink); }
.btn-cyan {
  background: var(--cyan);
  box-shadow: inset 0 -8px 0 var(--cyan-lip), 0 6px 0 var(--ink), 0 12px 18px rgba(30, 10, 90, 0.25);
}
.btn-cyan:active { box-shadow: inset 0 -5px 0 var(--cyan-lip), 0 2px 0 var(--ink); }
.big-btn:disabled { filter: grayscale(0.6) brightness(0.9); cursor: progress; }

.btn-row {
  display: flex;
  gap: 14px;
  width: 100%;
  max-width: 520px;
}
.btn-row .big-btn { flex: 1; padding: 0 12px; font-size: 1.35rem; }

.round-btn {
  width: 58px;
  height: 46px;
  border-radius: 999px;
  border: 3px solid #5a2a7a;
  background: linear-gradient(180deg, #4a1d63, #33113f);
  color: var(--white);
  font-size: 1.25rem;
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(30, 5, 50, 0.6), 0 8px 14px rgba(30, 10, 90, 0.25);
  display: grid;
  place-items: center;
  flex: none;
}
.round-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(30, 5, 50, 0.6); }

/* ---------- menu ---------- */
.screen-menu { justify-content: center; }
.topbar {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 520px;
}

.logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.logo-super {
  font-size: clamp(1.4rem, 6vw, 2rem);
  font-weight: 900;
  letter-spacing: 6px;
  color: var(--yellow);
  -webkit-text-stroke: 6px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
  transform: rotate(-3deg);
}
.logo-tiles {
  display: flex;
  gap: clamp(4px, 1.5vw, 8px);
}
.logo-tile {
  --t: clamp(44px, 13vw, 66px);
  width: var(--t);
  height: var(--t);
  border-radius: 20%;
  display: grid;
  place-items: center;
  font-size: calc(var(--t) * 0.58);
  font-weight: 800;
  color: var(--white);
  background: linear-gradient(180deg, var(--tile-hi), var(--tile));
  box-shadow: inset 0 calc(var(--t) * -0.08) 0 rgba(0, 0, 0, 0.2), 0 calc(var(--t) * 0.08) 0 var(--tile-lip),
    0 calc(var(--t) * 0.16) calc(var(--t) * 0.2) rgba(30, 10, 90, 0.35);
  animation: logo-bob 2.6s ease-in-out infinite;
}
.logo-tile.mint {
  background: linear-gradient(180deg, var(--mint-hi), var(--mint));
  color: var(--ink);
  box-shadow: inset 0 calc(var(--t) * -0.08) 0 rgba(0, 0, 0, 0.12), 0 calc(var(--t) * 0.08) 0 var(--mint-lip),
    0 calc(var(--t) * 0.16) calc(var(--t) * 0.2) rgba(30, 10, 90, 0.35);
}
@keyframes logo-bob {
  0%, 100% { transform: translateY(0) rotate(var(--r, 0deg)); }
  50% { transform: translateY(-6px) rotate(calc(var(--r, 0deg) * -1)); }
}

.options h2 {
  margin: 0 0 10px;
  text-align: center;
  font-size: 1.7rem;
  font-weight: 800;
}
.opt-group + .opt-group { margin-top: 12px; }
.opt-label {
  font-weight: 800;
  font-size: 0.95rem;
  margin: 0 0 6px 6px;
  opacity: 0.85;
}
.opt-row { display: flex; gap: 10px; }
.opt {
  flex: 1;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--cyan);
  font-size: clamp(0.95rem, 4vw, 1.15rem);
  font-weight: 800;
  box-shadow: inset 0 -6px 0 var(--cyan-lip), 0 4px 0 var(--ink);
  transition: transform 0.08s, background 0.15s;
  padding: 0 6px;
  white-space: nowrap;
}
.opt:active { transform: translateY(3px); box-shadow: inset 0 -4px 0 var(--cyan-lip), 0 1px 0 var(--ink); }
.opt.on {
  background: var(--mint);
  box-shadow: inset 0 -6px 0 var(--mint-lip), 0 4px 0 var(--ink);
  animation: opt-pop 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes opt-pop {
  from { transform: scale(0.9); }
  to { transform: scale(1); }
}
.opt-group[data-opt='minLen'] .opt { font-size: clamp(0.8rem, 3.4vw, 1.05rem); }
.opt { flex: 1 1 0; min-width: 0; }
@media (max-width: 400px) {
  .opt-group[data-opt='minLen'] .ico { display: none; }
}

/* Small CSS icons */
.ico { display: inline-block; flex: none; }
.ico-grid {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  background-color: var(--ink);
  --c: 3;
  background-image:
    linear-gradient(90deg, transparent calc(100% - 2px), rgba(255, 255, 255, 0.55) 0),
    linear-gradient(0deg, transparent calc(100% - 2px), rgba(255, 255, 255, 0.55) 0);
  background-size: calc(100% / var(--c)) calc(100% / var(--c));
  border: 2px solid var(--ink);
}
.ico-grid.g4 { --c: 4; }
.ico-grid.g5 { --c: 5; }
.ico-grid.g6 { --c: 6; }
.ico-glass {
  width: 18px;
  height: 26px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 26'%3E%3Cpath d='M2 2h14M2 24h14M4 2c0 7 10 7 10 11S4 17 4 24M14 2c0 7-10 7-10 11s10 4 10 11' fill='none' stroke='%232a0b4d' stroke-width='2.6' stroke-linecap='round'/%3E%3Cpath d='M6 22c1-3 5-3 6 0z' fill='%23ffb13d'/%3E%3C/svg%3E") center / contain no-repeat;
}
.ico-glass.light {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 26'%3E%3Cpath d='M2 2h14M2 24h14M4 2c0 7 10 7 10 11S4 17 4 24M14 2c0 7-10 7-10 11s10 4 10 11' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round'/%3E%3Cpath d='M6 22c1-3 5-3 6 0z' fill='%23ffd84a'/%3E%3C/svg%3E");
}
.ico-min {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--mint);
  font-size: 0.95rem;
  font-weight: 900;
  display: grid;
  place-items: center;
}

.best-line {
  font-weight: 800;
  color: var(--white);
  text-shadow: 0 2px 0 rgba(42, 11, 77, 0.6);
  min-height: 1.2em;
  text-align: center;
}

#btn-start { width: 100%; max-width: 520px; font-size: 2rem; min-height: 80px; }

/* ---------- countdown ---------- */
.screen-countdown { justify-content: center; gap: 60px; }
.count-num {
  font-size: clamp(8rem, 40vw, 13rem);
  font-weight: 900;
  line-height: 1;
  color: #3df5c8;
  -webkit-text-stroke: 12px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink), 0 12px 0 var(--ink), 0 18px 0 var(--ink), 0 30px 30px rgba(30, 10, 90, 0.35);
}
.count-num.pop { animation: count-pop 0.9s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes count-pop {
  0% { transform: scale(0.2) rotate(-20deg); opacity: 0; }
  30% { transform: scale(1.15) rotate(4deg); opacity: 1; }
  55% { transform: scale(1) rotate(0); }
  85% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.2; }
}
.settings-chips {
  display: flex;
  justify-content: center;
  gap: 18px;
  max-width: 340px;
  background: rgba(42, 30, 140, 0.35);
  padding: 18px;
}
.chip-big {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--white);
  text-shadow: 0 2px 0 var(--ink);
}
.chip-big .ico-grid { border-color: #6e4cc9; background-color: #3a2a9a; }
.chip-big .ico-min { background: var(--mint); color: var(--ink); }

/* ---------- game ---------- */
.screen-game {
  display: none;
  overflow: hidden;
  gap: 10px;
}
.screen-game.active {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(90px, 1fr);
  grid-template-areas: 'head' 'word' 'board' 'side';
  justify-items: center;
  align-items: start;
}
.screen-game .found-panel { align-self: stretch; }
.game-head { grid-area: head; }
.word-zone { grid-area: word; }
.screen-game .board-wrap { grid-area: board; }
.found-panel { grid-area: side; }

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  max-width: 560px;
}
.timer {
  position: relative;
  flex: 1;
  max-width: 230px;
  height: 56px;
  border-radius: 999px;
  border: 5px solid var(--white);
  background: var(--ink);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--white);
  box-shadow: 0 6px 14px rgba(30, 10, 90, 0.3);
}
.timer-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: linear-gradient(180deg, #6a35a8, #53208c);
  transition: width 0.25s linear;
}
.timer .ico, .timer-text { position: relative; }
.timer-text { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.timer.hurry .timer-fill { background: linear-gradient(180deg, #ff7a8a, var(--red)); }
.timer.hurry { animation: hurry 0.5s ease-in-out infinite alternate; }
@keyframes hurry {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.score-badge {
  min-width: 86px;
  height: 52px;
  padding: 0 14px;
  border-radius: 18px;
  border: 4px solid var(--ink);
  background: var(--yellow);
  box-shadow: inset 0 -5px 0 var(--yellow-lip), 0 4px 0 var(--ink);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding-top: 6px;
}
.score-num { font-size: 1.6rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.score-cap { font-size: 0.8rem; font-weight: 800; }
.score-badge.bump { animation: bump 0.35s cubic-bezier(0.3, 1.8, 0.5, 1); }
@keyframes bump {
  from { transform: scale(1.3) rotate(-4deg); }
  to { transform: scale(1); }
}

.word-zone {
  position: relative;
  width: 100%;
  height: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}
.word-pill {
  min-height: 56px;
  min-width: 56px;
  padding: 0 26px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 2px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(30, 10, 90, 0.3);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
}
.word-pill.show { display: flex; }
.word-pill.good { background: var(--mint); color: var(--ink); animation: pill-good 0.45s cubic-bezier(0.3, 1.8, 0.5, 1); }
.word-pill.bad { background: var(--red); animation: shake 0.4s; }
.word-pill.dupe { background: var(--orange); color: var(--ink); animation: shake 0.4s; }
.word-pill.short { background: #8e7bd6; animation: shake 0.4s; }
@keyframes pill-good {
  from { transform: scale(1.25); }
  to { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px) rotate(-2deg); }
  40% { transform: translateX(9px) rotate(2deg); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}
.hint {
  position: absolute;
  bottom: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--white);
  text-shadow: 0 2px 0 rgba(42, 11, 77, 0.55);
  text-align: center;
  transition: opacity 0.3s;
  padding: 0 8px;
}
@media (max-width: 420px) {
  .hint { font-size: 0.82rem; }
}
.word-pill.show ~ .hint { opacity: 0; }
.toast {
  position: absolute;
  top: 0;
  padding: 5px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.05rem;
  background: #7ff5b8;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { animation: toast 1.1s ease forwards; }
.toast.bad { background: #ffb3bd; }
.toast.dupe { background: #ffd79a; }
.toast.short { background: #d4cbff; }
.toast.swap { background: #fff1a8; }
@keyframes toast {
  0% { opacity: 0; transform: translateY(8px) scale(0.8); }
  15% { opacity: 1; transform: translateY(0) scale(1.05); }
  25% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

/* ---------- board ---------- */
.board-wrap { width: 100%; display: flex; justify-content: center; }
.board {
  --n: 4;
  --size: min(calc(100vw - 20px), 560px, calc(100dvh - 330px - var(--safe-top) - var(--safe-bottom)));
  position: relative;
  width: var(--size);
  height: var(--size);
  min-width: 240px;
  min-height: 240px;
  padding: 2.4%;
  gap: 2.2%;
  border-radius: 26px;
  background: var(--panel);
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  container-type: inline-size;
  touch-action: none;
}
.tile {
  --t: calc(100cqi / var(--n));
  --face-a: var(--tile-hi);
  --face-b: var(--tile);
  --lip: var(--tile-lip);
  --fg: var(--white);
  position: relative;
  border-radius: 21%;
  background: linear-gradient(180deg, var(--face-a), var(--face-b));
  color: var(--fg);
  display: grid;
  place-items: center;
  font-size: calc(var(--t) * 0.5);
  font-weight: 700;
  line-height: 1;
  box-shadow:
    inset 0 calc(var(--t) * -0.07) 0 rgba(0, 0, 0, 0.2),
    inset 0 calc(var(--t) * 0.03) 0 rgba(255, 255, 255, 0.08),
    0 calc(var(--t) * 0.06) 0 var(--lip),
    0 calc(var(--t) * 0.1) calc(var(--t) * 0.12) rgba(30, 10, 90, 0.3);
  transition: transform 0.12s ease, background 0.12s;
  will-change: transform;
}
.tile .letter {
  transform: translateY(-4%);
  text-shadow: 0 calc(var(--t) * 0.03) 0 rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.tile .letter.qu { font-size: 0.8em; letter-spacing: -1px; }
.tile.path, .tile.reveal {
  --face-a: var(--mint-hi);
  --face-b: var(--mint);
  --lip: var(--mint-lip);
  --fg: var(--ink);
  transform: scale(1.04);
}
.tile.path .letter, .tile.reveal .letter { text-shadow: none; }
.tile.path.head { transform: scale(1.1); }
.tile.press { transform: scale(0.93); filter: brightness(1.2); }
.tile.selected {
  --face-a: #ffe98a;
  --face-b: var(--yellow);
  --lip: var(--yellow-lip);
  --fg: var(--ink);
  animation: wiggle 0.5s ease-in-out infinite alternate;
  z-index: 2;
}
.tile.selected .letter { text-shadow: none; }
.tile.can-swap::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 24%;
  border: 3px dashed rgba(255, 255, 255, 0.85);
  pointer-events: none;
  animation: dash-pulse 0.8s ease-in-out infinite alternate;
}
@keyframes dash-pulse {
  from { opacity: 0.4; }
  to { opacity: 1; }
}
@keyframes wiggle {
  from { transform: rotate(-4deg) scale(1.06); }
  to { transform: rotate(4deg) scale(1.06); }
}
.tile.flash-good { --face-a: var(--mint-hi); --face-b: var(--mint); --lip: var(--mint-lip); --fg: var(--ink); animation: tile-pop 0.4s cubic-bezier(0.3, 1.8, 0.5, 1); }
.tile.flash-bad { --face-a: #ff8a98; --face-b: var(--red); --lip: var(--red-lip); animation: shake 0.35s; }
.tile.flash-dupe { --face-a: #ffd08a; --face-b: var(--orange); --lip: #c9780b; --fg: var(--ink); animation: shake 0.35s; }
.tile.flash-short { --face-a: #b7a8f0; --face-b: #8e7bd6; --lip: #5a49a3; animation: shake 0.35s; }
@keyframes tile-pop {
  from { transform: scale(1.22); }
  to { transform: scale(1); }
}
.tile.swapping { z-index: 3; transition: transform 0.22s cubic-bezier(0.4, 1.4, 0.6, 1); }
.tile.deal { animation: deal 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) backwards; }
@keyframes deal {
  from { transform: scale(0) rotate(-30deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.tile .order {
  position: absolute;
  top: 6%;
  left: 8%;
  font-size: 0.32em;
  font-weight: 900;
  opacity: 0.7;
}

.trail {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 4;
}
.trail polyline {
  fill: none;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.trail .seg {
  stroke: var(--ink);
  stroke-linecap: round;
  opacity: 0.85;
}
.trail .seg.draw { animation: seg-draw 0.3s ease-out forwards; }
@keyframes seg-draw { to { stroke-dashoffset: 0; } }

/* ---------- found words ---------- */
.found-panel {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 12px;
  border-radius: 22px;
}
.found-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 0 4px 8px;
}
.min-chip {
  font-size: 0.8rem;
  background: var(--ink);
  color: var(--mint);
  padding: 4px 10px;
  border-radius: 999px;
}
.found-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  padding: 2px 2px 6px;
  -webkit-overflow-scrolling: touch;
}
.found-empty { opacity: 0.6; font-weight: 700; padding: 4px; }
.word-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 12px;
  border-radius: 999px;
  background: var(--white);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
  box-shadow: 0 3px 0 rgba(42, 11, 77, 0.25);
  animation: chip-in 0.35s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.word-chip b {
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--mint);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
}
.word-chip.long b { background: var(--yellow); }
.word-chip.hl { animation: chip-hl 0.6s; }
@keyframes chip-in {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes chip-hl {
  0%, 100% { transform: none; background: var(--white); }
  30% { transform: scale(1.15); background: var(--orange); }
}

/* ---------- banner ---------- */
.banner {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 40;
  background: rgba(42, 11, 77, 0.35);
}
.banner.show { display: grid; }
.banner span {
  font-size: clamp(3rem, 15vw, 6rem);
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 12px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 8px 0 var(--ink), 0 20px 30px rgba(0, 0, 0, 0.3);
  animation: banner 1.6s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
  text-align: center;
}
@keyframes banner {
  0% { transform: scale(0.2) rotate(-12deg); opacity: 0; }
  25% { transform: scale(1.1) rotate(3deg); opacity: 1; }
  40% { transform: scale(1) rotate(-2deg); }
  85% { transform: scale(1) rotate(-2deg); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* ---------- tally ---------- */
.screen-tally { gap: 12px; }
.tally-total {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}
.tally-total-num {
  font-size: clamp(4rem, 20vw, 6rem);
  font-weight: 900;
  color: var(--yellow);
  -webkit-text-stroke: 10px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink), 0 14px 20px rgba(30, 10, 90, 0.3);
  font-variant-numeric: tabular-nums;
}
.tally-total-num.bump { animation: bump 0.25s cubic-bezier(0.3, 1.8, 0.5, 1); }
.tally-total-cap { font-weight: 900; color: var(--white); font-size: 1.1rem; text-shadow: 0 2px 0 var(--ink); margin-top: 4px; }
.tally-panel {
  flex: 1;
  min-height: 140px;
  overflow-y: auto;
  padding: 12px;
  scroll-behavior: smooth;
}
.tally-list { display: flex; flex-direction: column; gap: 8px; }
.tally-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.55);
  animation: row-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes row-in {
  from { transform: translateX(-40px) scale(0.9); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.tally-row.big { background: rgba(255, 245, 190, 0.9); }
.tally-row.huge { background: linear-gradient(90deg, #fff2a8, #9fffd6); animation: row-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1), row-glow 1s ease 0.3s; }
@keyframes row-glow {
  0%, 100% { box-shadow: none; }
  40% { box-shadow: 0 0 0 4px var(--yellow), 0 0 24px var(--yellow); }
}
.mini-tiles { display: flex; gap: 3px; flex-wrap: wrap; flex: 1; }
.mini-tile {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--tile-hi), var(--tile));
  color: var(--white);
  font-weight: 800;
  font-size: 0.95rem;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 var(--tile-lip);
}
.mini-tile.qu { font-size: 0.75rem; }
.tally-len { font-size: 0.8rem; font-weight: 800; opacity: 0.65; white-space: nowrap; }
.tally-pts {
  min-width: 52px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  background: var(--mint);
  font-weight: 900;
  text-align: center;
  animation: pts-pop 0.4s cubic-bezier(0.3, 2, 0.5, 1) 0.12s backwards;
}
.tally-row.big .tally-pts, .tally-row.huge .tally-pts { background: var(--yellow); }
@keyframes pts-pop {
  from { transform: scale(0) rotate(-30deg); }
  to { transform: none; }
}
.tally-empty { text-align: center; font-weight: 800; font-size: 1.2rem; padding: 24px 8px; }

.tally-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 520px;
}
.stat {
  background: var(--panel-strong);
  border-radius: 18px;
  padding: 10px 8px;
  text-align: center;
  animation: chip-in 0.4s cubic-bezier(0.3, 1.8, 0.5, 1) backwards;
}
.stat:nth-child(2) { animation-delay: 0.1s; }
.stat:nth-child(3) { animation-delay: 0.2s; }
.stat-label { font-size: 0.75rem; font-weight: 800; opacity: 0.75; }
.stat-value { font-size: 1.35rem; font-weight: 900; overflow-wrap: anywhere; }
.stat-value.word { font-size: 1rem; letter-spacing: 0.5px; }
.stat.best { box-shadow: 0 0 0 3px var(--yellow); }
@media (max-width: 480px) {
  .tally-stats { grid-template-columns: 1fr 1fr 1.45fr; gap: 8px; }
  .stat-value.word { font-size: min(0.95rem, 3.5vw); overflow-wrap: normal; }
  .tally-len { display: none; }
  .tally-row { gap: 8px; padding: 7px 8px; }
  .mini-tiles { gap: 2px; }
  .mini-tile { width: 24px; height: 24px; font-size: 0.82rem; border-radius: 6px; }
  .mini-tile.qu { font-size: 0.65rem; }
}
.new-best {
  display: inline-block;
  margin-top: 2px;
  font-size: 0.7rem;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--yellow);
}

/* ---------- reveal ---------- */
.screen-reveal { gap: 10px; }
.screen-reveal .screen-title { font-size: clamp(1.2rem, 5.3vw, 2.2rem); }
.reveal-word-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 92px;
  justify-content: center;
}
.word-pill.big { font-size: 2.1rem; min-height: 62px; }
.reveal-sub { font-weight: 800; color: var(--white); text-shadow: 0 2px 0 var(--ink); min-height: 1.3em; text-align: center; }
.screen-reveal .board { --size: min(calc(100vw - 20px), 480px, calc(100dvh - 400px)); }
.reveal-panel { padding: 12px 14px; }
.reveal-summary { font-weight: 800; text-align: center; line-height: 1.5; }
.reveal-summary .deep { display: block; font-size: 0.85rem; opacity: 0.8; font-weight: 700; }
.missed { margin-top: 8px; }
.missed summary {
  cursor: pointer;
  font-weight: 800;
  text-align: center;
  list-style: none;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.35);
}
.missed summary::-webkit-details-marker { display: none; }
.missed summary::after { content: ' ▾'; }
.missed[open] summary::after { content: ' ▴'; }
.missed-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 10px;
  max-height: 160px;
  overflow-y: auto;
}
.missed-list .word-chip { animation: none; font-size: 0.85rem; }
.missed-list .word-chip.obscure { opacity: 0.6; }

/* ---------- help modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(42, 11, 77, 0.5);
}
.modal.show { display: grid; animation: screen-in 0.3s ease; }
.modal-card {
  background: #e9fbff;
  border: 4px solid var(--ink);
  box-shadow: 0 8px 0 var(--ink), 0 20px 40px rgba(0, 0, 0, 0.3);
  max-height: 90dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-card h2 { margin: 0; text-align: center; font-size: 1.6rem; font-weight: 900; }
.help-list { margin: 0; padding-left: 22px; font-weight: 600; line-height: 1.45; }
.help-list li { margin-bottom: 8px; }
.points-table { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.points-table span {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font-size: 0.85rem;
  font-weight: 800;
}
.points-table span b { color: var(--mint); }

/* ---------- wide screens: board left, words right ---------- */
@media (min-width: 900px) and (min-height: 560px) {
  .screen-game.active {
    grid-template-columns: auto 300px;
    grid-template-rows: auto auto 1fr;
    grid-template-areas: 'head head' 'word side' 'board side';
    justify-content: center;
    column-gap: 24px;
  }
  .screen-game .board { --size: min(620px, calc(100dvh - 210px)); }
  .found-panel { height: 100%; max-height: calc(100dvh - 120px); }
  .game-head { max-width: none; }
}

/* Short phones: tighten vertical spacing so the board stays big. */
@media (max-height: 700px) {
  .screen { gap: 8px; padding-top: calc(8px + var(--safe-top)); }
  .word-zone { height: 70px; }
  .word-pill { min-height: 48px; font-size: 1.6rem; }
  .timer { height: 50px; }
  .board { --size: min(calc(100vw - 16px), 560px, calc(100dvh - 290px - var(--safe-top) - var(--safe-bottom))); }
  .opt { min-height: 52px; }
  .big-btn { min-height: 60px; }
  #btn-start { min-height: 66px; }
}

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