/* The Random Game 2026 — phosphor arcade.
   Committed single-theme dark stage; player accent colors are the only large
   color fields. Green = hit, red = miss, gold = special. Everywhere, always. */

:root {
  --ground: #0a0a12;
  --ground-2: #12121d;
  --ground-3: #1a1a28;
  --ink: #eceaf4;
  --dim: #8b89a0;
  --line: #26263a;
  --hit: #3dff8a;
  --miss: #ff4757;
  --gold: #ffd23f;
  --orange: #ff9f1a;   /* Comeback Kid */
  --magenta: #ff4dd8;  /* Clutch Hit */
  --lookout: #00e676;  /* Look Out! */
  --tier-common: #9aa0b4;
  --tier-uncommon: #4fd8eb;
  --tier-rare: #ffd23f;
  --tier-epic: #ff9f1a;
  --tier-mythic: #ff4dd8;
  --display: 'Bungee', 'Arial Black', sans-serif;
  --mono: 'Martian Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* The hidden attribute always wins — display rules on classes must never resurrect
   an overlay (a hidden #mythic with display:grid dims the whole app at load). */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 70% at 50% -12%, #161628 0%, transparent 58%),
    radial-gradient(130% 80% at 50% 112%, #131322 0%, transparent 52%),
    var(--ground);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

/* CRT pass: faint scanlines + vignette over everything. Pure texture, no events. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 95;
  pointer-events: none;
  background:
    radial-gradient(120% 120% at 50% 50%, transparent 62%, rgba(0, 0, 0, 0.4) 100%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 3px);
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- top bar ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
  flex: 0 0 auto;
}

.brand {
  font-family: var(--display);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  color: var(--dim);
}
.brand em {
  font-style: normal;
  color: var(--gold);
  text-shadow: 0 0 14px color-mix(in srgb, var(--gold) 65%, transparent);
}

.topbar-actions { display: flex; gap: 6px; }

.iconbtn {
  background: var(--ground-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 1rem;
  padding: 6px 10px;
  cursor: pointer;
}
.iconbtn:hover { border-color: var(--dim); }

/* ---------- stage & panels ---------- */

#stage {
  flex: 1 1 auto;
  display: grid;
  gap: 10px;
  padding: 6px 12px 10px;
  min-height: 0;
}
#stage[data-layout='one'] { grid-template-columns: 1fr; }
#stage[data-layout='two'] { grid-template-columns: 1fr 1fr; }
@media (orientation: portrait) {
  #stage[data-layout='two'] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  #stage[data-layout='two'].faceoff .panel:first-child { transform: rotate(180deg); }
}

.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1.2vh, 14px);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line));
  border-radius: 12px;
  background:
    radial-gradient(85% 55% at 50% 42%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
    var(--ground-2);
  overflow: hidden;
  cursor: pointer;
  min-height: 0;
  --accent: #58a6ff;
  transition: scale 70ms ease-out, filter 90ms ease-out;
}
.panel.winner { outline: 5px solid var(--accent); outline-offset: -5px; }
.panel.inactive { cursor: default; opacity: 0.92; }

/* The whole tile depresses under your finger — a real button, not a surface. */
.panel.pressed { scale: 0.984; filter: brightness(0.93); }

/* HUD corner brackets — the arcade cabinet frame. */
.cnr {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  pointer-events: none;
}
.cnr.tl { top: 7px; left: 7px; border-right: 0; border-bottom: 0; }
.cnr.tr { top: 7px; right: 7px; border-left: 0; border-bottom: 0; }
.cnr.bl { bottom: 7px; left: 7px; border-right: 0; border-top: 0; }
.cnr.br { bottom: 7px; right: 7px; border-left: 0; border-top: 0; }

.panel .flash {
  position: absolute;
  inset: 0;
  background: var(--flash-color, transparent);
  opacity: 0;
  pointer-events: none;
  border-radius: inherit;
}
.panel .flash.on { opacity: 0.16; transition: none; }
.panel .flash.fading { opacity: 0; transition: opacity var(--flash-ms, 300ms) ease-out; }

.panel.glow { box-shadow: 0 0 0 3px var(--glow-color, var(--gold)), 0 0 34px color-mix(in srgb, var(--glow-color, var(--gold)) 55%, transparent); }

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}
.pname { color: var(--accent); }
.chip {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}
.chip.hot { color: var(--gold); border-color: var(--gold); }

.score {
  font-family: var(--mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.6rem, 9vh, 5.2rem);
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 30px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 180ms ease;
  transform: scale(calc(var(--win-scale, 1) * var(--streak-build, 1)));
}
.score.bump { animation: scorebump 220ms ease; }
@keyframes scorebump {
  40% { scale: 1.06; }
  100% { scale: 1; }
}

