:root {
  --bg: #0B1220;
  --surface: #131C2E;
  --surface-2: #1A2540;
  --line: #26324D;
  --text: #E8EEF7;
  --muted: #8C99B0;
  --mint: #34E5A6;
  --mint-ink: #052A1D;
  --danger: #F2555A;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #12324A 0%, transparent 60%), var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--mint); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: clamp(1.9rem, 5vw, 3rem); letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
.mint { color: var(--mint); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; justify-content: center; }
.row.end { justify-content: flex-end; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* Header / footer */
.top { display: flex; align-items: center; justify-content: space-between; padding: .9rem clamp(1rem, 4vw, 2rem); }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.logo { width: 32px; height: 32px; border-radius: 9px; background: var(--mint); color: var(--mint-ink); display: grid; place-items: center; font-weight: 900; }
.online { color: var(--muted); font-size: .9rem; }
.online:not(:empty)::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--mint); margin-right: .45rem; box-shadow: 0 0 8px var(--mint); }
main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 clamp(.75rem, 3vw, 2rem) 2rem; }
.foot { display: flex; gap: 1rem; justify-content: center; padding: 1.2rem; color: var(--muted); font-size: .85rem; }

/* Cards & controls */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.5rem); }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: .7rem 1.1rem; border-radius: 11px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: #3A4A6E; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .av:focus-visible, .chip:focus-visible, .dice:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }
.btn-mint { background: var(--mint); color: var(--mint-ink); border-color: var(--mint); }
.btn-mint:hover { background: #5AF0BC; border-color: #5AF0BC; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-wa { background: #25D366; border-color: #25D366; color: #06290F; }
.btn.sm { padding: .4rem .75rem; font-size: .9rem; border-radius: 9px; }
input {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: .65rem .8rem; width: 100%;
}
input:focus { outline: 2px solid var(--mint); outline-offset: 0; border-color: transparent; }
label, .label { display: block; font-size: .85rem; color: var(--muted); margin: .8rem 0 .35rem; font-weight: 600; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: .4rem .8rem; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.tag { font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); margin-left: .4rem; }
.shake { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* Home */
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 2rem; align-items: center; padding: 2rem 0 1.5rem; }
.lede { color: var(--muted); font-size: 1.15rem; max-width: 32ch; }
.points { list-style: none; padding: 0; margin: 1.2rem 0 0; display: grid; gap: .45rem; color: var(--text); }
.me-card label:first-child { margin-top: 0; }
.avatars { display: grid; grid-template-columns: repeat(6, 1fr); gap: .4rem; }
.av { font-size: 1.5rem; aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.av.on { border-color: var(--mint); background: #103327; box-shadow: 0 0 0 2px var(--mint) inset; }
.game-card { margin-top: .5rem; }
.game-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.game-head h2 { margin: 0; font-size: 1.6rem; }
.game-head p { margin: 0; }
.game-icon { width: 56px; height: 56px; font-size: 2rem; display: grid; place-items: center; background: var(--surface-2); border-radius: 14px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.action { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.action p { margin: 0; font-size: .92rem; flex: 1; }
.action h3 { margin: 0; }
.join-code { display: flex; gap: .4rem; width: 100%; }
.code-in { text-transform: uppercase; letter-spacing: .2em; font-weight: 700; }
.slot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: 1rem; padding: .85rem 1rem; border-radius: 12px; background: linear-gradient(90deg, #10302A, #12203A); border: 1px solid #1E4A3E; }
.slot:empty { display: none; }
.waiting-h { margin: 1.2rem 0 .6rem; }
.room-list { display: grid; gap: .5rem; }
.room-row { display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.soon { margin-top: 2rem; }
.soon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; }
.soon-card { text-align: center; color: var(--muted); font-weight: 600; }
.ad-slot { margin: 1.5rem auto; max-width: 970px; min-height: 90px; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: .5rem; z-index: 50; width: min(94vw, 460px); }
.toast { background: #1F2B47; border: 1px solid #33456D; border-radius: 12px; padding: .75rem 1rem; box-shadow: 0 12px 30px rgba(0,0,0,.45); opacity: 0; transform: translateY(12px); transition: .22s; }
.toast.in { opacity: 1; transform: none; }
.toast-invite { border-color: var(--mint); }
.invite { display: flex; align-items: center; gap: .6rem; }
.invite-text { flex: 1; font-size: .95rem; }
.invite-av { font-size: 1.5rem; }

/* Dialog */
.dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; width: min(92vw, 420px); }
.dialog::backdrop { background: rgba(3,6,14,.7); }
.dialog .row { margin-top: 1.2rem; }

/* Room */
.room { display: flex; flex-direction: column; gap: .8rem; }
.room-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.room-code strong { letter-spacing: .15em; margin-left: .3rem; }
.room-main { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
.stage { position: relative; min-height: 60vh; }
.chat-toggle { display: none; position: relative; }
.badge { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; font-size: .7rem; border-radius: 99px; padding: 0 .4rem; }
.chat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; height: min(78vh, 720px); }
.chat-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.chat-close { display: none; margin-left: auto; }
.msgs { flex: 1; overflow-y: auto; padding: .8rem 1rem; display: flex; flex-direction: column; gap: .45rem; }
.msg { font-size: .93rem; word-wrap: break-word; }
.msg-name { background: none; border: 0; color: var(--mint); font: inherit; font-weight: 700; padding: 0; margin-right: .4rem; cursor: pointer; }
.msg.mine .msg-name { color: #9FB4FF; cursor: default; }
.msg.sys { color: var(--muted); font-size: .85rem; font-style: italic; text-align: center; }
.quick { display: flex; gap: .35rem; overflow-x: auto; padding: .5rem .8rem; border-top: 1px solid var(--line); scrollbar-width: none; }
.chip { flex: none; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 99px; padding: .3rem .7rem; font: inherit; font-size: .85rem; cursor: pointer; }
.chat-form { display: flex; gap: .4rem; padding: .6rem .8rem .8rem; }

/* Waiting room */
.waiting-card { max-width: 560px; margin: 0 auto; display: grid; gap: 1rem; }
.waiting-card h2 { margin: 0; }
.code-big { display: flex; flex-direction: column; align-items: center; padding: .8rem; background: var(--bg); border-radius: 12px; border: 1px dashed #33456D; }
.code-big strong { font-size: 2.2rem; letter-spacing: .3em; margin-right: -.3em; }
.share { display: flex; gap: .5rem; flex-wrap: wrap; }
.share > * { flex: 1; }
.seats { display: grid; gap: .5rem; }
.seat { display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.seat.empty { border-style: dashed; }
.seat-av { font-size: 1.6rem; width: 2rem; text-align: center; }
.host-ctl { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.host-ctl .btn { margin-left: auto; }
.switch { display: inline-flex; align-items: center; gap: .35rem; margin: 0; color: var(--text); font-weight: 500; }
.switch input { width: auto; accent-color: var(--mint); }

/* Game */
.game { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.board-box { width: min(100%, calc(100dvh - 300px)); min-width: 260px; aspect-ratio: 1; display: grid; place-items: center; }
.board-box canvas { border-radius: 12px; box-shadow: 0 18px 40px rgba(0,0,0,.45); touch-action: manipulation; }
.chips-row { width: min(100%, calc(100dvh - 300px)); min-width: 260px; display: flex; justify-content: space-between; gap: .5rem; }
.pchip { position: relative; display: flex; align-items: center; gap: .5rem; min-width: 0; flex: 0 1 48%; padding: .4rem .6rem; border-radius: 12px; background: var(--surface); border: 2px solid transparent; border-left: 5px solid var(--c, #444); }
.pchip.none { visibility: hidden; }
.pchip.tr, .pchip.br { flex-direction: row-reverse; text-align: right; border-left-width: 2px; border-right: 5px solid var(--c, #444); }
.pchip.turn { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 35%, transparent); }
.pchip-av { font-size: 1.5rem; }
.pchip-body { display: flex; flex-direction: column; min-width: 0; }
.pchip-name { font-weight: 700; font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip-sub { font-size: .75rem; color: var(--muted); }
.tbar { position: absolute; left: 8px; right: 8px; bottom: 3px; height: 3px; border-radius: 3px; overflow: hidden; }
.tfill { display: block; height: 100%; width: 0; background: var(--c); transition: width .2s linear; }
.bubble { position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; max-width: 220px; background: #fff; color: #111; font-size: .85rem; padding: .35rem .6rem; border-radius: 10px; box-shadow: 0 6px 16px rgba(0,0,0,.35); }
.pchip.bl .bubble, .pchip.br .bubble { top: auto; bottom: calc(100% + 6px); }
.pchip.tr .bubble, .pchip.br .bubble { left: auto; right: 0; }
.dice-row { display: flex; align-items: center; gap: 1rem; margin-top: .3rem; }
.status { font-weight: 600; min-width: 12ch; text-align: right; }
.dice {
  width: 64px; height: 64px; padding: 9px; border-radius: 14px; background: #fff; border: 4px solid var(--c, #ccc);
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); cursor: pointer;
}
.dice span { display: block; }
.dice .pip { width: 11px; height: 11px; border-radius: 50%; background: #111827; place-self: center; }
.dice:disabled { cursor: default; opacity: .9; }
.dice.ready { animation: nudge 1.2s infinite; }
.dice.rolling { animation: roll .38s linear; }
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); box-shadow: 0 0 22px var(--c); } }
@keyframes roll { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(200deg) scale(.85); } 100% { transform: rotate(360deg) scale(1); } }
.over { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5,9,18,.72); border-radius: var(--radius); z-index: 10; }
.over-card, .center-card { text-align: center; max-width: 420px; margin: 2rem auto; }
.big-emoji { font-size: 3.5rem; }

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

/* Mobile */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; gap: 1rem; padding-top: 1rem; }
  .actions { grid-template-columns: 1fr; }
  .soon-grid { grid-template-columns: repeat(2, 1fr); }
  .room-main { grid-template-columns: 1fr; }
  .chat-toggle, .chat-close { display: inline-flex; }
  .chat {
    position: fixed; left: 0; right: 0; bottom: 0; height: 60dvh; z-index: 40;
    border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .25s;
  }
  .chat.open { transform: none; }
  .board-box, .chips-row { width: min(100%, calc(100dvh - 280px)); }
}
