*, *::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(--text); }
.primary-button:hover { background: var(--primary-dark); color: var(--text); }
.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;
}

.puzzle-picker-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 220px;
  min-width: 0;
}

.puzzle-picker-label select {
  flex: 1 1 auto;
  min-width: 0;
}

.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, .defense-panel h3 { 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; }
}

/* Presentation for the Walnut Chess Table. Game layout and controls live in the base theme. */
:root {
  --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);
  --bg: #211611;
  --surface: #2d2019;
  --text: #f5e8cf;
  --muted: #cdb99a;
  --primary: #283e29;
  --primary-dark: #18291a;
  --accent: #dfae66;
  --ink: var(--text);
  --line: #755138;
  --board-light: #ddb87d;
  --board-dark: #775035;
  --board-check: #a54232;
  --walnut-shadow: #160e0a;
  --walnut-room-image: none;
  --walnut-board-light: none;
  --walnut-board-dark: none;
  color-scheme: dark;
}

body { background: var(--bg); color: var(--text); color-scheme: dark; }
a { color: var(--accent); }
a:hover { color: var(--ink); }

:where(a, button, input, textarea, select, summary):focus-visible {
  outline-color: var(--accent);
}

.site-header {
  background: var(--walnut-shadow);
  border-bottom-color: var(--accent);
}

.site-header .topbar, .site-footer .footbar { max-width: 1380px; }
.site-logo { font-size: 28px; }
.logo-mark {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  width: 28px;
  height: 32px;
  transform: none;
}
.logo-mark i { display: none; }
.logo-mark::before {
  color: var(--accent);
  content: "♞";
  font: 30px/1 Georgia, serif;
}
.site-header nav { gap: 24px; }
.site-header nav a {
  color: var(--text);
  font: 400 20px/1.3 var(--heading-font);
  padding-inline: 12px;
}

.site-footer { background: var(--walnut-shadow); }

.home-main {
  max-width: none;
  padding: 0;
}

.play-section {
  --hero-gutter: clamp(20px, 5vw, 80px);
  position: relative;
  isolation: isolate;
  padding: 36px var(--hero-gutter) 46px;
  background: radial-gradient(ellipse at 50% 6%, var(--board-dark), var(--walnut-shadow) 72%);
  border-bottom: 1px solid var(--accent);
}

.play-section::before {
  position: absolute;
  z-index: -1;
  inset: 0;
  background:
    linear-gradient(to bottom, transparent 23%, color-mix(in srgb, var(--walnut-shadow) 42%, transparent) 74%, var(--bg)),
    var(--walnut-room-image) center clamp(-70px, -4vw, -38px) / cover no-repeat;
  content: "";
}

.play-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 4px;
  margin: 0 auto 20px;
  text-align: center;
  text-shadow: 0 12px 24px var(--walnut-shadow);
}

.play-heading h1 {
  color: var(--ink);
  font-size: clamp(56px, 7vw, 104px);
  line-height: 1;
}

.play-heading span {
  color: var(--text);
  font: italic 400 clamp(17px, 2vw, 28px)/1.25 var(--heading-font);
}

.play-section > .game-stage {
  max-width: 1320px;
  height: var(--walnut-stage-height, clamp(424px, 42vw, 555px));
  margin: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.play-section > .game-stage.game-stage--inline,
.challenge-stage.game-stage--inline {
  height: auto;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.play-section > .game-stage.game-stage--inline:fullscreen {
  display: grid;
  align-content: center;
  padding: 24px;
  overflow: auto;
}

.chess-notice h1,
.chess-notice .chess-notice-title {
  font-size: 28px;
  margin-bottom: 4px;
  color: var(--ink);
}

.play-section > .game-stage:fullscreen {
  max-width: none;
  height: 100%;
  background: var(--bg);
}

.game-cover, .game-loading {
  color: var(--ink);
  background: var(--walnut-shadow);
}
.game-cover {
  width: min(100%, 1120px);
  margin: auto;
  background: transparent;
}
.play-section > .game-stage[data-gf-state="loading"] .game-cover {
  display: grid;
}
.play-section > .game-stage[data-gf-state="loading"] .game-cover .primary-button {
  opacity: 0;
  pointer-events: none;
}
.play-section > .game-stage .game-loading {
  background: transparent;
  align-content: end;
  padding-bottom: 36px;
  pointer-events: none;
}
.game-cover img { width: min(100%, 950px); max-height: 260px; }
.loading-tiles i { background: var(--accent); }

.game-tools {
  max-width: 1200px;
  margin: auto;
  padding-block: 8px 0;
}
.play-section .mode-shortcuts a { color: var(--text); }
.utility-buttons button { font-size: 13px; }

.primary-button, .walnut-play-button {
  background: linear-gradient(165deg, var(--primary), var(--primary-dark));
  border: 1px solid var(--accent);
  color: var(--ink);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--ink) 28%, transparent), 0 4px 12px var(--walnut-shadow);
}

