: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; }
.nav { display: flex; align-items: center; gap: 16px; }
.nav a { color: var(--text); font-size: 15px; }
.nav a:hover { color: var(--accent); text-decoration: none; }
.nav-dropdown { position: relative; }
.nav-dropdown-toggle { background: none; border: 0; color: var(--text); font-size: 15px; cursor: pointer; padding: 4px 0; }
.nav-dropdown-menu {
  display: none; position: absolute; right: 0; top: 100%;
  min-width: 190px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 0; z-index: 30;
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a { display: block; padding: 8px 14px; color: var(--text); font-size: 14px; text-decoration: none; }
.nav-dropdown-menu a:hover { background: #242a45; text-decoration: none; }

#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; }
.status-left { display: flex; align-items: center; gap: 12px; }
.status-right { display: flex; align-items: center; gap: 12px; }
#turn-indicator { font-weight: 700; color: var(--accent); }
#score-indicator { font-weight: 700; color: var(--gold); }
.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: 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; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
#lobby-players li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.lobby-options { display: flex; flex-wrap: wrap; gap: 16px; margin: 12px 0; align-items: flex-end; }
.lobby-options > label { display: block; color: var(--muted); font-size: 13px; }
.lobby-options select { margin-top: 4px; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: #12152a; color: var(--text); font-size: 14px; }

/* ---------- game ---------- */
.message { min-height: 22px; font-size: 16px; color: var(--gold); }
.category { color: var(--muted); font-size: 14px; margin: 2px 0; }

.board-label { font-size: 12px; color: var(--muted); font-weight: 700; margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 0.6px; }

#board-wrap { max-width: 720px; }
#board {
  position: relative;
  margin: 8px 0;
  background: #12152a;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#board-outline { position: absolute; left: 0; top: 0; pointer-events: none; }
#board-pieces { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }

.board-piece {
  position: absolute;
  cursor: grab;
  pointer-events: none;
  will-change: transform;
}
.board-piece.placed { pointer-events: none; }

#pile-wrap { max-width: 720px; }
#pile {
  height: 168px;
  overflow-y: auto;
  overflow-x: hidden;
  background: #12152a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 10px;
  touch-action: pan-y;
}
.pile-piece {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  border-radius: 4px;
}
.pile-piece.returning { transition: transform 0.5s cubic-bezier(0.3, 0, 0.2, 1); }

.drag-piece {
  position: fixed;
  z-index: 5000;
  pointer-events: none;
  cursor: grabbing;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.5));
}

/* solve row */
#solve-row { display: flex; gap: 10px; align-items: center; margin: 14px 0 4px; flex-wrap: wrap; }
#solve-input { flex: 1; min-width: 180px; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: #12152a; color: var(--text); font-size: 15px; text-transform: uppercase; letter-spacing: 1px; }

/* scores */
.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; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 7px; vertical-align: middle; }
.score-row .sname { display: inline-flex; align-items: center; }

/* timer */
.timer-row { display: flex; align-items: center; gap: 8px; margin: 2px 0 10px; }
.timerbar { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 0; }
.timer-text { font-size: 13px; font-weight: 700; color: var(--muted); min-width: 28px; text-align: right; }
#timer-fill { height: 100%; width: 100%; background: var(--accent); transition: width 0.2s linear; }
.timerbar.warn #timer-fill { background: var(--gold); }
.timerbar.low #timer-fill { background: var(--red); }

/* ---------- 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 ---------- */
#final-reveal { font-size: 22px; letter-spacing: 2px; font-weight: 700; color: var(--green); margin: 10px 0; }
.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; }

/* ---------- goop overlay (loser) ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 9999; }
#goop-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 9998; overflow: hidden; }
#goop-overlay.hidden { display: none; }
.goop { position: absolute; top: -50%; left: 8%; width: 22%; height: 130%; border-radius: 50% 50% 38% 38%; background: linear-gradient(#7ec850, #3f9b3f); opacity: 0.85; animation: goop-drip 4.2s ease-in forwards; }
.goop:nth-child(2) { left: 31%; width: 18%; animation-delay: 0.35s; background: linear-gradient(#8fd460, #4cae4c); }
.goop:nth-child(3) { left: 55%; width: 24%; animation-delay: 0.7s; background: linear-gradient(#6cc04a, #357a35); }
.goop:nth-child(4) { left: 78%; width: 15%; animation-delay: 1.05s; background: linear-gradient(#9adf6b, #559f55); }
@keyframes goop-drip {
  0% { transform: translateY(-30%); opacity: 0.9; }
  100% { transform: translateY(150%); opacity: 0; }
}

@media (max-width: 720px) {
  #layout { flex-direction: column; height: auto; overflow: visible; }
  #chat-panel { position: static; order: 2; width: auto; height: auto; min-height: 0; border-right: 0; border-top: 1px solid var(--border); }
  #content { flex: none; }
  #content-body { flex: none; overflow: visible; }
  #chat-messages { flex: none; max-height: 45vh; }
  #chat-panel .chat-close { display: inline; }
  #chat-panel.collapsed > *:not(.chat-title) { display: none; }
  #chat-panel.collapsed .chat-close { display: none; }
  #chat-panel.collapsed .chat-title::after { content: "…"; }
}

/* ---------- flag dialog ---------- */
.flag-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 1rem; }
.flag-modal { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; max-width: 440px; width: 100%; max-height: 84vh; overflow: auto; box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4); }
.flag-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; font-weight: 700; border-bottom: 1px solid var(--border); }
.flag-close { background: none; border: 0; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--muted); }
.flag-close:hover { color: var(--text); }
.flag-body { padding: 16px 18px; }
.flag-body .mini { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.flag-url { word-break: break-all; }
.flag-body label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.flag-body select, .flag-body textarea { width: 100%; padding: 9px; border-radius: 8px; border: 1px solid var(--border); background: #12152a; color: var(--text); font-size: 14px; margin-bottom: 14px; font-family: inherit; }
.flag-body textarea { resize: vertical; }
.flag-submit { background: var(--accent); color: #0b0e1c; border: 0; border-radius: 8px; padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; }
.flag-submit:disabled { opacity: 0.6; cursor: not-allowed; }
#flag-result .flash { padding: 10px 12px; border-radius: 8px; margin-top: 12px; font-size: 14px; }
.flash-ok { background: #1f3a2c; color: var(--green); }
.flash-error { background: #3a1f1f; color: var(--red); }

/* ---------- features & bugs page ---------- */
.page-title { font-size: 24px; margin: 0 0 4px; }
.page-sub { margin: 0 0 18px; }
.fb-item { border-bottom: 1px solid var(--border); padding: 10px 0; }
.fb-item:last-child { border-bottom: 0; }
.fb-field { margin: 2px 0; font-size: 14px; }
.fb-label { color: var(--muted); font-weight: 600; }

/* ---- collapsible chat (mobile) ---- */
.chat-title { position: relative; }
.chat-close {
  display: none;
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-style: normal;
  font-size: 1.2em;
  line-height: 1;
  cursor: pointer;
}
