@font-face {
  font-family: "Familjen Grotesk";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(fonts/familjen-grotesk.woff2) format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/ibm-plex-mono-400.woff2) format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(fonts/ibm-plex-mono-500.woff2) format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(fonts/ibm-plex-mono-600.woff2) format("woff2");
}

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url(fonts/ibm-plex-sans.woff2) format("woff2");
}

:root {
  --bg: #eef1f5;
  --surface: #f8f9fb;
  --ink: #18212e;
  --muted: #586477;
  --line: #d3d9e2;
  --accent: #2b56c9;
  --accent-ink: #ffffff;
  --stage: #f8f9fb;
  --ax-x: #2b56c9;
  --ax-y: #17897c;
  --ax-z: #b07a12;
  --ax-w: #c0396f;
  --tile-low: #d5ddeb;
  --tile-high: #2b2f6b;
  --tile-ink-light: #18212e;
  --tile-ink-dark: #ffffff;
  --display: "Familjen Grotesk", "Helvetica Neue", Arial, sans-serif;
  --body: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #161d27;
    --ink: #e6ebf2;
    --muted: #93a0b3;
    --line: #273243;
    --accent: #7d9cf0;
    --accent-ink: #0f141b;
    --stage: #121820;
    --ax-x: #7d9cf0;
    --ax-y: #3fc4b2;
    --ax-z: #e3b04b;
    --ax-w: #ff6f9f;
    --tile-low: #3d4d6b;
    --tile-high: #f0d7a1;
    --tile-ink-light: #e6ebf2;
    --tile-ink-dark: #121820;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b;
  --surface: #161d27;
  --ink: #e6ebf2;
  --muted: #93a0b3;
  --line: #273243;
  --accent: #7d9cf0;
  --accent-ink: #0f141b;
  --stage: #121820;
  --ax-x: #7d9cf0;
  --ax-y: #3fc4b2;
  --ax-z: #e3b04b;
  --ax-w: #ff6f9f;
  --tile-low: #3d4d6b;
  --tile-high: #f0d7a1;
  --tile-ink-light: #e6ebf2;
  --tile-ink-dark: #121820;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 0.9375rem;
  line-height: 1.5;
  padding: 1.25rem 1rem;
}

.wrap {
  max-width: 73.75rem;
  margin: 0 auto;
  display: grid;
  gap: 1.125rem;
}

header { display: grid; gap: 0.25rem; }

h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.625rem, 4vw, 2.25rem);
  letter-spacing: -0.01em;
  line-height: 1.1;
  margin: 0;
  text-wrap: balance;
}

.lede { margin: 0; color: var(--muted); max-width: 68ch; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 20.625rem;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "stage scorebar"
    "stage panel";
  gap: 1.125rem;
  align-items: start;
}

.stage { grid-area: stage; }
.scorebar { grid-area: scorebar; }
.panel { grid-area: panel; }

/* One column: the score sits above the board so it stays in view while playing. */
@media (max-width: 53.75rem) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "scorebar" "stage" "panel";
  }
}

.stage {
  background: var(--stage);
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  overflow: hidden;
  display: grid;
}

.canvas-box {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 78vh;
  max-width: 100%;
  touch-action: none;
  cursor: grab;
}

.canvas-box:active { cursor: grabbing; }

/* On narrow screens the extra height holds the on-board buttons, so the board keeps its size. */
@media (max-width: 37.5rem) {
  .canvas-box { aspect-ratio: 3 / 4; }
}

canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.caption {
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 0.875rem 1rem;
  color: var(--muted);
  font-size: 0.875rem;
  /* The border spans the stage; the text stays near 75 characters wide. */
  padding-right: max(1rem, calc(100% - 75ch));
}

.panel,
.scorebar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  padding: 1rem;
  display: grid;
  gap: 1.125rem;
}

.group { display: grid; gap: 0.5rem; }

.label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.hint { font-size: 0.78125rem; color: var(--muted); margin: 0; }

.scorebar {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
}
.scorebar .btn-primary { grid-column: 1 / -1; }

@media (max-width: 53.75rem) {
  /* The score boxes span both rows; New game and the move count stack beside them. */
  .scorebar {
    grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    row-gap: 0.25rem;
    padding: 0.75rem;
  }
  .scorebar .score-box { grid-row: 1 / span 2; min-width: 5.25rem; padding: 0.375rem 0.625rem; gap: 0; }
  .scorebar .score-box output { font-size: 1.25rem; }
  .scorebar .btn-primary { grid-column: 3; grid-row: 1; min-height: 2.375rem; }
  .scorebar .move-count { grid-column: 3; grid-row: 2; line-height: 1.3; }
}

.score-box {
  display: grid;
  gap: 2px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  min-width: 6rem;
}

.score-box output {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
}

.move-count { grid-column: 1 / -1; font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }

.board-info { display: flex; align-items: baseline; justify-content: space-between; gap: 0.625rem; }
.board-size { font-family: var(--mono); font-size: 0.875rem; }

