:root {
  --bg: #f3f6f1;
  --surface: #ffffff;
  --text: #1d2a1f;
  --muted: #5d6e60;
  --primary: #2f7d4f;
  --accent: #d9a441;
  --primary-dark: #225f3b;
  --ink: #203b2b;
  --line: #dbe3d7;
  --board-light: #e9e7d6;
  --board-dark: #a8b8a1;
  --board-check: #efc0b0;
  --radius: 12px;
  --heading-font: "DM Serif Display", Georgia, serif;
  --body-font: Inter, system-ui, sans-serif;
  --shadow: 0 8px 24px rgba(0, 0, 0, .08);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.6 var(--body-font);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .58; }

a { color: var(--primary-dark); text-underline-offset: .22em; }
a:hover { color: var(--ink); }

:where(a, button, input, textarea, select, summary):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 4px;
}

h1, h2, h3 {
  font-family: var(--heading-font);
  font-weight: 400;
  line-height: 1.2;
  margin: 0 0 12px;
}

h1 { font-size: 48px; }
h2 { font-size: 36px; }
h3 { font-size: 22px; }
p { margin: 0 0 16px; }
img { display: block; max-width: 100%; }
.muted { color: var(--muted); }

.shell {
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 24px;
}

.skip-link {
  position: absolute;
  z-index: 10;
  left: 16px;
  top: 0;
  transform: translateY(-160%);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 16px;
}

.skip-link:focus { top: 8px; transform: none; }

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar, .footbar, .site-logo, .site-header nav, .site-footer nav {
  display: flex;
  align-items: center;
}

.topbar, .footbar { justify-content: space-between; gap: 16px; }
.topbar { min-height: 64px; }

.site-logo {
  gap: 12px;
  color: var(--ink);
  font: 400 22px/1.2 var(--heading-font);
  text-decoration: none;
  white-space: nowrap;
}

.logo-mark {
  display: inline-grid;
  grid-template-columns: repeat(3, 8px);
  gap: 2px;
  transform: rotate(-10deg);
}

.logo-mark i { height: 12px; border: 1px solid var(--primary); background: var(--primary); }
.logo-mark i:nth-child(2) { background: var(--surface); transform: translateY(-3px); }
.logo-mark i:nth-child(3) { border-color: var(--accent); background: var(--accent); }

.site-header nav { gap: 12px; }
.site-header nav a {
  position: relative;
  padding: 12px 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}

.site-header nav a:hover, .site-header nav a[aria-current="page"] { color: var(--ink); }
.site-header nav a[aria-current="page"]::after {
  position: absolute;
  right: 8px;
  bottom: 6px;
  left: 8px;
  height: 2px;
  background: var(--accent);
  content: "";
}

.home-main { padding-top: 24px; }
.subpage-main { padding-top: 48px; padding-bottom: 64px; }

.play-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.play-heading h1, .subpage-heading h1 { margin: 0; }
.play-heading span, .subpage-heading p { color: var(--muted); }
.play-heading span { font-size: 14px; }
.subpage-heading { margin-bottom: 24px; }
.subpage-heading p { margin: 12px 0 0; max-width: 62ch; font-size: 18px; }

.game-stage {
  position: relative;
  width: 100%;
  height: 416px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.game-stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.game-stage:fullscreen { border: 0; border-radius: 0; width: 100%; height: 100%; }
.challenge-stage { height: 452px; }
.proof-stage { height: 500px; margin-top: 12px; }

.game-cover, .game-loading {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
}

.game-cover {
  background: var(--ink);
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 24px;
}

.game-cover img {
  width: min(100%, 660px);
  max-height: 260px;
  margin: auto;
  border-radius: var(--radius);
  object-fit: contain;
}

.game-cover .primary-button { position: relative; z-index: 1; }
.game-loading {
  display: none;
  gap: 12px;
  color: var(--ink);
  background: var(--surface);
  font-size: 14px;
  text-align: center;
}

.game-stage[data-gf-state="loading"] .game-cover, .game-stage[data-gf-state="playing"] .game-cover { display: none; }
.game-stage[data-gf-state="loading"] .game-loading { display: grid; }
.game-stage noscript { display: block; position: relative; z-index: 2; padding: 12px; background: var(--surface); }
.loading-tiles { display: inline-flex; gap: 4px; }

.loading-tiles i {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--board-dark);
  animation: loading-tile 1s infinite alternate ease-in-out;
}

.loading-tiles i:nth-child(2) { animation-delay: .15s; }
.loading-tiles i:nth-child(3) { animation-delay: .3s; }

@keyframes loading-tile {
  to { transform: translateY(-6px); background: var(--primary); }
}

.game-tools, .mode-shortcuts, .utility-buttons, .chess-actions, .not-found-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.game-tools { justify-content: space-between; gap: 12px; padding-block: 12px; }
.mode-shortcuts { gap: 16px; }
.mode-shortcuts a { text-decoration: none; font-size: 14px; font-weight: 600; }
.mode-shortcuts a:hover { text-decoration: underline; }
.share-message:not(:empty) { color: var(--muted); font-size: 14px; }

