:root {
  --sun: #FFD84D;
  --sun-deep: #F2C21B;
  --ink: #1E2147;
  --tile: #2C3170;
  --paper: #FFF6CF;
  --p0: #FF5A4E;
  --p1: #12B5A0;
  --p2: #3D7BFF;
  --p3: #FF7FC8;
  --radius: 14px;
  font-family: 'Bricolage Grotesque', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--sun); }
body { padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom)); }
main { max-width: 480px; margin: 0 auto; }
[hidden] { display: none !important; }

.top { max-width: 480px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; padding: 12px 0; }
.home { color: var(--ink); font-weight: 800; text-decoration: none; font-size: 15px; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: default; }

.chip { padding: 6px 12px; border-radius: 999px; border: 2px solid var(--ink); font-size: 14px; font-weight: 500; min-height: 36px; }
.big {
  display: block; width: 100%; min-height: 56px; margin: 10px 0; border-radius: var(--radius);
  background: var(--ink); color: var(--paper); font-size: 19px; font-weight: 800;
  box-shadow: 0 5px 0 #0D0F2B; transition: transform .08s, box-shadow .08s;
}
.big:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #0D0F2B; }
.ghost { display: block; width: 100%; min-height: 48px; margin: 6px 0; border-radius: var(--radius); border: 2px solid var(--ink); font-weight: 500; font-size: 17px; }

.screen { padding-top: 8px; }
.logo { font-size: clamp(88px, 30vw, 150px); line-height: .82; font-weight: 800; letter-spacing: -.05em; margin: 12px 0 18px; }
.lede { font-size: 18px; line-height: 1.4; max-width: 34ch; margin: 0 0 24px; }
h2 { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 12px 0 16px; }
.code { background: var(--ink); color: var(--sun); padding: 0 10px; border-radius: 10px; letter-spacing: .08em; }
.field { display: block; font-weight: 500; margin-bottom: 8px; }
.field input, .setup input {
  display: block; width: 100%; margin-top: 6px; min-height: 52px; padding: 0 14px; font: inherit; font-size: 19px;
  border-radius: var(--radius); border: 2px solid var(--ink); background: var(--paper); color: var(--ink);
}
.msg { min-height: 1.4em; font-weight: 500; }

/* Player identity: color + shape, so colorblind players can tell seats apart */
[data-p="0"] { --c: var(--p0); }
[data-p="1"] { --c: var(--p1); }
[data-p="2"] { --c: var(--p2); }
[data-p="3"] { --c: var(--p3); }
.piece {
  position: absolute; inset: 12%; background: var(--c); display: flex; flex-wrap: wrap;
  align-content: center; justify-content: center; gap: 8%; padding: 14%;
  transition: transform .15s ease-out, background-color .15s;
}
.piece[data-p="0"] { border-radius: 50%; }
.piece[data-p="1"] { border-radius: 22%; }
.piece[data-p="2"] { clip-path: polygon(50% 2%, 98% 94%, 2% 94%); padding-top: 34%; }
.piece[data-p="3"] { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); padding: 20%; gap: 4%; }
.piece[data-p="3"] i { width: 32%; } /* % padding is of the cell, so the diamond's content box is small: bigger pip % keeps pips the same size */
.piece i { flex: none; width: 24%; aspect-ratio: 1; border-radius: 50%; background: #fff; }
.piece[data-v="1"] { transform: scale(.68); }
.piece[data-v="2"] { transform: scale(.84); }
.mini { position: relative; display: inline-block; width: 22px; height: 22px; flex: none; }
.mini .piece { inset: 0; padding: 0; }

.seats { list-style: none; padding: 0; margin: 12px 0; }
.seats li { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 12px; margin-bottom: 6px; border-radius: var(--radius); background: var(--paper); font-weight: 500; }
.seats li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seats li .tag { font-size: 13px; opacity: .75; }
.seats li.out { opacity: .45; text-decoration: line-through; }
.seats li .x { min-width: 44px; min-height: 36px; border-radius: 10px; border: 2px solid var(--ink); font-size: 14px; }
.seats.compact { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seats.compact li { margin: 0; min-height: 44px; }
.seats li.turn { box-shadow: inset 0 0 0 3px var(--ink); }

.setup { list-style: none; padding: 0; margin: 0 0 8px; }
.setup li { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.setup input { margin: 0; flex: 1; min-width: 0; }
.setup .kind { min-width: 84px; min-height: 52px; border-radius: var(--radius); border: 2px solid var(--ink); font-weight: 500; }
.setup .kind[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.setup .x { min-width: 44px; min-height: 52px; border-radius: var(--radius); font-size: 22px; }

.banner {
  position: relative; overflow: hidden; display: flex; align-items: center; min-height: 56px; padding: 0 16px 6px;
  border-radius: var(--radius) var(--radius) 0 0; background: var(--c, var(--ink)); color: #fff;
  font-size: 22px; font-weight: 800; transition: background-color .2s;
}
.clock { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: rgba(0,0,0,.25); }
#clock-bar { display: block; height: 100%; width: 100%; background: #fff; transform-origin: left; }

.board-wrap { position: relative; }
.board {
  display: grid; gap: 5px; padding: 8px; background: var(--ink);
  border-radius: 0 0 var(--radius) var(--radius); touch-action: manipulation;
}
.cell { position: relative; aspect-ratio: 1; border-radius: 9px; background: var(--tile); padding: 0; }
.cell.legal { box-shadow: inset 0 0 0 2px rgba(255,246,207,.55); }
.cell.legal:active { background: #3A408A; }
.cell.pop::after {
  content: ''; position: absolute; inset: 10%; border-radius: 50%; border: 4px solid var(--c, #fff);
  animation: ring .35s ease-out forwards; pointer-events: none;
}
@keyframes ring { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.7); opacity: 0; } }

.result {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; padding: 24px;
  background: rgba(30,33,71,.88); border-radius: 0 0 var(--radius) var(--radius); color: var(--paper); text-align: center;
}
#result-text { font-size: 34px; font-weight: 800; margin: 0 0 12px; }
.result .big { background: var(--sun); color: var(--ink); box-shadow: 0 5px 0 var(--sun-deep); }
.result .ghost { border-color: var(--paper); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 999px; font-weight: 500;
  transition: transform .25s, opacity .25s; max-width: calc(100vw - 32px); opacity: 0; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

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