:root {
  --bg: #0b1020;
  --panel: #131b33;
  --panel-2: #0f1730;
  --line: #2a355e;
  --text: #eef3ff;
  --muted: #b9c3e6;
  --accent: #74c0fc;
  --danger: #ff6b6b;
  --success: #63e6be;
  --warning: #ffd43b;

  --player-0: #ff6b6b;
  --player-1: #4dabf7;
  --player-2: #69db7c;
  --player-3: #fcc419;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top, #172445 0%, #0b1020 45%),
    var(--bg);
  color: var(--text);
}

#app {
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

h1, h2, h3, p {
  margin-top: 0;
}

.subtitle {
  color: var(--muted);
  margin-bottom: 0;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}

.menu-panel,
.result-panel {
  max-width: 720px;
  margin: 50px auto;
}

.menu-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 20px 0;
}

.rules-summary ul {
  padding-left: 18px;
  color: var(--muted);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #08111f;
}

.btn-secondary {
  background: #26365f;
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.hud-panel {
  margin-bottom: 14px;
}

.hud-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr 1.5fr;
  gap: 14px;
}

.label {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.value {
  font-size: 1.1rem;
  font-weight: bold;
}

.value.small {
  font-size: 0.98rem;
  line-height: 1.4;
}

.board-panel {
  margin-bottom: 14px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.legend-chip {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: middle;
  border: 1px solid rgba(255,255,255,0.25);
}

.legend-chip.quest {
  background: rgba(99, 230, 190, 0.22);
}

.legend-chip.station {
  background: rgba(255, 212, 59, 0.22);
}

.legend-chip.finish {
  background: rgba(116, 192, 252, 0.22);
}

.legend-chip.legal {
  background: rgba(255,255,255,0.25);
  outline: 2px solid white;
}

.board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 8px;
}

.tile {
  position: relative;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #101831;
  padding: 6px;
  transition: border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.tile:hover {
  border-color: #5272c7;
}

.tile.quest {
  background: linear-gradient(180deg, rgba(99, 230, 190, 0.18), rgba(16,24,49,1));
}

.tile.station {
  background: linear-gradient(180deg, rgba(255, 212, 59, 0.18), rgba(16,24,49,1));
}

.tile.finish {
  background: linear-gradient(180deg, rgba(116, 192, 252, 0.2), rgba(16,24,49,1));
  border-color: #5da3d5;
}

.tile.overflow {
  background: linear-gradient(180deg, rgba(167, 139, 250, 0.12), rgba(16,24,49,1));
}

.tile.legal {
  outline: 3px solid rgba(255,255,255,0.8);
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(255,255,255,0.1);
}

.tile.selected {
  transform: translateY(-2px);
  border-color: #ffffff;
  box-shadow:
    0 0 0 3px rgba(255,255,255,0.22),
    0 0 18px 6px rgba(255,255,255,0.20);
}

.tile.blocked {
  opacity: 0.55;
}

.tile-index {
  font-size: 0.9rem;
  color: var(--muted);
}

.tile-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
  min-height: 14px;
}

.tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.token {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.8);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.token-0 { background: var(--player-0); }
.token-1 { background: var(--player-1); }
.token-2 { background: var(--player-2); }
.token-3 { background: var(--player-3); }

.token.active {
  outline: 2px solid white;
  transform: scale(1.08);
}

.bottom-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 0.92rem;
}

.player-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: bold;
}

.player-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.badge {
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: bold;
  display: inline-block;
}

.badge.done {
  background: rgba(99, 230, 190, 0.15);
  color: var(--success);
  border: 1px solid rgba(99, 230, 190, 0.3);
}

.badge.todo {
  background: rgba(255, 107, 107, 0.12);
  color: #ffa8a8;
  border: 1px solid rgba(255, 107, 107, 0.25);
}

.action-panel {
  min-width: 280px;
}

.preview-empty {
  color: var(--muted);
  min-height: 120px;
}

.preview-box.hidden {
  display: none;
}

.preview-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.preview-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.hint-box {
  color: var(--muted);
  font-size: 0.95rem;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.log {
  max-height: 230px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.log-entry {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 10px;
  line-height: 1.4;
  color: var(--text);
}

.log-entry .log-turn {
  color: var(--muted);
  font-size: 0.85rem;
  display: block;
  margin-bottom: 4px;
}

.winner-text {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--success);
}

.error-text {
  color: #ffb3b3;
}

@media (max-width: 980px) {
  .hud-grid,
  .bottom-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .menu-actions {
    flex-direction: column;
  }
}