/* Light: joaoapinho.dev. Dark: the site's terminal (GitHub-dark greys).
   Players: ultramarine vs light wood. The page accent (challenge, slider) is the same
   colour dimmed: blue, or red on the classic board (the wooden Gigamic set). */
:root {
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #f3f4f6;
  --line-2: #e5e7eb;
  --surface: #ffffff;
  --header: rgb(255 255 255 / 0.9);
  --board: #f3f4f6;
  --cell: #ffffff;
  --seg: #f3f4f6;
  --seg-on: #ffffff;
  --primary: #0a0a0a;
  --on-primary: #ffffff;
  --hover: rgb(0 0 0 / 0.05);
  --outline: rgb(0 0 0 / 0.2);
  --crumb: #9ca3af;
  --accent: #4f6bf5; /* the homepage hero's ultramarine, lifted to read in both themes */
  --accent-text: #4f6bf5;
  --accent-soft: #eef1fe;
  --accent-edge: #c4cefb;
  --p1: var(--accent);
  --p1-text: var(--accent-text);
  --p1-soft: var(--accent-soft);
  --p1-edge: var(--accent-edge);
  --p2: #ead6a6;
  --p2-text: #8f6a30;
  --p2-soft: rgb(234 214 166 / 0.2);
  --p2-edge: rgb(234 214 166 / 0.6);
  --wall-p1: var(--p1);
  --wall-p2: var(--p2);
  --wall-edge: none;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --fg: #e6edf3;
  --muted: #8b949e;
  --faint: #6e7681;
  --line: #21262d;
  --line-2: #30363d;
  --surface: #161b22;
  --header: rgb(13 17 23 / 0.85);
  --board: #161b22;
  --cell: #21262d;
  --seg: #0d1117;
  --seg-on: #30363d;
  --primary: #e6edf3;
  --on-primary: #0d1117;
  --hover: rgb(255 255 255 / 0.06);
  --outline: #30363d;
  --crumb: #e6edf3;
  --accent-text: #8193f8; /* text only: lighter to read on near-black */
  --accent-soft: rgb(79 107 245 / 0.16);
  --accent-edge: rgb(79 107 245 / 0.5);
  --p2-text: #e6cf98;
  color-scheme: dark;
}

/* Classic: bordeaux board, dark grey squares, red vs light wood, fir walls */
:root[data-board="classic"] {
  --board: #290f15;
  --cell: #2b2829;
  --accent: #c8312d; /* P1 follows the accent, so the banner and slider turn red too */
  --accent-text: #b02a25;
  --accent-soft: rgb(200 49 45 / 0.07);
  --accent-edge: rgb(200 49 45 / 0.3);
  --p1-soft: rgb(200 49 45 / 0.3); /* the goal row is stronger than the page's wash */
  --p1-edge: rgb(214 80 70 / 0.7);
  --p2: #ead6a6;
  --p2-text: #8f6a30;
  --p2-soft: rgb(234 214 166 / 0.2);
  --p2-edge: rgb(234 214 166 / 0.6);
  --wall-p1: #e9a765;
  --wall-p2: #e9a765;
  --wall-edge: #c4834a;
}
:root[data-theme="dark"][data-board="classic"] {
  --accent-text: #e5574e;
  --accent-soft: rgb(200 49 45 / 0.14);
  --accent-edge: rgb(214 80 70 / 0.45);
  --p2-text: #e6cf98;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

/* header, as on the blog posts */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.3s;
}
.back:hover { color: var(--fg); }
.back svg { transition: transform 0.3s; }
.back:hover svg { transform: translateX(-4px); }
.top-right { display: flex; align-items: center; gap: 1rem; }
.crumb { font-size: 0.875rem; font-weight: 300; color: var(--crumb); }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.3s, background 0.3s;
}
.icon-btn:hover { color: var(--fg); background: var(--hover); }
.icon-btn[aria-pressed="true"] { color: var(--fg); background: var(--hover); border-color: var(--outline); }
:root[data-theme="dark"] .icon-moon, :root:not([data-theme="dark"]) .icon-sun { display: none; }

main { max-width: 64rem; margin: 0 auto; padding: 3rem 1.5rem 4rem; }

.intro h1 { margin: 0 0 0.75rem; font-size: 3rem; font-weight: 300; letter-spacing: -0.01em; }
.intro p { margin: 0 0 2.5rem; color: var(--muted); font-weight: 300; font-size: 1.125rem; max-width: 40rem; line-height: 1.55; }

.game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 19rem;
  gap: 2rem;
  align-items: start;
}

/* win probability */
.odds { margin-bottom: 1rem; }
.odds-labels { display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; font-size: 0.875rem; margin-bottom: 0.4rem; }
.odds-labels > :last-child { text-align: right; }
.odds-title { color: var(--faint); font-weight: 300; font-size: 0.8rem; text-align: center; }
.p1-text { color: var(--p1-text); font-weight: 500; }
.p2-text { color: var(--p2-text); font-weight: 500; }
.odds-bar { height: 6px; border-radius: 999px; background: var(--p2); overflow: hidden; }
#odds-fill { height: 100%; width: 50%; background: var(--p1); transition: width 0.8s ease; }

#board { width: 100%; height: auto; display: block; touch-action: manipulation; user-select: none; }
.status { margin: 1rem 0 0; min-height: 1.5rem; color: var(--muted); font-weight: 300; text-align: center; }