.primary-button:hover, .walnut-play-button:hover {
  color: var(--ink);
  background: var(--primary);
}
.walnut-play-button {
  min-width: clamp(220px, 24vw, 360px);
  min-height: clamp(48px, 4.5vw, 64px);
  padding: 10px 24px;
  font-size: 20px;
}

.small-button {
  color: var(--text);
  background: color-mix(in srgb, var(--walnut-shadow) 68%, transparent);
  border-color: var(--line);
}

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

.walnut-daily-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vw, 40px);
  width: min(100%, 720px);
  margin: 16px auto 4px;
  padding: 12px 24px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background:
    linear-gradient(140deg, var(--surface), color-mix(in srgb, var(--walnut-shadow) 87%, transparent)),
    var(--walnut-board-dark) center / cover;
  color: var(--text);
  font: 400 clamp(17px, 2vw, 25px)/1.25 var(--heading-font);
  text-decoration: none;
}

.walnut-daily-link strong {
  color: var(--ink);
  font-weight: 400;
  font-size: 1.2em;
}
.walnut-daily-link span { font-style: italic; }
.walnut-daily-link:hover { background-color: var(--surface); text-decoration: underline; }

.home-main .reading-area {
  width: min(100%, 73ch);
  padding-inline: 24px;
}

.embed-page { background: transparent; }
.chess-app {
  max-width: 1320px;
  padding: 6px 6px 12px;
}

.play-mode-bar {
  position: relative;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 0 0 clamp(14px, 2vw, 28px);
  border: 0;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 999px;
  background-color: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  transition: border-color 160ms ease, background-color 160ms ease, opacity 160ms ease;
}
.sound-toggle:hover {
  border-color: var(--accent);
  background-color: var(--primary-dark);
}
.sound-toggle[aria-pressed="false"] {
  border-color: var(--line);
  color: var(--muted);
  opacity: 0.8;
}
.sound-toggle-icon {
  font-size: 14px;
  line-height: 1;
}

.play-mode-buttons {
  justify-content: center;
  gap: clamp(4px, 2.4vw, 32px);
  padding: 0;
  background: transparent;
}

.mode-caption { display: none; }
.mode-button {
  min-width: 130px;
  padding: 8px 18px;
  color: var(--text);
  border-radius: 999px;
  font-size: 17px;
}

.mode-button:hover { background: var(--surface); }
.mode-button[aria-pressed="true"] {
  color: var(--ink);
  background: linear-gradient(165deg, var(--primary), var(--primary-dark));
  border-color: var(--accent);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--ink) 34%, transparent), 0 3px 8px var(--walnut-shadow);
}

.chess-app[data-active-mode="classic"] .chess-notice { display: none; }
.chess-notice, .puzzle-picker {
  max-width: 768px;
  margin-inline: auto;
}

.chess-notice h1 { color: var(--ink); }
.puzzle-picker select { background: var(--bg); }

.chess-board-wrap {
  --coordinate-rail: clamp(22px, 3vw, 40px);
  padding: clamp(5px, 1.25vw, 16px);
  border: 1px solid color-mix(in srgb, var(--accent) 80%, var(--line));
  border-radius: clamp(7px, 1.4vw, 25px);
  background:
    linear-gradient(170deg, color-mix(in srgb, var(--board-light) 18%, transparent), transparent 25%, color-mix(in srgb, var(--walnut-shadow) 23%, transparent) 60%),
    var(--walnut-board-dark) center / cover,
    var(--board-dark);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--ink) 48%, transparent),
    inset 0 -5px 14px color-mix(in srgb, var(--walnut-shadow) 65%, transparent),
    0 12px 28px color-mix(in srgb, var(--walnut-shadow) 72%, transparent);
}

