:root {
  --bg: #1b1440;
  --bg2: #261d57;
  --card: #30266b;
  --card2: #3b3080;
  --ink: #ffffff;
  --muted: #b7b0e0;
  --accent: #ffd23f;
  --accent-ink: #1b1440;
  --good: #22c55e;
  --bad: #ff5a5f;
  --line: rgba(255,255,255,.14);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #3a2a8a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 16px/1.4 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
#app { min-height: 100%; max-width: 560px; margin: 0 auto; padding: calc(12px + var(--safe-t)) 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; }
h1, h2, h3 { margin: 0; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
input { font: inherit; }

.btn { background: var(--accent); color: var(--accent-ink); font-weight: 800; padding: 14px 18px; border-radius: 14px; font-size: 17px; width: 100%; box-shadow: 0 4px 0 #c99a00; transition: transform .06s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c99a00; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.ghost { background: var(--card2); color: var(--ink); box-shadow: 0 4px 0 #221a52; }
.btn.small { padding: 9px 14px; font-size: 15px; width: auto; }
.row { display: flex; gap: 10px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.center { text-align: center; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; }
.field { width: 100%; background: var(--bg2); border: 2px solid var(--line); color: var(--ink); padding: 14px; border-radius: 14px; font-size: 18px; outline: none; -webkit-user-select: text; user-select: text; }
.field:focus { border-color: var(--accent); }
.code-input { text-transform: uppercase; letter-spacing: .35em; text-align: center; font-weight: 800; }

/* home */
.logo { font-size: 52px; font-weight: 900; letter-spacing: -1px; text-align: center; margin: 28px 0 0; }
.logo span { color: var(--accent); }
.tagline { text-align: center; color: var(--muted); margin: 4px 0 22px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.game-strip { display: flex; justify-content: center; gap: 10px; font-size: 28px; margin-top: 18px; }

/* lobby */
.room-code { font-size: 44px; font-weight: 900; letter-spacing: .18em; text-align: center; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pl { display: flex; align-items: center; gap: 8px; background: var(--bg2); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.pl .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.pl.off { opacity: .5; }
.dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; color: #fff; flex: none; }
.empty-seat { border: 2px dashed var(--line); background: transparent; color: var(--muted); justify-content: center; }
.kick { background: none; color: var(--muted); padding: 2px 6px; font-size: 18px; }
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gtile { background: var(--bg2); border: 3px solid transparent; border-radius: 16px; padding: 12px; text-align: left; }
.gtile.sel { border-color: var(--accent); background: var(--card2); }
.gtile .e { font-size: 30px; }
.gtile .n { font-weight: 800; margin-top: 2px; }
.gtile .p { font-size: 12px; color: var(--muted); }
.gtile.nope { opacity: .45; }

/* game chrome */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.topbar .title { font-weight: 800; flex: 1; }
.iconbtn { background: var(--card); width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: 999px; padding: 4px 10px 4px 4px; flex: none; border: 2px solid transparent; font-size: 14px; }
.chip.turn { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,210,63,.25); }
.chip.gone { opacity: .4; text-decoration: line-through; }
.chip .dot { width: 24px; height: 24px; font-size: 12px; }
.chip b { font-variant-numeric: tabular-nums; }
.status { text-align: center; font-weight: 700; min-height: 26px; margin: 4px 0 8px; }
.status.mine { color: var(--accent); }
.skipbar { display: flex; justify-content: center; min-height: 0; margin: -4px 0 6px; }
.skip-btn { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #a8343a; }
.skip-warn { background: rgba(255,90,95,.18); color: #ffb3b6; font-weight: 700; padding: 6px 12px; border-radius: 999px; font-size: 14px; }
.skip-note { font-size: 13px; }
.stage { flex: 1; display: flex; flex-direction: column; }
.react-bar { display: flex; justify-content: space-around; margin-top: 12px; }
.react-bar button { background: none; font-size: 24px; padding: 4px 8px; opacity: .8; }
.react-bar button:active { transform: scale(1.3); }

/* end-of-game overlay */
.overlay { position: fixed; inset: 0; background: rgba(10,6,30,.72); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade .2s; }
.sheet { background: var(--bg2); width: 100%; max-width: 560px; border-radius: 24px 24px 0 0; padding: 20px 16px calc(20px + var(--safe-b)); max-height: 88vh; overflow-y: auto; animation: up .25s ease-out; }
.trophy { font-size: 54px; text-align: center; }
.rank { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rank:last-child { border: 0; }
.rank .pos { width: 22px; color: var(--muted); font-weight: 800; }
@keyframes fade { from { opacity: 0 } }
@keyframes up { from { transform: translateY(40px); opacity: 0 } }

#toast { position: fixed; left: 50%; top: calc(14px + var(--safe-t)); transform: translateX(-50%) translateY(-120px); background: #fff; color: #1b1440; font-weight: 700; padding: 10px 16px; border-radius: 999px; z-index: 50; transition: transform .25s; max-width: 90vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }
#reactions { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.floater { position: absolute; bottom: 80px; font-size: 40px; animation: float 2.2s ease-out forwards; text-align: center; }
.floater small { display: block; font-size: 12px; font-weight: 700; background: rgba(0,0,0,.4); border-radius: 8px; padding: 1px 6px; }
@keyframes float { to { transform: translateY(-55vh) scale(1.2); opacity: 0; } }
.conn { position: fixed; bottom: calc(8px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: var(--bad); padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; z-index: 30; }

/* ---------- Word Hunt ---------- */
.wh-timer { font-size: 28px; font-weight: 900; text-align: center; font-variant-numeric: tabular-nums; }
.wh-timer.low { color: var(--bad); }
.wh-word { height: 44px; text-align: center; font-size: 26px; font-weight: 900; letter-spacing: .08em; }
.wh-word.ok { color: var(--good); } .wh-word.bad { color: var(--bad); } .wh-word.dupe { color: var(--accent); }
.wh-board { position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; touch-action: none; width: 100%; max-width: 380px; margin: 0 auto; aspect-ratio: 1; }
.wh-tile { background: #f7f0dc; color: #2a1d10; border-radius: 16px; display: grid; place-items: center; font-size: clamp(28px, 9vw, 42px); font-weight: 900; box-shadow: 0 5px 0 #c9b98f; transition: background .1s, transform .1s; }
.wh-tile.on { background: var(--accent); transform: scale(.94); }
.wh-tile.ok { background: #7ee2a0; } .wh-tile.bad { background: #ff9b9e; }
.wh-svg { position: absolute; inset: 0; pointer-events: none; }
.wh-found { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; max-height: 120px; overflow-y: auto; }
.wh-found span { background: var(--card); border-radius: 8px; padding: 2px 8px; font-size: 14px; text-transform: uppercase; }
.wordlist { display: flex; flex-wrap: wrap; gap: 4px; font-size: 13px; text-transform: uppercase; color: var(--muted); }
.wordlist span { background: var(--card); border-radius: 6px; padding: 1px 6px; }

/* ---------- Dots ---------- */
.dots-wrap { width: 100%; max-width: 420px; margin: 8px auto 0; touch-action: manipulation; }
.dots-wrap svg { width: 100%; height: auto; display: block; }
.dl-hit { stroke: transparent; stroke-width: 26; cursor: pointer; }
.dl { stroke: rgba(255,255,255,.12); stroke-width: 7; stroke-linecap: round; pointer-events: none; }
.dl-hit:hover + .dl { stroke: rgba(255,255,255,.35); }
.dl.last { animation: pulse 1s ease-in-out 2; }
@keyframes pulse { 50% { stroke-width: 12; } }

/* ---------- Dice ---------- */
.dice-row { display: flex; justify-content: center; gap: 10px; margin: 6px 0 12px; }
.die { width: 56px; height: 56px; border-radius: 14px; background: #fff; display: grid; grid-template: repeat(3,1fr)/repeat(3,1fr); padding: 7px; box-shadow: 0 5px 0 #c9c3e8; position: relative; transition: transform .15s; }
.die i { width: 11px; height: 11px; border-radius: 50%; background: #1b1440; place-self: center; }
.die.held { background: var(--accent); box-shadow: 0 5px 0 #c99a00; transform: translateY(-6px); }
.die.held::after { content: "HOLD"; position: absolute; bottom: -22px; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 800; color: var(--accent); }
.die.blank { opacity: .35; }
.die.roll { animation: shake .45s; }
@keyframes shake { 20% { transform: rotate(-18deg) } 40% { transform: rotate(14deg) } 60% { transform: rotate(-10deg) } 80% { transform: rotate(6deg) } }
.score-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 10px; }
.score-table th, .score-table td { padding: 5px 3px; text-align: center; border-bottom: 1px solid var(--line); }
.score-table td:first-child, .score-table th:first-child { text-align: left; color: var(--muted); white-space: nowrap; }
.score-table td.pick { color: var(--accent); font-weight: 800; background: rgba(255,210,63,.1); border-radius: 6px; cursor: pointer; }
.score-table td.pick.zero { color: var(--muted); }
.score-table td.mine { background: rgba(255,255,255,.04); }
.score-table tr.tot td { font-weight: 800; color: var(--ink); }
.score-table td.fresh { animation: flash 1.2s; }
@keyframes flash { 0% { background: var(--accent); color: var(--accent-ink) } }

/* ---------- Eights ---------- */
.e-table { display: flex; justify-content: center; align-items: center; gap: 22px; margin: 14px 0; }
.pcard { width: 64px; height: 92px; border-radius: 10px; background: #fff; color: #111; display: flex; flex-direction: column; justify-content: space-between; padding: 5px 6px; font-weight: 800; box-shadow: 0 3px 8px rgba(0,0,0,.35); flex: none; position: relative; }
.pcard.red { color: #d0263a; }
.pcard .big { font-size: 30px; text-align: center; line-height: 1; }
.pcard .tl { font-size: 15px; line-height: 1; }
.pcard.back { background: repeating-linear-gradient(45deg, #5b48c9 0 8px, #4a39b0 8px 16px); border: 3px solid #fff; }
.pcard.back span { margin: auto; color: #fff; font-size: 13px; }
.pcard.big-c { width: 84px; height: 120px; }
.pcard.big-c .big { font-size: 42px; }
.suit-badge { font-size: 13px; text-align: center; margin-top: 4px; }
.hand { display: flex; overflow-x: auto; padding: 18px 6px 10px; gap: 0; scrollbar-width: none; justify-content: safe center; }
.hand::-webkit-scrollbar { display: none; }
.hand .pcard { margin-left: -18px; transition: transform .12s; }
.hand .pcard:first-child { margin-left: 0; }
.hand .pcard.can { transform: translateY(-12px); box-shadow: 0 0 0 3px var(--accent), 0 6px 12px rgba(0,0,0,.4); }
.hand .pcard.cant { filter: brightness(.6); }
.opps { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.opp { background: var(--card); border-radius: 12px; padding: 6px 10px; display: flex; align-items: center; gap: 6px; font-size: 14px; border: 2px solid transparent; }
.opp.turn { border-color: var(--accent); }
.suit-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.suit-pick button { background: #fff; border-radius: 14px; font-size: 40px; padding: 10px 0; }
