:root {
  --bg: #15100c; --panel: #241a14; --panel2: #2f231b; --text: #f2e8d8; --muted: #b9a892;
  --accent: #d9a441; --accent2: #f0c86b; --danger: #d9534f; --ok: #6ccf7a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #3a2a1e 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
header.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: 1px; font-weight: 700; color: var(--accent2); }
.logo { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg,#7a4f2c,#3e2614); position: relative; box-shadow: inset 0 0 0 1px #0006; }
.logo::before, .logo::after { content:""; position:absolute; width: 10px; height:10px; border-radius:50%; }
.logo::before { left:4px; top:4px; background:#f1e6d0; } .logo::after { right:4px; bottom:4px; background:#222; }
.top-right { display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: #0006; color: var(--muted); border: 1px solid #fff2; }
.badge.gpu { color: #9be3ff; border-color: #9be3ff55; }
.badge.gl { color: #c9f59b; border-color: #c9f59b55; }
.icon-btn { background: #0005; color: var(--text); border: 1px solid #fff2; border-radius: 10px; width: 36px; height: 34px; font-size: 16px; cursor: pointer; }
.icon-btn.off { opacity: .5; text-decoration: line-through; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid #fff2; background: var(--panel2); color: var(--text); padding: 9px 14px; transition: transform .08s, background .15s; }
button:hover:not(:disabled) { background: #3d2e23; }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, var(--accent2), #b8832a); color: #2a1b08; font-weight: 700; border-color: #0004; }
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffd77e, #c8933a); }
button.small { padding: 5px 10px; font-size: 13px; }
button.ghost { background: transparent; }

.game { display: grid; grid-template-columns: 1fr 300px; gap: 14px; padding: 0 14px 14px; flex: 1; align-items: start; align-content: start; }
.board-wrap { width: 100%; aspect-ratio: 1000 / 640; position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: 0 20px 50px #000a, 0 0 0 1px #0008; }
canvas#board { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.panel { background: var(--panel); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 30px #0006; }
.room-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.room-line b { font-family: ui-monospace, monospace; letter-spacing: 2px; color: var(--accent2); }
.players { display: flex; flex-direction: column; gap: 6px; }
.player { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--panel2); border: 1px solid transparent; }
.player.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, 0 0 14px #d9a44133; }
.player .dot { width: 8px; height: 8px; border-radius: 50%; background: #666; flex: none; }
.player .dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.player .chk { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: inset 0 -2px 3px #0006, 0 1px 2px #0008; }
.player .chk.white { background: radial-gradient(circle at 35% 30%, #fff8e8, #d9c9a8); }
.player .chk.black { background: radial-gradient(circle at 35% 30%, #5a5a5a, #111); }
.player .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .pips { color: var(--muted); font-size: 12px; }
.player .score { font-weight: 800; font-size: 18px; min-width: 24px; text-align: right; color: var(--accent2); }
.target { color: var(--muted); font-size: 13px; }
.status { min-height: 44px; padding: 8px 10px; border-radius: 10px; background: #0004; font-size: 14px; }
.status.me { background: #d9a44122; border: 1px solid #d9a44155; }
.actions { display: flex; gap: 8px; }
.actions button { flex: 1; }
.toast { padding: 8px 10px; border-radius: 10px; background: #d9534f33; border: 1px solid #d9534f66; font-size: 13px; }
.help { color: var(--muted); font-size: 13px; }
.help summary { cursor: pointer; }
.help ul { padding-left: 18px; margin: 6px 0; }

.lobby { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { width: min(440px, 100%); background: var(--panel); border-radius: 18px; padding: 22px; box-shadow: 0 30px 60px #000a; display: flex; flex-direction: column; gap: 12px; }
.card h2 { margin: 0; color: var(--accent2); }
.card .sub { margin: 0; color: var(--muted); }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.card input, .card select { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid #fff2; background: #0006; color: var(--text); }
.card .row { display: flex; gap: 10px; }
.card .row.buttons button { flex: 1; }
.card .join { display: flex; gap: 8px; }
.card .join input { flex: 1; text-transform: uppercase; letter-spacing: 3px; font-family: ui-monospace, monospace; }
.msg { min-height: 20px; margin: 0; color: #ffb4b0; font-size: 13px; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #0007; z-index: 10; pointer-events: none; }
.overlay-card { background: var(--panel); border: 1px solid #d9a44155; border-radius: 18px; padding: 22px 30px; text-align: center; box-shadow: 0 20px 60px #000c; animation: pop .35s cubic-bezier(.2,1.4,.4,1); }
.overlay-card h3 { margin: 0 0 6px; font-size: 26px; color: var(--accent2); }
.overlay-card p { margin: 0; color: var(--muted); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 900px) {
  .game { grid-template-columns: 1fr; padding: 0 8px 8px; gap: 10px; }
  .board-wrap { border-radius: 10px; }
  .panel { padding: 10px; }
  header.top { padding: 6px 10px; }
}

.chat { display: flex; flex-direction: column; gap: 6px; }
.chat-log { max-height: 140px; min-height: 40px; overflow-y: auto; background: #0004; border-radius: 10px; padding: 6px 8px; font-size: 13px; display: flex; flex-direction: column; gap: 3px; }
.chat-log .m { padding: 3px 8px; border-radius: 10px; background: #3d2e23; align-self: flex-start; max-width: 92%; word-break: break-word; }
.chat-log .m.me { background: #d9a44133; align-self: flex-end; }
.chat-log .m b { color: var(--accent2); font-weight: 600; margin-right: 4px; }
.quick { display: flex; flex-wrap: wrap; gap: 4px; }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; font: inherit; padding: 7px 10px; border-radius: 10px; border: 1px solid #fff2; background: #0006; color: var(--text); min-width: 0; }
.bubble { position: absolute; background: #fff5dd; color: #2a1b08; padding: 6px 10px; border-radius: 12px; font-size: 13px; max-width: 220px; box-shadow: 0 6px 20px #0008; animation: pop .3s; pointer-events: none; z-index: 5; }
.bubble.top { top: 8px; left: 12px; } .bubble.bottom { bottom: 8px; left: 12px; }
.banner { position: fixed; left: 50%; top: 18%; transform: translate(-50%, 0) scale(1); background: linear-gradient(180deg, var(--accent2), #b8832a); color: #2a1b08; font-weight: 900; font-size: clamp(26px, 6vw, 54px); padding: 10px 34px; border-radius: 16px; box-shadow: 0 20px 60px #000c; z-index: 30; animation: pop .35s cubic-bezier(.2,1.4,.4,1); pointer-events: none; letter-spacing: 1px; transition: opacity .5s, transform .5s; }
.banner.out { opacity: 0; transform: translate(-50%, -30px); }
.banner.bad { background: linear-gradient(180deg, #7a3b3b, #4a1f1f); color: #ffd9d9; }