.chess-board {
  border-radius: clamp(3px, .65vw, 10px);
  box-shadow: 0 0 0 1px var(--walnut-shadow), 0 0 5px var(--walnut-shadow);
  overflow: visible;
}

.chess-square:first-child {
  border-radius: clamp(3px, .65vw, 10px) 0 0 clamp(3px, .65vw, 10px);
}
.chess-square:first-child::before {
  border-bottom-left-radius: clamp(3px, .65vw, 10px);
}
.chess-square:last-child {
  border-radius: 0 clamp(3px, .65vw, 10px) clamp(3px, .65vw, 10px) 0;
}
.chess-square:last-child::before {
  border-bottom-right-radius: clamp(3px, .65vw, 10px);
}

.chess-square {
  isolation: isolate;
  height: auto;
  min-height: calc(44px + var(--coordinate-rail));
  aspect-ratio: auto;
  padding-block-end: var(--coordinate-rail);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--ink) 13%, transparent), color-mix(in srgb, var(--board-dark) 10%, transparent)),
    var(--walnut-board-light) center / cover,
    var(--board-light);
}

.chess-app .chess-square {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1.1;
  max-height: 194px;
}

.chess-square:nth-child(even) {
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--board-light) 14%, transparent), color-mix(in srgb, var(--walnut-shadow) 25%, transparent)),
    var(--walnut-board-dark) center / cover,
    var(--board-dark);
}

.chess-square::before {
  position: absolute;
  z-index: -1;
  inset: auto 0 0;
  height: var(--coordinate-rail);
  border-top: 1px solid color-mix(in srgb, var(--accent) 65%, transparent);
  background:
    linear-gradient(to bottom, color-mix(in srgb, var(--walnut-shadow) 55%, transparent), color-mix(in srgb, var(--walnut-shadow) 68%, transparent)),
    var(--walnut-board-dark) center bottom / 220px auto,
    var(--board-dark);
  content: "";
}

.chess-coordinate {
  display: grid;
  inset: auto 0 0;
  height: var(--coordinate-rail);
  place-items: center;
  color: var(--accent);
  font: 600 clamp(12px, 2vw, 25px)/1 var(--heading-font);
  text-shadow: 0 1px 2px var(--walnut-shadow);
}

.chess-square:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -5px;
}

.chess-square:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--primary); }
.chess-square.is-last { box-shadow: inset 0 0 0 3px var(--accent); }
.chess-square.is-hint { box-shadow: inset 0 0 0 4px var(--accent); }
.chess-square.is-selected { box-shadow: inset 0 0 0 4px var(--primary); }
.chess-square.is-check { background-color: var(--board-check); }
.chess-square.is-check::after {
  position: absolute;
  z-index: -1;
  inset: 0 0 var(--coordinate-rail);
  background: color-mix(in srgb, var(--board-check) 60%, transparent);
  content: "";
}

.chess-square.is-legal::after {
  bottom: var(--coordinate-rail);
  background: var(--primary-dark);
  outline: 1px solid var(--accent);
}
.chess-square.is-legal:not([data-color="empty"])::after {
  height: calc(100% - var(--coordinate-rail) - 8px);
  border-color: var(--primary-dark);
}

.chess-square[data-piece="K"] { --walnut-piece-art: var(--walnut-white-k, none); }
.chess-square[data-piece="N"] { --walnut-piece-art: var(--walnut-white-n, none); }
.chess-square[data-piece="R"] { --walnut-piece-art: var(--walnut-white-r, none); }
.chess-square[data-piece="k"] { --walnut-piece-art: var(--walnut-black-k, none); }
.chess-square[data-piece="n"] { --walnut-piece-art: var(--walnut-black-n, none); }
.chess-square[data-piece="r"] { --walnut-piece-art: var(--walnut-black-r, none); }

.chess-square .chess-piece {
  width: 85%;
  height: 89%;
  min-width: 0;
  max-width: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--walnut-piece-art, none) center bottom / contain no-repeat;
  box-shadow: none;
  color: var(--walnut-shadow);
  font: 400 var(--walnut-glyph-size, clamp(31px, 8.9vw, 130px))/1 Georgia, serif;
  -webkit-text-stroke: .45px var(--text);
  text-shadow: 0 2px 3px color-mix(in srgb, var(--walnut-shadow) 72%, transparent);
  pointer-events: none;
}

.chess-square[data-color="white"] .chess-piece {
  background: var(--walnut-piece-art, none) center bottom / contain no-repeat;
  color: var(--ink);
  -webkit-text-stroke-color: var(--walnut-shadow);
}

