:root {
  --ink: #1a1433; --night: #2b2257; --dusk: #453a7a; --shadow: #6b5fa3; --mist: #a9a3d1;
  --paper: #f2ecdc; --shade: #cfc5ab; --gold: #f5c542; --ember: #e8743b; --heart: #d9425b; --teal: #4fc2b0;
  --big: 'Press Start 2P', monospace;
  --text: 'VT323', monospace;
}
* { box-sizing: border-box; margin: 0; }
html, body { min-height: 100%; }
body.locked { overflow: hidden; }
body {
  background: var(--night) url(assets/bg-night.png) 0 0 / 128px repeat;
  color: var(--paper); font: 22px/1.2 var(--text);
  -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
  user-select: none; -webkit-user-select: none; overscroll-behavior: none;
}
img, .card, .mini, .pad { image-rendering: pixelated; }
#app {
  max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
/* Game screens: exactly one screen tall. Fixed rows keep their size, .grow takes what is left. */
#app.game {
  height: 100vh; height: 100dvh; overflow: hidden; gap: 8px;
  padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom));
}
#app.game > * { flex-shrink: 0; }
#app.game > .grow { flex: 1 1 0; min-height: 0; }
#app.game > .pad.grow { min-height: 88px; }
.choices.grow { grid-auto-rows: 1fr; max-height: 260px; }
.px { width: 24px; height: 24px; vertical-align: middle; }
.sub { color: var(--mist); text-align: center; }
.small { font-size: 18px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* text */
.logo { font: 34px/1.35 var(--big); color: var(--gold); text-align: center; margin: 24px 0 8px;
  text-shadow: 3px 3px 0 var(--ember), 6px 6px 0 var(--ink); }
.code { font: 40px var(--big); letter-spacing: 8px; text-align: center; color: var(--gold); text-shadow: 4px 4px 0 var(--ink); }
.level { font: 18px var(--big); text-align: center; }
.result { font: 10px/1.6 var(--big); text-align: center; padding: 6px 8px; border: 3px solid var(--ink); }
.result.cleared { background: var(--gold); color: var(--ink); }
.result.failed { background: var(--heart); color: var(--paper); }

/* controls */
button {
  font: 13px/1.4 var(--big); color: var(--ink); background: var(--gold); cursor: pointer;
  border: 3px solid var(--ink); border-radius: 0; padding: 14px 12px;
  box-shadow: inset -3px -3px 0 var(--ember), 0 4px 0 var(--ink); touch-action: manipulation;
}
button:active { transform: translateY(3px); box-shadow: inset -3px -3px 0 var(--ember), 0 1px 0 var(--ink); }
button.quiet { background: var(--dusk); color: var(--paper); box-shadow: inset -3px -3px 0 var(--ink), 0 4px 0 var(--ink); }
button:disabled { opacity: .5; }
button.sm { font-size: 11px; padding: 10px 8px; display: flex; align-items: center; justify-content: center; gap: 6px; }
button.sm .px { width: 16px; height: 16px; }
input {
  font: 16px var(--big); padding: 14px 12px; width: 100%; border: 3px solid var(--ink); border-radius: 0;
  background: var(--paper); color: var(--ink); user-select: text; -webkit-user-select: text;
}
#code { text-transform: uppercase; letter-spacing: 4px; }
.panel { background: var(--dusk); border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px var(--shadow); padding: 12px 14px; }
.panel p + p { margin-top: 8px; }
summary { font: 12px var(--big); cursor: pointer; }
details[open] summary { margin-bottom: 10px; }
.strip {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 19px; line-height: 1.05;
  background: var(--dusk); border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px var(--shadow);
}
.strip .px { width: 16px; height: 16px; flex-shrink: 0; }
.strip .text { flex: 1; text-align: left; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#timer { color: var(--ember); font: 10px/1.4 var(--big); white-space: nowrap; }
#timer:empty { display: none; }
.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
button.choice { background: var(--dusk); color: var(--paper); text-align: left; display: flex; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 8px; }
button.choice b { font-size: 10px; }
button.choice span { font: 16px/1.05 var(--text); color: var(--mist); }
button.choice i { font: 9px var(--big); font-style: normal; text-transform: uppercase; }
/* Rarity colors: common mist, rare teal, epic heart, legendary gold. */
.r-common { --rar: var(--mist); }
.r-rare { --rar: var(--teal); }
.r-epic { --rar: var(--heart); }
.r-legendary { --rar: var(--gold); }
button.choice, button.sm[class*="r-"] { box-shadow: inset 0 0 0 3px var(--rar), 0 4px 0 var(--ink); }
button.choice i { color: var(--rar); }
.secret { display: flex; flex-direction: column; padding: 6px 10px; font-size: 19px; line-height: 1.1; background: var(--ink); border: 3px solid var(--teal); }
.secret b { font: 8px var(--big); color: var(--teal); margin-bottom: 3px; }
.secret span, .line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.powers { display: flex; gap: 8px; }
.powers > * { flex: 1 1 0; min-width: 0; }
.powers button.sm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 44px; }
.powers button[aria-label="Cancel"] { flex: 0 0 44px; }
.powers .aim { flex: 0 0 auto; align-self: center; font: 10px var(--big); color: var(--rar); }
.qr { width: 200px; height: 200px; margin: 0 auto; display: block; border: 3px solid var(--ink); }
.list div { padding: 4px 0; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font: 11px var(--big); }
.bar .icons { display: flex; gap: 2px; }

/* cards */
.card {
  width: 96px; height: 128px; margin: 0 auto; display: grid; place-items: center; position: relative;
  background: url(assets/card-front.png) 0 0 / 100% 100%; color: var(--ink); font: 26px var(--big);
}
.card.empty { background: none; outline: 3px dashed var(--shadow); outline-offset: -3px; }
.card.big { width: 132px; height: 176px; font-size: 40px; touch-action: none; transition: transform .1s ease-out; }
.table { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.table .sub { font-size: 19px; }
/* The pile card shrinks to whatever height the table has left. */
.table .card { flex: 0 1 128px; min-height: 44px; height: 128px; width: auto; aspect-ratio: 3 / 4; font-size: min(26px, 3.2dvh); margin: 0; }
.hand { display: flex; justify-content: center; align-items: center; gap: 14px; }
.hand .card.big { height: min(176px, 24dvh); width: auto; aspect-ratio: 3 / 4; font-size: min(40px, 5.4dvh); margin: 0; }
.rest { display: grid; grid-template-columns: repeat(3, auto); gap: 5px; align-content: center; }
.hand-empty { padding: 24px 0; }
.card.big.holding { transform: translateY(-12px) scale(1.05); }
.card.big.holding::after, .chip.reaching .mini::after {
  content: ''; position: absolute; inset: -8px;
  background: url(assets/reach-glow_4f_8fps.png) 0 0 / 400% 100%; image-rendering: pixelated;
  animation: glow .5s steps(4) infinite;
}
@keyframes glow { to { background-position: 133.333% 0; } }
.hand-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.hand-row span, .rest span { background: var(--paper); color: var(--ink); font: 12px var(--big); padding: 8px 6px; border: 2px solid var(--ink); }
.turn { align-self: center; font: 11px var(--big); padding: 8px 10px; border: 3px solid var(--ink); }
.turn.low { background: var(--teal); color: var(--ink); }
.turn.high { background: var(--ember); color: var(--ink); }

/* players */
.chips { display: flex; gap: 6px; justify-content: center; }
.chip { width: 64px; text-align: center; font-size: 17px; }
.chip .mini {
  width: 48px; height: 64px; margin: 0 auto 4px; position: relative; display: grid; place-items: center;
  background: url(assets/card-back.png) 0 0 / 100% 100%; font: 14px var(--big); color: var(--paper);
  text-shadow: 2px 2px 0 var(--ink); transition: transform .1s ease-out;
}
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.you .name { color: var(--gold); }
.chip.reaching .mini { transform: translateY(-8px); }
.chip.ready .mini { outline: 3px solid var(--teal); }
.chip.off { opacity: .4; }

/* ready pad */
.pad {
  min-height: 88px; display: grid; place-items: center; text-align: center; touch-action: none;
  font: 13px/1.8 var(--big); background: var(--dusk); border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--shadow);
}
.pad.holding { background: var(--teal); color: var(--ink); box-shadow: inset 0 0 0 3px var(--paper); }
.pad.counting { background: var(--gold); color: var(--ink); box-shadow: inset 0 0 0 3px var(--ember); }
.count { display: inline-block; font-size: 48px; line-height: 1.4; }

/* effects */
body.reaching::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 5;
  box-shadow: inset 0 0 0 6px var(--ember); animation: blink .5s steps(2) infinite;
}
@keyframes blink { 50% { box-shadow: inset 0 0 0 3px var(--gold); } }
.pop { animation: pop .15s ease-out; }
@keyframes pop { from { transform: translateY(60px) scale(.7); opacity: 0; } }
body.shake #app { animation: shake .35s steps(6); }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }
body.shake::after { content: ''; position: fixed; inset: 0; background: var(--heart); pointer-events: none; animation: flash .35s forwards; }
@keyframes flash { from { opacity: .45; } to { opacity: 0; } }
.bounce { animation: bounce .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bounce { from { transform: scale(.4); } }
.fly { position: fixed; bottom: -32px; width: 32px; pointer-events: none; z-index: 10; animation: fly 1.2s ease-out forwards; }
@keyframes fly { to { transform: translate(var(--drift), -75vh) rotate(180deg); opacity: 0; } }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 150%); z-index: 20; max-width: 90vw;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); padding: 10px 14px; text-align: center;
  opacity: 0; visibility: hidden; transition: transform .15s ease-out, opacity .15s, visibility .15s;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
