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

* { 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; }

/* ---------- header / status ---------- */
header.site-head { background: var(--panel); border-bottom: 1px solid var(--border); }
.head-inner { padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; width: 100%; }
.head-brand .brand { font-size: 20px; font-weight: 700; }
#status-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); font-size: 15px; }
#header-right { display: flex; align-items: center; gap: 8px; }
.header-btn { font-size: 14px; font-weight: 700; padding: 5px 14px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; }

/* ---------- layout ---------- */
#layout { display: flex; height: 100vh; overflow: hidden; }
#content { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#content-body { flex: 1; overflow-y: auto; padding: 20px; }
#content-body .panel { max-width: 980px; margin-left: auto; margin-right: auto; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-top: 20px; }
.panel h2 { margin: 0 0 12px; font-size: 18px; }
.panel h3 { margin: 18px 0 6px; font-size: 14px; color: var(--muted); }
.muted { color: var(--muted); }
.room-code { font-size: 20px; }
.room-code strong { letter-spacing: 2px; color: var(--accent); }

/* ---------- landing ---------- */
.landing-grid { max-width: 900px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
#content-body .landing-grid .panel { max-width: none; margin: 0; }
@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"] { width: 100%; margin-top: 4px; padding: 9px; border-radius: 8px; border: 1px solid var(--border); background: #12152a; color: var(--text); font-size: 15px; }

/* ---------- buttons ---------- */
.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; }
.pass-btn { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 11px 22px; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 4px; }
#lobby-players li { padding: 8px 0; border-bottom: 1px solid var(--border); }

/* ---------- game ---------- */
#game-progress { color: var(--muted); font-size: 14px; min-height: 18px; }
.message { min-height: 22px; font-size: 16px; color: var(--gold); }

#board { position: relative; margin: 12px 0; }
.tile {
  position: absolute;
  width: 46px; height: 62px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; cursor: pointer; user-select: none;
  background: linear-gradient(#f7f3e8, #ddd6c0);
  border: 1px solid #8a7a55;
  color: #1a1a1a;
  font-size: 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.tile .glyph { line-height: 1; }
.tile .fallback { display: block; font-size: 9px; color: #6a5b3a; margin-top: 2px; }
.tile.blocked { opacity: 0.55; cursor: not-allowed; filter: grayscale(0.5); }
.tile.free { outline: 2px solid rgba(110,168,255,0.9); outline-offset: 1px; }
.tile.selected { outline: 3px solid var(--gold); }
.tile.removed { display: none; }

.score-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.score-row.turn { color: var(--accent); font-weight: 700; }
.score-row .score { font-weight: 700; }

/* ---------- 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 .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; }

/* ---------- final ---------- */
.lb-row { margin: 10px 0; }
.lb-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; margin-bottom: 4px; }
.lb-score { font-weight: 700; }
.lb-row.lead .lb-name { color: var(--green); font-weight: 700; }
.lb-row.lead .lb-score { color: var(--green); }

/* ---------- 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; }

@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; }
}
