/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface2:    #1f2937;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --primary:     #2ea043;
  --primary-h:   #3fb950;
  --danger:      #da3633;
  --danger-h:    #f85149;
  --gold:        #d29922;
  --gold-h:      #e3b341;
  --blue:        #1f6feb;
  --blue-h:      #388bfd;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

/* ── Utility ───────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.hint {
  color: var(--text-muted);
  font-size: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }

.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-raise    { background: var(--blue);   color: #fff; width: 100%; }
.btn-raise:hover    { background: var(--blue-h); }
.btn-doubt    { background: var(--danger); color: #fff; flex: 1; }
.btn-doubt:hover    { background: var(--danger-h); }
.btn-exact    { background: var(--gold);   color: #000; flex: 1; }
.btn-exact:hover    { background: var(--gold-h); }
.btn-lg { padding: 14px 28px; font-size: 17px; border-radius: var(--radius); }

.btn-link {
  background: none;
  border: none;
  color: var(--blue-h);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 99px;
  font-size: 14px;
  z-index: 999;
  transition: opacity .3s;
  box-shadow: var(--shadow);
}
.toast.error { background: #3d1b1b; border-color: var(--danger); color: #ffa0a0; }

/* ══════════════════════════════════════════════════════════════════════
   LOBBY PAGE
══════════════════════════════════════════════════════════════════════ */
.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}
.logo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.center-card {
  max-width: 480px;
  margin: 0 auto 24px;
}
.center-card h2 { margin-bottom: 16px; }

.input-row {
  display: flex;
  gap: 8px;
}
input[type="text"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
}
input[type="text"]:focus { border-color: var(--primary); }
.code-input { text-transform: uppercase; letter-spacing: 2px; font-weight: 700; }

.lobby-top {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 32px;
}
.lobby-actions {
  flex: 1;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.or-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.greeting {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
  font-size: 15px;
  min-width: 160px;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.games-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty-hint {
  color: var(--text-muted);
  font-size: 14px;
  padding: 16px 0;
}
.game-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.game-entry-info { flex: 1; }
.game-entry-host { font-weight: 600; }
.game-entry-meta { font-size: 13px; color: var(--text-muted); }
.game-entry-code {
  font-family: monospace;
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

/* ══════════════════════════════════════════════════════════════════════
   GAME PAGE
══════════════════════════════════════════════════════════════════════ */
.game-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 12px 32px;
}

/* Header */
.game-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.back-link { font-size: 14px; }
.game-code-badge {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
}
.game-code-badge strong { color: var(--text); font-size: 16px; letter-spacing: 1px; }
.copy-btn { font-size: 14px; text-decoration: none; }
.my-name-badge {
  font-size: 14px;
  color: var(--text-muted);
}
.my-name-badge strong { color: var(--primary-h); }

/* Phase views */
.phase-view { width: 100%; }

/* Lobby wait */
#phase-lobby h2 { margin-bottom: 8px; }
.lobby-player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}
.lobby-player-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
}
.lobby-player-chip.host::after {
  content: " 👑";
}
.lobby-btns { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }

/* Game layout */
.game-layout {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  align-items: flex-start;
}

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.sidebar-players {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .2s, background .2s;
}
.player-row.active {
  border-color: var(--primary);
  background: rgba(46, 160, 67, 0.1);
}
.player-row.me {
  border-color: var(--blue);
}
.player-row.me.active {
  border-color: var(--primary);
  background: rgba(46, 160, 67, 0.15);
}
.player-name-label { flex: 1; font-size: 14px; font-weight: 600; }
.player-dice-count {
  display: flex;
  gap: 2px;
  align-items: center;
}
.dice-pip {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}
.player-row.active .dice-pip { background: var(--primary-h); }
.player-row.me .dice-pip     { background: var(--blue-h); }
.player-row.me.active .dice-pip { background: var(--primary-h); }
.player-crown { font-size: 12px; }

.palifico-banner {
  background: rgba(210, 153, 34, 0.15);
  border: 1px solid var(--gold);
  color: var(--gold-h);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

/* Main game area */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.current-bid-card { text-align: center; }
.bid-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.bid-display {
  font-size: 42px;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 8px;
}
.bid-display .bid-value { font-size: 52px; }
.bid-history-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 22px;
}
.bid-hist-chip {
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  color: var(--text-muted);
}

