/* jistevenson.com's palette and type, mobile first: base rules target a 360–390 px phone. */

@font-face {
  font-family: 'Newsreader Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(fonts/newsreader.woff2) format('woff2-variations');
}

@font-face {
  font-family: 'Hanken Grotesk Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(fonts/hanken-grotesk.woff2) format('woff2-variations');
}

:root {
  --ground: #ffffff;
  --surface: #f6f6ee;
  --ink: #1d2114;
  --muted: #51553f;
  --line: #e0e2d4;
  --primary: #4d6a26;
  --primary-deep: #3a501c;
  --tint: #eef2e2;
  --accent: #b02a3a;
  --accent-deep: #8e1f2e;
  /* The two players: X in olive, O in a warm amber-brown */
  --x: #4d6a26;
  --o: #8a5a00;
  --o-tint: #fbf3df;
  /* The board's lines: thin inside a small board, thick between them */
  --thin: #cfd3bf;
  --thick: #3a501c;

  --serif: 'Newsreader Variable', 'Iowan Old Style', Georgia, serif;
  --sans: 'Hanken Grotesk Variable', 'Segoe UI', system-ui, sans-serif;
  --gutter: clamp(16px, 5vw, 48px);

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
}

p,
ol,
ul {
  margin: 0;
}

a {
  color: var(--primary);
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--primary-deep);
  text-decoration-color: var(--accent);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

h1,
h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.018em;
}

h2 {
  font-size: clamp(1.625rem, 3.6vw, 2.25rem);
}

[hidden] {
  display: none !important;
}

.wrap {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding-inline: var(--gutter);
}

/* The bar back to the main site */
.top {
  border-bottom: 1px solid var(--line);
}

.top-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: 16px;
}

.home,
.top-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  color: var(--ink);
  text-decoration: none;
}

.home {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.25rem;
}

.top-nav {
  display: flex;
  gap: 16px;
}

.top-nav a {
  font-weight: 600;
  font-size: 0.9375rem;
}

.home:hover,
.top-nav a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 2px solid var(--primary);
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--primary-deep);
  background: var(--primary-deep);
  color: #fff;
}

.btn.secondary {
  background: var(--ground);
  color: var(--primary-deep);
}

.btn.secondary:hover {
  background: var(--tint);
  color: var(--primary-deep);
}

.btn.ghost {
  min-height: 44px;
  padding: 0 14px;
  border-color: var(--line);
  background: var(--ground);
  color: var(--ink);
  font-size: 0.9375rem;
}

.btn.ghost:hover {
  border-color: var(--primary);
  background: var(--ground);
  color: var(--ink);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--primary-deep);
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--tint);
}

.icon-btn:disabled {
  color: var(--line);
  background: transparent;
  cursor: default;
}

/* The game: the bar, the board, and the panel under it */
.game {
  width: min(100% - 16px, 560px);
  margin: 0 auto;
  padding-block: 12px 32px;
}

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 3px solid var(--primary);
  margin-bottom: 10px;
}

.bar.o-turn {
  border-bottom-color: var(--o);
}

.turn {
  flex: 1;
  text-align: center;
  font-weight: 600;
}

.turn .mark-x {
  color: var(--x);
}

.turn .mark-o {
  color: var(--o);
}

.board-wrap {
  position: relative;
  aspect-ratio: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  height: 100%;
  background: var(--thick);
}

.mini {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--thin);
}

.cell {
  position: relative;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--ground);
  font: inherit;
  cursor: default;
}

.cell:focus-visible {
  z-index: 2;
  outline-offset: -3px;
}

.mini.active .cell {
  background: var(--tint);
}

.board.o-turn .mini.active .cell {
  background: var(--o-tint);
}

.cell.legal {
  cursor: pointer;
}

/* Marks: X as two bars, O as a ring */
.cell.x::before,
.cell.x::after,
.board.x-turn .cell.legal:hover::before,
.board.x-turn .cell.legal:hover::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 20%;
  width: 60%;
  height: 10%;
  border-radius: 99px;
  background: var(--x);
  transform: translateY(-50%) rotate(45deg);
}

.cell.x::after,
.board.x-turn .cell.legal:hover::after {
  transform: translateY(-50%) rotate(-45deg);
}

.cell.o::before,
.board.o-turn .cell.legal:hover::before {
  content: '';
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, transparent 68%, var(--o) 70%, var(--o) 98%, transparent 100%);
}

.board.x-turn .cell.legal:hover::before,
.board.x-turn .cell.legal:hover::after,
.board.o-turn .cell.legal:hover::before {
  opacity: 0.3;
}

