/* Dots and Boxes — table-and-ink board, two harmonised inks. */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* ---- Controls (tab-style chips, like the other games) ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  margin-bottom: 16px;
}
.control-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.opt-label {
  font: 600 11px 'Inter', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  padding: 0 10px 0 12px;
}
.opt {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 600 13px 'Inter', sans-serif;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}
.opt:hover { background: var(--accent-soft); color: var(--ink); }
.opt.is-active {
  background: var(--accent);
  color: var(--paper);
}
.opt.is-active:hover { background: var(--accent); color: var(--paper); }

/* ---- Board layout ---- */
.board-wrap {
  display: grid;
  gap: 16px;
}

.scoreboard {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: wrap;
}
.score-cell {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  min-width: 170px;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
.score-cell.is-turn {
  background: var(--paper);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-lift);
  transform: translateY(-1px);
}
.score-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}
#scoreP1 .score-swatch { background: var(--p1); }
#scoreP2 .score-swatch { background: var(--p2); }
.score-name {
  font: 600 13px 'Inter', sans-serif;
  color: var(--ink);
  letter-spacing: 0.01em;
}
.score-value {
  margin-left: auto;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  min-width: 22px;
  text-align: right;
  line-height: 1;
}

/* ---- Player colours: P1 is the navy accent; P2 is a warm rust that harmonises with the cream paper ---- */
.play { --p1: #1f3a5f; --p2: #b6552f; }

.board-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
}
.board {
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
  display: block;
  touch-action: manipulation;
  user-select: none;
}

/* SVG element styles */
.board .dot {
  fill: var(--line-strong);
  opacity: 0.65;
}
.board .edge-hit {
  fill: transparent;
  cursor: pointer;
}
.board .edge-line {
  stroke: transparent;
  stroke-width: 4;
  stroke-linecap: round;
  pointer-events: none;
  transition: stroke 140ms ease, opacity 140ms ease;
}
.board .edge-line.is-hover {
  stroke: var(--line-strong);
  opacity: 0.35;
}
.board .edge-line.is-drawn {
  opacity: 1;
}
.board .edge-line.player-1 { stroke: var(--p1); }
.board .edge-line.player-2 { stroke: var(--p2); }

/* Claim flash — box is captured with a punch */
@keyframes db-claim {
  0%   { opacity: 0.02; transform: scale(0.85); }
  55%  { opacity: 0.42; transform: scale(1.06); }
  100% { opacity: 0.18; transform: scale(1); }
}
.board .box-fill.is-claimed {
  animation: db-claim 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center;
}
@keyframes db-label-in {
  0%   { opacity: 0; transform: scale(0.5); }
  100% { opacity: 0.9; transform: scale(1); }
}
.board .box-label.is-claimed {
  animation: db-label-in 340ms cubic-bezier(0.34, 1.56, 0.64, 1) 120ms both;
  transform-origin: center;
  transform-box: fill-box;
}

@media (prefers-reduced-motion: reduce) {
  .board .box-fill.is-claimed, .board .box-label.is-claimed { animation: none; }
}

.board .box-fill {
  opacity: 0;
  transition: opacity 220ms ease;
}
.board .box-fill.is-claimed { opacity: 0.18; }
.board .box-fill.player-1 { fill: var(--p1); }
.board .box-fill.player-2 { fill: var(--p2); }

.board .box-label {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
}
.board .box-label.is-claimed { opacity: 0.9; }
.board .box-label.player-1 { fill: var(--p1); }
.board .box-label.player-2 { fill: var(--p2); }

/* Disable hover when waiting on CPU */
.play.is-locked .board .edge-hit { cursor: default; }

/* ---- Win overlay ---- */
.win-overlay {
  position: fixed; inset: 0; background: rgba(28, 42, 58, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 30px; text-align: center; box-shadow: var(--shadow-lift); max-width: 380px;
  width: 100%;
}
.win-card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 28px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.win-sub {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.win-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 14px;
  margin-bottom: 22px;
}
.win-score > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 100px;
}
.ws-name {
  font: 600 12px 'Inter', sans-serif;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.ws-val {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 40px;
  color: var(--ink);
  line-height: 1;
}
.ws-divider {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 28px;
  color: var(--muted);
}
.win-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* aside-info */
.aside-info { margin-top: 22px; }
.aside-info details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.aside-info summary {
  cursor: pointer;
  font: 700 14px 'Inter', sans-serif;
  color: var(--ink);
}
.aside-info .help-body {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}
.aside-info .help-body p { margin: 0 0 8px; }
.aside-info .help-body ul { margin: 0; padding-left: 18px; }
.aside-info .help-body li { margin: 4px 0; }

@media (max-width: 560px) {
  .controls { gap: 8px; }
  .control-group { padding: 3px; }
  .opt { padding: 6px 10px; font-size: 12px; }
  .opt-label { padding: 0 6px 0 10px; font-size: 10px; }
  .score-cell { min-width: 0; flex: 1 1 0; padding: 8px 12px; }
  .score-value { font-size: 20px; }
}
