:root {
  --gap: 2px;
  --bg: #fdf4ff;
  --board-cell: #fad9f7;
  --board-cell-alt: #e4d4f9;
  --ladder: #a78bfa;
  --snake: #f472b6;
  --text: #6b21a8;
  --muted: #a78bba;
  --board-border: #7c3aed;
  --sidebar-w: 290px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ── Setup ──────────────────────────────────── */

#setup {
  background: white;
  padding: 28px;
  border-radius: 14px;
  box-shadow: 0 2px 16px rgba(147, 51, 234, 0.12);
  width: min(420px, 100%);
  margin: auto;
  border: 1px solid #e9d5ff;
}

#setup h1 { text-align: center; margin-bottom: 20px; }

.field { margin-bottom: 12px; display: flex; align-items: center; gap: 12px; }
.field label { width: 100px; font-weight: 500; }

.field input,
.field select {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #d8b4fe;
  border-radius: 6px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
}

.field input:focus,
.field select:focus { outline: none; border-color: var(--board-border); }

button {
  background: var(--board-border);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
}

button:hover:not(:disabled) { background: var(--text); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

#start-btn { width: 100%; margin-top: 8px; }

/* ── Game layout ────────────────────────────── */

#game {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  gap: 14px;
}

/* ── Board (entire left column) ─────────────── */

#board-section {
  min-height: 0;
  min-width: 0;
}

#board {
  width: 100%;
  height: 100%;

  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: var(--gap);
  background: var(--board-border);
  padding: var(--gap);
  border-radius: 10px;
  box-shadow: 0 6px 28px rgba(124, 58, 237, 0.3);
}

.cell {
  background: var(--board-cell);
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 4px;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.cell.alt { background: var(--board-cell-alt); }
.cell.ladder-bottom, .cell.ladder-top { background: var(--ladder); }
.cell.snake-head, .cell.snake-tail { background: var(--snake); }

.cell .num {
  font-weight: 700;
  font-size: 11px;
  opacity: 0.6;
  color: var(--text);
  line-height: 1;
  flex-shrink: 0;
}

.cell .hint {
  font-size: 10px;
  font-weight: 700;
  margin-top: auto;
  color: var(--text);
  opacity: 0.85;
  line-height: 1;
  flex-shrink: 0;
}

.tokens {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 1px;
  padding: 3px;
  pointer-events: none;
}

.token {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 34px;
  display: grid;
  place-items: center;
  background: white;
  border: 3px solid transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  line-height: 1;
  flex-shrink: 0;
}

/* ── Sidebar (right column) ─────────────────── */

#sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

#sidebar h1 {
  font-size: 18px;
  color: var(--text);
  flex-shrink: 0;
}

#hud {
  background: white;
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(147, 51, 234, 0.1);
  border: 1px solid #e9d5ff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

#hud-turn {
  display: flex;
  align-items: center;
  gap: 8px;
}

#hud-dice {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-label { color: var(--muted); font-size: 13px; }

#current-player { font-weight: 700; font-size: 17px; }

#dice-display {
  font-size: 20px;
  font-weight: 700;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: #f3e8ff;
  border-radius: 8px;
  border: 2px solid #d8b4fe;
  color: var(--text);
  flex-shrink: 0;
}

#message {
  color: var(--muted);
  font-size: 13px;
  min-height: 16px;
  flex-shrink: 0;
}

#legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 4px;
}

.legend-swatch.ladder { background: var(--ladder); }
.legend-swatch.snake  { background: var(--snake); }

/* ── Leaderboard ────────────────────────────── */

#lb-players { display: flex; flex-direction: column; gap: 10px; }

.lb-player {
  background: #faf5ff;
  border-radius: 8px;
  padding: 10px;
  border: 1px solid #e9d5ff;
}

.lb-header {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
}

.lb-emoji { font-size: 22px; line-height: 1; }
.lb-name  { font-weight: 700; font-size: 14px; flex: 1; }
.lb-pos   { font-size: 11px; color: var(--muted); background: #f3e8ff; padding: 2px 7px; border-radius: 10px; }

.lb-rolls { display: flex; flex-direction: column; gap: 3px; }

.lb-roll {
  font-size: 11px;
  color: #555;
  padding: 2px 6px;
  background: white;
  border-radius: 4px;
  border-left: 3px solid #e9d5ff;
}

.lb-roll.is-snake  { border-left-color: var(--snake); }
.lb-roll.is-ladder { border-left-color: var(--ladder); }
.lb-roll.is-current { background: #f3e8ff; font-weight: 600; }

.lb-waiting { font-size: 12px; color: var(--muted); font-style: italic; }

/* ── Responsive ─────────────────────────────── */

@media (max-width: 800px) {
  body { overflow: auto; }
  #game { grid-template-columns: 1fr; grid-template-rows: auto auto; }
  #board-section { justify-content: center; }
  #board { height: min(90vw, 70vh); }
  #sidebar { flex-direction: row; flex-wrap: wrap; }
}
