/* Loot Letters — "Candy Heist" (design 2a). Tokens first; the canvas reads the --tile-* ones. */
:root {
  --bg: #FFFCF6; /* design 13a: lighter page */
  --ink: #2B1D3A;
  --muted: #9A8C86;
  --panel: #FFFFFF;
  --panel-shadow: #EADBC6;
  --board: transparent;
  --ring-track: #F1E8DA;
  --coral: #FF6B4A;
  --coral-dark: #B8432B;
  --mint: #4ED6B8;
  --mint-dark: #2BA88C;
  --gold: #FFC436;
  --gold-dark: #B8861C;
  --plum: #2B1D3A;
  --plum-deep: #15102A;
  --door: #3A2A4F;
  --bolt: #D9B99A;
  --rivet: #5A4870;
  --danger: #E0452F;
  --good: #2BA88C;
  --accent: var(--gold);
  --accent-2: var(--gold);
  /* canvas tiles */
  --tile: #FFFFFF;
  --tile-ink: #2B1D3A;
  --tile-value: #B3A592;
  --tile-shadow: #DCC29A; /* design 13a: deeper drop */
  /* traced tiles (design 12a): pressed into the table, deeper amber, ink letters (white was 2.1:1) */
  --tile-selected: #F5A300;
  --tile-selected-ink: #2B1D3A;
  --tile-selected-value: #5C3A00;
  --tile-selected-shadow: #C9801A;
  --tile-highlight: #FFC436;
  --tile-highlight-shadow: #C9951E;
  --tile-highlight-value: #8A6410;
  --tile-flash: #FF6B4A;
  --tile-dim: #EFE6DA;
  --tile-dim-ink: #B3A592;
  --path: rgba(43, 29, 58, 0.45);
  --font-display: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font-body); overscroll-behavior: none; }
body { display: flex; justify-content: center; }
.app { width: 100%; max-width: 480px; min-height: 100dvh; display: flex; flex-direction: column; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom)); }
.hidden { display: none !important; }
button { font-family: inherit; }