/* Short screens: smaller player chips and only the latest private answer. */
@media (max-height: 700px) {
  #app.game { gap: 6px; }
  .chip { font-size: 15px; }
  .chip .mini { width: 32px; height: 43px; font-size: 11px; margin-bottom: 2px; }
  .chip.reaching .mini { transform: translateY(-4px); }
  .secret span:not(:last-child) { display: none; }
  .table { gap: 4px; }
  .turn { padding: 5px 8px; font-size: 9px; }
  .strip { padding: 4px 8px; font-size: 17px; }
}
/* Very short screens: drop the thrown-away line from the table. */
@media (max-height: 520px) {
  .table .line { display: none; }
}
/* install sheet */
#install { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; pointer-events: none; }
.sheet {
  pointer-events: auto; width: 100%; max-width: 480px; display: flex; gap: 14px; align-items: flex-start;
  margin: 0 8px max(8px, env(safe-area-inset-bottom)); padding: 16px;
  background: var(--dusk); border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--gold), 0 -6px 0 rgba(26, 20, 51, .6);
  animation: sheet-in .35s cubic-bezier(.3, 1.4, .5, 1);
}
@keyframes sheet-in { from { transform: translateY(110%); } }
.app-icon { width: 64px; height: 64px; flex-shrink: 0; border: 3px solid var(--ink); }
.sheet-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sheet h2 { font: 12px/1.4 var(--big); color: var(--gold); }
.sheet p { font-size: 20px; line-height: 1.1; }
.steps { margin: 0; padding-left: 22px; font-size: 20px; line-height: 1.25; color: var(--paper); }
.steps b { color: var(--gold); font-weight: normal; }
.steps svg { vertical-align: -3px; color: var(--teal); }
.sheet .row { margin-top: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
