*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e94560;
  --text: #eaeaea;
  --muted: #8888aa;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Auth overlay ─────────────────────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
}
#auth-overlay h1 { font-size: 2.5rem; color: var(--accent); }
#auth-overlay input {
  padding: 12px 20px; font-size: 1.1rem;
  border: 2px solid var(--muted); border-radius: var(--radius);
  background: var(--surface); color: var(--text); outline: none;
  width: 280px; text-align: center;
}
#auth-overlay input:focus { border-color: var(--accent); }
#auth-overlay .error { color: var(--accent); font-size: 0.9rem; }

/* ── Top bar ──────────────────────────────────────────────────────────── */
#top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  flex-shrink: 0;
  height: 52px;
  gap: 12px;
}
#top-bar h1 { font-size: 1.3rem; color: var(--accent); letter-spacing: 1px; white-space: nowrap; }
#turn-label { font-size: 0.95rem; color: var(--text); flex: 1; text-align: center; }
#settings-btn {
  background: none; border: none; color: var(--muted);
  font-size: 1.4rem; cursor: pointer; padding: 4px 8px;
  transition: color 0.2s;
}
#settings-btn:hover { color: var(--text); }

/* ── Word tooltip ─────────────────────────────────────────────────────── */
.word-tooltip {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--muted);
  border-bottom: 1px dashed var(--muted);
  position: relative;
  white-space: nowrap;
  user-select: none;
}
.word-tooltip::after {
  content: attr(data-word);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--accent);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  border: 1px solid rgba(255,255,255,0.15);
  z-index: 200;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.word-tooltip:hover::after { opacity: 1; }

/* ── Main layout ──────────────────────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Canvas area ──────────────────────────────────────────────────────── */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
  background: var(--bg);
  position: relative;
  min-width: 0;
  overflow: hidden;
}

/* Lobby state: center the placeholder */
#lobby-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}
#lobby-center h2 { font-size: 2rem; }
#lobby-center p  { color: var(--muted); }
#start-section {
  display: flex; flex-direction: column; gap: 8px; align-items: center; width: 100%; max-width: 300px;
}
#start-btn {
  width: 100%; padding: 14px; font-size: 1.1rem;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius); cursor: pointer; font-weight: 700;
  transition: opacity 0.2s;
}
#start-btn:hover { opacity: 0.85; }

/* Game state: canvas + controls fill the area */
#canvas-area-inner {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 8px;
}
#canvas-wrap {
  flex: 1;
  display: flex;
  gap: 10px;
  align-items: stretch;
  min-height: 0;
}
.canvas-container {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  min-height: 0;
}
.canvas-container { display: flex; align-items: center; justify-content: center; }
.canvas-container canvas { display: block; }
.canvas-label {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,0.55); color: #fff;
  padding: 2px 10px; border-radius: 20px; font-size: 0.8rem;
  pointer-events: none;
}

/* ── Timer bar ────────────────────────────────────────────────────────── */
#timer-bar {
  display: none;
  align-items: center; gap: 10px;
  flex-shrink: 0;
}
#timer-track {
  flex: 1; height: 8px; background: var(--surface2); border-radius: 4px; overflow: hidden;
}
#timer-fill {
  height: 100%; width: 100%; background: var(--accent);
  transition: width 1s linear, background 0.3s;
  border-radius: 4px;
}
#timer-label {
  min-width: 36px; text-align: right; font-size: 0.9rem; color: var(--text);
}

/* ── Round controls ───────────────────────────────────────────────────── */
#round-controls {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  flex-shrink: 0;
  padding: 2px 0;
}
.winner-btn {
  padding: 9px 18px; font-size: 0.95rem; border-radius: var(--radius);
  border: 2px solid; cursor: pointer; font-weight: 600;
  transition: transform 0.1s, opacity 0.2s;
  white-space: nowrap;
}
.winner-btn:hover { transform: scale(1.04); }
.winner-btn.nobody {
  border-color: var(--muted); color: var(--muted); background: transparent;
}

