:root {
  --paper: #eef1ec;
  --paper-2: #e2e8e1;
  --ink: #15301f;
  --ink-2: #4d6455;
  --line: #c9d3c8;
  --accent: #2e6b4a;
  --accent-ink: #ffffff;
  --gold: #b8892a;
  --miss: #c23a4b;
  --radius: 14px;
  --font: 'Archivo', system-ui, sans-serif;
  --wide: 'wdth' 125;
  --shadow-lift: 0 10px 24px -12px rgba(21, 48, 31, 0.45);
  /* Accent used as text on the page. Dark mode lightens it so it stays readable. */
  --accent-text: var(--accent);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1a13;
    --paper-2: #16261c;
    --ink: #e4ede6;
    --ink-2: #9db3a4;
    --line: #2a3f31;
    --shadow-lift: 0 10px 24px -12px rgba(0, 0, 0, 0.7);
    --accent-text: color-mix(in srgb, var(--accent) 45%, #ffffff);
  }
}

:root[data-accent='cobalt'] { --accent: #2f5da8; }
:root[data-accent='ruby'] { --accent: #b23a48; }
:root[data-accent='saffron'] { --accent: #b87c0c; }
:root[data-accent='pinstripe'] { --accent: #3d4a5c; }
:root[data-accent='violet'] { --accent: #6b4fa0; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen { display: flex; flex-direction: column; flex: 1; gap: 20px; }

h1, h2, h3 { margin: 0; font-weight: 800; line-height: 1.1; }
h2 { font-size: 1.6rem; font-variation-settings: var(--wide); letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }

.money {
  font-variation-settings: var(--wide);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* Buttons */
button { font: inherit; color: inherit; }
.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 60%, #000);
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.2s;
  touch-action: manipulation;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 transparent; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line);
}
.btn.big { padding: 18px 26px; font-size: 1.1rem; width: 100%; }
.btn.small { padding: 9px 14px; font-size: 0.9rem; }
.link {
  background: none; border: 0; padding: 6px 2px; cursor: pointer;
  color: var(--ink-2); font-weight: 600; text-decoration: underline;
  text-decoration-color: var(--line); text-underline-offset: 4px;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--paper-2); color: var(--ink-2); display: grid; place-items: center;
}
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .icon path:first-child { fill: currentColor; }

/* Home */
.home-hero { display: flex; flex-direction: column; align-items: center; gap: 18px; margin: auto 0; padding: 4vh 0; text-align: center; }
.logo { display: flex; gap: 5px; justify-content: center; flex-wrap: nowrap; }
.logo .tile { --size: clamp(34px, 10vw, 50px); }
.balance { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.balance .money { font-size: clamp(2.6rem, 12vw, 3.6rem); line-height: 1; }
.home-meta { display: flex; gap: 10px; justify-content: center; color: var(--ink-2); font-weight: 600; }
.home-actions { display: flex; flex-direction: column; gap: 12px; }
.home-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px clamp(12px, 4vw, 22px); }
.home-links .link { white-space: nowrap; }
.mode-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-btns .btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 12px 14px; border-radius: 18px; }
.mode-btns .soon { font-size: 0.72rem; font-weight: 600; color: var(--ink-2); }
/* Sits in the grid's second row, under the Unlimited button (first column). */
.mode-note { margin: -4px 0 0; font-size: 0.75rem; font-weight: 600; color: var(--ink-2); text-align: center; line-height: 1.3; }

/* Timer */
.timer { display: flex; align-items: center; gap: 12px; }
.timer-track { flex: 1; height: 8px; border-radius: 99px; background: var(--paper-2); overflow: hidden; }
.timer-fill { height: 100%; width: 100%; background: var(--accent); border-radius: 99px; transform-origin: left; }
.timer-num { font-variant-numeric: tabular-nums; font-weight: 800; min-width: 3.2em; text-align: right; }
.timer.low .timer-fill { background: var(--miss); animation: pulse 0.9s ease-in-out infinite; }
.timer.low .timer-num { color: var(--miss); }
@keyframes pulse { 50% { opacity: 0.45; } }

/* Bank */
.phase-name { font-weight: 700; color: var(--ink-2); }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.beta-tag {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--accent-text); border: 1px solid currentColor; border-radius: 99px; padding: 2px 8px; white-space: nowrap;
}
.prompt-card { display: flex; flex-direction: column; gap: 16px; padding-top: 2vh; }
.prompt-text { font-size: clamp(1.5rem, 6.5vw, 2rem); font-weight: 800; line-height: 1.15; min-height: 2.3em; }
.answer-row { display: flex; gap: 10px; }
.answer-field { position: relative; flex: 1; min-width: 0; display: flex; border-radius: var(--radius); background: var(--paper-2); }
.answer, .answer-mirror {
  font: inherit; font-size: 1.25rem; font-weight: 600; letter-spacing: normal;
  padding: 14px 18px; border-radius: var(--radius); border: 2px solid var(--line);
}
.answer {
  position: relative; flex: 1; width: 100%; min-width: 0;
  background: transparent; color: transparent; caret-color: var(--ink);
  outline: none;
}
.answer::placeholder { color: var(--ink-2); opacity: 1; }
.answer::selection { color: transparent; background: color-mix(in srgb, var(--accent) 25%, transparent); }
.answer:focus { border-color: var(--accent); }
/* Draws the typed text under the transparent input so the banked letter can be gold. */
.answer-mirror {
  position: absolute; inset: 0; overflow: hidden; white-space: pre;
  border-color: transparent; color: var(--ink); pointer-events: none;
}
.answer-mirror > span { display: inline-block; }
.bank-letter { color: var(--gold); }
.hint { min-height: 1.4em; font-weight: 600; color: var(--ink-2); }
.hint.bad { color: var(--miss); }
.hint.good { color: var(--accent-text); }
.bank-tools { display: flex; justify-content: space-between; align-items: center; }

/* Tray */
.tray-wrap { display: flex; flex-direction: column; gap: 10px; }
.tray-head { display: flex; justify-content: space-between; color: var(--ink-2); font-weight: 600; }
.tray {
  display: flex; flex-wrap: wrap; gap: 7px; min-height: 64px;
  padding: 12px; border-radius: 18px;
  background: var(--paper-2);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.08);
}
/* A little space between the vowels and the consonants. */
.tray .tile.vowel + .tile:not(.vowel) { margin-left: 10px; }
.tray:empty::before { content: 'Banked letters land here'; color: var(--ink-2); font-weight: 600; align-self: center; padding-left: 4px; }

