:root {
  --ink: #f4ecdd;
  --muted: rgba(244, 236, 221, .62);
  --faint: rgba(244, 236, 221, .38);
  --glass: rgba(22, 17, 13, .66);
  --glass-strong: rgba(18, 14, 11, .86);
  --line: rgba(255, 240, 215, .1);
  --gold: #e2bd77;
  --lime: #dfff63;
  --danger: #ff6a55;
  --radius: 18px;
  --serif: "DM Serif Display", Georgia, serif;
  --sans: Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0a08; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(0, 0, 0, .55) 100%); }
body > * { transition: opacity .8s ease; }
body:not(.is-ready) > *:not(#scene):not(.vignette) { opacity: 0; }

/* ---------- Top bar ---------- */
.topbar { position: fixed; z-index: 20; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: max(14px, env(safe-area-inset-top)) 20px 14px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.back { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px 9px 10px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 700; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: background .2s; }
.back:hover { background: rgba(40, 31, 24, .8); }
.mark { position: absolute; left: 50%; transform: translateX(-50%); font-family: var(--serif); font-size: 26px; letter-spacing: .01em; text-shadow: 0 2px 18px rgba(0, 0, 0, .6); }
.mark sup { font-family: var(--sans); font-size: 10px; font-weight: 800; letter-spacing: .12em; color: var(--gold); margin-left: 3px; vertical-align: top; position: relative; top: 4px; }
.top-actions { display: flex; gap: 8px; }
.top-actions button { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: background .2s, transform .2s; }
.top-actions button:hover { background: rgba(40, 31, 24, .85); transform: translateY(-1px); }
.top-actions .menu { width: auto; padding: 0 16px; border-radius: 999px; font-size: 13px; font-weight: 800; display: none; }
body.is-playing .top-actions .menu { display: block; }
#btn-theme .fill { fill: currentColor; stroke: none; opacity: .55; }
#btn-sound .mute { display: none; }
#btn-sound.is-off .mute { display: block; }
#btn-sound.is-off .wave { display: none; }

/* ---------- Player cards ---------- */
.card { position: fixed; z-index: 10; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); box-shadow: 0 18px 50px rgba(0, 0, 0, .35); }
.player { left: 20px; width: 290px; display: flex; align-items: center; gap: 12px; padding: 12px 14px; transition: border-color .3s, box-shadow .3s, transform .4s, opacity .4s; }
.player.top { top: 76px; }
.player.bottom { bottom: 20px; }
body:not(.is-playing) .player, body:not(.is-playing) .side { opacity: 0; pointer-events: none; transform: translateY(8px); }
.player.is-turn { border-color: rgba(223, 255, 99, .55); box-shadow: 0 0 0 1px rgba(223, 255, 99, .2), 0 18px 50px rgba(0, 0, 0, .35), 0 0 34px rgba(223, 255, 99, .12); }
.avatar { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 14px; font-size: 28px; line-height: 1; }
.avatar[data-color="w"] { background: linear-gradient(160deg, #fbf3e3, #d9c9a8); color: #2a201c; }
.avatar[data-color="b"] { background: linear-gradient(160deg, #3a302b, #16110e); color: #f1e6cf; border: 1px solid rgba(255, 255, 255, .1); }
.player.is-thinking .avatar { animation: think 1.1s ease-in-out infinite; }
@keyframes think { 50% { transform: scale(.92); box-shadow: 0 0 0 6px rgba(223, 255, 99, .14); } }
.who { flex: 1; min-width: 0; }
.who .name { display: block; font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .sub { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; margin-top: 1px; }
.caps { display: flex; flex-wrap: wrap; align-items: center; gap: 0; min-height: 18px; margin-top: 4px; font-size: 16px; line-height: 1; }
.caps i { font-style: normal; margin-right: -3px; }
.caps i[data-c="w"] { color: #f4ead6; text-shadow: 0 0 1px #000, 0 1px 2px rgba(0, 0, 0, .8); }
.caps i[data-c="b"] { color: #1b1512; text-shadow: 0 0 1px rgba(255, 255, 255, .65), 0 0 2px rgba(255, 255, 255, .35); }
.caps b { margin-left: 8px; font-size: 12px; color: var(--muted); }
.clock { font-variant-numeric: tabular-nums; font-size: 20px; font-weight: 800; padding: 8px 12px; border-radius: 12px; background: rgba(0, 0, 0, .3); color: var(--muted); min-width: 78px; text-align: center; }
.clock.is-running { background: var(--ink); color: #15110e; }
.clock.is-low.is-running { background: var(--danger); color: #fff; animation: low 1s steps(2) infinite; }
@keyframes low { 50% { opacity: .75; } }

/* ---------- Side panel ---------- */
.side { position: fixed; z-index: 10; right: 20px; top: 76px; bottom: 20px; width: 300px; display: flex; flex-direction: column; padding: 16px; gap: 12px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); box-shadow: 0 18px 50px rgba(0, 0, 0, .35); transition: opacity .4s, transform .4s; max-height: 640px; }
.status { margin: 0; font-size: 14px; font-weight: 700; line-height: 1.35; min-height: 38px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, .05); }
.moves { flex: 1; margin: 0; padding: 0; list-style: none; overflow: auto; font-variant-numeric: tabular-nums; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .2) transparent; }
.moves li { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px; padding: 4px 6px; border-radius: 8px; font-size: 13.5px; }
.moves li:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.moves li span { color: var(--faint); font-weight: 600; }
.moves li b { font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.moves li b.is-last { background: rgba(223, 255, 99, .16); color: var(--lime); }
.moves li.is-empty { display: block; color: var(--faint); font-size: 13px; padding: 14px 6px; background: none; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions button { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 6px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .04); font-size: 12px; font-weight: 700; transition: background .2s, transform .15s, opacity .2s; }
.actions button:hover:not(:disabled) { background: rgba(255, 255, 255, .1); transform: translateY(-1px); }
.actions button:disabled { opacity: .35; cursor: default; }
.actions button.accent { background: var(--lime); color: #17200a; border-color: transparent; }
.actions button.accent:hover:not(:disabled) { background: #eaff8f; }
.room-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 12px; background: rgba(223, 255, 99, .08); font-size: 13px; color: var(--muted); }
.room-bar b { color: var(--ink); letter-spacing: .14em; margin-left: 4px; }
.room-bar button { border: 0; background: none; color: var(--lime); font-weight: 800; font-size: 12.5px; }

/* ---------- Start screen ---------- */
.start { position: fixed; z-index: 15; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); align-items: center; gap: 48px; padding: 96px clamp(24px, 6vw, 96px) 40px; background: linear-gradient(90deg, rgba(10, 8, 6, .9) 0%, rgba(10, 8, 6, .45) 45%, rgba(10, 8, 6, .2) 62%, rgba(10, 8, 6, .82) 100%); overflow: auto; }
.start-copy { max-width: 520px; }
.eyebrow { margin: 0 0 14px; font-size: 12px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.start h1 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: clamp(72px, 11vw, 150px); line-height: .9; letter-spacing: -.02em; }
.start h1 em { font-style: normal; color: var(--lime); }
.lede { margin: 22px 0 0; max-width: 430px; font-size: 17px; line-height: 1.6; color: var(--muted); }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 26px 0 0; padding: 0; list-style: none; }
.facts li { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, .04); font-size: 13px; color: var(--muted); font-weight: 600; }
.facts b { color: var(--ink); }
.start-card { display: flex; flex-direction: column; gap: 18px; padding: 22px; border-radius: 26px; background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, .5); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 16px; background: rgba(255, 255, 255, .05); }
.tabs button { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 11px 6px; border: 0; border-radius: 12px; background: none; color: var(--muted); font-size: 13.5px; font-weight: 800; transition: background .2s, color .2s; }
.tabs button[aria-selected="true"] { background: var(--ink); color: #17120e; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 4px rgba(223, 255, 99, .2); animation: live 1.6s ease-in-out infinite; }
@keyframes live { 50% { box-shadow: 0 0 0 7px rgba(223, 255, 99, 0); } }
.tab-body { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 11.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.field input, .join input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .28); outline: none; font-weight: 600; transition: border-color .2s; }
.field input:focus, .join input:focus { border-color: rgba(223, 255, 99, .6); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 0; padding: 10px 8px; border-radius: 11px; border: 1px solid var(--line); background: rgba(255, 255, 255, .03); color: var(--muted); font-size: 13px; font-weight: 700; white-space: nowrap; transition: all .2s; }
.seg button:hover { color: var(--ink); border-color: rgba(255, 255, 255, .2); }
.seg button[aria-pressed="true"] { color: var(--ink); border-color: rgba(223, 255, 99, .7); background: rgba(223, 255, 99, .1); box-shadow: inset 0 0 0 1px rgba(223, 255, 99, .3); }
.chip { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.chip.w { background: #f1e6cf; }
.chip.b { background: #2a201c; border: 1px solid rgba(255, 255, 255, .35); }
.chip.r { background: linear-gradient(90deg, #f1e6cf 50%, #2a201c 50%); border: 1px solid rgba(255, 255, 255, .35); }
.sw { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.sw.walnut { background: conic-gradient(#e6cb9d 0 25%, #6e4327 0 50%, #e6cb9d 0 75%, #6e4327 0); }
.sw.marble { background: conic-gradient(#efece6 0 25%, #33403b 0 50%, #efece6 0 75%, #33403b 0); }
.sw.tournament { background: conic-gradient(#ecebd0 0 25%, #6f9450 0 50%, #ecebd0 0 75%, #6f9450 0); }
.primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 15px 18px; border: 0; border-radius: 14px; background: var(--lime); color: #17200a; font-size: 15px; font-weight: 800; transition: transform .15s, background .2s, box-shadow .2s; box-shadow: 0 10px 30px rgba(223, 255, 99, .18); }
.primary:hover { background: #eaff8f; transform: translateY(-1px); box-shadow: 0 14px 34px rgba(223, 255, 99, .26); }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: .2em; font-weight: 800; }
.join button { padding: 0 20px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .08); font-weight: 800; }
.join button:hover { background: rgba(255, 255, 255, .14); }
.note { margin: 0; font-size: 12.5px; color: var(--faint); text-align: center; }
.note.is-error { color: var(--danger); }

/* ---------- Overlays ---------- */
.waiting, .result, .promo { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(8, 6, 5, .45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade .3s ease; }
@keyframes fade { from { opacity: 0; } }
.waiting-card, .result-card, .promo-card { width: min(420px, 100%); padding: 30px 26px; border-radius: 26px; text-align: center; background: var(--glass-strong); border: 1px solid var(--line); box-shadow: 0 30px 90px rgba(0, 0, 0, .55); animation: rise .45s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes rise { from { transform: translateY(18px) scale(.96); opacity: 0; } }
.waiting-card h2, .result-card h2 { margin: 6px 0 8px; font-family: var(--serif); font-weight: 400; font-size: 40px; line-height: 1.05; }
.waiting-card p, .result-card p { margin: 0 auto; max-width: 320px; color: var(--muted); line-height: 1.5; font-size: 14.5px; }
.pulse { display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--lime); animation: live 1.4s ease-in-out infinite; box-shadow: 0 0 0 6px rgba(223, 255, 99, .2); }
.code { display: block; margin: 22px 0; font-size: 40px; letter-spacing: .28em; font-weight: 800; padding-left: .28em; color: var(--lime); }
.waiting-actions, .result-actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.waiting-actions .primary, .result-actions .primary { grid-column: 1 / -1; }
.waiting-actions button:not(.primary), .result-actions button:not(.primary) { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, .05); font-weight: 700; font-size: 13.5px; }
.waiting-actions button:not(.primary):hover, .result-actions button:not(.primary):hover { background: rgba(255, 255, 255, .1); }
.result-card small { font-size: 12px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); }
.result-card p { margin-bottom: 24px; }
.promo-card p { margin: 0 0 16px; font-weight: 800; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.promo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.promo-row button { aspect-ratio: 1; border-radius: 18px; border: 1px solid var(--line); font-size: 46px; line-height: 1; display: grid; place-items: center; transition: transform .15s, border-color .2s; }
.promo-row button[data-c="w"] { background: linear-gradient(160deg, #fbf3e3, #d9c9a8); color: #2a201c; }
.promo-row button[data-c="b"] { background: linear-gradient(160deg, #3a302b, #16110e); color: #f1e6cf; }
.promo-row button:hover { transform: translateY(-3px) scale(1.04); border-color: var(--lime); }
.offer { position: fixed; z-index: 25; left: 50%; top: 76px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 18px; border-radius: 999px; background: var(--glass-strong); border: 1px solid rgba(223, 255, 99, .4); box-shadow: 0 16px 40px rgba(0, 0, 0, .45); font-size: 14px; font-weight: 700; white-space: nowrap; animation: rise .35s ease; }
.offer button { padding: 8px 14px; border-radius: 999px; border: 0; font-weight: 800; font-size: 13px; background: rgba(255, 255, 255, .08); }
.offer #offer-accept { background: var(--lime); color: #17200a; }
.toast { position: fixed; z-index: 40; left: 50%; bottom: 28px; transform: translate(-50%, 20px); padding: 11px 18px; border-radius: 999px; background: var(--ink); color: #15110e; font-size: 13.5px; font-weight: 800; opacity: 0 !important; pointer-events: none; transition: opacity .3s, transform .3s; box-shadow: 0 12px 30px rgba(0, 0, 0, .4); }
.toast.is-on { opacity: 1 !important; transform: translate(-50%, 0); }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; }

/* ---------- Medium screens ---------- */
@media (max-width: 1180px) {
  .player { width: 250px; }
  .side { width: 260px; }
}
@media (max-width: 980px) {
  .start { grid-template-columns: 1fr; align-content: start; gap: 26px; padding-top: 84px; background: linear-gradient(180deg, rgba(10, 8, 6, .82), rgba(10, 8, 6, .55) 40%, rgba(10, 8, 6, .9)); }
  .start-copy { max-width: none; }
  .start h1 { font-size: 76px; }
  .lede { font-size: 15.5px; margin-top: 12px; }
  .facts { margin-top: 16px; }
  .start-card { max-width: 520px; width: 100%; }
}

/* ---------- Phones and tablets: cards top and bottom, panel docked ---------- */
@media (max-width: 900px) and (orientation: portrait), (max-width: 600px) {
  .topbar { padding: max(10px, env(safe-area-inset-top)) 12px 10px; }
  .back span { display: none; }
  .back { padding: 9px; }
  .mark { font-size: 22px; }
  .top-actions { gap: 6px; }
  .top-actions button { width: 38px; height: 38px; }
  .player { left: 12px; right: 12px; width: auto; padding: 9px 10px; gap: 10px; border-radius: 16px; }
  .player.top { top: 62px; }
  .player.bottom { bottom: calc(118px + env(safe-area-inset-bottom)); }
  body[data-mode="online"] .player.bottom { bottom: calc(158px + env(safe-area-inset-bottom)); }
  .avatar { width: 38px; height: 38px; font-size: 24px; border-radius: 12px; }
  .caps { margin-top: 2px; font-size: 14px; min-height: 0; }
  .clock { font-size: 17px; min-width: 64px; padding: 6px 10px; }
  .side { left: 12px; right: 12px; top: auto; bottom: calc(10px + env(safe-area-inset-bottom)); width: auto; max-height: none; padding: 10px; gap: 8px; border-radius: 18px; }
  .status { min-height: 0; padding: 0 4px; background: none; font-size: 12.5px; text-align: center; color: var(--muted); }
  .moves { flex: none; display: flex; gap: 2px; overflow-x: auto; overflow-y: hidden; white-space: nowrap; scrollbar-width: none; }
  .moves::-webkit-scrollbar { display: none; }
  .moves li { display: flex; flex: none; gap: 2px; padding: 3px 4px; font-size: 12.5px; background: none !important; }
  .moves li span { margin-right: 1px; }
  .moves li b { padding: 1px 4px; }
  .moves li.is-empty { padding: 3px 4px; }
  .actions { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .actions button { flex-direction: row; justify-content: center; padding: 10px 4px; font-size: 0; gap: 0; }
  .actions button svg { width: 20px; height: 20px; }
  .room-bar { padding: 6px 10px; font-size: 12px; }
  .offer { top: 120px; font-size: 13px; }
  .toast { bottom: calc(190px + env(safe-area-inset-bottom)); }
}
@media (max-width: 560px) {
  .start { padding: 76px 14px 20px; }
  .start h1 { font-size: 64px; }
  .eyebrow { margin-bottom: 8px; font-size: 11px; }
  .facts { display: none; }
  .start-card { padding: 16px; gap: 14px; border-radius: 22px; }
  .seg button { padding: 9px 4px; font-size: 12.5px; gap: 5px; }
  .tabs button svg { display: none; }
  .waiting-card h2, .result-card h2 { font-size: 34px; }
  .code { font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
@media (max-width: 520px) { .mark { display: none; } }
@media (max-width: 980px) and (orientation: landscape) {
  .player { left: auto; right: 12px; width: 236px; padding: 8px 10px; gap: 10px; }
  .player.top { top: 64px; }
  .player.bottom { bottom: 12px; }
  .avatar { width: 36px; height: 36px; font-size: 22px; border-radius: 11px; }
  .clock { font-size: 16px; min-width: 60px; padding: 6px 8px; }
  .side { width: 236px; top: 138px; bottom: 86px; right: 12px; padding: 10px; gap: 8px; }
  .status { min-height: 0; padding: 8px 10px; font-size: 13px; }
  .actions { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .actions button { padding: 7px 4px; font-size: 11px; gap: 3px; }
  .room-bar { padding: 7px 10px; }
}

/* A compact mobile dock gives the board priority; desktop controls stay open. */
.panel-heading, .panel-details { display: contents; }
.panel-toggle { display: none; }
@media (max-width: 900px) and (orientation: portrait), (max-width: 600px) {
  .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; }
  .panel-heading .status { text-align: left; flex: 1; }
  .panel-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 36px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.05); font-size: 11px; font-weight: 800; }
  .panel-toggle svg { width: 16px; height: 16px; }
  .panel-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
  .panel-toggle:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; }
  .panel-details { display: flex; flex-direction: column; gap: 8px; }
  .side[data-collapsed="true"] .panel-details { display: none; }
  .player.bottom, body[data-mode="online"] .player.bottom { bottom: calc(var(--mobile-panel-height, 58px) + 20px + env(safe-area-inset-bottom)); }
  .side:has(.actions button:nth-child(6):not([hidden])) .actions { grid-template-columns: repeat(6, 1fr); }
}