.cell.last {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* A finished small board: its marks fade under one big one */
.mini.closed .cell {
  background: var(--surface);
}

.mini.closed .cell::before,
.mini.closed .cell::after {
  opacity: 0.3;
}

.mini.won-x::before,
.mini.won-x::after {
  content: '';
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 14%;
  width: 72%;
  height: 9%;
  border-radius: 99px;
  background: var(--x);
  transform: translateY(-50%) rotate(45deg);
  pointer-events: none;
}

.mini.won-x::after {
  transform: translateY(-50%) rotate(-45deg);
}

.mini.won-o::before {
  content: '';
  position: absolute;
  z-index: 1;
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, transparent 76%, var(--o) 78%, var(--o) 98%, transparent 100%);
  pointer-events: none;
}

.mini.line .cell {
  background: var(--tint);
}

/* Analysis on the board: a dot per legal move, or what the solver proved */
.cell[data-q]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.cell[data-q='best']::after,
.dot.q-best {
  background: var(--primary-deep);
}

.cell[data-q='good']::after,
.dot.q-good {
  background: #93a86a;
}

.cell[data-q='ok']::after,
.dot.q-ok {
  background: #d9b46a;
}

.cell[data-q='bad']::after,
.dot.q-bad {
  background: var(--accent);
  width: 18%;
  height: 18%;
}

.dot.q-bad {
  width: 8px;
  height: 8px;
}

.cell[data-p]::after,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
}

.cell[data-p]::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58%;
  height: 58%;
  transform: translate(-50%, -50%);
  font-size: clamp(0.625rem, 2.6vw, 0.875rem);
}

.badge {
  width: 18px;
  height: 18px;
}

.cell[data-p='win']::after,
.badge.p-win {
  content: 'W';
  background: var(--primary-deep);
}

.cell[data-p='draw']::after,
.badge.p-draw {
  content: 'D';
  background: var(--muted);
}

.cell[data-p='loss']::after,
.badge.p-loss {
  content: 'L';
  background: var(--accent);
}

/* The card over the board: the menu, the bot's settings, and the result */
.card {
  position: absolute;
  inset: 3%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  overflow: auto;
  border-radius: 14px;
  background: var(--ground);
  box-shadow: 0 10px 30px rgb(29 33 20 / 0.22);
  text-align: center;
}

.card h1 {
  font-size: clamp(1.875rem, 7vw, 2.75rem);
}

.card-lead {
  color: var(--muted);
}

.card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(100%, 280px);
  margin: 0 auto;
}

.card-actions.row {
  flex-direction: row;
}

.card-actions.row .btn {
  flex: 1;
}

.choice {
  margin: 0;
  padding: 0;
  border: 0;
}

.choice legend {
  margin: 0 auto 6px;
  font-weight: 600;
  font-size: 0.9375rem;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: min(100%, 360px);
  margin: 0 auto;
}

.options label {
  position: relative;
  cursor: pointer;
}

.options input {
  position: absolute;
  opacity: 0;
}

.options span {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 52px;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--ground);
  font-size: 0.8125rem;
  line-height: 1.3;
  color: var(--muted);
}

.options b {
  font-size: 1rem;
  color: var(--ink);
}

.options input:checked + span {
  border-color: var(--primary);
  background: var(--tint);
}

.options input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* The panel under the board */
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 14px;
}

.status {
  min-height: 1.6em;
  color: var(--muted);
}

.analysis {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 0;
  border-block: 1px solid var(--line);
}

.meter {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--o);
}

.meter-x {
  display: block;
  height: 100%;
  background: var(--x);
  transform-origin: left;
  transform: scaleX(0.5);
  transition: transform 0.3s ease;
}

.verdict {
  font-weight: 600;
}

.proof {
  font-size: 0.9375rem;
  color: var(--muted);
}

.proof:empty {
  display: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 0;
  list-style: none;
  font-size: 0.875rem;
  color: var(--muted);
}

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

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-left: auto;
  font-size: 0.9375rem;
  cursor: pointer;
}

.toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

/* The rules and the story, between thin rules */
.text {
  display: flex;
  flex-direction: column;
}

.text section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-block: 40px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 8px;
}

.text h2:not(:first-of-type) {
  margin-top: 18px;
}

.eyebrow {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.rules,
.credits {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 1.4em;
}

.rules li::marker,
.credits li::marker {
  color: var(--accent);
}

.foot {
  padding-block: 28px 40px;
  border-top: 1px solid var(--line);
  font-size: 0.9375rem;
  color: var(--muted);
}

@media (min-width: 720px) {
  .game {
    padding-top: 24px;
  }

  .card {
    inset: 9%;
  }

  .options {
    grid-template-columns: repeat(4, 1fr);
  }

  .options[data-name='side'] {
    grid-template-columns: 1fr 1fr;
    width: min(100%, 240px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .meter-x {
    transition: none;
  }
}
