:root {
  color-scheme: light;
  --bg: #f4f2ed;
  --surface: #fbfaf7;
  --ink: #16150f;
  --muted: #6b6860;
  --line: #dcd8cd;
  --accent: #d9411e;
  --on-accent: #fff;
  --sea: #dde6e2;
  --sea-line: #c3d2cd;
  --sand: #efe6cf;
  --sand-edge: #cdbf9d;
  --wool: #fffdf6;
  --wool-edge: #d8d2bf;
  --head: #3b3934;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0d;
  --surface: #171714;
  --ink: #ecebe4;
  --muted: #8f8c82;
  --line: #2b2a26;
  --accent: #ff6a3d;
  --on-accent: #16150f;
  --sea: #141d1c;
  --sea-line: #1f2e2c;
  --sand: #3b3629;
  --sand-edge: #26231a;
  --wool: #f1eddf;
  --wool-edge: #8c8670;
  --head: #1d1c18;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font-body); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.icons { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.topbar { border-bottom: 1px solid var(--line); }
.top-inner, main { max-width: 1120px; margin: 0 auto; padding-inline: 24px; }
.top-inner { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { color: var(--ink); text-decoration: none; font: 600 17px var(--font-display); letter-spacing: -.02em; }
.brand-accent { color: var(--accent); }
.top-actions { display: flex; gap: 8px; }
.game-picker { text-decoration: none; }
@media (max-width: 520px) {
  .game-picker span { display: none; }
  .game-picker { width: 38px; padding: 0; }
}
@media (max-width: 410px) {
  .game-picker:not([hidden]) ~ .help-button span { display: none; }
  .game-picker:not([hidden]) ~ .help-button { width: 38px; padding: 0; }
}
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 7px 14px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--ink); font-size: 13px; font-weight: 500; transition: border-color .15s, filter .15s, transform .1s; }
.button:hover:not(:disabled) { border-color: var(--muted); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: .45; }
.icon-button { width: 38px; padding: 0; }
.icon-button[aria-pressed="true"] { border-color: var(--ink); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.button.primary:hover:not(:disabled) { filter: brightness(1.08); border-color: var(--accent); }
.button.wide { width: 100%; margin-top: 12px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase; }
.intro { padding: 40px 0 28px; }
.intro h1 { margin: 0; font: 600 clamp(36px, 5vw, 56px)/1 var(--font-display); letter-spacing: -.04em; }
.intro p { margin: 12px 0 0; color: var(--muted); max-width: 52ch; }
.layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); align-items: start; gap: 24px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.stage-panel { padding: 16px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-heading h2 { margin: 0; font: 600 15px var(--font-display); letter-spacing: -.01em; }
.badge { padding: 2px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.hud { width: min(100%, 640px); margin: 0 auto 10px; display: flex; align-items: center; justify-content: space-between; min-height: 24px; }
.danger { color: var(--accent); font: 600 12px var(--font-display); letter-spacing: .06em; text-transform: uppercase; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.arena-wrap { position: relative; width: min(100%, 640px); margin: 0 auto; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--sea); touch-action: none; user-select: none; }
#arena { display: block; width: 100%; height: 100%; }
.legend { width: min(100%, 640px); margin: 12px auto 0; color: var(--muted); font-size: 12px; }
kbd { padding: 1px 6px; margin: 0 1px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--bg); font: 500 11px var(--font-body); color: var(--ink); }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: color-mix(in srgb, var(--bg) 62%, transparent); backdrop-filter: blur(2px); animation: fade .3s ease both; }
.overlay-card { width: min(92%, 360px); padding: 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: center; animation: rise .35s cubic-bezier(.2,.8,.3,1) both; }
.overlay-card h2 { margin: 0; font: 600 30px/1.1 var(--font-display); letter-spacing: -.03em; }
.overlay-card p:not(.eyebrow) { margin: 8px 0 16px; color: var(--muted); }
.overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.97); } }

.sidebar { display: grid; gap: 12px; }
.score-panel, .setup-panel, .keys-panel { padding: 14px; }
.scores { margin: 12px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.scores li { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 6px 8px; border: 1px solid transparent; border-radius: 8px; transition: opacity .3s, background .3s; }
.scores li.out { opacity: .4; }
.scores li.leader { background: var(--bg); border-color: var(--line); }
.avatar { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--seat); }
.avatar svg { width: 100%; height: 100%; display: block; }
.avatar.bot { border-radius: 8px; }
.eye { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
.scores .who { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pips { display: flex; gap: 4px; }
.pip { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--muted); }
.pip.on { background: var(--accent); border-color: var(--accent); animation: pop .4s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(0); } }
label { display: block; margin-top: 12px; font-size: 13px; font-weight: 500; }
select { display: block; width: 100%; min-height: 40px; margin-top: 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented button { padding: 8px 4px; border: 0; background: transparent; font-weight: 500; color: var(--muted); transition: background .15s, color .15s; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.keys { margin: 12px 0 0; display: grid; gap: 8px; }
.keys div { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.keys dt { color: var(--muted); }
.keys dd { margin: 0; text-align: right; }
footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 28px 2px 32px; color: var(--muted); font-size: 12px; }
footer > span:first-child { display: flex; align-items: center; gap: 7px; font-size: 11px; letter-spacing: .08em; }
.footer-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }

.touch { position: absolute; inset: auto 0 0 0; display: none; justify-content: space-between; align-items: flex-end; padding: 14px 16px; pointer-events: none; }
.stick { position: relative; width: 112px; height: 112px; border-radius: 50%; border: 2px solid var(--line); background: color-mix(in srgb, var(--surface) 70%, transparent); pointer-events: auto; touch-action: none; }
.stick i { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px; border-radius: 50%; background: var(--ink); opacity: .8; }
.zap { width: 92px; height: 92px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); font: 600 13px var(--font-display); pointer-events: auto; touch-action: none; box-shadow: 0 6px 16px -6px var(--accent); }
.zap.held { transform: scale(.92); filter: brightness(1.15); }
@media (pointer: coarse) { .touch:not([hidden]) { display: flex; } }

dialog { width: min(92vw, 440px); max-height: 85dvh; border: 1px solid var(--line); border-radius: 12px; padding: 22px; color: var(--ink); background: var(--surface); box-shadow: 0 20px 60px #0006; }
dialog::backdrop { background: #0008; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dialog-heading h2 { margin: 2px 0 0; font: 600 24px var(--font-display); letter-spacing: -.03em; }
.rules { padding-left: 20px; margin: 0; color: var(--muted); line-height: 1.6; }
.rules li + li { margin-top: 8px; }
.toast { position: fixed; z-index: 30; bottom: 18px; left: 50%; transform: translateX(-50%); width: max-content; max-width: 90vw; padding: 9px 14px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 13px; }

@media (max-width: 900px) {
  .top-inner, main { padding-inline: 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}
@media (max-width: 680px) {
  .top-inner { min-height: 56px; }
  .intro { padding: 24px 0 18px; }
  .stage-panel { padding: 10px; }
  .legend { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (max-width: 360px) {
  .help-button span { display: none; }
  .help-button { width: 38px; padding: 0; }
  .top-actions { gap: 5px; }
}
