/* Ludo Live: a night game-table look. One committed dark theme: deep navy felt, ivory board, gold for actions.
   Layout: board in the middle with a player plate at each corner; chat rail on the right (below on phones). */
:root {
  --bg0: #0a1124;
  --bg1: #13204a;
  --panel: rgba(255, 255, 255, .055);
  --panel2: rgba(255, 255, 255, .09);
  --solid: #18244d;
  --line: rgba(255, 255, 255, .11);
  --ink: #eef2ff;
  --muted: #9ba7ca;
  --gold: #ffc53d;
  --gold2: #ffad0d;
  --gold-ink: #2b1d00;
  --ok: #3ddc84;
  --danger: #ff6b6b;

  --red: #e5484d;    --red-t: #fbd6d7;    --red-l: #ff8a8d;
  --green: #30a46c;  --green-t: #cdeedc;  --green-l: #6fd9a2;
  --yellow: #f5b301; --yellow-t: #fdecb3; --yellow-l: #ffd75e;
  --blue: #3e7bfa;   --blue-t: #d6e3fe;   --blue-l: #86acff;
  --ivory: #fffaf0;
  --grid: #7a6c55;

  --f-display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --f-body: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  touch-action: manipulation; /* no double-tap zoom while tapping fast in a game */
  background: var(--bg0);
  color: var(--ink);
  font: 15px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  overflow-x: hidden;
}
.backdrop {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(62, 123, 250, .22), transparent 60%),
    radial-gradient(700px 500px at 110% 20%, rgba(229, 72, 77, .14), transparent 60%),
    radial-gradient(800px 600px at 50% 120%, rgba(48, 164, 108, .14), transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--bg0) 70%);
}
.backdrop::after {
  content: ""; position: absolute; inset: 0; opacity: .5;
  background-image: radial-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px);
  background-size: 22px 22px;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; margin: 0; line-height: 1.15; text-wrap: balance; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.sw-red { background: var(--red); } .sw-green { background: var(--green); } .sw-yellow { background: var(--yellow); } .sw-blue { background: var(--blue); }
.c-red { color: var(--red-l); } .c-green { color: var(--green-l); } .c-yellow { color: var(--yellow-l); } .c-blue { color: var(--blue-l); }