.demo-board { --coordinate-rail: 17px; }
.demo-board .chess-square { min-height: 45px; height: clamp(54px, 10vw, 74px); }
.demo-board .chess-piece {
  font-size: var(--walnut-glyph-size, clamp(22px, 4vw, 46px));
}
.demo-board .chess-coordinate { font-size: 12px; }

.chess-status {
  margin-top: clamp(12px, 2vw, 24px);
  color: var(--ink);
  font: 400 clamp(23px, 3vw, 36px)/1.1 var(--heading-font);
  text-align: center;
}

.chess-feedback { text-align: center; }
.chess-actions { justify-content: center; }
.move-log { width: fit-content; max-width: 100%; margin: 8px auto 0; }
.move-log summary { color: var(--text); text-align: center; }
.move-log summary::marker { color: var(--accent); }
.move-log ol { justify-content: center; }
.defense-panel { max-width: 768px; margin-inline: auto; text-align: center; }
.defense-panel [data-chess-replies] { justify-content: center; }

.challenge-stage, .proof-stage { background: var(--bg); }
.challenge-stage { height: clamp(445px, 43vw, 570px); }
.proof-stage { height: clamp(490px, 46vw, 610px); }

@media (max-width: 640px) {
  .site-logo { font-size: 23px; gap: 6px; }
  .logo-mark { width: 22px; }
  .logo-mark::before { font-size: 25px; }
  .site-header nav { gap: 4px; flex-wrap: nowrap; }
  .site-header nav a { padding-inline: 4px; font-size: 13px; white-space: nowrap; }
  .home-main { padding: 0; }
  .play-section {
    --hero-gutter: 10px;
    --walnut-room-image: none;
    padding-top: 22px;
    padding-bottom: 24px;
  }
  .play-heading { margin-bottom: 15px; align-items: center; gap: 5px; }
  .play-heading h1 { font-size: clamp(47px, 11vw, 66px); }
  .play-heading span { font-size: 17px; }
  .play-section > .game-stage { height: var(--walnut-stage-height, 366px); }
  .play-section .game-tools { flex-direction: row; align-items: center; justify-content: center; }
  .chess-app { padding: 8px 3px; }
  .play-mode-bar { padding-bottom: 15px; }
  .play-mode-buttons { width: auto; gap: 4px; flex-wrap: wrap; justify-content: center; }
  .mode-button { min-width: 0; flex: 0 1 auto; padding-inline: 9px; font-size: 13px; }
  .chess-board-wrap {
    --coordinate-rail: 19px;
    padding: 4px;
    background: var(--board-dark);
  }
  .chess-square .chess-piece { font-size: var(--walnut-glyph-size, clamp(29px, 10vw, 54px)); }
  .chess-app .chess-square {
    aspect-ratio: auto;
    height: clamp(63px, 13vw, 92px);
  }
  .chess-notice { padding-top: 8px; padding-bottom: 10px; }
  .chess-notice h1 { font-size: 23px; }
  .challenge-stage { height: 445px; }
  .proof-stage { height: 510px; }
  .walnut-play-button { font-size: 16px; }
  .walnut-daily-link { padding-inline: 14px; }
  .home-main .reading-area { padding-inline: 16px; }
}

@media (max-width: 540px) {
  .topbar { flex-wrap: wrap; row-gap: 2px; padding-block: 6px; }
  .site-header nav { flex-wrap: wrap; }
}

@media (max-width: 360px) {
  .topbar { flex-wrap: wrap; row-gap: 2px; padding-block: 6px; }
  .site-logo { font-size: 20px; }
  .site-header nav a { font-size: 12.5px; }
  .play-section { --hero-gutter: 7px; }
  .play-heading span { font-size: 16px; }
  .mode-button { padding-inline: 8px; }
  .walnut-daily-link { flex-wrap: wrap; gap: 4px 12px; }
}


.logo-mark { object-fit: contain; }
.logo-mark::before { content: none; }
.chess-app [data-chess-action="begin"] {
  display: block;
  margin: 14px auto 0;
}
.game-cover img { object-fit: contain; }