.view-controls.view-hint {
  left: 0.75rem;
  top: 0.75rem;
  right: auto;
  bottom: auto;
  max-width: min(16.25rem, calc(100% - 8.75rem));
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78125rem;
  line-height: 1.4;
}

.pad { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.375rem; }

.pad-btn {
  font: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  border-left: 0.25rem solid var(--axis);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.875rem;
}

.pad-btn:hover { border-color: var(--axis); }

.pad-btn kbd { font-family: var(--mono); font-size: 0.6875rem; color: var(--muted); }

.axis-x { --axis: var(--ax-x); }

.axis-y { --axis: var(--ax-y); }

.axis-z { --axis: var(--ax-z); }

.axis-w { --axis: var(--ax-w); }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--stage) 70%, transparent);
  padding: 1rem;
}

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  padding: 1.125rem 1.25rem;
  display: grid;
  gap: 0.625rem;
  max-width: 20rem;
  text-align: center;
}

.overlay-card h2 { font-family: var(--display); font-size: 1.625rem; margin: 0; }

.overlay-card p { margin: 0; color: var(--muted); }

.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.overlay-actions button { flex: 1 1 auto; }
@media (max-width: 30rem) {
  .overlay-actions { flex-direction: column; }
}

.overlay-card button {
  font: inherit;
  padding: 0.5rem 0.875rem;
  border-radius: 0.5rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.overlay-card button.overlay-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.overlay-card button.overlay-secondary:hover { border-color: var(--accent); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 1.2em;
  height: 1.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.btn-settings {
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.625rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.btn-settings:hover { color: var(--ink); border-color: var(--accent); }
.btn-settings .icon { width: 1.35em; height: 1.35em; }

.settings {
  width: min(26.25rem, calc(100% - 2rem));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: var(--surface);
  color: var(--ink);
}
.settings::backdrop { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.settings-body { padding: 1.125rem 1.25rem 1.25rem; display: grid; gap: 1.125rem; }
.settings-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.settings-head h2 { font-family: var(--display); font-size: 1.375rem; margin: 0; }
.settings-close {
  font: inherit;
  font-size: 1.375rem;
  line-height: 1;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.settings-close:hover { color: var(--ink); border-color: var(--line); }
.settings-group { display: grid; gap: 0.5rem; }
.settings-group-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0;
}
.settings-options {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  overflow: hidden;
}
.settings-options li + li .settings-option { border-top: 1px solid var(--line); }
.settings-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  width: 100%;
  min-height: 2.875rem;
  padding: 0.625rem 0.875rem;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.settings-option:hover { background: var(--bg); }
.settings-option.active { font-weight: 600; color: var(--accent); }
.settings-option .settings-check { opacity: 0; flex-shrink: 0; }
.settings-option.active .settings-check { opacity: 1; }
.settings-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.settings-note { margin: 0.125rem 0 0; font-size: 0.78125rem; color: var(--muted); }
.settings-credit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.settings-credit p { margin: 0; }
.settings-sources { margin: 0; font-size: 0.75rem; color: var(--muted); }
/* Side by side, the two lists keep the dialog short enough that a laptop screen shows it whole. */
@media (min-width: 45rem) {
  .settings { width: 40rem; }
  .settings-body { grid-template-columns: 1fr 1fr; column-gap: 1.25rem; align-items: start; }
  .settings-head, .settings-credit, .settings-sources { grid-column: 1 / -1; }
}
.credit-links { display: flex; gap: 0.25rem; }
.credit-links a {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  color: inherit;
  border-radius: 0.375rem;
}
.credit-links a:hover { color: var(--ink); }
.credit-links .icon { width: 1.125rem; height: 1.125rem; }
.icon-brand { fill: currentColor; stroke: none; }
/* The wave from the personal site's favicon, without its square; a thin stroke would read as a scribble. */
.icon-profile { stroke-width: 3.2; }
.credit-links a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.over-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.over-row:not(:has(:not([hidden]))) { display: none; }
.over-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.625rem;
  border-radius: 62rem;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.btn-link {
  font: inherit;
  font-size: 0.875rem;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.btn-link:hover { border-color: var(--accent); }

.view-controls {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.view-btn,
.view-chip {
  font: inherit;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.625rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.view-controls-top { top: 0.75rem; bottom: auto; }
.view-btn { width: 2.75rem; }
.view-btn .icon { width: 1.35em; height: 1.35em; }
.view-btn .icon-on,
.view-btn[aria-pressed="true"] .icon-off { display: none; }
.view-btn[aria-pressed="true"] .icon-on { display: block; }
.view-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.view-chip { padding: 0 0.75rem; font-family: var(--mono); font-size: 0.875rem; }
.view-btn:hover,
.view-chip:hover { border-color: var(--accent); }

.btn-primary {
  font: inherit;
  font-weight: 600;
  width: 100%;
  min-height: 2.75rem;
  border-radius: 0.625rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }
