:root {
  --bg: #101014;
  --panel: #1a1a21;
  --panel2: #22222b;
  --line: #2e2e3a;
  --text: #ececf1;
  --muted: #9a9aad;
  --accent: #0091ff;
  --red: #d64550;
  --black: #3d3938;
  --gold: #f5d90a;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --ok: #46a758;
  --bad: #e5484d;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--bad); font-size: 13px; min-height: 1em; margin: 6px 0; }
button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
input, select {
  background: #14141a; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 12px; font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* ── onboarding ─────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(8,8,12,.92);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px; width: min(420px, 92vw); display: flex; flex-direction: column; gap: 10px;
}
.modal h1 { margin: 0; font-size: 22px; }
.modal label { font-size: 13px; color: var(--muted); }
.modal input { width: 100%; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
}
.swatch.sel { border-color: #fff; transform: scale(1.12); }
.eyes-row { display: flex; flex-wrap: wrap; gap: 6px; }
.eyes-row button.sel { border-color: var(--accent); color: var(--accent); }
.avatar-preview { display: flex; justify-content: center; padding: 6px 0; }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 4px; }
.auth-tabs .tab {
  flex: 1; padding: 8px 6px; font-size: 13px; border-radius: 8px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.auth-tabs .tab.active { border-color: var(--accent); color: var(--text); font-weight: 600; }

/* ── layout ─────────────────────────────────── */
.app { max-width: 1080px; margin: 0 auto; padding: 0 16px 60px; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 0;
  border-bottom: 1px solid var(--line); margin-bottom: 18px;
}
.brand { font-weight: 800; letter-spacing: .3px; color: var(--accent); }
.topbar nav { flex: 1; }
.nav-btn { background: transparent; border: none; color: var(--muted); }
.nav-btn.active, .nav-btn:hover { color: var(--text); }
.me { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.me img, .person img { border-radius: 50%; }

.view { display: flex; flex-direction: column; gap: 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px;
}
.panel h2, .panel h3 { margin: 0 0 10px; font-size: 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row input { flex: 1; min-width: 140px; }

.code-row { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; }
.code-row code, .code-row pre {
  flex: 1; background: #0d0d12; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; margin: 0;
}
.copy { font-size: 12px; padding: 6px 10px; }

.room-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.room-card {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px;
}
.room-card:hover { border-color: var(--accent); }
.room-card .rname { font-weight: 700; }
.room-card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; background: #14141a;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 12px;
}
.chip img { width: 16px; height: 16px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.off { background: #555; }

/* ── room ───────────────────────────────────── */
.room-head { display: flex; align-items: center; gap: 12px; }
.room-head h2 { margin: 0; }
.badge {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.badge.playing { color: var(--gold); border-color: var(--gold); }
.badge.finished { color: var(--muted); }

.room-grid { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 16px; }
@media (max-width: 860px) { .room-grid { grid-template-columns: 1fr; } }

.play-col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.side-row {
  width: min(512px, 94vw); display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
}
.side-row .side-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); width: 38px; }
.people { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.person { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.person img { width: 30px; height: 30px; }
.person.seated { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 50%; }
.person.waiting { opacity: .75; }
.person .who { display: flex; flex-direction: column; line-height: 1.1; }
.person .who b { font-size: 13px; }
.person .who span { font-size: 11px; color: var(--muted); }

.board {
  width: min(512px, 94vw); aspect-ratio: 1; display: grid;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border: 4px solid #0a0a0e; border-radius: 8px; overflow: hidden; user-select: none;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.sel { box-shadow: inset 0 0 0 4px var(--accent); }
.sq.target::after {
  content: ''; width: 26%; height: 26%; border-radius: 50%;
  background: rgba(0,145,255,.75); position: absolute;
}
.sq.target.cap::after { width: 70%; height: 70%; background: rgba(0,145,255,.28); box-shadow: inset 0 0 0 4px rgba(0,145,255,.8); }
.piece {
  width: 78%; height: 78%; border-radius: 50%; position: relative; cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,.35), inset 0 -4px 8px rgba(0,0,0,.3);
}
.piece.red { background: radial-gradient(circle at 35% 30%, #ff7b84, var(--red) 65%); border: 3px solid #8f2730; }
.piece.black { background: radial-gradient(circle at 35% 30%, #6a6564, var(--black) 65%); border: 3px solid #171515; }
.piece.king::after {
  content: 'K'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-weight: 900; font-size: clamp(12px, 3.4vw, 22px); text-shadow: 0 1px 2px #000;
}
.piece.mine { outline: 2px solid var(--gold); outline-offset: 2px; }

.turn-bar {
  width: min(512px, 94vw); text-align: center; font-size: 14px; padding: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.turn-bar b { color: var(--gold); }
.winner-bar {
  width: min(512px, 94vw); text-align: center; font-weight: 800; padding: 10px;
  background: rgba(245,217,10,.12); border: 1px solid var(--gold); color: var(--gold); border-radius: 10px;
}
.room-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ai-help { width: min(512px, 94vw); }

.side-col { display: flex; flex-direction: column; gap: 16px; }
.chat-panel { display: flex; flex-direction: column; gap: 8px; }
.chat-log {
  height: 260px; overflow-y: auto; background: #0d0d12; border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;
}
.chat-line { font-size: 13px; }
.chat-line b { color: var(--accent); }
.chat-line.ai b { color: #b388ff; }
.chat-line .t { color: #5b5b6e; font-size: 11px; margin-left: 6px; }
.emote-row { display: flex; gap: 6px; flex-wrap: wrap; }
.emote-row button { padding: 4px 10px; font-size: 15px; }
.members { display: flex; flex-direction: column; gap: 8px; }
.members .person { justify-content: flex-start; }

.emote-fx {
  position: fixed; left: 50%; top: 38%; transform: translateX(-50%);
  font-size: 72px; z-index: 60; pointer-events: none;
  animation: emote-pop 1.8s ease-out forwards; text-shadow: 0 4px 18px rgba(0,0,0,.6);
}
@keyframes emote-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(.4); }
  15% { opacity: 1; transform: translateX(-50%) scale(1.15); }
  70% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(.9); }
}
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 10px; z-index: 70; max-width: 90vw;
}
.toast.err { border-color: var(--bad); color: var(--bad); }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; }
  .side-row { padding: 6px 8px; }
  .person .who span { display: none; }
}