/* Smooth piece glide, capture ring, check/checkmate shake & golden medallion modal */
.chess-square.is-animating {
  z-index: 4;
}
.chess-square.is-animating .chess-piece {
  will-change: transform, filter;
}
.chess-square.is-captured::after {
  position: absolute;
  z-index: 2;
  inset: 6% 10% calc(var(--coordinate-rail) + 6%);
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 85%, transparent);
  pointer-events: none;
  content: "";
  animation: walnut-capture-ring 380ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes walnut-capture-ring {
  0% { transform: scale(0.55); opacity: 0.95; }
  100% { transform: scale(1.18); opacity: 0; }
}

.chess-square.is-check::after {
  animation: walnut-check-pulse 1.15s ease-in-out infinite;
}
@keyframes walnut-check-pulse {
  0%, 100% { opacity: 0.72; box-shadow: inset 0 0 12px rgba(214, 62, 42, 0.65); }
  50% { opacity: 1; box-shadow: inset 0 0 24px rgba(255, 102, 74, 0.95); }
}

.chess-board-wrap.is-check-shake {
  animation: walnut-check-shake 300ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
.chess-board-wrap.is-wrong-shake {
  animation: walnut-wrong-shake 340ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--ink) 40%, transparent),
    0 0 0 2px var(--board-check),
    0 0 22px color-mix(in srgb, var(--board-check) 60%, transparent),
    0 12px 28px var(--walnut-shadow);
}
.chess-board-wrap.is-mate-shake {
  animation: walnut-mate-shake 460ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
.chess-board-wrap.is-victory-glow {
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--ink) 55%, transparent),
    0 0 0 2px var(--accent),
    0 0 38px color-mix(in srgb, var(--accent) 68%, transparent),
    0 14px 34px var(--walnut-shadow);
}
.chess-board-wrap.is-defeat-glow {
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--ink) 30%, transparent),
    0 0 0 2px var(--board-check),
    0 0 34px color-mix(in srgb, var(--board-check) 68%, transparent),
    0 14px 34px var(--walnut-shadow);
}
@keyframes walnut-wrong-shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-6px, 0, 0); }
  45% { transform: translate3d(6px, 0, 0); }
  70% { transform: translate3d(-3px, 0, 0); }
}

.chess-fx-canvas {
  position: fixed;
  inset: 0;
  z-index: 45;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
@keyframes walnut-check-shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  18% { transform: translate3d(-4px, 0, 0); }
  38% { transform: translate3d(4px, 0, 0); }
  58% { transform: translate3d(-2.5px, 0, 0); }
  78% { transform: translate3d(2px, 0, 0); }
}
@keyframes walnut-mate-shake {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  14% { transform: translate3d(-7px, -1.5px, 0) rotate(-0.35deg); }
  28% { transform: translate3d(7px, 1.5px, 0) rotate(0.35deg); }
  44% { transform: translate3d(-5px, 1px, 0) rotate(-0.2deg); }
  60% { transform: translate3d(4px, -1px, 0) rotate(0.15deg); }
  78% { transform: translate3d(-2px, 0, 0); }
}