/* Cash-in */
.slot {
  display: flex; gap: 6px; justify-content: center; align-items: center;
  min-height: 74px; padding: 10px; border-radius: 18px;
  border: 2px dashed var(--line);
}
.slot:empty::before { content: 'Tap tiles to spell a word'; color: var(--ink-2); font-weight: 600; }
.slot-value { text-align: center; font-weight: 700; color: var(--ink-2); min-height: 1.4em; }
.cash-actions { display: flex; gap: 10px; }
.cash-actions .btn { flex: 1; }
.ledger { display: flex; flex-direction: column; gap: 6px; }
.ledger-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-radius: 12px; background: var(--paper-2);
  border: 0; width: 100%; cursor: pointer; text-align: left;
}
.ledger-row .w { font-variation-settings: var(--wide); font-weight: 800; letter-spacing: 0.04em; }
.ledger-total { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 14px 0; }
.ledger-total .money { font-size: 1.6rem; }

/* Receipt */
.receipt {
  background: #fdfdfb; color: #15301f;
  border-radius: 6px 6px 0 0; padding: 26px 22px 30px;
  box-shadow: var(--shadow-lift);
  position: relative;
  --zig: 12px;
  -webkit-mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / var(--zig) 100%;
          mask: conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) 50% / var(--zig) 100%;
  padding-bottom: calc(30px + var(--zig) / 2);
}
.receipt h2 { text-align: center; }
.receipt .sub { text-align: center; color: #4d6455; margin-top: 4px; }
.receipt hr { border: 0; border-top: 2px dashed #c9d3c8; margin: 16px 0; }
.r-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-variant-numeric: tabular-nums; }
.r-row .w { font-variation-settings: var(--wide); font-weight: 800; letter-spacing: 0.04em; }
.r-total { font-size: 1.5rem; }
.r-total .money { font-size: 1.9rem; }
.r-empty { color: #4d6455; text-align: center; }
.r-note { color: #4d6455; text-align: center; font-size: 0.85rem; margin-top: 6px; }
.r-head { font-weight: 800; margin-bottom: 10px; }
.answers-list { display: flex; flex-direction: column; gap: 10px; }
.a-row { display: flex; gap: 12px; align-items: center; }
.a-row .tile { --size: 30px; }
.a-row > div:last-child { display: flex; flex-direction: column; line-height: 1.25; }
.a-row .small { color: #4d6455; }

/* Shop */
.shop-section { display: flex; flex-direction: column; gap: 10px; }
.shop-section h3 { font-size: 1.05rem; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.shop-item {
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start;
  padding: 14px; border-radius: 16px; background: var(--paper-2);
  border: 2px solid transparent;
}
.shop-item.equipped { border-color: var(--accent); }
.shop-item .name { font-weight: 700; }
.shop-item .bonus { color: var(--accent-text); font-size: 0.8rem; font-weight: 700; }
.portfolio { display: flex; flex-direction: column; gap: 2px; }
.portfolio strong { font-size: 1.6rem; color: var(--accent-text); }
.shop-item.listen { cursor: pointer; }
.play-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; padding: 0 0 0 2px;
}
.play-btn .icon { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.swatch { width: 36px; height: 36px; border-radius: 50%; }
.shop-item .btn { width: 100%; }
/* Keep shop labels readable when a button can't be pressed: an outline, not a faded fill. */
.shop-item .btn:disabled { opacity: 1; background: transparent; color: var(--ink-2); box-shadow: inset 0 0 0 2px var(--line); }
.shop-item .btn.equipped-btn:disabled { color: var(--accent-text); box-shadow: inset 0 0 0 2px var(--accent); }

/* Statement: printed lines, like the receipt but on the page itself */
.statement { display: flex; flex-direction: column; }
.statement hr { border: 0; border-top: 2px dashed var(--line); margin: 14px 0; width: 100%; }
.st-balance { display: flex; flex-direction: column; gap: 2px; }
.st-balance .money { font-size: clamp(2.2rem, 10vw, 2.8rem); line-height: 1.05; }
.st-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; }
.st-row > span:first-child { color: var(--ink-2); font-weight: 600; }
.st-row .money { font-size: 1.15rem; }
.st-word .money { letter-spacing: 0.04em; }

/* How to */
.howto { display: flex; flex-direction: column; gap: 18px; }
.howto ol { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 14px; }
.howto li::marker { font-weight: 800; }
.pay-table { display: grid; grid-template-columns: auto 1fr; gap: 4px 18px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--ink); color: var(--paper);
  padding: 12px 18px; border-radius: 999px; font-weight: 700; z-index: 50;
}

/* Longest-word line on the receipt */
.r-best .r-note { color: #4d6455; font-size: 0.85rem; margin-top: 4px; }
.r-best.found .r-note { color: var(--accent); font-weight: 700; }

/* Load failure (offline) */
.load-error { justify-content: center; text-align: center; }
.load-error-card { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.load-error-tiles { display: flex; gap: 4px; justify-content: center; margin-bottom: 6px; }

/* Phase interstitial */
.interstitial {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 40;
  background: var(--paper); text-align: center; padding: 24px;
}
.interstitial .big { font-size: clamp(2.2rem, 10vw, 3.2rem); font-variation-settings: var(--wide); font-weight: 900; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (min-width: 900px) {
  #app { padding-top: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* Multiplayer: head to head */
.answer.plain { color: var(--ink); background: transparent; }
.answer.plain::selection { color: inherit; }
.answer.need { border-color: var(--miss); }
.code-input { text-transform: uppercase; letter-spacing: 0.3em; font-variation-settings: var(--wide); font-weight: 800; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field .answer-field, .field .answer { flex: none; }
.or { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-weight: 600; font-size: 0.9rem; }
.or::before, .or::after { content: ''; flex: 1; border-top: 2px dashed var(--line); }
.invite { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.code-tiles { display: flex; gap: 6px; }
.code-tiles .tile { --size: clamp(46px, 14vw, 58px); }
.players { display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 14px; background: var(--paper-2); border: 2px solid transparent;
}
.player-row > div { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.player-row.ready { border-color: var(--accent); }
.ready-mark { font-weight: 700; font-size: 0.85rem; color: var(--ink-2); white-space: nowrap; }
.player-row.ready .ready-mark { color: var(--accent); }
.wager { display: flex; flex-direction: column; gap: 10px; }
.wager-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--line); background: transparent; border-radius: 999px;
  padding: 7px 13px; font-weight: 700; font-size: 0.9rem; cursor: pointer; font-variant-numeric: tabular-nums;
}
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.small-row .answer { font-size: 1rem; padding: 9px 14px; }
.duel-bar {
  display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 0.9rem; color: var(--ink-2);
  padding: 8px 12px; border-radius: 12px; background: var(--paper-2); margin-top: -8px;
}
.duel-bar .vs { font-variation-settings: var(--wide); font-weight: 900; color: var(--gold); text-transform: uppercase; font-size: 0.75rem; }
.wait-center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; margin: auto 0; text-align: center; }
.big-money { font-size: clamp(2.4rem, 11vw, 3.2rem); line-height: 1; }
.count-num { font-size: clamp(4rem, 26vw, 7rem); font-weight: 900; font-variation-settings: var(--wide); line-height: 1; color: var(--accent); }
.wait-dots { display: flex; gap: 6px; }
.wait-dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-2); animation: dot 1.2s ease-in-out infinite; }
.wait-dots span:nth-child(2) { animation-delay: 0.15s; }
.wait-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 100% { opacity: 0.25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-4px); } }
.duel-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.duel-col { min-width: 0; }
.duel-col .r-row { font-size: 0.92rem; }
.duel-col .r-total { font-size: 1.05rem; }
.duel-col .r-total .money { font-size: 1.25rem; }
.duel-col .w { overflow: hidden; text-overflow: ellipsis; }
.duel-col.winner .r-head { color: var(--accent); }
.win-tag { margin-left: 8px; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-ink); background: var(--accent); padding: 2px 7px; border-radius: 999px; vertical-align: middle; }

/* Friends */
.friends { display: flex; flex-direction: column; gap: 16px; }
.friends-join { display: flex; flex-direction: column; gap: 12px; }
.code-tiles.six .tile { --size: clamp(40px, 12vw, 50px); }
.friend-list { display: flex; flex-direction: column; gap: 8px; }
.f-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 14px; background: var(--paper-2); border: 2px solid transparent;
}
.f-row.you { border-color: var(--line); }
.f-who, .f-money { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.f-who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.f-money { align-items: flex-end; text-align: right; flex: none; }
.f-money .money { font-size: 1.15rem; }
.f-remove { align-self: flex-start; padding: 2px 0; font-size: 0.8rem; }
.f-empty { text-align: center; padding: 8px 0; }
.friends-note { text-align: center; }