.primary-button, .small-button, .mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-decoration: none;
  text-align: center;
}

.primary-button { background: var(--primary); color: var(--surface); }
.primary-button:hover { background: var(--primary-dark); color: var(--surface); }
.small-button { border-color: var(--line); background: var(--surface); color: var(--ink); }
.small-button:hover { border-color: var(--primary); background: var(--bg); }
[data-gf-like][aria-pressed="true"] { border-color: var(--primary); background: var(--bg); }

.reading-area {
  width: min(100%, 70ch);
  margin-inline: auto;
}

.reading-area > section, .home-main .reading-area, .learn-section, .proof-section {
  margin-top: 48px;
}

.home-main .reading-area { margin-bottom: 64px; }

.prose p, .prose ul, .prose ol, .prose blockquote { margin: 0 0 16px; }
.prose h2:not(:first-child), .prose h3:not(:first-child) { margin-top: 32px; }
.prose li + li { margin-top: 8px; }
.prose code { border-radius: 4px; background: var(--line); padding: 2px 4px; font-size: .9em; }
.prose img { border: 1px solid var(--line); border-radius: var(--radius); }
.prose figure { margin: 24px 0; }
.prose figcaption { padding-top: 8px; color: var(--muted); font-size: 14px; }
.prose blockquote { border-left: 3px solid var(--accent); padding-left: 16px; color: var(--muted); }
.prose table { width: 100%; border-collapse: collapse; }
.prose th, .prose td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }

.faq-section { margin-top: 48px; }
.faq-list { border-top: 1px solid var(--line); }
.faq-list details { border-bottom: 1px solid var(--line); padding: 12px 0; }
.faq-list summary, .proof-details summary, .move-log summary { font-weight: 600; cursor: pointer; color: var(--ink); }
.faq-list p { margin: 8px 0 0; }

.comments-section form {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.comment-fields, .comment-fields label { display: grid; gap: 4px; }
.comment-fields { gap: 12px; font-size: 14px; font-weight: 600; }
.comment-fields label span { color: var(--muted); }

.comment-fields input, .comment-fields textarea, .puzzle-picker select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  font-weight: 400;
}

.comment-fields textarea { resize: vertical; }
.reply-context { display: none; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
[data-gf-replying] .reply-context { display: flex; }
.comment-submit, .comment-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.comment-submit, .comments-list { margin-top: 12px; }
.comments-empty { display: none; }
[data-gf-empty]:not([data-gf-off]) .comments-empty { display: block; }

.comment {
  margin-top: 12px;
  padding: 12px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.comment p { margin: 8px 0; }
.comment time, .comment [data-gf-c-to] { color: var(--muted); font-size: 14px; }
.owner-label { display: none; color: var(--primary-dark); font-size: 12px; font-weight: 600; }
.comment[data-gf-owner] { border-color: var(--primary); }
.comment[data-gf-owner] > .comment-meta .owner-label { display: inline-block; }
.comment-replies { margin-left: 16px; }

.demo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.demo-card, .proof-details {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.demo-card p, .proof-section > p { max-width: 70ch; }
.demo-card .demo-feedback { margin: 8px 0 0; min-height: 1.6em; font-size: 14px; }
.demo-card .small-button { margin-top: 8px; }
.challenge-stage + .reading-area { margin-top: 48px; }

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-block: 24px;
}

.foot-brand { display: grid; gap: 4px; }
.foot-brand > span, .site-footer nav { color: var(--muted); font-size: 14px; }
.site-footer nav { flex-wrap: wrap; gap: 12px; }
.site-footer nav a { color: var(--muted); }

.embed-page {
  min-height: 100vh;
  background: var(--surface);
}

.chess-app {
  max-width: 856px;
  margin-inline: auto;
  padding: 16px 24px;
}

.play-mode-bar, .chess-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.play-mode-bar {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.play-mode-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--bg);
}

.mode-button { background: transparent; color: var(--muted); border-color: transparent; padding-inline: 12px; }
.mode-button:hover { color: var(--ink); }
.mode-button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.mode-caption { color: var(--muted); font-size: 14px; text-align: right; }
.chess-notice { align-items: flex-start; padding-top: 12px; padding-bottom: 12px; }
.chess-notice h1 { font-size: 28px; margin-bottom: 4px; }
.chess-notice p { margin: 0; color: var(--muted); font-size: 14px; }
.chess-progress { text-align: right; font-weight: 600; }

.puzzle-picker {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 12px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.chess-app:not([data-active-mode="practice"]) .puzzle-picker { display: none; }
.puzzle-picker select { width: auto; max-width: 100%; min-height: 44px; }

.chess-board-wrap {
  padding: 8px;
  border: 1px solid var(--text);
  border-radius: var(--radius);
  background: var(--ink);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--surface) 14%, transparent);
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  border-radius: 8px;
}