/* The total answers every tap in the house colors — green when it grew, red when
   it shrank — then settles back to the seat accent. Brief on purpose: this is the
   score reacting, not another celebration competing with the digits above it. */
.score.bump.up { --pulse: var(--hit); }
.score.bump.down { --pulse: var(--miss); }
.score.bump.up, .score.bump.down {
  animation: scorebump 220ms ease, scorepulse 460ms ease-out;
}
@keyframes scorepulse {
  18% {
    color: var(--pulse);
    text-shadow: 0 0 34px color-mix(in srgb, var(--pulse) 55%, transparent);
  }
}

.numberwrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 150ms ease;
  transform: scale(var(--streak-scale, 1));
}

.number {
  font-family: var(--mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.6rem, 5vh, 2.8rem);
  letter-spacing: 0.04em;
  color: var(--dim);
}
.number.hit { color: var(--hit); text-shadow: 0 0 18px color-mix(in srgb, var(--hit) 60%, transparent); }
.number.miss { color: var(--miss); text-shadow: 0 0 18px color-mix(in srgb, var(--miss) 60%, transparent); }
.number .d { display: inline-block; }
.number.settle .d { animation: settle 120ms ease both; }
.number.settle .d:nth-child(3) { animation-delay: 15ms; }
.number.settle .d:nth-child(4) { animation-delay: 30ms; }
.number.settle .d:nth-child(5) { animation-delay: 45ms; }
.number.settle .d:nth-child(6) { animation-delay: 60ms; }
.number.settle .d:nth-child(7) { animation-delay: 75ms; }
@keyframes settle {
  0% { transform: translateY(-0.5em); opacity: 0.2; }
  100% { transform: translateY(0); opacity: 1; }
}

.streakbadge {
  font-family: var(--display);
  font-size: 0.72rem;
  color: var(--hit);
  letter-spacing: 0.12em;
}
.streakbadge.lookout { color: var(--lookout); text-shadow: 0 0 12px var(--lookout); }

/* Rewards puff straight out of the score — raw glowing text, no chrome. */
.puff {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, -80%) rotate(var(--rot, 0deg));
  font-family: var(--display);
  letter-spacing: 0.03em;
  color: var(--tc, var(--tier-common));
  text-shadow:
    0 0 12px color-mix(in srgb, var(--tc, var(--tier-common)) 80%, transparent),
    0 2px 4px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  pointer-events: none;
  animation: puff 1100ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.puff .pp {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.72em;
  margin-left: 0.5ch;
  opacity: 0.95;
}
.puff.common { font-size: 0.85rem; animation-duration: 900ms; opacity: 0.92; }
.puff.uncommon { font-size: 1.05rem; animation-duration: 1000ms; }
.puff.rare { font-size: 1.35rem; animation-duration: 1300ms; }
.puff.epic { font-size: 1.7rem; animation-duration: 1700ms; }
.puff.bonus { font-size: 1.35rem; animation-duration: 1300ms; }
.puff.remote { opacity: 0.55; }
@keyframes puff {
  0% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(0.2); opacity: 0; }
  14% { transform: translate(-50%, -70%) rotate(var(--rot, 0deg)) scale(1.22); opacity: 1; }
  26% { transform: translate(-50%, -78%) rotate(var(--rot, 0deg)) scale(1); }
  72% { transform: translate(-50%, -150%) rotate(var(--rot, 0deg)) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -195%) rotate(var(--rot, 0deg)) scale(0.94); opacity: 0; }
}
/* Short panels (landscape phones): puffs drift instead of climbing into the header. */
.puff.flat { animation-name: puff-flat; }
@keyframes puff-flat {
  0% { transform: translate(-50%, -50%) rotate(var(--rot, 0deg)) scale(0.2); opacity: 0; }
  14% { transform: translate(-50%, -66%) rotate(var(--rot, 0deg)) scale(1.15); opacity: 1; }
  70% { transform: translate(-44%, -84%) rotate(var(--rot, 0deg)) scale(1); opacity: 1; }
  100% { transform: translate(-41%, -96%) rotate(var(--rot, 0deg)) scale(0.95); opacity: 0; }
}

/* Symbolic micro-feedback: each special performs its own meaning near the
   number for ~half a second. Digit gestures ride translate/rotate/scale props
   (never transform) so they layer cleanly over the settle animation. */

.sfx {
  position: absolute;
  z-index: 4;
  translate: -50% -50%;
  pointer-events: none;
  font-family: var(--mono);
  color: var(--gold);
}
.sfx.sweep { width: var(--nw); height: var(--nh); overflow: hidden; }
.sfx.sweep::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 45%;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--gold) 35%, transparent), transparent);
  animation: sfx-sweep 550ms ease-out both;
}
.sfx.sweep.l::after { animation-name: sfx-sweep-l; }
@keyframes sfx-sweep { from { translate: -130% 0; } to { translate: 300% 0; } }
@keyframes sfx-sweep-l { from { translate: 300% 0; } to { translate: -130% 0; } }

