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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --card: #0f3460;
  --accent: #e94560;
  --text: #eaeaea;
  --muted: #888;
  --yellow: #f0c040;
  --orange: #f07820;
  --pink:   #e040c0;
  --white:  #e8e8e8;
  --green:  #40c040;
  --blue:   #4080f0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ---- Screens ---- */
.screen { display: none; width: 100%; }
.screen.active { display: flex; align-items: center; justify-content: center; }

#screen-game.active {
  display: block;
  height: 100vh;
  position: relative;  /* needed for win overlay absolute positioning */
}

/* ---- Win overlay (shown over board so final state is visible) ---- */
#win-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* ---- Cards ---- */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 2rem;
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 8px 32px #0008;
}
.card.wide { max-width: 480px; }

h1 { font-size: 2.4rem; color: var(--accent); letter-spacing: 2px; text-align: center; }
h2 { font-size: 1.5rem; text-align: center; }
.tagline { text-align: center; color: var(--muted); }

/* ---- Inputs ---- */
input[type=text], input[type=number] {
  background: var(--surface);
  border: 1px solid #fff2;
  border-radius: 8px;
  color: var(--text);
  font-size: 1.1rem;
  padding: 0.6rem 1rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
input:focus { border-color: var(--accent); }

/* ---- Buttons ---- */
button {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.65rem 1.4rem;
  transition: opacity 0.15s, transform 0.1s;
}
button:hover:not(:disabled) { opacity: 0.85; transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.35; cursor: default; }
button.secondary { background: #fff2; }

.btn-row { display: flex; gap: 0.75rem; justify-content: center; }

/* ---- Lobby slots ---- */
#lobby-slots { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
#lobby-slots li {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.slot-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- Game layout ---- */
#game-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Board area takes remaining width; centres canvas without stretching it */
#board-area {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0d1b2a;
}

/* Canvas size is controlled by JS; no CSS override so click coords stay accurate */
#board-canvas {
  display: block;
  cursor: pointer;
}

#sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  overflow-y: auto;
}

/* ---- Dice ---- */
#dice-area {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ---- Commit / Undo area ---- */
#commit-area {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-height: 0;  /* collapse when both buttons are hidden */
}
.die {
  width: 52px; height: 52px;
  background: color-mix(in srgb, var(--die-color, #fff) 55%, #fff);
  color: #111;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  font-weight: 900;
  box-shadow: 2px 3px 6px #0006;
  transition: background 0.3s;
}
.die.used { background: #555; color: #888; }
.die.selected-die { outline: 3px solid #fff; outline-offset: 2px; }
.die.rolling { animation: shake 0.4s ease; }

@keyframes shake {
  0%,100% { transform: rotate(0); }
  25% { transform: rotate(-15deg) scale(1.1); }
  75% { transform: rotate(15deg) scale(1.1); }
}

/* ---- Turn banner ---- */
#turn-banner {
  background: var(--card);
  border-radius: 8px;
  padding: 0.5rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
}

/* ---- Player list ---- */
#player-list { display: flex; flex-direction: column; gap: 0.4rem; }
.player-row {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid transparent;
}
.player-row.active-turn { border-color: var(--accent); background: #fff1; }
.player-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- Move hint ---- */
#move-hint {
  font-size: 0.8rem;
  color: var(--yellow);
  text-align: center;
  padding: 0.3rem 0.5rem;
  background: #fff1;
  border-radius: 6px;
  min-height: 1.4em;
}

/* ---- Game log ---- */
#game-log {
  flex: 1;
  overflow-y: auto;
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.log-entry { padding: 1px 0; display: flex; align-items: baseline; gap: 5px; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }

/* ---- Player color CSS vars used in JS ---- */
.color-yellow { background: var(--yellow); }
.color-orange { background: var(--orange); }
.color-pink   { background: var(--pink);   }
.color-white  { background: var(--white);  }
.color-green  { background: var(--green);  }
.color-blue   { background: var(--blue);   }

/* ---- Green "go" button ---- */
.btn-go { background: #2a9d2a; }

/* ---- Icon button (copy code) ---- */
.btn-icon {
  background: transparent;
  border: 1px solid #fff3;
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: normal;
  padding: 0.2rem 0.5rem;
  margin-left: 0.5rem;
  transition: background 0.15s;
}
.btn-icon:hover { background: #fff1; }

/* ---- Color picker row ---- */
.color-picker-row { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.color-swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  padding: 0;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected { border-color: #fff; transform: scale(1.15); }

/* ---- Robot delete button in lobby slot ---- */
.btn-remove-robot {
  background: transparent;
  border: none;
  color: #f66;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  margin-left: auto;
  padding: 0 0.3rem;
}
.btn-remove-robot:hover { color: #f00; }

/* Lobby slot: allow delete button to sit at far right */
#lobby-slots li { justify-content: flex-start; }
