: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;
  --contested: #3a3f47;
  --contested-stripe: #4a505a;
  --tile-size: 8px;
  --label-size: 8px;
  --pin-size: 36px; /* 24px, 36px, 48px (multiple of 8) */
  --pin-opacity: 0.9;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: sans-serif;
  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 bar ---------- */

.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;
}

.controls label {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls input[type="number"] {
  width: 64px;
  background: var(--bg-deep);
  border: 1px solid var(--line-grid-strong);
  color: var(--text-primary);
  font-family: sans-serif;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 4px;
}

.controls input[type="number"]:focus {
  outline: 2px solid var(--accent-gold);
  outline-offset: 1px;
}

.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;
}

.btn-reset {
  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;
}

.btn-reset:hover {
  border-color: var(--text-dim);
  color: var(--text-primary);
}

.status-readout {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 140px;
  letter-spacing: 0.03em;
}

.status-readout .status-value {
  color: var(--accent-gold);
  font-weight: 700;
}

/* ---------- Main layout: board + scoreboard ---------- */

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

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

.board-wrap {
  background: var(--bg-panel);
  border: 1px solid var(--line-grid-strong);
  border-radius: 10px;
  padding: 0px;
  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);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background-color 0.8s 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);
}

/* ---------- Player photo pins ---------- */
/* Sit on top of the board grid, anchored at each player's starting tile.
   Fixed size regardless of tile-size, so they stay legible even when tiles
   shrink down for 100x100 boards. Semi-transparent so the tile color
   underneath (which never visually disappears — the pin just sits in front
   of it) still shows through. */

.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: auto;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.tile.contested {
  background: repeating-linear-gradient(
    45deg,
    var(--contested),
    var(--contested) 6px,
    var(--contested-stripe) 6px,
    var(--contested-stripe) 12px
  );
}

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

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

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

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

#leaderboardOverlay.active {
  display: flex;
}

#closeLeaderboard {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

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

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

.scoreboard h2 {
  margin: 0 0 4px;
  font-size: 15px;
  color: whitesmoke;
  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);
  background: var(--bg-panel);
  position: relative;
  will-change: transform;
}

.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-bar-track {
  flex-shrink: 0;
  width: 60px;
  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.contested-row {
  opacity: 0.65;
}

.score-row.contested-row .score-swatch {
  background: repeating-linear-gradient(
    45deg,
    var(--contested),
    var(--contested) 3px,
    var(--contested-stripe) 3px,
    var(--contested-stripe) 6px
  );
}

/* ---------- Legend / footer note ---------- */

.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;
}

.legend-dot.contested-dot {
  background: repeating-linear-gradient(
    45deg,
    var(--contested),
    var(--contested) 3px,
    var(--contested-stripe) 3px,
    var(--contested-stripe) 6px
  );
}

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

/* ---------- 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;
  line-height: 1.8;
  padding: 8px 12px;
  border-radius: 5px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  text-align: center;
}

#loadingOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
#loadingOverlay.active {
  display: flex;
}
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}