/* ── Dice overlay ─────────────────────────────────────────────────────── */
#dice-overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(15,15,26,0.8);
  z-index: 10;
}
#dice-overlay.visible { display: flex; }
#dice-face {
  font-size: 8rem;
  animation: rollIn 0.4s ease;
}
@keyframes rollIn {
  from { transform: scale(0.4) rotate(-30deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

/* ── Right panel ──────────────────────────────────────────────────────── */
#right-panel {
  width: 300px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow-y: auto;
  border-left: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

/* ── Board — snake 8×8 ────────────────────────────────────────────────── */
#board-section { padding: 10px; }
#board-section h3 { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
#board-wrap {
  position: relative;
  width: 100%;
  padding-top: 100%; /* square */
}
#board-inner {
  position: absolute; inset: 0;
}
.board-sq {
  position: absolute;
  border: 1px solid rgba(0,0,0,0.25);
  border-radius: 2px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  color: rgba(255,255,255,0.92);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  letter-spacing: 0;
  line-height: 1;
  z-index: 3;
}
.board-sq.finish {
  border: 2px solid #fff;
  font-size: 0.5rem;
}
.board-sq.start {
  border: 2px solid rgba(255,255,255,0.6);
  font-size: 0.5rem;
}
.pawn {
  position: absolute;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.8);
  transform: translate(-50%, -50%);
  transition: left 0.6s ease, top 0.6s ease;
  z-index: 5;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

/* ── Scores ───────────────────────────────────────────────────────────── */
#scores-section { padding: 0 10px 10px; }
#scores-section h3 { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.score-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.score-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.score-name { flex: 1; font-size: 0.9rem; }
.score-val { font-size: 1.05rem; font-weight: 700; }
.score-pos { font-size: 0.72rem; color: var(--muted); }

/* ── Players list ─────────────────────────────────────────────────────── */
#players-section { padding: 0 10px 10px; }
#players-section h3 { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.player-chip {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 0.8rem; margin: 2px; color: #fff;
  opacity: 0.85;
}
.player-chip.offline { opacity: 0.35; text-decoration: line-through; }

/* ── Winner banner ────────────────────────────────────────────────────── */
#winner-banner {
  position: fixed; inset: 0; z-index: 50;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(15,15,26,0.92);
  text-align: center;
  cursor: pointer;
}
#winner-banner.visible { display: flex; }
#winner-banner h1 { font-size: 3.5rem; margin-bottom: 8px; }
#winner-banner p  { font-size: 1.3rem; color: var(--muted); }

/* ── Settings drawer ──────────────────────────────────────────────────── */
#settings-panel {
  position: fixed; top: 0; right: -380px; width: 360px; height: 100%;
  background: var(--surface2); z-index: 100;
  box-shadow: -4px 0 24px rgba(0,0,0,0.5);
  transition: right 0.3s ease;
  display: flex; flex-direction: column;
  padding: 20px;
  gap: 0;
  overflow-y: auto;
}
#settings-panel.open { right: 0; }
#settings-panel h2 { font-size: 1.2rem; margin-bottom: 16px; }
.setting-group { margin-bottom: 18px; }
.setting-group label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.setting-group input[type="number"],
.setting-group input[type="text"],
.setting-group select {
  width: 100%; padding: 8px 12px; font-size: 1rem;
  background: var(--surface); border: 1px solid rgba(255,255,255,0.1);
  color: var(--text); border-radius: 6px; outline: none;
}
.setting-group input:focus { border-color: var(--accent); }
.checkbox-label {
  display: flex !important; align-items: center; gap: 8px; cursor: pointer; color: var(--text) !important;
}
.checkbox-label input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent);
}
.team-setting {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.team-setting .dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.team-setting input { flex: 1; }
.players-assign { margin-top: 6px; }
.assign-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.88rem;
}
.kick-btn {
  background: none; border: 1px solid rgba(255,255,255,0.15);
  color: var(--muted); cursor: pointer; border-radius: 4px;
  padding: 2px 7px; font-size: 0.8rem; flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.kick-btn:hover { color: var(--accent); border-color: var(--accent); }
#apply-settings-btn {
  width: 100%; padding: 12px; background: var(--accent); color: #fff;
  border: none; border-radius: 6px; font-size: 1rem; cursor: pointer;
  font-weight: 700; margin-bottom: 10px; flex-shrink: 0;
}
#end-game-btn {
  width: 100%; padding: 10px; background: transparent; color: #c0392b;
  border: 1px solid #c0392b; border-radius: 6px; font-size: 0.95rem;
  cursor: pointer; font-weight: 600; margin-bottom: 10px; flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}
#end-game-btn:hover { background: #c0392b; color: #fff; }
#close-settings {
  background: none; border: 1px solid var(--muted); color: var(--muted);
  padding: 8px 20px; border-radius: 6px; cursor: pointer; flex-shrink: 0;
}
#close-settings:hover { color: var(--text); border-color: var(--text); }

/* ── Category label ───────────────────────────────────────────────────── */
#category-badge {
  padding: 4px 12px; border-radius: 20px; font-size: 0.85rem;
  font-weight: 600; color: #fff;
  display: none;
  white-space: nowrap;
}

/* ── Big button shared ────────────────────────────────────────────────── */
.big-btn {
  cursor: pointer; border: none; border-radius: var(--radius);
  padding: 10px 20px; font-size: 1rem; font-family: var(--font);
  background: var(--accent); color: #fff;
}
.hidden { display: none !important; }
