@font-face { font-family: 'Press Start 2P'; src: url(press-start-2p.woff2) format('woff2'); font-display: swap; }

:root {
  --bg: #1b1530;
  --panel: #2b2350;
  --ink: #120e1c;
  --text: #f3ecd8;
  --dim: #9b93b8;
  --gold: #f5c84c;
  --gold-dark: #b5832a;
  --red: #ef5a5a;
  --green: #74d96e;
  --purple: #b897ec;
  --common: #d8d2e8;
  --uncommon: #74d96e;
  --rare: #4fa8ff;
  --epic: #ff5fd2;
  --legendary: #ffb02e;
  --bonus: #5ef0e0;
  --dots: radial-gradient(#ffffff0e 1px, transparent 1.5px) 0 0 / 8px 8px;
}

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

html { background: var(--bg); }

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  background: var(--dots), var(--bg);
  color: var(--text);
  font: 10px/1.7 'Press Start 2P', monospace;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 0 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* pixel border: notched corners via 4 offset shadows */
.px {
  box-shadow:
    0 -4px 0 var(--ink), 0 4px 0 var(--ink), -4px 0 0 var(--ink), 4px 0 0 var(--ink),
    inset 4px 4px 0 #ffffff14, inset -4px -4px 0 #00000040;
}

header { text-align: center; }

h1 {
  font-size: 30px;
  line-height: 1.15;
  color: var(--gold);
  letter-spacing: 2px;
  text-shadow: 3px 3px 0 var(--gold-dark), 6px 6px 0 var(--ink);
}
h1 span { color: var(--text); text-shadow: 3px 3px 0 var(--dim), 6px 6px 0 var(--ink); }

.meta, .dim { color: var(--dim); }
.meta { margin-top: 12px; }

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--panel);
}
#keys { display: flex; flex-wrap: wrap; gap: 8px; }
#keys svg { width: 32px; height: 32px; display: block; }
.score { text-align: right; }
.score small { display: block; font-size: 8px; color: var(--dim); }
.score b { font-size: 18px; color: var(--gold); }

#grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px 12px;
}

.vault {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
}
.vault svg {
  display: block;
  width: 100%;
  max-width: 128px;
  filter: drop-shadow(4px 4px 0 var(--ink));
}
.vault[style] svg { filter: drop-shadow(4px 4px 0 var(--ink)) drop-shadow(0 0 6px var(--glow)); }
.vault.ready svg { animation: bob 1.6s steps(2) infinite; }
.vault:nth-child(2n) svg { animation-delay: -0.8s; }
.vault:active:not(.locked) svg { transform: translate(3px, 3px); filter: drop-shadow(1px 1px 0 var(--ink)); }
.vault:disabled { cursor: default; }
.vault.locked { opacity: 0.4; }
.vault:focus-visible { outline: 3px dashed var(--gold); outline-offset: 6px; }

.name { font-size: 9px; text-align: center; word-break: break-word; }
.mystery .name { color: var(--purple); }
/* corner badge: +pts / miss / x1.5 */
.tag {
  position: absolute;
  top: -6px;
  right: -2px;
  padding: 3px 5px;
  font-size: 9px;
  line-height: 1.4;
  background: var(--ink);
  box-shadow: 0 -2px 0 currentColor, 0 2px 0 currentColor, -2px 0 0 currentColor, 2px 0 0 currentColor;
}
.t-common { color: var(--common); }
.t-uncommon { color: var(--uncommon); }
.t-rare { color: var(--rare); }
.t-epic { color: var(--epic); }
.t-legendary { color: var(--legendary); }
.miss { color: var(--red); }
.busted { color: var(--red); }
.tag.busted { background: var(--red); color: var(--ink); box-shadow: 0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink); }
.mult { color: var(--purple); }
.gold { color: var(--gold); }
.bonus { color: var(--bonus); }

#rules { font-size: 9px; padding: 14px; line-height: 1.8; }

