/* Caro page CSS: the board, its stones and the control panel. Tokens come from system.css. */
/* the game section is at least one screen and grows with the panel, so a short window never cuts it */
main > .game { height: auto; min-height: 100vh; min-height: 100svh; display: grid; align-content: center; }
.game > .wrap.game__grid {
  /* system.css makes every main > section > .wrap a flex column of the section's height; the game is a split */
  display: grid; grid-template-columns: minmax(320px, 5fr) 7fr; grid-template-rows: auto;
  gap: var(--s-8); align-items: center; height: auto;
}
.game > .wrap.game__grid > .game__panel { grid-column: 1; grid-row: 1; }
.game > .wrap.game__grid > .game__board { grid-column: 2; grid-row: 1; }
.game__panel { align-self: center; }
.game__panel > * + * { margin-top: var(--s-4); }
.game__panel h1 { margin: 0; font-size: var(--t-h2); line-height: 1.1; }
.game__lede { color: var(--muted); font-size: var(--t-body); line-height: 1.5; max-width: 42ch; }
.game__status {
  font: 500 var(--t-h3)/1.2 var(--font-display); letter-spacing: var(--display-tracking);
  min-height: 1.2em;
}
.game__status b { color: var(--accent); font-weight: 500; }
.game__status.is-note { color: var(--muted); }
.game__controls { display: grid; gap: var(--s-3); }

/* segmented radios */
.seg { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2); }
.seg legend { width: 100%; padding: 0; margin-bottom: var(--s-1); font: 400 var(--t-label)/1 var(--font-mono); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s-4);
  border: 1px solid var(--line-strong); border-radius: var(--r-btn); font-weight: 500;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}
.seg label:hover span { border-color: color-mix(in oklab, var(--ink) 45%, transparent); }
.seg input:checked + span { background: var(--surface); border-color: var(--accent); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--action); outline-offset: 2px; }
.seg label:active span { transform: translateY(1px); }
[data-mode="pvp"] [data-show="ai"] { display: none; }

.switch { display: flex; align-items: center; gap: var(--s-3); min-height: 44px; cursor: pointer; color: var(--muted); }
.switch input { appearance: none; margin: 0; flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--line-strong); position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); background: var(--accent-ink); }
.switch input:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }

.score { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-4); margin: var(--s-5) 0 0; padding-top: var(--s-4); border-top: 1px solid var(--line); }
.score div { display: grid; gap: var(--s-1); }
.score dt { font: 400 var(--t-label)/1 var(--font-mono); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.score dd { margin: 0; font: 500 var(--t-stat)/1 var(--font-display); font-variant-numeric: tabular-nums; }

/* the board: a canvas in a square stage; the stage is a size container so the canvas is the
   largest square that fits (the panel's height on desktop, the screen in full-screen play) */
.game__board { display: grid; grid-template-rows: minmax(0, 1fr) auto; justify-items: center; gap: var(--s-3);
  align-self: stretch; min-height: 0; min-width: 0; }
.play { width: 100%; height: 100%; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr); }
.play__bar { display: none; }
/* a big board (55x55) keeps cells at least --min-cell wide; when that is wider than the stage, the stage scrolls */
.play__stage { container-type: size; min-height: 0; min-width: 0; display: grid; place-items: safe center; overflow: auto;
  overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.board {
  --n: 15; --min-cell: 14px;
  display: block; width: max(min(100cqw, 100cqh), calc(var(--n) * var(--min-cell))); aspect-ratio: 1; box-sizing: border-box; flex: none;
  max-width: none; /* system.css caps canvas at 100%; a big board must be allowed past the stage */
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  touch-action: manipulation; user-select: none; -webkit-tap-highlight-color: transparent; cursor: pointer;
}
.board:focus-visible { outline: 2px solid var(--action); outline-offset: 3px; }
.board.is-locked { cursor: default; }
.play__open { display: inline-flex; align-items: center; gap: var(--s-2); min-height: 44px; background: none; border: 0; padding: 0;
  color: var(--ink); font: 500 var(--t-small)/1 var(--font-text); cursor: pointer; justify-self: end; }
.play__open svg, .play__icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* full-screen play: the Fullscreen API where there is one, a fixed layer over the page elsewhere (iPhone) */
.play.is-full {
  position: fixed; inset: 0; z-index: 1000; width: 100vw; height: 100vh; height: 100dvh;
  background: var(--bg); grid-template-rows: auto minmax(0, 1fr); gap: var(--s-3);
  padding: max(var(--s-3), env(safe-area-inset-top)) max(var(--s-3), env(safe-area-inset-right)) max(var(--s-3), env(safe-area-inset-bottom)) max(var(--s-3), env(safe-area-inset-left));
  box-sizing: border-box;
}
.play.is-full .play__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap; }
.play.is-full .board { border-radius: var(--r-sm); }
.play__status { margin: 0; font: 500 var(--t-card)/1.2 var(--font-display); letter-spacing: var(--display-tracking); }
.play__status b { color: var(--accent); font-weight: 500; }
.play__status.is-note { color: var(--muted); }
.play__actions { display: flex; gap: var(--s-2); align-items: center; }
.play__actions .btn { height: 44px; padding: 0 var(--s-4); }
.play__icon { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--line-strong); border-radius: var(--r-btn);
  background: transparent; color: var(--ink); cursor: pointer; transition: background .15s, transform .1s; }
