: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); }
#total-seconds { font-weight: 700; color: var(--muted); }
#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; }
#lobby-players li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.lobby-options { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; align-items: flex-end; }
.lobby-options > label { display: block; color: var(--muted); font-size: 13px; }
.lobby-options select { width: 100%; margin-top: 4px; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: #12152a; color: var(--text); font-size: 14px; }

/* ---------- 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; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  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 .face { font-size: 16px; font-weight: 700; line-height: 1; }
.tile .corner { position: absolute; top: 3px; left: 4px; font-size: 7px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: rgba(0,0,0,0.5); }
.tile .dragon-emoji { font-size: 20px; line-height: 1; }
.tile.suit-b { background: #4a90d9; border-color: #2f6fb0; color: #fff; }
.tile.suit-c { background: #d9534f; border-color: #a93732; color: #fff; }
.tile.suit-d { background: #4fa05a; border-color: #357c3f; color: #fff; }
.tile.wind { background: #fbf7e6; border-color: #d8cfae; color: #1a1a1a; }
.tile.dragon { background: #e8823a; border-color: #b5622a; color: #fff; }
.tile.dragon .corner { color: rgba(255,255,255,0.85); }
.dragon-emoji.dragon-red { filter: sepia(1) saturate(4) hue-rotate(-50deg); }
.dragon-emoji.dragon-green { filter: none; }
.dragon-emoji.dragon-white { filter: grayscale(1) brightness(1.6); }
.tile.covered { visibility: hidden; }
.tile.locked { filter: brightness(0.55) grayscale(0.5); cursor: not-allowed; }
.tile.free { outline: 2px solid rgba(110,168,255,0.9); outline-offset: 1px; cursor: pointer; }
.tile.selected { outline: 3px solid var(--gold); }
.tile.removed { display: none; }

#cheat-bar { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
#cheat-bar button:disabled { opacity: 0.4; cursor: not-allowed; background: transparent; }
#cheat-bar button:not(:disabled) { background: var(--accent); color: #0b0e1c; border-color: var(--accent); }
#revealed-wrap { margin: 10px 0; }
.revealed-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
#revealed-tray { display: flex; flex-wrap: wrap; gap: 6px; min-height: 34px; align-items: flex-start; }
#revealed-tray .tile { position: relative; left: auto; top: auto; }
#final-board { position: relative; margin: 12px 0; }
#final-revealed-tray { display: flex; flex-wrap: wrap; gap: 6px; min-height: 34px; align-items: flex-start; margin-top: 8px; }
#final-revealed-tray .tile { position: relative; left: auto; top: auto; }

.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; }

.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); }
.tile.hint { outline: 3px solid var(--gold); outline-offset: 1px; box-shadow: 0 0 8px var(--gold); }

/* ---------- 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; }

/* ---------- 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;
}

/* ---------- Wordsicle board (crossword + letter circle) ---------- */
.board-label { font-size: 12px; color: var(--muted); font-weight: 700; margin: 16px 0 6px; text-transform: uppercase; letter-spacing: 0.6px; }
#crossword, #final-crossword {
  --cell: 34px;
  display: grid;
  gap: 3px;
  justify-content: start;
  margin: 6px 0;
}
.xcell {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #0e1223;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
  box-sizing: border-box;
}
.xcell.filled { color: #0b0e1c; border-color: rgba(0,0,0,0.25); }
.xcell.blank { background: #161a30; }
.xempty { width: var(--cell); height: var(--cell); }

#letter-circle {
  position: relative;
  margin: 12px auto;
  touch-action: none;
}
.ltr {
  position: absolute;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #242a45;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  touch-action: none;
  box-sizing: border-box;
}
.ltr.spelled { background: var(--accent); color: #0b0e1c; border-color: var(--accent); }

#guess-row { display: flex; align-items: center; gap: 16px; margin: 10px 0; }
.guess-word { font-size: 24px; font-weight: 700; letter-spacing: 3px; min-height: 30px; color: var(--accent); }

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