.turn-banner {
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  border-color: var(--surface2);
  color: var(--text-muted);
}
.turn-banner.your-turn {
  border-color: var(--primary);
  color: var(--primary-h);
  background: rgba(46, 160, 67, 0.08);
}

/* Action panel */
.action-panel { display: flex; flex-direction: column; gap: 14px; }

.raise-form { display: flex; flex-direction: column; gap: 12px; }
.raise-row { display: flex; gap: 20px; }
.raise-field { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.raise-field label { font-size: 13px; color: var(--text-muted); }

.number-ctrl {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.num-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 30px; height: 30px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.num-btn:hover { background: var(--border); }
.num-display {
  font-size: 24px;
  font-weight: 700;
  min-width: 32px;
  text-align: center;
}

.die-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.die-pick-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 3px;
  transition: border-color .15s, background .15s;
  display: flex; align-items: center; justify-content: center;
}
.die-pick-btn:hover { border-color: var(--text-muted); }
.die-pick-btn.selected {
  border-color: var(--blue-h);
  background: rgba(56, 139, 253, 0.15);
  border-radius: 10px;
}
.die-pick-btn.joker-btn.selected {
  border-color: var(--gold-h);
  background: rgba(210, 153, 34, 0.15);
}

.challenge-btns { display: flex; gap: 10px; }

/* Your dice bar */
.your-dice-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 20px;
}
.dice-bar-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.your-dice-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── CSS Dice ──────────────────────────────────────────────────────── */
.die {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f0ece0;
  border-radius: 10px;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.4), inset 0 0 0 1px rgba(0,0,0,0.08);
  flex-shrink: 0;
  /* default size */
  width: 64px; height: 64px;
  padding: 9px;
}
.die.die-joker {
  background: #ffd060;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.3), 0 0 16px rgba(255,210,0,0.5);
}
.die.new { animation: popIn .3s ease-out; }
@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.die-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%; height: 100%;
}
.dc { display: flex; align-items: center; justify-content: center; }
.dp {
  width: 10px; height: 10px;
  background: #201825;
  border-radius: 50%;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
}
.die.die-joker .dp { background: #7a3800; }

/* Large: current bid */
.die.die-lg {
  width: 72px; height: 72px;
  padding: 9px;
  border-radius: 13px;
}
.die.die-lg .dp { width: 11px; height: 11px; }

/* Small: history + picker */
.die.die-sm {
  width: 36px; height: 36px;
  padding: 5px;
  border-radius: 7px;
  box-shadow: 1px 2px 0 rgba(0,0,0,0.3);
}
.die.die-sm .dp { width: 5px; height: 5px; }

/* ── Bid history in sidebar ────────────────────────────────────────── */
.bid-history-section { margin-top: 4px; }
.bid-history-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.hist-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 5px 8px;
  border-radius: 6px;
}
.hist-entry.hist-latest {
  background: rgba(46, 160, 67, 0.1);
  border: 1px solid rgba(46, 160, 67, 0.3);
  color: var(--text);
  font-weight: 600;
}
.hist-entry-by { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

/* ── Round end overlay ─────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.overlay-box {
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  animation: fadeUp .25s ease-out;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.round-result-text {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.4;
}
.round-result-text .result-loss { color: var(--danger-h); }
.round-result-text .result-win  { color: var(--primary-h); }
.round-result-text .result-gold { color: var(--gold-h); }

.revealed-dice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}
.reveal-player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
}
.reveal-player-name {
  font-size: 13px;
  font-weight: 600;
  min-width: 80px;
  text-align: left;
}
.reveal-dice-row { display: flex; gap: 6px; flex-wrap: wrap; }
.reveal-die {
  font-size: 22px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  background: var(--surface);
}
.reveal-die.match { background: rgba(46, 160, 67, 0.25); }
.reveal-die.joker { background: rgba(210, 153, 34, 0.2); }

.overlay-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.auto-timer {
  font-size: 13px;
  color: var(--text-muted);
}

/* Game over */
.gameover-emoji { font-size: 64px; }
.gameover-title { font-size: 28px; font-weight: 800; }
.winner-name { font-size: 22px; color: var(--gold-h); font-weight: 700; }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .game-layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .sidebar-players { flex-direction: row; flex-wrap: wrap; }
  .player-row { flex: 1; min-width: 120px; }
  .raise-row { flex-direction: column; gap: 12px; }
  .bid-display { font-size: 34px; }
  .bid-display .bid-value { font-size: 40px; }
}