.play__icon:hover { background: color-mix(in oklab, var(--bg) 90%, var(--ink)); }
.play__icon:active { transform: translateY(1px); }
.play__icon:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
html.is-playing { overflow: hidden; }
@media (pointer: coarse) { .board { --min-cell: 26px; } }

/* the rule diagrams are DOM: */
.cell {
  position: relative; display: grid; place-items: center; aspect-ratio: 1; min-width: 0;
  background: transparent; border: 0; padding: 0; margin: 0; color: var(--ink);
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
}

/* stones: X two pink bars, O a white ring */
.stone { position: absolute; inset: 20%; }
.stone--x::before, .stone--x::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 118%; height: 16%;
  background: var(--accent); border-radius: 999px; transform: translate(-50%, -50%) rotate(45deg);
}
.stone--x::after { transform: translate(-50%, -50%) rotate(-45deg); }
.stone--o { border: max(2px, 0.16em) solid var(--ink); border-radius: 50%; inset: 22%; }
@media (prefers-reduced-motion: no-preference) {
  .stone { animation: stone-in .16s cubic-bezier(.2, .8, .2, 1.2); }
  @keyframes stone-in { from { transform: scale(.4); opacity: 0; } }
}

/* rules */
.rules { border-top: 1px solid var(--line); }
.rules__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--card-gap, 24px); }
.rule { padding: var(--s-6); display: grid; gap: var(--s-3); align-content: start; }
.rule h3 { margin: var(--s-3) 0 0; }
.rule p { margin: 0; color: var(--muted); }
.rule--no h3 { color: var(--muted); }
.rules__note { margin-top: var(--s-6); color: var(--muted); max-width: 70ch; }
.mini { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; max-width: 320px; }
.mini .cell { cursor: default; font-size: 12px; }
.mini .cell:last-child { border-right: 0; }
.mini .cell { border-bottom: 0; }
.rule--no .mini .stone--x::before, .rule--no .mini .stone--x::after { background: var(--muted); }

.footer--statement .footer__lede { margin-top: var(--s-4); }
.footer--statement .footer__legal { margin-top: var(--s-8); padding-top: var(--s-5); border-top: 1px solid var(--line); color: var(--muted); font-size: var(--t-small); }

@media (max-width: 1099px) {
  .game > .wrap.game__grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; height: auto; gap: var(--s-6); }
  .game > .wrap.game__grid > .game__panel { grid-column: 1; grid-row: 2; }
  .game > .wrap.game__grid > .game__board { grid-column: 1; grid-row: 1; height: auto; }
  .game__board > .play:not(.is-full) { width: min(100%, 640px); height: auto; aspect-ratio: 1; }
}
@media (max-width: 899px) { .rules__grid { grid-template-columns: 1fr; } }
@media (max-width: 639px) {
  .board { border-radius: var(--r-sm); }
  .play.is-full { gap: var(--s-2); }
  .play.is-full .play__status { flex-basis: 100%; font-size: var(--t-body); }
  .play.is-full .play__actions { width: 100%; }
  .play.is-full .play__actions .btn { flex: 1; }
  .game__panel .btn-row { display: grid; gap: var(--s-3); }
  .game__panel .btn-row .btn { width: 100%; justify-content: center; }
  .nav__actions .btn { display: none; }
}
