/* Who goes first? Light and dark mode via CSS variables. */

:root {
  --bg: #f3edff;
  --bg-2: #e5dbff;
  --surface: #ffffff;
  --ink: #2a2140;
  --ink-soft: #6d6487;
  --line: #ddd3f5;
  --go: #20a868;
  --go-ink: #ffffff;
  --accent: #7950f2;
  --gold: #fcc419;
  --silver: #ced4da;
  --bronze: #e8a26b;
  --mystery: #e5dbff;
  --mystery-q: #9775fa;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1631;
    --bg-2: #241d42;
    --surface: #2a2350;
    --ink: #f7f2ff;
    --ink-soft: #b7add6;
    --line: #3b3368;
    --go: #2fcf83;
    --go-ink: #08281a;
    --accent: #b197fc;
    --mystery: #3b3368;
    --mystery-q: #b197fc;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
body { background: radial-gradient(120% 70% at 50% 0%, var(--bg-2), var(--bg) 70%) fixed; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr;
  padding:
    max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.topbar { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 8px; margin-bottom: 8px; }
.brand { margin: 0; text-align: center; font-size: 1.4rem; font-weight: 900; }
.icon-btn {
  width: 52px; height: 52px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface); box-shadow: 0 2px 0 var(--line);
  display: grid; place-items: center;
}
.icon-btn svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .spk { fill: var(--ink); }
.icon-btn .cross { display: none; }
.icon-btn.is-muted .wave { display: none; }
.icon-btn.is-muted .cross { display: inline; }
#back { grid-column: 1; }
#mute { grid-column: 3; }
.brand { grid-column: 2; grid-row: 1; }

.screen { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.lead { margin: 4px 0 0; text-align: center; font-size: 1.35rem; font-weight: 800; }
.fine { text-align: center; color: var(--ink-soft); font-size: 0.9rem; margin: 8px 0 0; }

.btn {
  min-height: 68px; border-radius: 999px; border: 0;
  font-size: 1.35rem; font-weight: 900; padding: 0 18px;
  transition: transform 0.08s;
}
.btn:active:not(:disabled) { transform: translateY(3px); }
.btn:disabled { opacity: 0.4; }
.btn-go { background: var(--go); color: var(--go-ink); box-shadow: 0 5px 0 color-mix(in srgb, var(--go) 70%, #000); }
.btn-ghost { background: var(--surface); border: 2px solid var(--line); box-shadow: 0 5px 0 var(--line); font-size: 1.1rem; }
.btn.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; margin-top: auto; padding-top: 8px; }

/* ---------- 1. Setup ---------- */
.hero { display: flex; justify-content: center; margin-top: 10px; }
.hero svg { width: min(30vw, 130px); height: auto; margin: 0 -10px; filter: drop-shadow(0 6px 10px rgba(40, 20, 80, 0.18)); }
.hero svg:nth-child(2) { transform: translateY(-14px) scale(1.12); z-index: 1; }
.count-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(100%, 380px); margin: 0 auto; }
.count-btn {
  aspect-ratio: 1.25; border-radius: 24px; border: 2px solid var(--line); background: var(--surface);
  box-shadow: 0 5px 0 var(--line); font-size: 2.4rem; font-weight: 900;
}
.count-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--line); }