/* board pieces */
.board-bg { fill: var(--board); transition: fill 0.3s; }
.cell { fill: var(--cell); transition: fill 0.3s; }
.goal-p1 { fill: var(--p1-soft); stroke: var(--p1-edge); stroke-width: 1.5; }
.goal-p2 { fill: var(--p2-soft); stroke: var(--p2-edge); stroke-width: 1.5; }
.edge-p1 { fill: var(--p1); }
.edge-p2 { fill: var(--p2); }
.wall-p1 { fill: var(--wall-p1); stroke: var(--wall-edge); }
.wall-p2 { fill: var(--wall-p2); stroke: var(--wall-edge); }
.pawn { stroke: var(--cell); stroke-width: 3.5; filter: drop-shadow(0 2px 3px rgb(0 0 0 / 0.2)); }
.pawn-p1 { fill: var(--p1); }
.pawn-p2 { fill: var(--p2); }
.move-dot { opacity: 0.4; pointer-events: none; }
.move-p1 { fill: var(--p1); }
.move-p2 { fill: var(--p2); }
.target { fill: transparent; cursor: pointer; pointer-events: all; }
.coord { fill: var(--faint); font-size: 11px; font-weight: 300; text-anchor: middle; dominant-baseline: central; user-select: none; }
.ghost-layer, .ghost { pointer-events: none; }
.ghost { opacity: 0.45; }

/* side panel */
.panel {
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 1.25rem;
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.04);
}
.group { margin-bottom: 1.25rem; }
.group[hidden] { display: none; }
.label { display: block; font-size: 0.75rem; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.5rem; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--seg); border-radius: 0.6rem; }
.segmented button {
  font: inherit;
  font-size: 0.875rem;
  border: 0;
  border-radius: 0.45rem;
  padding: 0.45rem 0.5rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.segmented button:hover { color: var(--fg); }
.segmented button[aria-pressed="true"] { background: var(--seg-on); color: var(--fg); font-weight: 500; box-shadow: 0 1px 2px rgb(0 0 0 / 0.1); }

.slider-row { display: flex; justify-content: space-between; align-items: baseline; margin: 0.9rem 0 0.25rem; font-size: 0.875rem; color: var(--muted); font-weight: 300; }
.slider-row output { color: var(--fg); font-weight: 500; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="range"]:disabled { opacity: 0.4; }
.hint { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--faint); font-weight: 300; line-height: 1.45; }

.players { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0.75rem 0; margin-bottom: 1.25rem; display: grid; gap: 0.5rem; }
.player { display: flex; align-items: center; gap: 0.6rem; font-size: 0.925rem; }
.player .walls { margin-left: auto; color: var(--muted); font-weight: 300; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.player.to-move { font-weight: 500; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.p1 { background: var(--p1); }
.dot.p2 { background: var(--p2); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 1.25rem; }
.btn {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid var(--outline);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { opacity: 0.88; }

.rules { margin-bottom: 1.25rem; font-size: 0.875rem; }
.rules summary { cursor: pointer; color: var(--muted); }
.rules p { color: var(--muted); font-weight: 300; line-height: 1.55; margin: 0.6rem 0 0; }

.history ol { margin: 0; padding: 0; list-style: none; max-height: 11rem; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.history li { font-size: 0.8rem; font-variant-numeric: tabular-nums; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line-2); color: var(--muted); }
.history li.p1 { border-color: var(--p1-edge); }
.history li.p2 { border-color: var(--p2-edge); }

dialog {
  border: 1px solid var(--line-2);
  border-radius: 1rem;
  padding: 2rem 2.5rem;
  text-align: center;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 20px 40px rgb(0 0 0 / 0.15);
  max-width: min(90vw, 24rem);
}
dialog::backdrop { background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 0.5rem; font-size: 1.7rem; font-weight: 300; line-height: 1.25; }
dialog p { margin: 0 0 1.5rem; color: var(--muted); font-weight: 300; }

/* challenge card, and the claim form in the result dialog */
.challenge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin: -1rem 0 2rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--accent-edge);
  border-radius: 1rem;
  background: var(--accent-soft);
}
.challenge[hidden] { display: none; }
.challenge.active { border-color: var(--accent); }
.challenge:not(.active) .challenge-active, .challenge.active .challenge-idle { display: none; }

/* while in the challenge: the settings are visibly locked, with a way out */
.lock-note {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
  padding: 0.7rem 0.8rem;
  border-radius: 0.6rem;
  border: 1px solid var(--accent-edge);
  background: var(--accent-soft);
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
}
.lock-note[hidden] { display: none; }
.panel.locked .group { opacity: 0.45; }
.link-btn {
  justify-self: start;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 500;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.dialog-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.dialog-actions [hidden] { display: none; }
.challenge strong { font-weight: 500; }
.challenge p { margin: 0.25rem 0 0; color: var(--muted); font-weight: 300; font-size: 0.925rem; line-height: 1.5; }
.challenge .btn { flex: none; }
.claim { text-align: left; margin: 0 0 1.25rem; }
.claim[hidden] { display: none; }
.claim label { display: block; font-size: 0.875rem; color: var(--muted); font-weight: 300; line-height: 1.5; margin-bottom: 0.6rem; }
.claim-row { display: flex; gap: 0.5rem; }
.claim input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--outline);
  background: var(--bg);
  color: var(--fg);
}
.claim input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.fine-print { margin-top: 0.75rem; font-size: 0.75rem; }
dialog h2 { text-wrap: balance; }
#result-detail:empty { display: none; }

footer { margin-top: 3rem; display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; font-size: 0.8rem; color: var(--faint); font-weight: 300; }

@media (max-width: 860px) {
  main { padding: 2rem 1rem 3rem; }
  .intro h1 { font-size: 2.25rem; }
  .intro p { font-size: 1rem; margin-bottom: 1.5rem; }
  .game { grid-template-columns: 1fr; gap: 1.5rem; }
  .topbar-inner { padding: 0.9rem 1rem; }
  .challenge { flex-direction: column; align-items: stretch; margin-top: 0; }
}