/* keyframes from the design doc */
@keyframes lhSlam { 0% { transform: scale(2.4); opacity: 0; } 55% { transform: scale(.88); opacity: 1; } 75% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes lhWobble { 0% { transform: rotate(-5deg) scale(1); } 25% { transform: rotate(6deg) scale(1.25); } 50% { transform: rotate(-8deg) scale(1.15); } 75% { transform: rotate(4deg) scale(1.05); } 100% { transform: rotate(0) scale(1); } }
@keyframes lhDrop { 0% { transform: translateY(-70px) scale(.9); opacity: 0; } 60% { transform: translateY(10px) scale(1.02); opacity: 1; } 80% { transform: translateY(-4px); } 100% { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes lhPop { 0% { transform: rotate(45deg) scale(0); } 60% { transform: rotate(45deg) scale(1.5); } 100% { transform: rotate(45deg) scale(1); } }
@keyframes lhSpin { 0% { transform: rotate(0); } 70% { transform: rotate(760deg); } 85% { transform: rotate(700deg); } 100% { transform: rotate(720deg); } }
@keyframes lhGlow { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,196,54,0), 0 6px 0 var(--gold-dark); } 50% { box-shadow: 0 0 0 14px rgba(255,196,54,.45), 0 6px 0 var(--gold-dark); } }
@keyframes lhFlash { 0% { background: #FFFFFF; } 30% { background: #FFF1BF; } 100% { background: #FFFFFF; } }
@keyframes lhShake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-5px) rotate(-1deg); } 40% { transform: translateX(5px) rotate(1deg); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes lhChip { 0% { transform: scale(0); opacity: 0; } 70% { transform: scale(1.2); opacity: 1; } 100% { transform: scale(1); } }
@keyframes lhRattle { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }

/* header */
.top { display: flex; justify-content: space-between; align-items: center; }
.brand { display: flex; flex-direction: column; }
.brand-name { font: 700 26px/1.1 var(--font-display); letter-spacing: 0.01em; color: var(--gold); text-shadow: 2px 2px 0 var(--plum), -1.5px -1.5px 0 var(--plum), 1.5px -1.5px 0 var(--plum), -1.5px 1.5px 0 var(--plum), 1.5px 1.5px 0 var(--plum); }
.day { font: 800 12px var(--font-body); letter-spacing: 0.12em; color: var(--muted); text-transform: uppercase; }
.top-right { display: flex; align-items: center; gap: 8px; }
.timer { font: 700 20px var(--font-display); background: var(--panel); padding: 6px 14px; border-radius: 999px; box-shadow: 0 4px 0 var(--panel-shadow); font-variant-numeric: tabular-nums; }
.timer.low { color: var(--danger); }
.badge { font: 900 11px var(--font-body); text-transform: uppercase; letter-spacing: 0.08em; color: var(--bg); background: var(--plum); padding: 4px 9px; border-radius: 999px; box-shadow: 0 2px 0 var(--plum-deep); }

/* score card with dial */
.score-card { flex-shrink: 0; background: var(--panel); border-radius: 26px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 6px 0 var(--panel-shadow); transition: box-shadow .5s; }
.score-main { padding: 12px 16px; display: flex; align-items: center; gap: 16px; }
.score-card.flash { animation: lhFlash .9s ease-out both, lhShake .5s ease-out .1s both; }
.dial { width: 88px; height: 88px; flex-shrink: 0; border-radius: 999px; position: relative; display: flex; align-items: center; justify-content: center; }
@property --deg { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
.dial-ring { position: absolute; inset: 0; border-radius: 999px; --deg: 0deg; background: conic-gradient(var(--gold) 0 var(--deg), var(--ring-track) 0); transition: --deg .45s cubic-bezier(.34,1.3,.64,1); }
.dial-ring.unwind { transition: --deg .3s ease-in; }
.dial-face { position: absolute; inset: 9px; border-radius: 999px; background: var(--panel); box-shadow: inset 0 2px 0 var(--ring-track); }
.dial-pointer { position: absolute; inset: 0; border-radius: 999px; transform: rotate(0deg); transition: transform .45s cubic-bezier(.34,1.56,.64,1); }
/* pointer rides on the ring band, clear of the centre text */
.dial-pointer span { position: absolute; top: -1px; left: 50%; width: 4px; height: 12px; margin-left: -2px; border-radius: 2px; background: var(--plum); } /* 13a: fixed start tick, the arc shows progress */
.dial-center { position: relative; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.mult { font: 700 26px var(--font-display); color: var(--plum); display: inline-block; }
.mult.pop { animation: lhSlam .5s cubic-bezier(.34,1.56,.64,1) both; }
.mult.wobble { animation: lhWobble .7s cubic-bezier(.34,1.56,.64,1) both; }
.mult.broken { animation: lhShake .4s ease-out both; }
.chain { font: 900 9px var(--font-body); color: var(--muted); letter-spacing: 0.1em; margin-top: 3px; text-transform: uppercase; }
.score-side { display: flex; flex-direction: column; flex: 1; gap: 10px; min-width: 0; }
.label { font: 900 11px var(--font-body); letter-spacing: 0.16em; color: var(--muted); text-transform: uppercase; }
.score { font: 700 34px/1 var(--font-display); color: var(--plum); font-variant-numeric: tabular-nums; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill { font: 800 13px var(--font-body); padding: 7px 12px; border-radius: 999px; white-space: nowrap; }
.mod-pill { color: var(--plum); background: var(--bg); }
.next-pill { display: inline-flex; align-items: center; gap: 6px; font: 800 13px var(--font-body); color: var(--muted); background: var(--panel); border: 2px solid var(--ring-track); padding: 4px 6px 4px 12px; border-radius: 999px; }
.next-pill .tile { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 26px; padding: 0 5px; border-radius: 7px; background: var(--gold); box-shadow: 0 2px 0 var(--gold-dark); font: 700 16px var(--font-display); color: var(--plum); text-transform: uppercase; }
.next-pill.free .tile { background: var(--panel); border: 2px dashed var(--gold-dark); box-shadow: none; font-size: 12px; }
.next-pill .aside { color: var(--muted); font-weight: 800; }

/* vault footer (6b): merged into the score card */
.vault-footer { position: relative; overflow: hidden; min-height: 46px; background: var(--bg); border-top: 2px solid var(--ring-track); transition: background .5s; }
.vf-row { display: flex; align-items: center; gap: 10px; padding: 8px 18px; min-height: 46px; }
.vf-open { background: var(--gold); border-top: 2px solid #E9B424; }
.vf-locked { position: absolute; inset: 0; background: var(--bg); transform: translateX(0); transition: transform .75s cubic-bezier(.6,0,.3,1) .45s; z-index: 1; box-shadow: -6px 0 14px rgba(43,29,58,.0); }
.vault-footer.open .vf-locked { transform: translateX(110%); box-shadow: -6px 0 14px rgba(43,29,58,.25); }
@keyframes lhFadeIn { from { opacity: 0; } to { opacity: 1; } }
.vault-footer.drop .pip { animation: lhFadeIn .5s ease both; }
.wheel-sm { width: 26px; height: 26px; flex-shrink: 0; border-radius: 999px; background: var(--panel); border: 3px solid var(--plum); display: grid; place-items: center; }
.wheel-sm i { width: 7px; height: 7px; border-radius: 999px; background: var(--plum); display: block; }
.vf-open .wheel-sm { background: var(--plum); transform: rotate(45deg); }
.vf-open .wheel-sm i { background: var(--gold); }
.vault-footer.cracked .vf-locked .wheel-sm { animation: lhRattle .35s ease-in-out 3; }
.vault-footer.open .vf-open .wheel-sm { animation: lhSpin 1.3s cubic-bezier(.2,.8,.2,1) both; }
.vf-title { font: 700 14px var(--font-display); color: var(--plum); letter-spacing: 0.04em; white-space: nowrap; }
.vf-title.gold { color: var(--plum); }
.vf-open-text { display: flex; flex-direction: column; line-height: 1.1; }
.vf-teach { font: 800 10px var(--font-body); letter-spacing: 0.06em; color: #8A6410; }
.vf-loot { display: flex; flex-direction: column; align-items: flex-end; line-height: 1; margin-left: auto; }
.vf-loot i { font: 900 9px var(--font-body); letter-spacing: 0.14em; color: #8A6410; font-style: normal; }
.vf-loot b { font: 700 18px var(--font-display); color: var(--plum); }
.vault-footer.cracked .vf-title { color: var(--gold-dark); }
.vf-sub { display: none; }
.vf-togo { font: 800 11px var(--font-body); letter-spacing: 0.06em; color: var(--muted); white-space: nowrap; }
.vault-footer.cracked .vf-togo { color: var(--gold-dark); }
.pips { flex: 1; display: flex; gap: 4px; margin: 0 6px; }
.pip { flex: 1; height: 8px; border-radius: 999px; background: var(--panel-shadow); transition: background .25s; }
.pip.on { background: var(--gold); box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
@keyframes lhPipPulse { 0%, 100% { background: var(--panel-shadow); } 50% { background: var(--gold); } }
.vault-footer.cracked .pip:not(.on) { animation: lhPipPulse 1s ease-in-out infinite; }
.gem-slots { display: flex; gap: 8px; padding-right: 2px; flex-wrap: wrap; justify-content: flex-end; max-width: 150px; }
.gem { width: 14px; height: 14px; border-radius: 3px; background: transparent; border: 2px dashed var(--plum); opacity: .45; transform: rotate(45deg); }
.gem.filled { opacity: 1; }
.gem.filled { border: 0; background: var(--gem); box-shadow: inset 2px 2px 0 rgba(255,255,255,.55), 0 1px 0 var(--gem-edge); animation: lhPop .5s cubic-bezier(.34,1.56,.64,1) both; }
/* 13a: small coloured diamond on word chips and in the reward chip (an emoji circle read as a radio button) */
.gem-mark { display: inline-block; width: 8px; height: 8px; margin-left: 6px; border-radius: 2px; background: var(--gem); box-shadow: inset 1px 1px 0 rgba(255,255,255,.6), 0 1px 0 var(--gem-edge); transform: rotate(45deg); vertical-align: 1px; }
.seek-chip .gem-mark { width: 10px; height: 10px; margin-left: 7px; vertical-align: 2px; }
.score-card.vault-open { box-shadow: 0 0 0 3px var(--gold), 0 6px 0 var(--gold-dark); }
.score-card.vault-open .dial-ring { box-shadow: 0 0 0 4px #FFF1C2; }

/* board */
.board-wrap { background: var(--board); border-radius: 28px; padding: 0; flex-shrink: 0; }
.stage { position: relative; width: 100%; aspect-ratio: 1 / 1; flex-shrink: 0; background: radial-gradient(ellipse at 50% 72%, #FFF0CC 0%, rgba(255, 240, 204, 0) 68%); } /* 13a: soft glow behind the board */
canvas { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.toast { position: absolute; left: 50%; top: 8px; transform: translateX(-50%) translateY(-20px); background: var(--plum); color: var(--bg); padding: 7px 14px; border-radius: 999px; font: 800 13px var(--font-body); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis; z-index: 3; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--coral); color: #fff; }
.toast.good { background: var(--gold); color: var(--plum); }

/* chain pills */
.chain-list { display: flex; flex-wrap: wrap; gap: 6px; min-height: 26px; align-content: flex-start; flex-shrink: 0; }
.chip { appearance: none; border: 0; cursor: pointer; font: 800 11px var(--font-body); letter-spacing: 0.06em; color: var(--plum); background: var(--panel); border-radius: 999px; padding: 6px 9px; box-shadow: 0 2px 0 var(--panel-shadow); white-space: nowrap; }
.chip.new { animation: lhChip .45s cubic-bezier(.34,1.56,.64,1) both; }
.chip.off { box-shadow: 0 2px 0 var(--gold-dark); background: #FFF1BF; }
.chip.has-gem { padding-right: 7px; }
.chip.empty { color: var(--muted); box-shadow: none; background: transparent; padding-left: 2px; }

/* actions (design 11a: quiet white button, gold only on the reward chip) */
.actions { display: flex; align-items: stretch; gap: 10px; flex-shrink: 0; }
.tapctl { display: flex; gap: 6px; }
.mini { appearance: none; border: 0; width: 44px; border-radius: 18px; background: var(--panel); color: var(--plum); font: 800 16px var(--font-body); box-shadow: 0 6px 0 var(--panel-shadow); cursor: pointer; }
.mini:disabled { opacity: .4; }
.seek { appearance: none; border: 2px solid transparent; flex: 1; min-width: 0; background: var(--panel); border-radius: 22px; padding: 10px 16px; box-shadow: 0 6px 0 var(--panel-shadow); display: flex; align-items: center; gap: 12px; cursor: pointer; text-align: left; transition: transform .08s, box-shadow .08s, border-color .2s; min-height: 68px; }
.seek:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--panel-shadow); }
.seek:disabled { cursor: default; }
.seek.ready { border-color: var(--gold); }
.seek.glow { animation: lhGlow 1.1s ease-in-out 2; }
.seek.bad { border-color: var(--coral); animation: lhShake .45s ease-out both; }
.seek-main { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.seek-word { font: 700 22px/1 var(--font-display); color: var(--plum); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seek-word.idle { font: 800 15px var(--font-body); text-transform: none; letter-spacing: 0; color: var(--muted); }
.seek-meta { font: 800 12px/1.3 var(--font-body); color: var(--muted); white-space: pre-line; }
.seek-meta .warn { color: var(--coral-dark); font-weight: 900; }
.seek-chip { flex-shrink: 0; font: 700 18px var(--font-display); color: var(--plum); background: var(--gold); padding: 7px 12px; border-radius: 12px; box-shadow: 0 3px 0 var(--gold-dark); white-space: nowrap; }
.seek-chip small { display: block; font: 800 10px/1.1 var(--font-body); margin-top: 1px; } /* 'play ▸' under the number: ~40px narrower chip */
.seek-chip:has(small) { text-align: center; padding: 5px 10px; }
.finish { appearance: none; width: 64px; flex-shrink: 0; font: 800 13px var(--font-body); color: var(--muted); background: transparent; border: 2px solid var(--panel-shadow); border-radius: 22px; padding: 0; cursor: pointer; } /* 13a: compact */

/* overlays and cards */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(43,29,58,.35); backdrop-filter: blur(3px); padding: 12px; overflow: auto; }
.card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 28px; padding: 20px; display: flex; flex-direction: column; gap: 10px; text-align: center; box-shadow: 0 8px 0 var(--panel-shadow), 0 30px 60px rgba(43,29,58,.18); margin: auto; }
.card.wide { max-width: 440px; }
.card h1 { margin: 0; font: 700 32px var(--font-display); letter-spacing: -0.01em; }
.card h2 { margin: 0; font: 700 22px var(--font-display); }
.sub { margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.4; font-weight: 600; }
.sub.hint { font-size: 0.78rem; }
.howto { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; text-align: left; }
.howto li { display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: start; font: 700 14px/1.35 var(--font-body); color: var(--ink); }
.howto .n { width: 24px; height: 24px; border-radius: 50%; background: var(--gold); color: var(--plum); font: 800 12px var(--font-body); display: grid; place-items: center; box-shadow: 0 2px 0 var(--gold-dark); }
.howto b { color: var(--gold-dark); }
.info { font: 700 14px/1.5 var(--font-body); color: var(--muted); }
.info b { color: var(--ink); }
.foot { font: 700 12px var(--font-body); color: var(--muted); }
.result-score { font: 700 52px/1 var(--font-display); color: var(--plum); font-variant-numeric: tabular-nums; }
.result-details { margin-top: 4px; font-size: 0.85rem; }
.result-details summary { cursor: pointer; color: var(--gold-dark); font-weight: 800; list-style: none; }
.result-details summary::after { content: ' ▾'; }
.result-details[open] summary::after { content: ' ▴'; }
.timeline { font-size: 0.95rem; letter-spacing: 1px; word-break: break-all; line-height: 1.3; }

.btn { appearance: none; border: 0; border-radius: 18px; padding: 14px 16px; font: 800 16px var(--font-body); background: var(--bg); color: var(--plum); cursor: pointer; box-shadow: 0 5px 0 var(--panel-shadow); }
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--gold); color: var(--plum); box-shadow: 0 6px 0 var(--gold-dark); font-family: var(--font-display); font-size: 20px; letter-spacing: 0.04em; }
.btn.secondary { background: var(--plum); color: var(--bg); box-shadow: 0 5px 0 var(--plum-deep); }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; }
.btn.small { padding: 8px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: .45; cursor: default; }

.seg { display: flex; align-items: center; gap: 4px; justify-content: center; margin-top: 2px; flex-wrap: wrap; }
.seg-label { font: 800 12px var(--font-body); color: var(--muted); margin-right: 4px; }
.seg-btn { appearance: none; border: 0; background: var(--bg); color: var(--muted); border-radius: 999px; padding: 6px 12px; font: 800 12px var(--font-body); cursor: pointer; }
.seg-btn.on { background: var(--plum); color: var(--bg); }

.draft { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mod { background: var(--bg); border: 3px solid transparent; border-radius: 18px; padding: 12px 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; align-items: center; min-height: 136px; box-shadow: 0 4px 0 var(--panel-shadow); }
.mod .icon { font-size: 1.8rem; }
.mod .name { font: 700 15px var(--font-display); }
.mod .rule { font: 700 11px/1.3 var(--font-body); color: var(--muted); }
.mod .note { margin-top: auto; font: 800 10px var(--font-body); color: var(--plum); background: var(--gold); padding: 2px 8px; border-radius: 999px; }
.mod.picked { border-color: var(--gold); background: var(--panel); transform: translateY(-2px); box-shadow: 0 6px 0 var(--gold-dark); }

/* debug */
.debug { background: var(--panel); border-radius: 14px; padding: 8px 12px; font-size: 0.8rem; box-shadow: 0 3px 0 var(--panel-shadow); }
.debug summary { cursor: pointer; color: var(--muted); font-weight: 800; }
#debugBody { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; margin: 8px 0; }
#debugBody label { color: var(--muted); }
#debugBody input[type="number"], #debugBody input[type="text"] { width: 90px; background: var(--bg); color: var(--ink); border: 1px solid var(--panel-shadow); border-radius: 6px; padding: 3px 6px; }
.debug-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* score breakdown under the word: 5 points × 4 letters × ×2 chain = +40 */
.seek-eq { display: flex; align-items: flex-start; gap: 4px; flex-wrap: wrap; }
.seek-eq .cell { display: flex; flex-direction: column; align-items: center; min-width: 34px; }
.seek-eq .cell b { font: 800 16px/1 var(--font-body); color: var(--plum); }
.seek-eq .cell i { font: 800 8px/1 var(--font-body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--plum); opacity: .65; font-style: normal; margin-top: 3px; white-space: nowrap; }
.seek-eq .op { font: 800 14px/1 var(--font-body); color: var(--plum); opacity: .6; padding-top: 1px; }
.seek-eq .cell.total b { font: 700 18px/1 var(--font-display); }
.seek.bad .seek-eq .cell b, .seek.bad .seek-eq .cell i, .seek.bad .seek-eq .op { color: #fff; }

/* word sheet: tap a chip to see how it scored and look it up */
.word-card { max-width: 340px; }
.word-sheet-word { font: 700 36px/1 var(--font-display); letter-spacing: 0.06em; text-transform: uppercase; }
.word-sheet-eq { justify-content: center; background: var(--bg); border-radius: 14px; padding: 10px 12px; }
.word-card .btn.primary { text-decoration: none; display: block; }