/* ---------- 2. Cards ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.cards:is([data-count="5"], [data-count="6"], [data-count="7"], [data-count="8"], [data-count="9"], [data-count="10"]) { grid-template-columns: repeat(3, 1fr); }
.cards:is([data-count="7"], [data-count="8"], [data-count="9"], [data-count="10"]) { gap: 8px; }
.cards:is([data-count="7"], [data-count="8"], [data-count="9"], [data-count="10"]) .card { padding: 8px 4px 6px; }
.cards:is([data-count="7"], [data-count="8"], [data-count="9"], [data-count="10"]) .card svg { max-width: 96px; }
.cards:is([data-count="7"], [data-count="8"], [data-count="9"], [data-count="10"]) .card-name { font-size: 1rem; margin-top: 2px; }
@media (min-width: 620px) {
  .cards[data-count="3"] { grid-template-columns: repeat(3, 1fr); }
  .cards:is([data-count="4"], [data-count="7"], [data-count="8"]) { grid-template-columns: repeat(4, 1fr); }
  .cards:is([data-count="9"], [data-count="10"]) { grid-template-columns: repeat(5, 1fr); }
}
.card {
  border: 2px solid var(--line); border-radius: 24px; background: var(--surface);
  box-shadow: 0 5px 0 var(--line); padding: 12px 8px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.card svg { width: 100%; max-width: 150px; height: auto; display: block; }
.card-name { font-size: 1.15rem; font-weight: 900; margin-top: 4px; }
.card-player { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }
.card.rolling svg { animation: jiggle 0.12s linear infinite alternate; }
@keyframes jiggle { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
.card.landed svg { animation: land 0.5s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes land { from { transform: scale(0.6); } to { transform: scale(1); } }
.card.has-char { border-color: var(--accent); }
.mystery-bg { fill: var(--mystery); }
.mystery-q { fill: var(--mystery-q); font: 900 60px var(--font); }

/* ---------- 3. Order ---------- */
.arena {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  min-height: 120px; padding: 12px; border-radius: 28px;
  background: var(--surface); border: 2px solid var(--line);
}
.arena:empty { display: none; }
.pawn { width: 92px; display: grid; justify-items: center; transition: transform 0.12s; }
.arena:is([data-count="5"], [data-count="6"], [data-count="7"], [data-count="8"]) .pawn { width: 72px; }
.arena:is([data-count="9"], [data-count="10"]) .pawn { width: 62px; }
.arena:is([data-count="9"], [data-count="10"]) .pawn span { font-size: 0.8rem; }
.pawn svg { width: 100%; height: auto; border-radius: 50%; transition: box-shadow 0.12s; }
.pawn span { font-weight: 800; font-size: 0.9rem; margin-top: 2px; }
.pawn.lit { transform: translateY(-6px) scale(1.15); }
.pawn.lit svg { box-shadow: 0 0 0 5px var(--gold), 0 0 26px 6px color-mix(in srgb, var(--gold) 70%, transparent); }

.podium { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.place {
  display: grid; grid-template-columns: 56px 52px 1fr; align-items: center; gap: 10px;
  min-height: 64px; padding: 6px 14px 6px 8px; border-radius: 20px;
  background: var(--surface); border: 2px solid var(--line);
}
.place b {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg-2); font-size: 1.05rem; font-weight: 900;
}
.place:nth-child(1) b { background: var(--gold); color: #3a2600; }
.place:nth-child(2) b { background: var(--silver); color: #212529; }
.place:nth-child(3) b { background: var(--bronze); color: #3a1d00; }
.place svg { width: 52px; height: 52px; }
.pname { font-weight: 800; font-size: 1.1rem; }
.place.empty { border-style: dashed; opacity: 0.6; }
.podium.many .place { min-height: 50px; padding-block: 3px; gap: 8px; grid-template-columns: 44px 40px 1fr; }
.podium.many .place b { width: 40px; height: 40px; font-size: 0.9rem; }
.podium.many .place svg { width: 40px; height: 40px; }
.podium.many .pname { font-size: 1rem; }
.finished .podium.many .place:nth-child(1) { min-height: 64px; grid-template-columns: 44px 52px 1fr; }
.finished .podium.many .place:nth-child(1) svg { width: 52px; height: 52px; }
.place.new { animation: land 0.5s cubic-bezier(.2, 1.8, .4, 1); }
.finished .place:nth-child(1) {
  border-color: var(--gold); min-height: 84px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 40%, transparent);
}
.finished .place:nth-child(1) svg { width: 70px; height: 70px; }
.finished .place:nth-child(1) .pname::after { content: " goes first!"; color: var(--accent); }
.finished .place:nth-child(1) { grid-template-columns: 56px 70px 1fr; }

/* ---------- Confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti i {
  position: absolute; top: -20px; left: var(--x); width: 10px; height: 6px; border-radius: 2px;
  animation: fall var(--d) ease-in var(--delay) forwards;
}
@keyframes fall { to { transform: translateY(105vh) rotate(var(--r)); } }

.noscript { padding: 24px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