/* how-to-play: ? button in the header opens the #help sheet */
header { position: relative; }
#help-btn { position: absolute; top: 0; right: 0; width: 40px; padding: 0; border: 0; background: none; cursor: pointer; }
#help-btn svg, #help-logo svg { display: block; width: 100%; filter: drop-shadow(3px 3px 0 var(--ink)); }
#help-btn:active svg { transform: translate(2px, 2px); filter: none; }
#help-btn:focus-visible { outline: 3px dashed var(--gold); outline-offset: 4px; }
#help[open] { display: flex; flex-direction: column; gap: 16px; }
/* X stays pinned top-right while the rules scroll; negative margin so it doesn't push the logo down */
#help-x { position: sticky; top: 0; z-index: 1; align-self: flex-end; width: 40px; height: 40px; margin-bottom: -56px; padding: 0; border: 0;
  background: var(--ink); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
#help-x:active { transform: translate(2px, 2px); }
#help-x:focus-visible { outline: 3px dashed var(--gold); outline-offset: 4px; }
#help-logo { width: 64px; margin: 0 auto; }
#help h2 { font-size: 16px; color: var(--gold); }
#help .panel { font-size: 9px; padding: 14px; line-height: 1.8; text-align: left; gap: 12px; }
#help h3 { font-size: 10px; color: var(--gold); margin-top: 8px; }
#help h3:first-child { margin-top: 0; }
#help h3.busted { color: var(--red); }
#help .row { display: flex; gap: 12px; align-items: center; }
#help i { flex: none; width: 36px; }
#help i svg, #loot-table svg { display: block; width: 100%; }
#loot-table { display: grid; grid-template-columns: 32px 1fr auto auto; gap: 8px 10px; align-items: center; }
#loot-table small { display: block; font-size: 8px; color: var(--dim); }
#loot-table .k { display: flex; align-items: center; gap: 4px; color: var(--bonus); }
#loot-table .k svg { width: 14px; }

.hint { text-align: center; color: var(--dim); animation: blink 1.2s steps(2) infinite; }

.panel {
  background: var(--panel);
  padding: 20px 16px;
  text-align: center;
  display: grid;
  gap: 10px;
}
.panel h2 { font-size: 16px; color: var(--gold); }
.big { font-size: 36px; line-height: 1.2; color: var(--gold); text-shadow: 4px 4px 0 var(--ink); }
.clock { font-size: 20px; }

/* question / reveal sheet */
dialog {
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  padding-inline: max(16px, calc(50% - 224px)); /* full-width sheet, 480px content column */
  border: 0;
  background: var(--dots), var(--bg);
  color: var(--text);
  text-align: center;
  overflow-y: auto;
}
dialog[open] { animation: pop 0.24s steps(4); }
dialog::backdrop { background: transparent; }

#q-vault { position: relative; width: 80px; margin: 0 auto 12px; }
#rv-vault svg { width: 64px; display: block; margin: 0 auto; }

#review[open] { display: flex; flex-direction: column; gap: 16px; }
#rv-prompt { font-size: 14px; line-height: 1.6; }
#rv-topic { margin: 0; }
.you { font-size: 16px; }
#rv-board { list-style: none; gap: 0; text-align: left; font-size: 9px; }
#rv-board p { text-align: center; margin-bottom: 8px; }
#rv-board li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 6px; }
#rv-board li + li { border-top: 2px solid #ffffff10; }
#rv-board li.mine { background: #ffffff18; }
#rv-close { position: sticky; bottom: 0; flex-shrink: 0; }
#q-vault svg { position: relative; width: 100%; display: block; animation: shake 0.4s steps(4); }

