:root {
  --bg: #1a1a2e;
  --bg-2: #16213e;
  --card: #0f3460;
  --text: #eaeaea;
  --muted: #94a3b8;
  --accent: #e94560;
  --board-bg: #faf6ee;
  --grid: #c8b89a;
  --path: #ffffff;
  --safe: #e5dccb;
  --red: #e74c3c;
  --green: #27ae60;
  --yellow: #f1c40f;
  --blue: #3498db;
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}
.screen.active { display: flex; }

button {
  border: none;
  border-radius: 12px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  background: transparent;
}
button.primary {
  background: var(--accent);
  color: white;
  transition: transform 0.1s, background 0.2s;
}
button.primary:active { transform: scale(0.97); }
button.primary:disabled {
  background: #3a4a6a;
  opacity: 0.55;
  cursor: not-allowed;
}
button.secondary {
  background: transparent;
  border: 1px solid #2a3756;
}
button.icon {
  padding: 8px 14px;
  font-size: 22px;
}

input {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid #2a3756;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
}
input:focus { border-color: var(--accent); }

/* ===== Home ===== */
#screen-home {
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.title {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: -1px;
  background: linear-gradient(90deg, var(--red), var(--yellow), var(--green), var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 4px;
  text-align: center;
}
.subtitle {
  color: var(--muted);
  margin-bottom: 32px;
  text-align: center;
}
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #2a3756;
}
.error {
  color: var(--accent);
  margin-top: 12px;
  min-height: 18px;
  font-size: 14px;
  text-align: center;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg-2);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.room-code-top {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 16px;
  letter-spacing: 3px;
  font-weight: 700;
}

/* ===== Lobby ===== */
.lobby-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.big-code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 38px;
  letter-spacing: 6px;
  font-weight: 800;
  text-align: center;
  background: var(--bg-2);
  padding: 16px;
  border-radius: 12px;
}
.color-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.color-swatch {
  aspect-ratio: 1;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  color: white;
  border: 3px solid transparent;
  padding: 0;
  transition: transform 0.15s;
}
.color-swatch[data-color="red"] { background: var(--red); }
.color-swatch[data-color="green"] { background: var(--green); }
.color-swatch[data-color="yellow"] { background: var(--yellow); color: #333; }
.color-swatch[data-color="blue"] { background: var(--blue); }
.color-swatch.selected { border-color: white; transform: scale(1.06); }
.color-swatch.taken { opacity: 0.25; cursor: not-allowed; }

.players-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-2);
  border-radius: 10px;
}
.player-color {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
}
.player-name { flex: 1; font-weight: 600; }
.player-tag {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  font-weight: 600;
}
.player-tag.host { color: var(--accent); }
.player-tag.you { color: #fbbf24; }
.player-tag.disconnected { color: #888; }
.hint {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  line-height: 1.4;
}
.lobby-actions {
  gap: 8px;
}

/* ===== Game ===== */
.turn-indicator {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.turn-color-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
}
.dice {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: white;
  color: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 900;
  font-family: ui-monospace, Menlo, monospace;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.dice.rolling {
  animation: shake 0.5s linear infinite;
}
@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}
.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: var(--bg);
  min-height: 0;
}
#board {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  background: var(--board-bg);
  border-radius: 10px;
  display: block;
}
.players-bar {
  display: flex;
  justify-content: space-around;
  padding: 8px 10px;
  background: var(--bg-2);
  gap: 6px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.pbar-player {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pbar-player.current {
  background: rgba(255,255,255,0.1);
  font-weight: 700;
}
.pbar-player.disconnected { opacity: 0.4; }
.pbar-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pbar-score {
  color: var(--muted);
  font-weight: 600;
}
.action-bar {
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.action-msg {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
  font-weight: 500;
}
.action-msg.highlight {
  color: var(--accent);
  font-weight: 700;
}

/* ===== Overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }
.modal {
  background: var(--card);
  border-radius: 16px;
  padding: 28px;
  width: calc(100% - 48px);
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h2 {
  text-align: center;
  font-size: 26px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 20;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.hidden { display: none; }
.toast.info { background: var(--blue); }
.toast.success { background: var(--green); }

/* ===== SVG board ===== */
#board .cell {
  stroke: var(--grid);
  stroke-width: 0.04;
}
#board .cell.path { fill: var(--path); }
#board .cell.safe { fill: var(--safe); }
#board .cell.r { fill: var(--red); }
#board .cell.g { fill: var(--green); }
#board .cell.y { fill: var(--yellow); }
#board .cell.b { fill: var(--blue); }
#board .yard-bg.r { fill: rgba(231, 76, 60, 0.4); }
#board .yard-bg.g { fill: rgba(39, 174, 96, 0.4); }
#board .yard-bg.y { fill: rgba(241, 196, 15, 0.4); }
#board .yard-bg.b { fill: rgba(52, 152, 219, 0.4); }
#board .yard-slot {
  fill: white;
  stroke: #555;
  stroke-width: 0.04;
}
#board .center-tri.r { fill: var(--red); }
#board .center-tri.g { fill: var(--green); }
#board .center-tri.y { fill: var(--yellow); }
#board .center-tri.b { fill: var(--blue); }
#board .center-tri { stroke: #555; stroke-width: 0.04; }
#board .token {
  stroke: rgba(0,0,0,0.5);
  stroke-width: 0.04;
  cursor: pointer;
  transition: transform 0.2s ease, r 0.2s ease;
  transform-origin: center;
  transform-box: fill-box;
}
#board .token.r { fill: var(--red); }
#board .token.g { fill: var(--green); }
#board .token.y { fill: var(--yellow); }
#board .token.b { fill: var(--blue); }
#board .token.movable {
  stroke: white;
  stroke-width: 0.12;
  animation: tokenPulse 1.1s ease-in-out infinite;
}
@keyframes tokenPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}
#board .star {
  fill: rgba(0,0,0,0.18);
}
#board .arrow {
  fill: rgba(0,0,0,0.35);
}

/* ===== Larger screens ===== */
@media (min-width: 500px) {
  .title { font-size: 76px; }
  .board-wrap { padding: 16px; }
}
