/* Territories — dark board-game UI, no dependencies. */

:root {
  --bg: #1e2024;
  --panel: #2a2d33;
  --panel-edge: #3a3e46;
  --grid-line: #14161a;
  --cell: #f4f5f7;
  --text: #e8eaed;
  --text-dim: #9aa1ab;
  --accent: #6ba3f5;
  --danger: #e2585f;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 20px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; letter-spacing: 0.2px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-dim); }

/* ---------- header ---------- */

.app-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto 16px;
}

.turn { margin: 0; color: var(--text-dim); font-size: 14px; }
.turn strong { color: var(--turn-color, var(--text)); font-weight: 600; }

/* ---------- layout ---------- */

.layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  max-width: 1100px;
  margin: 0 auto;
}

.board-panel { flex: 1 1 auto; min-width: 0; }
.side-panel {
  flex: 0 0 260px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 16px;
}


/* ---------- board ---------- */

.board-frame {
  max-width: min(72vh, 100%);
  margin-inline: auto;
}

.board {
  display: grid;
  gap: 1px;
  padding: 1px;
  aspect-ratio: 1;
  background: var(--grid-line);
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  overflow: hidden;
}

.cell {
  background: var(--cell);
  border: 0;
  padding: 0;
  transition: background-color 120ms ease;
  touch-action: manipulation;             /* no double-tap-to-zoom delay on taps */
  -webkit-tap-highlight-color: transparent;
}

.board.interactive .cell:not(.claimed) {
  cursor: pointer;
}

/* Only on real pointers — on touch, :hover sticks to the last-tapped cell. */
@media (hover: hover) {
  .board.interactive .cell:not(.claimed):hover {
    background: var(--hover-color, #d8dbe0);
  }
}

.result {
  margin: 16px auto 0;
  padding: 12px 16px;
  max-width: min(72vh, 100%);
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
}

/* ---------- score list ---------- */

.scores {
  list-style: none;
  margin: 12px 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.score-row {
  display: grid;
  grid-template-columns: 14px 20px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.score-row.current {
  background: #33373f;
  border-color: var(--panel-edge);
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

/* Only the player-supplied name truncates; the AI label stays whole. */
.score-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-tag { color: var(--text-dim); font-size: 12px; white-space: nowrap; }
.score-value { font-variant-numeric: tabular-nums; font-weight: 600; }

.icon { width: 20px; height: 20px; display: block; fill: none; stroke: var(--text-dim); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 14px;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: #383c44;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  cursor: pointer;
}

.btn:hover { background: #424751; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { background: #383c44; }

.btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #11151c; }
.btn-primary:hover { background: #7fb0f7; }

.btn-quiet { width: auto; background: transparent; }

/* ---------- setup dialog ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 16, 19, 0.8);
  backdrop-filter: blur(6px);
}

.overlay[hidden] { display: none; }

.dialog {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.setup-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 12px;
}

.setup-row {
  display: grid;
  grid-template-columns: 38px 1fr auto auto 32px;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #23262b;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
}

.type-toggle {
  touch-action: manipulation;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: #31353d;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
}

.type-toggle:hover { background: #3b404a; }
.type-toggle .icon { width: 22px; height: 22px; stroke: var(--text); }

.remove-player {
  touch-action: manipulation;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
}

.remove-player .icon { stroke: var(--danger); stroke-width: 2; }
.remove-player:hover { background: rgba(226, 88, 95, 0.12); }
.remove-player:disabled { opacity: 0.3; cursor: default; }
.remove-player:disabled:hover { background: transparent; }

input[type="text"], input[type="number"], select {
  font: inherit;
  color: var(--text);
  background: #31353d;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  padding: 7px 9px;
  min-width: 0;
}

input[type="text"]:focus-visible,
input[type="number"]:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[type="number"] { width: 64px; }

input[type="color"] {
  width: 36px;
  height: 32px;
  padding: 2px;
  background: #31353d;
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  cursor: pointer;
}

.ai-select[hidden] { display: none; }

.warning { margin: 0 0 12px; color: var(--danger); font-size: 13px; }

.dialog-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.board-size {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 14px;
}

.dialog-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--panel-edge);
}

/* ---------- small screens / touch ----------
   Last in the file on purpose: media queries add no specificity, so these
   must come after the rules they override. */

@media (max-width: 720px) {
  body { padding: 12px; }
  .app-header { margin-bottom: 12px; }

  /* Stacking makes the cross axis horizontal, so the panels must stretch.
     Without this they shrink-to-fit, and because the board's cells are empty
     its max-content width is zero — the whole board collapses to its gaps. */
  .layout { flex-direction: column; align-items: stretch; }
  .board-panel, .side-panel { flex: 0 0 auto; }

  /* Player rows reflow to two lines so the name field keeps usable width;
     the AI menu drops onto its own line beneath it. */
  .setup-row { display: flex; flex-wrap: wrap; align-items: center; }
  .setup-row .name-input { flex: 1 1 110px; }
  .setup-row .type-toggle,
  .setup-row .remove-player,
  .setup-row input[type="color"] { flex: none; }
  .setup-row .ai-select { order: 1; flex: 1 1 100%; }

  /* 16px stops iOS Safari zooming the page in when a field takes focus. */
  input[type="text"], input[type="number"], select { font-size: 16px; }

  .dialog { padding: 16px; }
}