/* spinning light rays behind the vault for rare+ hits */
#q-vault::before {
  content: '';
  position: absolute;
  inset: -70px;
  border-radius: 50%;
  background: repeating-conic-gradient(var(--ray) 0 12deg, transparent 12deg 30deg);
  mask: radial-gradient(closest-side, #000 30%, transparent);
  opacity: 0;
  animation: spin 6s linear infinite;
  transition: opacity 0.3s;
}
#q[data-tier=rare] { --ray: color-mix(in srgb, var(--rare) 45%, transparent); }
#q[data-tier=epic] { --ray: color-mix(in srgb, var(--epic) 55%, transparent); }
#q[data-tier=legendary] { --ray: color-mix(in srgb, var(--legendary) 65%, transparent); }
#q:is([data-tier=rare], [data-tier=epic], [data-tier=legendary]) #q-vault::before { opacity: 1; }
/* busted: spinning red/blue siren beacon instead of rays */
#q[data-tier=busted] #q-vault::before { opacity: 1; background: conic-gradient(#ef5a5a99 0 22%, transparent 0 50%, #4fa8ff99 0 72%, transparent 0); animation-duration: 0.8s; }
.verdict.busted { animation: blink 0.4s steps(2) infinite; }
#q-vault .cuffs { position: absolute; left: 15%; top: 15%; width: 70%; z-index: 1; }
#rv-board .traps { margin-top: 14px; }
#rv-board .busted { line-height: 1.8; }

