:root {
  --bg-deep: #0b0e11;
  --bg-panel: #12161b;
  --bg-panel-raised: #181d24;
  --line-grid: #232a33;
  --line-grid-strong: #2f3845;
  --text-primary: #e8edf2;
  --text-dim: #6b7686;
  --text-faint: #3d4654;
  --accent-gold: #00f4a7;
  --tile-size: 16px;
  --pin-size: 36px;
  --pin-opacity: 0.9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  min-height: 100vh;
}

body {
  background-image:
    radial-gradient(circle at 15% 10%, rgba(244, 163, 0, 0.04), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(58, 134, 255, 0.04), transparent 40%);
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px 64px;
  gap: 28px;
}

/* ---------- Header ---------- */

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.header h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-primary);
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--bg-panel);
  border: 1px solid var(--line-grid-strong);
  border-radius: 8px;
  padding: 14px 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-go {
  background: var(--accent-gold);
  color: #1a1300;
  border: none;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.1em;
  padding: 11px 28px;
  border-radius: 5px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  box-shadow: 0 0 0 0 rgba(244, 163, 0, 0.4);
}

.btn-go:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(244, 163, 0, 0.3);
}

.btn-go:active:not(:disabled) { transform: translateY(0); }

.btn-go:disabled {
  background: var(--line-grid-strong);
  color: var(--text-faint);
  cursor: not-allowed;
}

#showResultsBtn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--line-grid-strong);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.05em;
  padding: 10px 18px;
  border-radius: 5px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

#showResultsBtn:not(:disabled):hover {
  border-color: var(--text-dim);
  color: var(--text-primary);
}

#showResultsBtn:disabled { cursor: not-allowed; }

/* ---------- Layout ---------- */

.main-layout {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------- Board ---------- */

.board-wrap {
  background: var(--bg-panel);
  border-radius: 10px;
  padding: 20px;
  display: inline-block;
}

.board-grid {
  display: grid;
  border: 1px solid var(--line-grid-strong);
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  background: var(--bg-panel-raised);
  border: 1px solid var(--line-grid);
  position: relative;
  transition: background-color 0.2s ease;
}

.tile.claimed {
  border-color: rgba(0, 0, 0, 0.25);
}

.tile.seed::after {
  content: '';
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.tile.dead-head::after {
  content: '';
  position: absolute;
  inset: 20%;
  background: rgba(255, 255, 255, 0.6);
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.tile.just-claimed {
  animation: claim-pulse 0.3s ease;
}

@keyframes claim-pulse {
  0% { filter: brightness(2.2); }
  100% { filter: brightness(1); }
}

/* ---------- Player pins ---------- */

.player-pin {
  position: absolute;
  width: var(--pin-size);
  height: var(--pin-size);
  border-radius: 6px;
  background-size: cover;
  background-position: center;
  opacity: var(--pin-opacity);
  box-shadow: 0 0 0 2px var(--pin-color, rgba(255,255,255,0.85)), 0 2px 6px rgba(0,0,0,0.5);
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 10;
  transition: top 0.2s ease, left 0.2s ease;
}

/* ---------- Scoreboard ---------- */

.scoreboard {
  background: var(--bg-panel);
  border: 1px solid var(--line-grid-strong);
  border-radius: 10px;
  padding: 18px;
  width: 300px;
  flex-shrink: 0;
}

.scoreboard h2 {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  font-weight: 600;
}

.scoreboard .total-tiles {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 14px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-grid);
  position: relative;
}

.score-row:last-child { border-bottom: none; }

.score-rank {
  font-size: 12px;
  color: var(--text-faint);
  width: 18px;
  text-align: right;
  flex-shrink: 0;
}

.score-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
}

.score-name {
  font-size: 13px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}

.score-dir {
  font-size: 11px;
  color: var(--text-faint);
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.score-bar-track {
  flex-shrink: 0;
  width: 50px;
  height: 6px;
  background: var(--bg-deep);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.35s ease;
}

.score-count {
  font-size: 13px;
  font-weight: 700;
  width: 30px;
  text-align: right;
  flex-shrink: 0;
  color: var(--text-primary);
}

.score-row.leader .score-name,
.score-row.leader .score-count {
  color: var(--accent-gold);
}

.score-row.dead-row .score-name,
.score-row.dead-row .score-count {
  opacity: 0.5;
}

/* ---------- Leaderboard overlay ---------- */

#leaderboardOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

#leaderboardOverlay.active {
  display: flex;
}

.overlay-board {
  position: relative;
  width: 340px;
  max-height: 80vh;
  overflow-y: auto;
}

#closeLeaderboard {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: 1px solid var(--line-grid-strong);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#closeLeaderboard:hover {
  border-color: var(--text-dim);
  color: var(--text-primary);
}

/* ---------- Loading overlay ---------- */

#loadingOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 17, 0.75);
  z-index: 600;
  align-items: center;
  justify-content: center;
}

#loadingOverlay.active { display: flex; }

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line-grid-strong);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Legend ---------- */

.legend {
  display: flex;
  gap: 18px;
  font-size: 11px;
  color: var(--text-dim);
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.legend-dot.seed-dot {
  background: var(--bg-panel-raised);
  position: relative;
}

.legend-dot.seed-dot::after {
  content: '';
  position: absolute;
  inset: 20%;
  border-radius: 50%;
  background: white;
}

.player-pin {
  pointer-events: auto;
  overflow: visible;
}

.legend-dot.dead-dot {
  background: var(--line-grid-strong);
  position: relative;
}

.legend-dot.dead-dot::after {
  content: '';
  position: absolute;
  inset: 15%;
  background: rgba(255,255,255,0.5);
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

/* ---------- Tooltip ---------- */

.tile-tooltip {
  position: fixed;
  display: none;
  pointer-events: none;
  z-index: 1000;
  background: var(--bg-panel-raised);
  border: 1px solid var(--accent-gold);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 5px 10px;
  border-radius: 5px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

@media (prefers-reduced-motion: reduce) {
  .tile, .score-bar-fill, .player-pin { transition: none !important; }
  .tile.just-claimed { animation: none !important; }
  .loading-spinner { animation: none !important; }
}
