:root {
  --bg: #14131a; --felt: #1d2a24; --felt-2: #22332b; --ink: #f3efe6; --muted: #a49f93; --line: #ffffff1a;
  --accent: #e8b04a; --win: #6fd08c; --stun: #f0c94a; --lost: #ef6a5a; --push: #9aa3b5;
  --d4: #e5604d; --d6: #f0a33a; --d8: #e3cf45; --d10: #5cc27a; --d12: #4aa3e8; --d20: #9b6be8; --d100: #e46cb4;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { background: radial-gradient(120% 80% at 50% 0%, #26352e 0%, var(--felt) 45%, var(--bg) 100%) fixed; }
#app { max-width: 760px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0; line-height: 1.15; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; border-radius: 12px; padding: 12px 16px; background: #ffffff14; transition: transform .08s, background .15s, opacity .15s; }
button:active { transform: scale(.97); }
button.primary { background: var(--accent); color: #1a1408; font-weight: 700; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button:disabled { opacity: .4; cursor: default; }
input { font: inherit; color: var(--ink); background: #00000040; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.card { background: #0000002e; border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.stack { display: grid; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }

/* home */
.hero { text-align: center; padding: 28px 0 18px; }
.hero h1 { font-size: clamp(34px, 9vw, 54px); letter-spacing: -.02em; }
.hero .dice-strip { display: flex; justify-content: center; gap: 6px; margin: 0 0 14px; flex-wrap: wrap; }
.hero .dice-strip svg { width: 42px; height: 42px; }
.rules ol { margin: 6px 0 0; padding-left: 20px; }
.rules li { margin: 4px 0; }
.or { text-align: center; font-size: 13px; color: var(--muted); }
.code-input { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }

/* lobby */
.room-code { font-size: 40px; font-weight: 800; letter-spacing: .18em; color: var(--accent); }
.players { display: grid; gap: 8px; }
.player-line { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #ffffff0a; border-radius: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--win); flex: none; }
.dot.off { background: #666; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: #ffffff1a; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tag.host { background: #e8b04a33; color: var(--accent); }
.x { padding: 4px 10px; font-size: 13px; }

/* table */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.topbar .code { font-weight: 800; letter-spacing: .12em; color: var(--accent); }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #ffffff12; }
.timer.low { background: #ef6a5a33; color: var(--lost); }
.opps { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.opp { padding: 10px; border-radius: 12px; background: #0000002e; border: 1px solid var(--line); min-width: 0; }
.opp.out { opacity: .45; }
.opp .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp .status { font-size: 12px; color: var(--muted); }
.opp .status.locked { color: var(--win); }
.mini { display: flex; gap: 3px; margin-top: 6px; }
.mini svg { width: 18px; height: 18px; }

.stage { min-height: 150px; display: grid; place-items: center; text-align: center; padding: 14px; margin-bottom: 12px; }
.stage .big { font-size: 20px; font-weight: 700; }
.reveal { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; width: 100%; }
.play { width: 104px; padding: 8px 6px 10px; border-radius: 12px; background: #ffffff0a; border: 2px solid transparent; animation: flip .45s both; }
.play svg { width: 70px; height: 70px; display: block; margin: 0 auto 2px; }
.play .who { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play.win { border-color: var(--win); }
.play.stunned { border-color: var(--stun); }
.play.lost { border-color: var(--lost); }
.badge { display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; background: #ffffff14; color: var(--muted); }
.badge.win { background: #6fd08c2e; color: var(--win); }
.badge.stunned { background: #f0c94a2e; color: var(--stun); }
.badge.spared { background: #9aa3b52e; color: var(--push); }
.rolloff { color: var(--stun); text-align: center; }
.rolloff b { color: var(--ink); }
.badge.lost { background: #ef6a5a2e; color: var(--lost); }
@keyframes flip { from { transform: rotateY(90deg) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }

.tray-wrap h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.tray { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 560px) { .tray { grid-template-columns: repeat(7, 1fr); } }
.die-btn { position: relative; padding: 6px 2px 8px; background: #ffffff0a; border: 2px solid transparent; border-radius: 14px; display: grid; justify-items: center; gap: 2px; }
.die-btn svg { width: 100%; max-width: 76px; aspect-ratio: 1; }
.die-btn .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.die-btn.sel { border-color: var(--accent); background: #e8b04a1f; transform: translateY(-3px); }
.die-btn.played { border-color: var(--win); }
.die-btn.stunned svg, .die-btn.lost svg, .die-btn.idle svg { opacity: .3; }
.die-btn.lost .lbl { text-decoration: line-through; }
.die-btn .note { position: absolute; top: 6px; right: 6px; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 999px; }
.die-btn.stunned .note { background: #f0c94a33; color: var(--stun); }
.die-btn.lost .note { background: #ef6a5a33; color: var(--lost); }
.actions { margin-top: 12px; display: grid; }
.actions button { padding: 15px; font-size: 17px; }

.log { margin-top: 14px; }
.log summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.log ol { margin: 8px 0 0; padding-left: 0; list-style: none; font-size: 13px; color: var(--muted); display: grid; gap: 4px; max-height: 220px; overflow: auto; }

.winner { text-align: center; padding: 22px 12px; }
.winner .crown { font-size: 46px; }
.winner h2 { font-size: 30px; margin-top: 4px; }

.rolling text { animation: jitter .09s steps(2) infinite; }
@keyframes jitter { 50% { opacity: .55; } }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); opacity: 0; background: #000c; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; transition: .2s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.on { opacity: 1; transform: translateX(-50%); }