.fx, .flash { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.fx i { position: absolute; box-shadow: 2px 2px 0 var(--ink); }
.flash { opacity: 0; }
.drop { position: absolute; top: 0; filter: drop-shadow(2px 2px 0 var(--ink)); }
.drop svg { display: block; width: 100%; }
.topic { color: var(--gold); margin-bottom: 20px; }
.blurb { margin: -14px 0 20px; font-size: 8px; }

#ask, #reveal { display: flex; flex-direction: column; gap: 20px; }
#q-prompt { font-size: 16px; line-height: 1.6; }

input {
  width: 100%;
  padding: 16px 12px;
  border: 0;
  background: var(--ink);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* >=16px stops iOS zoom */
  text-align: center;
  text-transform: uppercase;
  box-shadow: 0 -4px 0 var(--dim), 0 4px 0 var(--dim), -4px 0 0 var(--dim), 4px 0 0 var(--dim);
}
input.wrong { color: var(--red); }
input:focus { outline: none; box-shadow: 0 -4px 0 var(--gold), 0 4px 0 var(--gold), -4px 0 0 var(--gold), 4px 0 0 var(--gold); }

.btn {
  width: 100%;
  padding: 18px;
  border: 0;
  background: var(--gold);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-transform: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.btn.px { box-shadow: 0 -4px 0 var(--ink), 0 4px 0 var(--ink), -4px 0 0 var(--ink), 4px 0 0 var(--ink), inset -4px -4px 0 var(--gold-dark); }
.btn:active { transform: translateY(3px); }
.btn:focus { outline: none; }
.btn:focus-visible { filter: brightness(1.15); }

.verdict { font-size: 22px; text-shadow: 3px 3px 0 var(--ink); }
.verdict.t-epic, .verdict.t-legendary { animation: glow 0.6s steps(2) infinite; }
#r-notes { list-style: none; padding: 0; display: grid; gap: 10px; }
#r-key { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; background: var(--panel); }
#r-key small { display: block; margin-top: 6px; font-size: 8px; color: var(--dim); }
#r-key.found { font-size: 14px; color: var(--bonus); }
#r-key.found svg { width: 40px; flex-shrink: 0; animation: glow 0.6s steps(2) infinite; }
#r-key.none { color: var(--dim); }

.timer { display: flex; align-items: center; gap: 14px; }
.timer .bar { flex: 1; height: 16px; background: var(--ink); }
#t-bar { display: block; height: 100%; background: var(--gold); }
#t-sec { min-width: 3ch; font-size: 14px; color: var(--gold); text-align: right; }
.timer.low #t-bar { background: var(--red); }
.timer.low #t-sec { color: var(--red); animation: blink 0.5s steps(2) infinite; }

#sugg { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
#sugg p { flex-basis: 100%; }
.chip {
  padding: 10px 12px;
  border: 0;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  text-transform: inherit;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink), inset -3px -3px 0 #00000040;
}
.chip.pick, .chip:active { background: var(--gold); color: var(--ink); }

/* after the heist: one-round gamble + share */
#bet { display: grid; gap: 10px; margin-top: 8px; }
.two { display: flex; gap: 14px; }
.two .btn { font-size: 11px; padding: 16px 8px; }
#g-line { color: var(--gold); }
.share { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 8px; }
.share a { text-decoration: none; }
#social { display: grid; gap: 12px; }
#practice .chip { display: inline-block; margin-top: 8px; text-decoration: none; }
#past .chip { padding: 8px; font-size: 10px; text-decoration: none; }
#past .chip.gold { color: var(--gold); }
/* friend's challenge link */
.vs { display: flex; justify-content: center; gap: 32px; }
.vs > div { display: grid; gap: 8px; }
.emo { font-family: system-ui, sans-serif; font-size: 22px; line-height: 1.2; }
#gamble[open] { display: flex; flex-direction: column; gap: 16px; }
#gamble h2 { font-size: 20px; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
#g-back { align-self: center; }
#coin-spin { width: 120px; margin: 24px auto; filter: drop-shadow(4px 4px 0 var(--ink)); }
#coin-spin svg { display: block; width: 100%; }
#coin-side { min-height: 1.4em; color: var(--gold); }
.hand { display: flex; justify-content: center; gap: 8px; min-height: 84px; }
.card { width: 56px; height: 80px; padding: 6px; display: flex; flex-direction: column; justify-content: space-between;
  background: var(--text); color: var(--ink); font-size: 14px; text-align: left;
  box-shadow: 0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink), inset -3px -3px 0 #0003; }
.card b:last-child { align-self: flex-end; font-size: 20px; }
.card.red { color: var(--red); }
.card.back { background: repeating-linear-gradient(45deg, var(--red) 0 6px, #a8323a 6px 12px); }
.card.new { animation: pop 0.24s steps(4) backwards; }
/* 5+ cards overlap so a hand fits at 390px */
.hand:has(.card:nth-child(5)) { gap: 0; }
.hand:has(.card:nth-child(5)) .card + .card { margin-left: -14px; }

.dev { position: fixed; left: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); display: flex; gap: 8px; font-size: 8px; }

@keyframes bob { 50% { transform: translateY(-3px); } }
@keyframes blink { 50% { opacity: 0.3; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
@keyframes spin { to { transform: rotate(1turn); } }
@keyframes glow { 50% { filter: brightness(1.5); } }
@keyframes shake { 25% { transform: translateX(-4px); } 50% { transform: translateX(4px); } 75% { transform: translateX(-2px); } }

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

/* footer links + analytics consent bar (only shown when GA is configured, see game.js) */
.foot { display: flex; justify-content: center; gap: 20px; font-size: 8px; }
.foot span { color: var(--dim); padding: 8px 0; }
.foot a, .foot button { color: var(--dim); background: none; border: 0; padding: 8px 0; font: inherit; text-transform: inherit; cursor: pointer; }
#consent { position: fixed; z-index: 10; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); max-width: 448px; margin: 0 auto;
  background: var(--panel); padding: 14px; display: grid; gap: 12px; font-size: 9px; }
#consent a { color: var(--gold); }
#consent .chip { flex: 1; }

/* privacy/terms: long text, so a readable font instead of the pixel one */
.legal main { max-width: 640px; display: block; }
.legal article { font: 15px/1.6 system-ui, sans-serif; text-transform: none; }
.legal h1 { font: 18px/1.5 'Press Start 2P', monospace; text-transform: uppercase; color: var(--gold); margin-bottom: 8px; }
.legal h2 { font-size: 17px; color: var(--gold); margin: 28px 0 8px; }
.legal p, .legal ul { margin: 0 0 12px; }
.legal li { margin-bottom: 6px; }
.legal a { color: var(--gold); }
.legal .back { display: inline-block; font-size: 10px; margin-bottom: 24px; color: var(--dim); }