.chess-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 14px;
  background: radial-gradient(circle at 50% 42%, rgba(33, 22, 17, 0.64), rgba(14, 9, 6, 0.84));
  backdrop-filter: blur(4px);
  animation: walnut-backdrop-in 240ms ease-out;
}
@keyframes walnut-backdrop-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chess-modal {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 20px 24px 18px;
  border: 1.5px solid var(--accent);
  border-radius: 16px;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% -10%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 60%),
    linear-gradient(170deg, var(--surface), var(--bg) 72%, var(--walnut-shadow));
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 198, 0.35),
    0 20px 48px rgba(0, 0, 0, 0.65),
    0 0 0 4px rgba(223, 174, 102, 0.14);
  color: var(--text);
  text-align: center;
  animation: walnut-modal-pop 380ms cubic-bezier(0.22, 1, 0.36, 1);
}
.chess-modal:focus { outline: none; }
@keyframes walnut-modal-pop {
  0% { opacity: 0; transform: translateY(16px) scale(0.92); }
  28% { opacity: 1; }
  65% { opacity: 1; transform: translateY(-2px) scale(1.015); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.chess-medallion {
  position: relative;
  width: 78px;
  height: 78px;
  margin: 0 auto 10px;
  border-radius: 50%;
  overflow: hidden;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.55));
  animation: walnut-medal-drop 520ms cubic-bezier(0.22, 1, 0.36, 1);
}
.chess-medallion svg {
  display: block;
  width: 100%;
  height: 100%;
}
.chess-medallion::after {
  position: absolute;
  inset: -10% -60%;
  background: linear-gradient(110deg, transparent 38%, rgba(255, 249, 224, 0.65) 50%, transparent 62%);
  transform: translateX(-80%);
  animation: walnut-medal-gleam 1.6s ease-in-out 260ms 1 forwards;
  pointer-events: none;
  content: "";
}
.chess-modal-backdrop[data-outcome="victory"] {
  background: radial-gradient(circle at 50% 40%, rgba(78, 52, 22, 0.62), rgba(14, 9, 6, 0.84));
}
.chess-modal-backdrop[data-outcome="defeat"] {
  background: radial-gradient(circle at 50% 42%, rgba(84, 22, 16, 0.66), rgba(12, 6, 6, 0.88));
}
.chess-modal-backdrop[data-outcome="defeat"] .chess-modal {
  border-color: var(--board-check);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 50% -10%, color-mix(in srgb, var(--board-check) 32%, transparent), transparent 62%),
    linear-gradient(170deg, var(--surface), var(--bg) 72%, var(--walnut-shadow));
  box-shadow:
    inset 0 1px 0 rgba(242, 166, 150, 0.28),
    0 20px 48px rgba(0, 0, 0, 0.72),
    0 0 0 4px rgba(165, 66, 50, 0.24);
}
.chess-modal-backdrop[data-outcome="defeat"] .chess-modal-eyebrow {
  color: #f09584;
}
.chess-modal-backdrop[data-outcome="victory"] .chess-medallion {
  box-shadow: 0 0 28px color-mix(in srgb, var(--accent) 65%, transparent);
}
.chess-modal-backdrop[data-outcome="defeat"] .chess-medallion {
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.65));
  box-shadow: 0 0 24px color-mix(in srgb, var(--board-check) 65%, transparent);
  animation: walnut-defeat-drop 460ms cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes walnut-defeat-drop {
  0% { opacity: 0; transform: translateY(-16px) scale(0.75); }
  55% { opacity: 1; transform: translateY(3px) scale(1.03) rotate(-4deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
}
.chess-medallion .medal-svg { display: none; }
.chess-modal-backdrop[data-outcome="victory"] .chess-medallion .medal-svg--victory,
.chess-modal-backdrop:not([data-outcome]) .chess-medallion .medal-svg--victory { display: block; }
.chess-modal-backdrop[data-outcome="defeat"] .chess-medallion .medal-svg--defeat { display: block; }
.chess-modal-backdrop[data-outcome="draw"] .chess-medallion .medal-svg--draw { display: block; }
@keyframes walnut-medal-drop {
  0% { opacity: 0; transform: scale(0.45) rotate(-18deg); }
  68% { opacity: 1; transform: scale(1.08) rotate(4deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
@keyframes walnut-medal-gleam {
  to { transform: translateX(90%); }
}

.chess-modal-eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.chess-modal-title {
  margin: 0 0 6px;
  color: var(--ink);
  font: 400 clamp(24px, 4vw, 32px)/1.1 var(--heading-font);
}
.chess-modal-copy {
  margin: 0 auto 12px;
  max-width: 38ch;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.48;
}
.chess-modal-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
}
.chess-modal-meta:empty { display: none; }
.chess-modal-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 999px;
  background: rgba(22, 14, 10, 0.55);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}
.chess-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.chess-modal-actions button {
  min-height: 40px;
  padding: 7px 15px;
}

@media (max-width: 640px) {
  .chess-modal { padding: 16px 16px 14px; }
  .chess-medallion { width: 64px; height: 64px; margin-bottom: 8px; }
}
.is-cta-pulse {
  animation: walnut-cta-pulse 520ms ease-out;
}
@keyframes walnut-cta-pulse {
  0% { box-shadow: 0 0 0 0 rgba(223, 174, 102, 0.72); }
  70% { box-shadow: 0 0 0 10px rgba(223, 174, 102, 0); }
  100% { box-shadow: 0 0 0 0 rgba(223, 174, 102, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .is-cta-pulse,
  .chess-square.is-captured::after,
  .chess-square.is-check::after,
  .chess-board-wrap.is-check-shake,
  .chess-board-wrap.is-mate-shake,
  .chess-modal-backdrop,
  .chess-modal,
  .chess-medallion,
  .chess-medallion::after {
    animation: none !important;
  }
}
