:root {
  --bg: #0f1220;
  --panel: #1b1f33;
  --border: #32374f;
  --text: #e6e9f5;
  --muted: #8b91ad;
  --accent: #6ea8ff;
  --gold: #f5c518;
  --red: #e05a5a;
  --green: #4fc07a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- layout ---------- */
#layout { display: flex; height: 100vh; overflow: hidden; }
#content { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; max-width: none; margin: 0; padding: 0; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 20px; }
#timer { color: var(--muted); font-size: 15px; }

#content-body { flex: 1; overflow-y: auto; padding: 20px; }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-top: 20px; max-width: none; }
.panel h2 { margin: 0 0 12px; font-size: 18px; }
.panel h3 { margin: 18px 0 6px; font-size: 14px; color: var(--muted); }

.landing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 600px) { .landing-grid { grid-template-columns: 1fr; } }

.room-form > label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.room-form input[type="text"], .room-form select {
  width: 100%; margin-top: 4px; padding: 9px; border-radius: 8px;
  border: 1px solid var(--border); background: #12152a; color: var(--text); font-size: 15px;
}

.primary {
  background: var(--accent); color: #0b0e1c; border: 0; border-radius: 8px;
  padding: 11px 22px; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 4px;
}

.muted { color: var(--muted); }
.room-code { font-size: 20px; }
.room-code strong { letter-spacing: 2px; color: var(--accent); }
#lobby-players li { padding: 8px 0; border-bottom: 1px solid var(--border); }

/* ---------- board ---------- */
#board {
  display: grid;
  gap: 0;
  background: #000;
  border: 2px solid #000;
  border-radius: 4px;
  width: min(92vw, 560px);
  margin: 12px auto 4px;
}
.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
}
.cell.br { border-right: 2px solid #000; }
.cell.bb { border-bottom: 2px solid #000; }
.cell.given { color: var(--muted); font-weight: 700; }
.cell.selected { background: #2a3560; }
.cell.peer { background: #222742; }
.cell.same-digit { background: #33406e; }
.cell.conflict { color: var(--red); }

#message { min-height: 24px; font-size: 20px; font-weight: 700; color: var(--gold); text-align: center; }

/* ---------- number pad ---------- */
#numpad {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px auto;
  max-width: 560px;
}
#numpad button {
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  font-size: 17px;
  font-weight: 700;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
#numpad button:hover { border-color: var(--accent); }
#numpad button.erase { color: var(--muted); font-size: 16px; }

.hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 16px; }

/* ---------- chat sidebar + voice ---------- */
#chat-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
  min-height: 100vh;
}
#chat-panel.hidden { display: none; }
.chat-title { margin: 0; padding: 14px 16px; border-bottom: 1px solid var(--border); }
#chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { align-self: flex-start; max-width: 82%; line-height: 1.4; font-size: 14px; background: #22263e; border-radius: 10px; padding: 6px 10px; }
.chat-msg .who { color: var(--accent); font-weight: 600; }
.chat-msg.mine { align-self: flex-end; background: #1f3a2c; }
.chat-msg.mine .who { color: var(--green); }
.chat-msg .when { color: var(--muted); font-size: 11px; margin-left: 6px; }
.chat-msg .body { word-wrap: break-word; overflow-wrap: anywhere; }
#chat-input-row { display: flex; border-top: 1px solid var(--border); padding: 8px; gap: 8px; }
#chat-input { flex: 1; min-width: 0; padding: 9px; border-radius: 6px; border: 1px solid var(--border); background: #12152a; color: var(--text); font-size: 14px; }
#chat-send { background: var(--accent); color: #0b0e1c; border: 0; border-radius: 8px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; }

#voice-panel { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--panel); }
#voice-panel button { flex: 1; position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 10px; font-size: 12px; line-height: 1.2; border: 0; border-radius: 8px; cursor: pointer; }
#voice-panel button.on { background: #3dbb6d; color: #0b0e1c; }
#voice-panel button.off { background: #e57373; color: #0b0e1c; }
#voice-panel button:disabled { opacity: .5; cursor: not-allowed; }
#voice-panel .btn-line1 { font-weight: 700; }
#voice-panel .btn-line2 { font-size: 11px; opacity: 0.85; }
.meter { position: absolute; left: 0; bottom: 0; height: 5px; width: 0%; background: #0a5a2a; transition: width 0.08s linear; }

@media (max-width: 720px) {
  #layout { flex-direction: column; }
  #chat-panel { position: fixed; left: 0; right: 0; bottom: 0; width: auto; height: 45vh; min-height: 0; border-right: 0; border-top: 1px solid var(--border); z-index: 20; }
  #content { padding-bottom: 46vh; }
}

/* ---------- hub auth gate ---------- */
#auth-gate { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 10000; }
#auth-gate.hidden { display: none; }
.auth-gate-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; text-align: center; max-width: 420px; }
.auth-gate-box h2 { margin: 0 0 8px; }
.auth-gate-box p { color: var(--muted); margin: 0 0 12px; }
.auth-gate-box .btn { display: inline-block; padding: 10px 18px; border-radius: 8px; background: var(--accent); color: #0b0e1c; text-decoration: none; font-weight: 600; }

/* ---------- turn bar (competitive) ---------- */
#turn-row { margin: 8px 0; }
.turn-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
#turn-label { font-size: 14px; font-weight: 700; color: var(--accent); }
#end-turn-btn { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 10px; font-size: 13px; font-weight: 600; cursor: pointer; }
#end-turn-btn:hover { border-color: var(--accent); }
.turnbar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
#turn-fill { height: 100%; width: 100%; background: var(--accent); transition: width 0.2s linear; }

/* ---------- readonly board (not your turn) ---------- */
#board.readonly { opacity: 0.75; }
#board.readonly .cell { cursor: not-allowed; }

/* ---------- final leaderboard ---------- */
#final-leaderboard { margin-top: 12px; }
.lb-row { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--border); }
.lb-row.lead .lb-name, .lb-row.lead .lb-score { color: var(--gold); font-weight: 700; }
.lb-name { font-size: 15px; }
.lb-score { font-size: 15px; font-weight: 700; }