.sfx.mirror {
  width: 2px;
  height: calc(var(--nh) * 1.3);
  background: linear-gradient(180deg, transparent, var(--gold), transparent);
  animation: sfx-glintline 600ms ease both;
}
@keyframes sfx-glintline { 0% { scale: 1 0; opacity: 0; } 35% { scale: 1 1; opacity: 0.9; } 100% { scale: 1 1; opacity: 0; } }

.sfx.ping {
  width: 22px;
  height: 22px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  animation: sfx-ping 750ms ease-out both;
}
@keyframes sfx-ping { from { scale: 0.6; opacity: 0.8; } to { scale: 7; opacity: 0; } }

.sfx.bigglyph {
  font-family: var(--display);
  font-size: calc(var(--nh) * 1.7);
  color: var(--tier-mythic);
  text-shadow: 0 0 30px color-mix(in srgb, var(--tier-mythic) 80%, transparent);
  animation: sfx-rise 950ms ease-out both;
}
.sfx.sum { font-weight: 700; font-size: 0.95rem; animation: sfx-rise 850ms ease-out both; }
.sfx.fibrow {
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.2em;
  color: var(--tier-mythic);
  white-space: nowrap;
  animation: sfx-rise 950ms ease-out both;
}
@keyframes sfx-rise {
  0% { opacity: 0; translate: -50% -30%; }
  25% { opacity: 0.9; }
  100% { opacity: 0; translate: -50% -160%; }
}

.sfx.sevens b {
  display: inline-block;
  font-family: var(--display);
  font-size: 1.5rem;
  margin: 0 8px;
  opacity: 0;
  animation: sfx-fall 700ms ease-in both;
}
.sfx.sevens b:nth-child(2) { animation-delay: 90ms; }
.sfx.sevens b:nth-child(3) { animation-delay: 180ms; }
@keyframes sfx-fall {
  0% { opacity: 0; transform: translateY(-46px); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translateY(40px); }
}

.sfx.streaks { width: var(--nw); height: 0; }
.sfx.streaks i {
  position: absolute;
  bottom: -20px;
  width: 3px;
  height: 42px;
  background: linear-gradient(0deg, transparent, var(--orange));
  animation: sfx-ember 800ms ease-out both;
}
.sfx.streaks i:nth-child(1) { left: 18%; }
.sfx.streaks i:nth-child(2) { left: 50%; animation-delay: 110ms; }
.sfx.streaks i:nth-child(3) { left: 80%; animation-delay: 220ms; }
@keyframes sfx-ember {
  0% { opacity: 0; translate: 0 30px; }
  30% { opacity: 0.9; }
  100% { opacity: 0; translate: 0 -90px; }
}

.sfx.glint {
  inset: 0;
  translate: 0 0;
  overflow: hidden;
  border-radius: inherit;
}
.sfx.glint::after {
  content: '';
  position: absolute;
  top: -30%;
  bottom: -30%;
  width: 70px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--magenta) 40%, transparent), transparent);
  rotate: 16deg;
  animation: sfx-glide 600ms ease-in-out both;
}
@keyframes sfx-glide { from { left: -20%; } to { left: 115%; } }

.number .d.fx-hop { animation: dhop 480ms cubic-bezier(0.34, 1.56, 0.64, 1) var(--hd, 0ms) both; }
@keyframes dhop { 0%, 100% { translate: 0 0; } 40% { translate: 0 var(--hy, -8px); } }
.number .d.fx-pulse { animation: dpulse 420ms ease var(--hd, 0ms) both; }
@keyframes dpulse { 45% { scale: 1.22; filter: brightness(1.5); } 100% { scale: 1; } }
.number .d.fx-pulse2 { animation: dpulse 300ms ease var(--hd, 0ms) 2 both; }
.number .d.fx-blink { animation: dblink 260ms ease var(--hd, 0ms) 2 both; }
@keyframes dblink { 50% { opacity: 0.25; scale: 1.12; } 100% { scale: 1; } }
.number .d.fx-dim { animation: ddim 520ms ease var(--hd, 0ms) both; }
@keyframes ddim { 40% { opacity: 0.3; } }
.number .d.fx-lean { animation: dlean 540ms cubic-bezier(0.34, 1.56, 0.64, 1) var(--hd, 0ms) both; }
@keyframes dlean { 40% { rotate: var(--lr, 8deg); translate: 0 -4px; } 100% { rotate: 0deg; translate: 0 0; } }