/* ---------- top bar ---------- */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 31; background: var(--bg1); }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  background: rgba(10, 17, 36, .72); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font: 700 1.3rem var(--f-display); letter-spacing: .01em; }
.mark { display: grid; grid-template-columns: 1fr 1fr; width: 30px; height: 30px; border-radius: 9px; overflow: hidden; position: relative; transform: rotate(-8deg); box-shadow: 0 4px 12px rgba(0, 0, 0, .35); }
.mark i:nth-child(1) { background: var(--red); } .mark i:nth-child(2) { background: var(--green); }
.mark i:nth-child(3) { background: var(--blue); } .mark i:nth-child(4) { background: var(--yellow); }
.mark::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: var(--ivory); }
.top-right { display: flex; align-items: center; gap: 8px; }
.chip { font: 600 .9rem var(--f-display); letter-spacing: .14em; padding: 6px 12px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); cursor: pointer; }
.chip:hover { background: rgba(255, 255, 255, .14); }
.conn { font-size: .8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 3px rgba(255, 107, 107, .2); }
.conn[data-state="on"]::before { background: var(--ok); box-shadow: 0 0 0 3px rgba(61, 220, 132, .2); }
@media (max-width: 520px) { .conn-label { display: none; } }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; color: var(--ink); }
.icon-btn:hover { background: var(--panel2); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .mute { display: none; }
.icon-btn[aria-pressed="false"] .mute { display: inline; }
.icon-btn[aria-pressed="false"] .wave { display: none; }

/* ---------- buttons / inputs / panels ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); font-weight: 800; cursor: pointer;
  transition: transform .08s ease, background .15s ease, box-shadow .15s, opacity .15s;
  touch-action: manipulation;
}
.btn:hover { background: rgba(255, 255, 255, .15); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn.gold {
  background: linear-gradient(180deg, var(--gold), var(--gold2)); color: var(--gold-ink); border-color: transparent;
  box-shadow: 0 4px 0 #c27c00, 0 8px 20px rgba(255, 173, 13, .25);
}
.btn.gold:hover { filter: brightness(1.05); }
.btn.gold:active { transform: translateY(3px); box-shadow: 0 1px 0 #c27c00, 0 4px 10px rgba(255, 173, 13, .2); }
.btn.gold:disabled { box-shadow: none; filter: grayscale(.6); }
.btn.big { padding: 15px 20px; font-size: 1.08rem; width: 100%; }
.btn.small { padding: 7px 12px; font-size: .85rem; border-radius: 11px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
input, select {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, .25); outline: none; color: var(--ink);
}
input::placeholder { color: #6f7ba0; }
input:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 197, 61, .18); }
select option { background: var(--solid); }
.label { font-weight: 800; font-size: .85rem; color: var(--muted); letter-spacing: .02em; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; min-width: 0;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.eyebrow { font: 600 .78rem var(--f-display); letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.err { color: var(--danger); font-weight: 800; font-size: .9rem; }

/* ---------- home ---------- */
.home {
  max-width: 1120px; margin: 0 auto;
  padding: 28px max(16px, env(safe-area-inset-right, 0px)) 56px max(16px, env(safe-area-inset-left, 0px));
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start;
}
.hero { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 28px; align-items: center; padding: 8px 0 12px; }
.hero-copy { display: grid; gap: 14px; }
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.5rem); font-weight: 700; max-width: 15ch; }
.lede { color: var(--muted); max-width: 56ch; font-size: 1.06rem; }
.perks { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.perks li { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); font-weight: 700; font-size: .88rem; }
.hero-art { justify-self: center; width: min(340px, 100%); aspect-ratio: 1; padding: 12px; border-radius: 26px; background: linear-gradient(145deg, #3a2a17, #20160b); box-shadow: 0 30px 60px rgba(0, 0, 0, .45), inset 0 0 0 2px rgba(255, 255, 255, .06); transform: rotate(4deg); }
.hero-art svg { width: 100%; height: 100%; display: block; border-radius: 14px; }
.start-card { display: grid; gap: 16px; grid-row: span 2; }
.field { display: grid; gap: 8px; }
.avatar-picker { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.avatar-picker button {
  aspect-ratio: 1; border-radius: 12px; border: 2px solid transparent; background: rgba(0, 0, 0, .22);
  font-size: clamp(1.15rem, 3.2vw, 1.5rem); cursor: pointer; display: grid; place-items: center; transition: transform .1s, border-color .1s;
}
.avatar-picker button:hover { transform: scale(1.08); }
.avatar-picker button[aria-checked="true"] { border-color: var(--gold); background: rgba(255, 197, 61, .14); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; font-weight: 700; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: .3em; font: 600 1.15rem var(--f-display); text-align: center; }
.live-dot { font-size: .78rem; font-weight: 800; color: var(--ok); display: inline-flex; align-items: center; gap: 6px; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.table-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.table-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: rgba(0, 0, 0, .2); }
.t-av { font-size: 1.5rem; }
.t-main { flex: 1; min-width: 0; display: grid; }
.t-code { font: 600 1rem var(--f-display); letter-spacing: .12em; }
.t-meta { font-size: .84rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pips { display: inline-flex; gap: 3px; }
.pips b { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .15); }
.how { margin: 12px 0 0; padding-left: 20px; display: grid; gap: 9px; color: var(--muted); }
.how b { color: var(--ink); }
@media (max-width: 860px) {
  .home { grid-template-columns: minmax(0, 1fr); }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-art { width: min(240px, 70%); order: -1; }
  .start-card { grid-row: auto; }
}

/* ---------- room layout ---------- */
.room {
  max-width: 1240px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px));
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start;
}
@media (max-width: 960px) { .room { grid-template-columns: minmax(0, 1fr); padding-bottom: 90px; } }
.side { display: grid; gap: 14px; min-width: 0; position: sticky; top: 80px; }
@media (max-width: 960px) { .side { position: static; } }

/* ---------- game ---------- */
.game { width: 100%; max-width: min(660px, max(380px, calc(100vh - 210px))); margin: 0 auto; display: grid; gap: 10px; }
@media (max-width: 960px) { .game { max-width: 640px; } }
.plates { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.plate {
  --c: var(--muted);
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; min-height: 74px; min-width: 0;
  border-radius: 18px; background: var(--panel); border: 2px solid var(--line);
  transition: border-color .2s, background .2s, transform .2s, box-shadow .2s;
}
.plate[data-c="red"] { --c: var(--red); } .plate[data-c="green"] { --c: var(--green); }
.plate[data-c="yellow"] { --c: var(--yellow); } .plate[data-c="blue"] { --c: var(--blue); }
#plate-green, #plate-yellow { flex-direction: row-reverse; text-align: right; }
.plate.empty { opacity: .35; }
.plate.active { border-color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 18%, transparent), 0 10px 26px rgba(0, 0, 0, .3); }
.plate.done { opacity: .75; }
.avatar { position: relative; width: 52px; height: 52px; flex: none; display: grid; place-items: center; }
.avatar .emoji { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.55rem; background: color-mix(in srgb, var(--c) 30%, #0d1530); box-shadow: inset 0 0 0 2px var(--c); }
.avatar svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.avatar .track { fill: none; stroke: transparent; stroke-width: 4; }
.avatar .prog { fill: none; stroke: var(--c); stroke-width: 4; stroke-linecap: round; transition: stroke-dashoffset .25s linear, stroke .2s; }
.avatar .prog.low { stroke: var(--danger); }
.avatar .medal { position: absolute; right: -4px; bottom: -4px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 99px; background: var(--gold); color: var(--gold-ink); font: 700 .72rem/22px var(--f-display); text-align: center; }
.avatar .off { position: absolute; left: 2px; bottom: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--bg0); }
.avatar .off.is-off { background: #6b7280; }
.pinfo { min-width: 0; flex: 1; display: grid; gap: 1px; }
.pname { font: 600 1rem var(--f-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pstat { font-size: .78rem; font-weight: 800; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate.active .pstat { color: var(--ink); }
.pdots { display: flex; gap: 3px; }
#plate-green .pdots, #plate-yellow .pdots { justify-content: flex-end; }
.pdots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, .14); }
.pdots i.out { background: color-mix(in srgb, var(--c) 55%, transparent); }
.pdots i.home { background: var(--c); box-shadow: 0 0 6px var(--c); }
.dice-slot { flex: none; width: 58px; height: 58px; display: grid; place-items: center; }
@media (max-width: 480px) {
  .plates { gap: 8px; }
  .plate { gap: 6px; padding: 6px; min-height: 60px; border-radius: 14px; }
  .avatar { width: 36px; height: 36px; }
  .avatar .emoji { width: 30px; height: 30px; font-size: 1.05rem; }
  .avatar .medal { min-width: 18px; height: 18px; font-size: .62rem; line-height: 18px; right: -6px; bottom: -6px; }
  .pname { font-size: .84rem; }
  .pstat { font-size: .7rem; }
  .pdots i { width: 7px; height: 7px; }
  .dice-slot { width: 42px; height: 42px; }
  .plate.empty .dice-slot { display: none; }
}

.dice {
  --dc: var(--muted);
  width: 54px; height: 54px; border-radius: 14px; border: 0; padding: 8px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); place-items: center;
  background: linear-gradient(160deg, #ffffff, #e9e6dd);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .13), 0 0 0 3px var(--dc), 0 6px 14px rgba(0, 0, 0, .35);
  cursor: default; transition: transform .12s;
  touch-action: manipulation;
}
.dice i { width: 9px; height: 9px; border-radius: 50%; background: #1b1b1b; opacity: 0; }
.dice[data-v="1"] i:nth-child(5),
.dice[data-v="2"] i:nth-child(1), .dice[data-v="2"] i:nth-child(9),
.dice[data-v="3"] i:nth-child(1), .dice[data-v="3"] i:nth-child(5), .dice[data-v="3"] i:nth-child(9),
.dice[data-v="4"] i:nth-child(1), .dice[data-v="4"] i:nth-child(3), .dice[data-v="4"] i:nth-child(7), .dice[data-v="4"] i:nth-child(9),
.dice[data-v="5"] i:nth-child(1), .dice[data-v="5"] i:nth-child(3), .dice[data-v="5"] i:nth-child(5), .dice[data-v="5"] i:nth-child(7), .dice[data-v="5"] i:nth-child(9),
.dice[data-v="6"] i:nth-child(1), .dice[data-v="6"] i:nth-child(3), .dice[data-v="6"] i:nth-child(4), .dice[data-v="6"] i:nth-child(6), .dice[data-v="6"] i:nth-child(7), .dice[data-v="6"] i:nth-child(9) { opacity: 1; }
.dice[data-v="1"] i:nth-child(5) { background: var(--red); width: 13px; height: 13px; }
/* blank die = "not rolled yet this turn": never shows an old number */
.dice { position: relative; }
.dice[data-v="0"] i { opacity: 0 !important; }
.dice.ready[data-v="0"]::after {
  content: "TAP"; position: absolute; inset: 0; display: grid; place-items: center;
  font: 700 .8rem var(--f-display); letter-spacing: .08em; color: #1b2236;
}
.dice.ready { cursor: pointer; animation: nudge 1.3s ease-in-out infinite; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .13), 0 0 0 3px var(--dc), 0 0 0 8px color-mix(in srgb, var(--dc) 35%, transparent), 0 6px 14px rgba(0, 0, 0, .35); }
.dice.ready:hover { transform: scale(1.07); }
.dice.rolling { animation: tumble 1s cubic-bezier(.25, .8, .35, 1) forwards; }
.dice.landed { animation: land .3s ease-out; }
@keyframes land { 0% { transform: scale(1.18); } 60% { transform: scale(.94); } 100% { transform: scale(1); } }
.dice.waiting { opacity: .7; }
@keyframes nudge { 0%, 100% { transform: rotate(0); } 8% { transform: rotate(-10deg) scale(1.05); } 16% { transform: rotate(8deg) scale(1.05); } 24% { transform: rotate(0); } }
@keyframes tumble {
  0% { transform: rotate(0) scale(1); }
  20% { transform: rotate(250deg) scale(.86) translateY(-8px); }
  45% { transform: rotate(480deg) scale(1.06) translateY(2px); }
  70% { transform: rotate(640deg) scale(.96) translateY(-3px); }
  100% { transform: rotate(720deg) scale(1); }
}
@media (max-width: 480px) { .dice { width: 40px; height: 40px; padding: 6px; border-radius: 11px; } .dice i { width: 6px; height: 6px; } .dice[data-v="1"] i:nth-child(5) { width: 10px; height: 10px; } }

.board-wrap {
  position: relative; width: 100%; aspect-ratio: 1; padding: 12px; border-radius: 26px;
  background: linear-gradient(145deg, #3d2c18, #1f150a);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .5), inset 0 0 0 2px rgba(255, 255, 255, .06), inset 0 2px 0 rgba(255, 255, 255, .08);
}
@media (max-width: 520px) { .board-wrap { padding: 6px; border-radius: 16px; } }
#board { width: 100%; height: 100%; display: block; border-radius: 14px; overflow: visible; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }

.tok { transition: transform .15s ease-out; cursor: default; }
.tok .ring { fill: none; stroke: #fff; stroke-width: .075; opacity: 0; }
.tok .ring2 { fill: none; stroke: #111; stroke-width: .05; stroke-dasharray: .22 .12; opacity: 0; }
.tok.can { cursor: pointer; }
.tok.can .ring { opacity: 1; animation: softblink 1.2s ease-in-out infinite; }
.tok.can .ring2 { opacity: .9; animation: spin 1.1s linear infinite; }
/* The browser's focus outline is measured in board units inside the SVG (1 unit = 1 square), so a
   "5px" ring becomes 5 squares wide. Never draw it on the board; keyboard focus gets a gold ring instead. */
#board, #board * { outline: none !important; }
.tok:focus-visible .ring2 { opacity: 1; stroke: var(--gold); stroke-dasharray: none; stroke-width: .08; }
/* SVG transforms default to the board's top-left corner; pin them to the pawn itself */
.tok .pawn, .tok .ring, .tok .ring2 { transform-box: fill-box; transform-origin: 50% 50%; }
.tok.can .pawn { animation: hop .8s ease-in-out infinite; }
.tok.can:hover .pawn, .tok.can:focus .pawn { filter: brightness(1.18) drop-shadow(0 0 .08px #fff); }
.tok.last .ring { opacity: .7; stroke: var(--gold); stroke-width: .06; }
@keyframes spin { to { stroke-dashoffset: -.68; } }
@keyframes hop { 50% { transform: translateY(-.09px); } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes softblink { 50% { opacity: .45; } }
.ghost { pointer-events: none; opacity: 0; transition: opacity .15s; }
.ghost.on { opacity: 1; }
.ghost circle { animation: pulse 1s ease-in-out infinite; }
.yglow { fill: none; stroke: #fff; stroke-width: .2; opacity: 0; transition: opacity .3s; }
.yglow.on { opacity: .95; animation: glow 1.3s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .3; } }
.nostars .star-safe { opacity: .15; }

.fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 26px; }
.float { position: absolute; bottom: 10%; display: grid; justify-items: center; gap: 2px; animation: floatUp 2.4s ease-out forwards; }
.float .e { font-size: clamp(36px, 8vw, 58px); line-height: 1; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .35)); }
.float .n { font: 800 .75rem var(--f-body); padding: 2px 9px; border-radius: 99px; background: rgba(10, 17, 36, .85); color: #fff; }
@keyframes floatUp { 0% { transform: translateY(20px) scale(.5); opacity: 0; } 15% { transform: translateY(0) scale(1.15); opacity: 1; } 100% { transform: translateY(-280px) scale(1); opacity: 0; } }
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font: 700 clamp(1.3rem, 4.5vw, 2.1rem) var(--f-display); color: #fff; padding: 10px 24px; border-radius: 18px;
  background: rgba(10, 17, 36, .88); border: 2px solid var(--bc, var(--gold)); animation: pop 1.4s ease forwards; white-space: nowrap;
  box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
}
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1); } }

.result {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(8, 12, 26, .62); border-radius: 26px; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.result-card { background: var(--solid); border: 1px solid var(--line); border-radius: 22px; padding: 22px; width: min(380px, 100%); display: grid; gap: 14px; box-shadow: 0 30px 60px rgba(0, 0, 0, .5); animation: rise .4s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.result-card .trophy { font-size: 3rem; text-align: center; line-height: 1; }
.result-card h2 { font-size: 1.7rem; text-align: center; }
.rank { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 14px; background: rgba(0, 0, 0, .25); font-weight: 800; }
.rank li:first-child { background: rgba(255, 197, 61, .16); box-shadow: inset 0 0 0 1px rgba(255, 197, 61, .4); }
.rank .place { font: 700 1rem var(--f-display); width: 2.3em; color: var(--gold); }
.rank .ra { font-size: 1.3rem; }
.result-actions { display: flex; gap: 8px; }
.result-actions .btn { flex: 1; }

.game-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 2px 2px 0; }
.prompt { font: 600 1.1rem var(--f-display); min-width: 0; }
.big-roll { flex: 1 1 100%; padding: 15px 20px; font: 700 1.2rem var(--f-display); letter-spacing: .02em; }
.prompt .you { color: var(--gold); }
.game-tools { display: flex; gap: 8px; }
.btn[aria-pressed="true"] { background: rgba(61, 220, 132, .18); border-color: rgba(61, 220, 132, .5); color: var(--ok); }

/* ---------- lobby ---------- */
.lobby { display: grid; gap: 16px; }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.lobby-head h2 { font-size: clamp(2rem, 6vw, 3rem); letter-spacing: .14em; font-weight: 700; }
.lobby-head p.muted { max-width: 46ch; }
.invite { display: flex; gap: 8px; flex-wrap: wrap; }
.seats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 560px) { .seats { grid-template-columns: minmax(0, 1fr); } }
.seat {
  --c: var(--muted);
  border-radius: var(--r); padding: 14px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; align-items: center;
  background: var(--panel); border: 2px dashed var(--line); min-height: 108px; position: relative;
}
.seat[data-c="red"] { --c: var(--red); } .seat[data-c="green"] { --c: var(--green); }
.seat[data-c="yellow"] { --c: var(--yellow); } .seat[data-c="blue"] { --c: var(--blue); }
.seat.filled { border-style: solid; border-color: color-mix(in srgb, var(--c) 70%, transparent); background: color-mix(in srgb, var(--c) 12%, transparent); }
.seat .avatar { grid-row: span 2; }
.seat.open .avatar .emoji { background: transparent; box-shadow: inset 0 0 0 2px var(--c); opacity: .6; font-size: 1.2rem; }
.seat-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.seat-color { font: 600 .74rem var(--f-display); letter-spacing: .14em; text-transform: uppercase; color: var(--c); filter: brightness(1.25); }
.seat-name { font: 600 1.15rem var(--f-display); overflow-wrap: anywhere; }
.seat-name em { font-style: normal; color: var(--muted); font-size: .88rem; }
.seat-empty { color: var(--muted); font-weight: 700; }
.tag { font-size: .7rem; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: rgba(255, 255, 255, .09); color: var(--muted); }
.tag.on { color: var(--ok); background: rgba(61, 220, 132, .12); }
.tag.host { color: var(--gold); background: rgba(255, 197, 61, .12); }
.seat-btns { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.rules-box { display: grid; gap: 4px; }
.rules-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 22px; }
@media (max-width: 640px) { .rules-grid { grid-template-columns: minmax(0, 1fr); } }
.rule { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.rule span:first-child { font-weight: 700; }
.rule select { width: auto; padding: 7px 10px; border-radius: 10px; }
.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch b { position: absolute; inset: 0; border-radius: 99px; background: rgba(255, 255, 255, .16); transition: background .15s; }
.switch b::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.switch input:checked + b { background: var(--ok); }
.switch input:checked + b::after { transform: translateX(19px); }
.switch input:focus-visible + b { outline: 3px solid var(--gold); outline-offset: 2px; }
.switch input:disabled { cursor: not-allowed; }
.lobby-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.lobby-actions .gold { flex: 1; min-width: 220px; }

/* ---------- chat & log ---------- */
.chat-card { display: grid; gap: 10px; }
.chat-card .panel-head { margin: 0; }
.reacts { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.reacts button { font-size: 1.2rem; aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .2); cursor: pointer; transition: transform .1s; padding: 0; }
.reacts button:hover { transform: scale(1.12); background: rgba(255, 255, 255, .08); }
.chat-list { list-style: none; margin: 0; padding: 4px 2px; display: flex; flex-direction: column; gap: 10px; height: 300px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 92%; }
.msg .mav { font-size: 1.2rem; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .08); flex: none; }
.msg .mbody { display: grid; gap: 2px; min-width: 0; }
.msg .who { font-size: .74rem; font-weight: 800; }
.msg .txt { padding: 8px 12px; border-radius: 16px 16px 16px 5px; background: rgba(255, 255, 255, .09); overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.me .mbody { justify-items: end; }
.msg.me .txt { background: linear-gradient(180deg, var(--gold), var(--gold2)); color: var(--gold-ink); border-radius: 16px 16px 5px 16px; font-weight: 700; }
.msg .time { font-size: .68rem; color: #6f7ba0; }
.chat-empty { color: var(--muted); font-size: .9rem; margin: auto; text-align: center; max-width: 24ch; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; }
.chat-form .btn { padding: 0 16px; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .86rem; max-height: 210px; overflow-y: auto; scrollbar-width: thin; }
.log li { display: flex; gap: 8px; align-items: baseline; color: var(--muted); }
.log li .sw { transform: translateY(1px); width: 9px; height: 9px; }
.log li:first-child { color: var(--ink); font-weight: 800; }

.chat-fab {
  position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  display: none; align-items: center; gap: 8px; padding: 12px 18px; border-radius: 99px; border: 0; cursor: pointer;
  background: linear-gradient(180deg, var(--gold), var(--gold2)); color: var(--gold-ink); font-weight: 800;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .45);
}
@media (max-width: 960px) { .chat-fab:not([hidden]) { display: inline-flex; } }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--danger); color: #fff; font-size: .75rem; line-height: 20px; text-align: center; }

/* ---------- toast & confetti ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--ivory); color: #1b2236; font-weight: 800; box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

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