.chess-board:empty { min-height: 72px; background: var(--board-light); }
.demo-board { border: 1px solid var(--line); }
.demo-board:empty { min-height: 60px; }

.chess-square {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-width: 0;
  height: clamp(64px, 12vw, 92px);
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  background: var(--board-light);
  font: 600 12px/1 var(--body-font);
}

.chess-square:nth-child(even) { background: var(--board-dark); }
.chess-square:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--primary); }
.chess-square:focus-visible { z-index: 3; outline-offset: -4px; }
.chess-square:disabled { opacity: 1; }
.chess-square.is-last { box-shadow: inset 0 0 0 2px var(--accent); }
.chess-square.is-hint { box-shadow: inset 0 0 0 3px var(--accent); }
.chess-square.is-selected { z-index: 1; box-shadow: inset 0 0 0 3px var(--primary-dark); }
.chess-square.is-check { background: var(--board-check); }

.chess-square.is-legal::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  width: 14px;
  height: 14px;
  margin: auto;
  border-radius: 50%;
  background: var(--primary-dark);
  content: "";
}

.chess-square.is-legal:not([data-color="empty"])::after { width: calc(100% - 10px); height: calc(100% - 12px); border: 2px solid var(--primary-dark); border-radius: 8px; background: transparent; }

.chess-piece {
  display: grid;
  place-items: center;
  width: clamp(27px, 68%, 56px);
  aspect-ratio: 1;
  margin-bottom: 8px;
  border: 1px solid var(--text);
  border-radius: 11px;
  background: var(--ink);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--surface) 18%, transparent), 0 2px 3px color-mix(in srgb, var(--text) 25%, transparent);
  color: var(--surface);
  font: 400 clamp(17px, 5vw, 29px)/1 var(--heading-font);
}

[data-color="white"] .chess-piece {
  border-color: var(--board-dark);
  background: var(--surface);
  color: var(--ink);
}

[data-color="empty"] .chess-piece { display: none; }

.chess-coordinate {
  position: absolute;
  right: 4px;
  bottom: 4px;
  color: var(--text);
  font-size: 12px;
}

.demo-board .chess-square { height: clamp(48px, 8vw, 66px); }
.demo-board .chess-piece { width: clamp(24px, 65%, 42px); font-size: 18px; }

.chess-status, .chess-feedback {
  margin: 8px 0 0;
  font-size: 14px;
}

.chess-status { color: var(--ink); font-weight: 600; }
.chess-feedback { color: var(--muted); overflow-wrap: anywhere; }
.chess-feedback:empty, .chess-progress:empty { display: none; }
.chess-actions { margin-top: 12px; }

.defense-panel {
  margin-top: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.defense-panel h2 { margin: 0 0 8px; font-size: 18px; }
.defense-panel [data-chess-replies] { display: flex; flex-wrap: wrap; gap: 8px; }
.defense-panel button {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
}
.defense-panel button[aria-pressed="true"] { border-color: var(--primary-dark); background: var(--bg); }

.move-log { margin-top: 8px; font-size: 14px; }
.move-log summary { padding: 8px 0; }
.move-log ol { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 0; padding-left: 16px; }
.move-log li { margin-right: 8px; color: var(--muted); }
.not-found-links { margin-top: 24px; }

@media (max-width: 640px) {
  h1 { font-size: 32px; }
  h2 { font-size: 28px; }
  .shell { padding-inline: 16px; }
  .topbar { min-height: 56px; gap: 8px; }
  .site-logo { gap: 8px; font-size: 18px; }
  .site-header nav { gap: 4px; }
  .site-header nav a { padding-inline: 6px; }
  .play-heading { align-items: flex-start; flex-direction: column; gap: 4px; }
  .home-main, .subpage-main { padding-top: 16px; }
  .demo-grid { grid-template-columns: minmax(0, 1fr); }
  .game-tools { flex-direction: column; align-items: flex-start; }
  .game-stage { height: 404px; }
  .challenge-stage { height: 480px; }
  .proof-stage { height: 530px; }
  .game-cover { padding: 12px; }
  .game-cover .primary-button { width: 100%; max-width: 260px; }
  .chess-app { padding: 12px; }
  .mode-caption { display: none; }
  .play-mode-buttons { width: 100%; }
  .mode-button { flex: 1; padding-inline: 8px; white-space: nowrap; }
  .chess-notice h1 { font-size: 22px; }
  .chess-board-wrap { padding: 4px; }
  .chess-square { height: 64px; }
  .chess-piece { margin-bottom: 12px; border-radius: 7px; }
  .chess-coordinate { font-size: 12px; right: 3px; bottom: 3px; }
  .footbar { flex-direction: column; align-items: flex-start; gap: 12px; }
}

@media (max-width: 360px) {
  .shell { padding-inline: 12px; }
  .chess-app { padding-inline: 8px; }
  .chess-piece { width: 25px; font-size: 16px; }
  .mode-button { padding-inline: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-tiles i { animation: none; }
}