/* Ribbons live on the panel they belong to — no more orphaned center badges. */
.ribbon {
  position: absolute;
  z-index: 6;
  top: 17%;
  left: 50%;
  transform: translateX(-50%) rotate(-2deg);
  font-family: var(--display);
  font-size: clamp(0.8rem, 2.4vw, 1.05rem);
  letter-spacing: 0.05em;
  color: #fff;
  padding: 9px 30px;
  background: linear-gradient(135deg, rgba(255, 60, 60, 0.95), rgba(255, 160, 20, 0.95));
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 14px 100%, 0 50%);
  pointer-events: none;
  white-space: nowrap;
  animation: ribbon 2300ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.ribbon.gold { background: linear-gradient(135deg, #b8860b, #ffd23f); color: #1a1200; }
.ribbon.green { background: linear-gradient(135deg, #0a7d43, #3dff8a); color: #00160a; }
@keyframes ribbon {
  0% { transform: translateX(-50%) rotate(-3deg) scale(0.5); opacity: 0; }
  10% { transform: translateX(-50%) rotate(2deg) scale(1.08); opacity: 1; }
  16% { transform: translateX(-50%) rotate(-2deg) scale(1); }
  85% { transform: translateX(-50%) rotate(-2deg) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) rotate(-2deg) scale(0.96); opacity: 0; }
}

/* Taps drain across a segmented fuse — count is the small print. */
.tapszone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.tapsbar {
  display: flex;
  gap: 3px;
  width: min(62%, 320px);
  height: 6px;
}
.tapsbar i {
  flex: 1;
  background: color-mix(in srgb, var(--accent) 72%, transparent);
  box-shadow: 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent);
  transition: background 150ms, box-shadow 150ms, opacity 150ms;
}
.tapsbar i.used { background: var(--line); box-shadow: none; opacity: 0.55; }
.tapsbar.final i:not(.used) { background: var(--gold); box-shadow: 0 0 8px var(--gold); animation: pulse 900ms ease-in-out infinite; }

.tapsleft {
  font-size: 0.72rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.14em;
}
.tapsleft .count { color: var(--ink); font-weight: 700; }
.tapsleft.final { color: var(--gold); font-family: var(--display); animation: pulse 900ms ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* Pre-game invitation: pulsing rings around a gold TAP TO PLAY, mystery digits
   shimmering like a slot about to spin. Visible only while phase is 'ready'. */
.cta {
  display: none;
  position: relative;
  align-items: center;
  justify-content: center;
  min-height: 66px;
  pointer-events: none;
}
.panel.ready .cta { display: flex; }
.cta span {
  font-family: var(--display);
  font-size: clamp(1rem, 3.4vw, 1.4rem);
  letter-spacing: 0.14em;
  color: var(--gold);
  text-shadow: 0 0 22px color-mix(in srgb, var(--gold) 70%, transparent);
  animation: cta-breathe 1.5s ease-in-out infinite;
}
.cta i {
  position: absolute;
  width: 58px;
  height: 58px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  opacity: 0;
  animation: cta-ripple 2.2s ease-out infinite;
}
.cta i:nth-child(2) { animation-delay: 1.1s; }
@keyframes cta-breathe { 50% { transform: scale(1.06); opacity: 0.85; } }
@keyframes cta-ripple {
  0% { transform: scale(0.5); opacity: 0.55; }
  100% { transform: scale(3.2); opacity: 0; }
}
.panel.ready .number .d { animation: qshimmer 2s ease-in-out infinite; }
.panel.ready .number .d:nth-child(3) { animation-delay: 0.15s; }
.panel.ready .number .d:nth-child(4) { animation-delay: 0.3s; }
.panel.ready .number .d:nth-child(5) { animation-delay: 0.45s; }
.panel.ready .number .d:nth-child(6) { animation-delay: 0.6s; }
.panel.ready .number .d:nth-child(7) { animation-delay: 0.75s; }
@keyframes qshimmer { 50% { opacity: 0.35; } }

.taphint {
  position: absolute;
  bottom: 12px;
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.28em;
  color: color-mix(in srgb, var(--accent) 55%, var(--dim));
  animation: pulse 2.4s ease-in-out infinite;
  pointer-events: none;
}

.sitbtn {
  font-family: var(--display);
  background: var(--accent);
  color: var(--ground);
  border: 0;
  border-radius: 12px;
  padding: 10px 22px;
  font-size: 0.9rem;
  cursor: pointer;
}

/* screen shake — original 0.4s curve */
@keyframes shake {
  0%, 100% { translate: 0 0; }
  10%, 50%, 90% { translate: -5px 0; }
  30%, 70% { translate: 5px 0; }
}
.panel.shake { animation: shake 0.4s ease-in-out; }

/* ---------- banners ---------- */

/* Global banner — whole-match moments only (sudden death, reconnects).
   Sits at the stage midline, not hovering awkwardly over one panel. */
.banner {
  position: fixed;
  top: 44%;
  left: 50%;
  translate: -50% -50%;
  z-index: 70;
  font-family: var(--display);
  font-size: clamp(0.95rem, 3vw, 1.3rem);
  letter-spacing: 0.05em;
  color: #fff;
  background: linear-gradient(135deg, rgba(255, 60, 60, 0.95), rgba(255, 160, 20, 0.95));
  padding: 12px 34px;
  clip-path: polygon(16px 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 16px 100%, 0 50%);
  animation: shake 0.4s ease-in-out;
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
}
.banner.gold { background: linear-gradient(135deg, #b8860b, #ffd23f); color: #1a1200; }
.banner.green { background: linear-gradient(135deg, #0a7d43, #3dff8a); color: #00160a; }

/* ---------- mythic takeover ---------- */

.mythic {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(5, 5, 12, 0.86);
  pointer-events: none;
  animation: mythic-fade 1400ms ease both;
}
@keyframes mythic-fade { 0% { opacity: 0; } 12% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }
.mythic-inner { text-align: center; animation: mythic-zoom 1400ms cubic-bezier(0.16, 1, 0.3, 1) both; }
@keyframes mythic-zoom { 0% { transform: scale(0.6); } 18% { transform: scale(1.05); } 24% { transform: scale(1); } 100% { transform: scale(1.02); } }
.mythic-name {
  font-family: var(--display);
  font-size: clamp(2.2rem, 9vw, 5rem);
  color: var(--mc, var(--tier-mythic));
  text-shadow: 0 0 40px var(--mc, var(--tier-mythic)), 0 0 80px color-mix(in srgb, var(--mc, var(--tier-mythic)) 60%, transparent);
}
.mythic-digits {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(1.2rem, 4.4vw, 2rem);
  color: var(--ink);
  margin-top: 8px;
  letter-spacing: 0.12em;
}
.mythic-flavor { color: var(--dim); font-size: 0.85rem; margin-top: 10px; }

/* ---------- mode strip ---------- */

#modestrip {
  display: flex;
  gap: 6px;
  padding: 4px 12px calc(10px + env(safe-area-inset-bottom));
  flex: 0 0 auto;
}
#modestrip button {
  flex: 1;
  font-family: var(--display);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  padding: 11px 4px;
  background: var(--ground-3);
  color: var(--dim);
  border: 0;
  clip-path: polygon(9px 0, 100% 0, calc(100% - 9px) 100%, 0 100%);
  cursor: pointer;
}
#modestrip button.active {
  color: #1a1200;
  background: var(--gold);
  text-shadow: none;
}
#modestrip button.locked { opacity: 0.32; cursor: not-allowed; }

/* leaderboard */

.lb-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}
.lb-rank { font-family: var(--display); font-size: 0.8rem; color: var(--dim); min-width: 2.4ch; text-align: right; }
.lb-rank.r1 { color: var(--gold); text-shadow: 0 0 10px var(--gold); }
.lb-rank.r2 { color: #c8c8d4; }
.lb-rank.r3 { color: #cd7f32; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.lb-score { font-weight: 700; }
.lb-row.me { background: color-mix(in srgb, var(--gold) 7%, transparent); }
.lb-row.me .lb-name { color: var(--gold); }

.lb-submit { display: flex; gap: 8px; margin-top: 16px; }
.lb-submit input {
  flex: 1;
  min-width: 0;
  background: var(--ground);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 11px 10px;
  border-radius: 8px;
}
.lb-submit button {
  flex: 0 0 auto;
  font-family: var(--display);
  font-size: 0.72rem;
  background: var(--ground-3);
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
}
.lb-note { font-size: 0.6rem; color: var(--dim); text-align: center; margin-top: 7px; letter-spacing: 0.08em; }
.lb-hype {
  text-align: center;
  font-family: var(--display);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-shadow: 0 0 14px color-mix(in srgb, var(--gold) 60%, transparent);
  margin-top: 14px;
  animation: pulse 1.6s ease-in-out infinite;
}
.lb-note.bad { color: var(--miss); }
.lb-result {
  text-align: center;
  font-family: var(--display);
  color: var(--gold);
  font-size: 1rem;
  margin-top: 16px;
  text-shadow: 0 0 14px color-mix(in srgb, var(--gold) 55%, transparent);
}

/* sign in */

.auth-note {
  text-align: center;
  color: var(--dim);
  font-family: var(--display);
  font-size: 0.56rem;
  letter-spacing: 0.14em;
  margin-bottom: 4px;
}
.authwide { width: 100%; margin-top: 12px; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 12px;
  color: var(--dim);
  font-family: var(--display);
  font-size: 0.58rem;
  letter-spacing: 0.24em;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}
.googlebtn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #f4f4f8;
  color: #1a1d24;
  border: 0;
  font-family: var(--display);
  font-size: 0.76rem;
  letter-spacing: 0.05em;
  padding: 13px;
  border-radius: 12px;
  cursor: pointer;
}
.googlebtn:disabled { opacity: 0.35; cursor: not-allowed; }
.googlebtn.slim { padding: 11px; font-size: 0.68rem; margin-top: 12px; }
.gmark { color: #4285f4; font-size: 1.05rem; }
.soonchip {
  font-family: var(--mono);
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--gold);
  background: var(--ground);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 2px 8px;
}
#account-state { flex: 1; text-align: right; color: var(--gold); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
#btn-account { flex: 0 1 auto; }
.linkish {
  background: none !important;
  border: 0 !important;
  padding: 0 !important;
  color: var(--gold);
  font: inherit;
  letter-spacing: inherit;
  text-decoration: underline;
  cursor: pointer;
  flex: 0 !important;
}

/* ---------- sheets & overlays ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(4, 4, 10, 0.72);
}

/* Every sheet is a centered arcade modal — never a bottom drawer. */
.sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  z-index: 60;
  width: min(560px, calc(100vw - 20px));
  max-height: min(86dvh, calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow-y: auto;
  background: var(--ground-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  animation: sheet-pop 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes sheet-pop { from { translate: -50% -46%; opacity: 0; scale: 0.96; } }

/* The recap is the RESULTS screen — same centering, a little more room and punch. */
#recap {
  max-height: min(90dvh, calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  animation: recap-pop 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes recap-pop {
  from { translate: -50% -47%; opacity: 0; scale: 0.95; }
}

.sheet h2 {
  font-family: var(--display);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  color: var(--gold);
  margin-bottom: 14px;
  text-align: center;
}

.sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet-actions button, .sheet button {
  font-family: var(--display);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--ground-3);
  color: var(--ink);
  cursor: pointer;
  flex: 1;
}
.sheet button.primary { background: var(--gold); border-color: var(--gold); color: #1a1200; }
.sheet button.danger { background: transparent; border-color: var(--miss); color: var(--miss); flex: 0 1 auto; }

/* recap — the payout screen */

#recap-title { color: var(--ink); }
#recap-title.win { color: var(--gold); }

#recap-scores {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 8px;
}

.recap-hero {
  position: relative;
  flex: 1;
  text-align: center;
  padding-top: 4px;
}
.recap-hero .rname { font-family: var(--display); font-size: 0.78rem; color: var(--rc, var(--ink)); letter-spacing: 0.08em; }
.recap-hero .rscore {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 3.4rem;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  color: var(--rc, var(--ink));
  text-shadow: 0 0 28px color-mix(in srgb, var(--rc, var(--ink)) 45%, transparent);
}
.recap-hero .rsub { font-size: 0.66rem; color: var(--dim); letter-spacing: 0.14em; font-variant-numeric: tabular-nums; }

/* The verdict, stamped on at an angle like it hit the paper hard. */
.rank-stamp {
  position: absolute;
  top: -16px;
  right: 2%;
  font-family: var(--display);
  font-size: 3rem;
  line-height: 1;
  color: var(--rk);
  border: 3px solid var(--rk);
  padding: 4px 16px;
  transform: rotate(9deg);
  clip-path: polygon(8px 0, 100% 0, calc(100% - 8px) 100%, 0 100%);
  text-shadow: 0 0 24px var(--rk);
  box-shadow: inset 0 0 22px color-mix(in srgb, var(--rk) 16%, transparent);
  animation: stamp 480ms cubic-bezier(0.16, 1, 0.3, 1) both 120ms;
  pointer-events: none;
}
@keyframes stamp {
  0% { transform: rotate(9deg) scale(2.4); opacity: 0; }
  55% { transform: rotate(9deg) scale(0.94); opacity: 1; }
  100% { transform: rotate(9deg) scale(1); opacity: 1; }
}
.rank-chip {
  display: inline-block;
  font-family: var(--display);
  font-size: 0.9rem;
  color: var(--rk);
  border: 2px solid var(--rk);
  padding: 0 7px;
  margin-left: 8px;
  vertical-align: middle;
  transform: rotate(6deg);
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
}

/* The run's rhythm — every tap, in order. Tall greens, short reds, tier-lit specials. */
.runstrip {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  justify-content: center;
  width: min(94%, 430px);
  height: 14px;
  margin: 12px auto 0;
}
.runstrip i { flex: 1; min-width: 3px; height: 100%; background: var(--hit); opacity: 0.9; border-radius: 1px; }
.runstrip i.m { background: var(--miss); height: 45%; opacity: 0.55; }
.runstrip i.s.common { background: var(--tier-common); }
.runstrip i.s.uncommon { background: var(--tier-uncommon); box-shadow: 0 0 5px var(--tier-uncommon); }
.runstrip i.s.rare { background: var(--tier-rare); box-shadow: 0 0 6px var(--tier-rare); }
.runstrip i.s.epic { background: var(--tier-epic); box-shadow: 0 0 8px var(--tier-epic); }
.runstrip i.s.mythic { background: var(--tier-mythic); box-shadow: 0 0 10px var(--tier-mythic); }
.runstrip i.b { box-shadow: 0 0 7px var(--gold); }

.recap-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 14px;
}
.stat {
  background: var(--ground-3);
  padding: 9px 4px 7px;
  text-align: center;
  clip-path: polygon(7px 0, 100% 0, calc(100% - 7px) 100%, 0 100%);
}
.stat b {
  display: block;
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.stat span {
  font-family: var(--display);
  font-size: 0.52rem;
  letter-spacing: 0.14em;
  color: var(--dim);
}

.moment {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--tc, var(--gold)) 9%, var(--ground-3));
  border-left: 3px solid var(--tc, var(--gold));
  border-right: 3px solid var(--tc, var(--gold));
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 10px 100%, 0 50%);
  font-variant-numeric: tabular-nums;
}
.moment .mlabel { font-family: var(--display); font-size: 0.56rem; letter-spacing: 0.16em; color: var(--dim); }
.moment b { font-family: var(--display); font-size: 0.95rem; color: var(--tc, var(--gold)); text-shadow: 0 0 12px color-mix(in srgb, var(--tc, var(--gold)) 60%, transparent); }
.moment .mdigits { color: var(--ink); font-size: 0.8rem; }
.moment em { font-style: normal; font-weight: 700; color: var(--tc, var(--gold)); font-size: 0.85rem; }
.moment .mwho { font-family: var(--display); font-size: 0.6rem; color: var(--dim); }

.recap-player { flex: 1; text-align: center; min-width: 0; }
.recap-player .rname { font-family: var(--display); font-size: 0.72rem; color: var(--rc, var(--ink)); }
.recap-player .rscore { font-family: var(--mono); font-weight: 700; font-size: 2rem; font-variant-numeric: tabular-nums; color: var(--rc, var(--ink)); }
.recap-player .rsub { font-size: 0.6rem; color: var(--dim); letter-spacing: 0.08em; margin-top: 8px; }
.recap-player.lost { opacity: 0.55; }
.recap-player .runstrip { height: 10px; margin-top: 8px; }

#recap-breakdown { font-size: 0.78rem; }
.bd-section { margin-top: 14px; }
.bd-head {
  display: flex;
  justify-content: space-between;
  color: var(--dim);
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
  margin-bottom: 6px;
}
.bd-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
}
.bd-row .n { color: var(--tc, var(--ink)); }
.bd-row .ct {
  flex: 1;
  color: var(--dim);
  font-size: 0.68rem;
  /* dotted leader carries the eye from name to payout */
  background-image: radial-gradient(circle, var(--line) 1px, transparent 1.5px);
  background-size: 7px 3px;
  background-position: 0 70%;
  background-repeat: repeat-x;
  padding: 0 4px;
  text-align: left;
}
.bd-row .pts { font-weight: 700; color: var(--tc, var(--ink)); }
.bd-empty { color: var(--dim); padding: 4px 0; }

/* trophies */

.trophy-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.trophy-row .tname { font-family: var(--display); font-size: 0.72rem; color: var(--tc); }
.trophy-row .tmeta { color: var(--dim); font-size: 0.66rem; }
.guide-intro { color: var(--dim); font-size: 0.75rem; margin-bottom: 10px; text-align: center; }

/* settings */

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}
.setting-row input[type='checkbox'] { width: 22px; height: 22px; accent-color: var(--gold); }
.setting-row input[type='text'] {
  background: var(--ground);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--mono);
  border-radius: 8px;
  padding: 8px 10px;
  width: 9ch;
  text-transform: uppercase;
}
.colorbtn { flex: 0 0 auto; width: 40px; font-size: 1rem; }

/* wifi */

#wifi-status { text-align: center; color: var(--dim); font-size: 0.78rem; margin-bottom: 12px; }
#wifi-status.bad { color: var(--miss); }
.joinrow { display: flex; gap: 8px; margin-top: 10px; }
.joinrow input {
  flex: 1;
  background: var(--ground);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.2rem;
  letter-spacing: 0.4em;
  text-align: center;
  text-transform: uppercase;
  border-radius: 12px;
  padding: 10px;
}
#wifi-setup .primary { width: 100%; }
.roomcode { text-align: center; font-family: var(--display); font-size: 1rem; color: var(--dim); margin-bottom: 10px; }
.roomcode span { color: var(--gold); font-size: 1.6rem; letter-spacing: 0.3em; }
#room-qr { display: block; margin: 0 auto 10px; width: min(220px, 60vw); border-radius: 12px; background: #fff; padding: 8px; }
.roomurl { text-align: center; color: var(--dim); font-size: 0.72rem; word-break: break-all; margin-bottom: 10px; }
#room-players { font-size: 0.8rem; text-align: center; color: var(--ink); margin-bottom: 6px; }

.eggfx {
  position: fixed;
  inset: 0;
  z-index: 85;
  pointer-events: none;
  overflow: hidden;
}
.eggfx span { position: absolute; will-change: transform, opacity; }

/* confetti canvas */

#confetti {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 75;
  pointer-events: none;
}

/* focus visibility */

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* reduced motion — system preference or in-app toggle */

/* ---------- phones ---------- */

@media (max-width: 480px) {
  .sheet { padding: 16px 14px; }
  .rank-stamp { top: -8px; right: 6px; font-size: 2rem; padding: 2px 10px; border-width: 2px; }
  .recap-hero .rscore { font-size: 2.7rem; }
  .recap-stats { gap: 6px; margin-top: 12px; }
  .stat b { font-size: 0.88rem; }
  .stat span { font-size: 0.46rem; }
  .moment { gap: 6px 10px; padding: 9px 12px; margin-top: 12px; }
  .moment b { font-size: 0.82rem; }
  .moment .mdigits, .moment em { font-size: 0.74rem; }
  #recap-scores { gap: 12px; }
  .recap-player .rscore { font-size: 1.6rem; }
  .rank-chip { font-size: 0.72rem; margin-left: 5px; }
  #recap-breakdown { font-size: 0.72rem; }
  .lb-submit { flex-wrap: wrap; }
  .lb-submit input { flex: 1 1 40%; }
  .lb-submit button { flex: 1 1 100%; padding: 12px; }
}

/* Landscape phones — 2P face-to-face on one horizontal screen is a first-class mode. */
@media (max-height: 470px) and (orientation: landscape) {
  #topbar { padding: 5px 12px 2px; }
  .brand { font-size: 0.66rem; }
  .iconbtn { padding: 3px 8px; font-size: 0.85rem; }
  #stage { padding: 4px 10px 6px; gap: 8px; }
  .panel { gap: clamp(2px, 1vh, 8px); }
  .panel-head { font-size: 0.7rem; }
  .score { font-size: clamp(2rem, 16vh, 3.4rem); }
  .number { font-size: clamp(1.1rem, 9vh, 1.9rem); }
  .tapsleft { font-size: 0.6rem; }
  .taphint { bottom: 5px; font-size: 0.5rem; }
  .ribbon { top: 8%; padding: 6px 20px; font-size: 0.78rem; }
  #modestrip { padding: 2px 10px calc(5px + env(safe-area-inset-bottom)); gap: 5px; }
  #modestrip button { padding: 7px 4px; font-size: 0.58rem; }
  .cta { min-height: 44px; }
  .cta span { font-size: 0.95rem; }
  .cta i { width: 40px; height: 40px; }

  /* Drawers don't fit sideways — every sheet becomes a centered modal. */
  .sheet {
    left: 50%;
    bottom: auto;
    top: 50%;
    translate: -50% -50%;
    width: min(640px, calc(100vw - 20px));
    max-height: min(94dvh, calc(100dvh - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px 20px;
    animation: recap-pop 260ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sheet h2 { font-size: 0.9rem; margin-bottom: 8px; }
  .setting-row { padding: 7px 0; }
  .sheet-actions { margin-top: 10px; }
  .sheet-actions button, .sheet button { padding: 9px 14px; }
  .recap-hero .rscore { font-size: 2.4rem; }
  .rank-stamp { top: -4px; right: 4px; font-size: 1.7rem; padding: 2px 9px; border-width: 2px; }
  .recap-stats { margin-top: 8px; }
  .stat { padding: 6px 4px 5px; }
  .moment { margin-top: 8px; padding: 7px 12px; }
  .auth-divider { margin: 10px 0 8px; }
  .googlebtn { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel.shake, .banner { animation: none; }
  .number.settle .d { animation: none; }
  .mythic { animation: mythic-fade-rm 1400ms ease both; }
  .puff, .ribbon { animation-name: fadeonly; }
}
html[data-reduced] .panel.shake, html[data-reduced] .banner { animation: none; }
html[data-reduced] .number.settle .d { animation: none; }
html[data-reduced] .puff, html[data-reduced] .ribbon { animation-name: fadeonly; }
@keyframes mythic-fade-rm { 0% { opacity: 0; } 15% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }
@keyframes fadeonly { 0% { opacity: 0; } 15% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }
