/* The public reading room and chessboard share a light, warm palette. */
:root {
  color-scheme: light;
  --paper: #f9f3e8;
  --surface: #fffaf1;
  --cream: #f2e7d5;
  --ink: #30281e;
  --muted: #64584a;
  --green: #354b36;
  --green-deep: #243626;
  --green-pale: #e6eadb;
  --line: #d9cbb7;
  --rust: #963c2c;
  --focus: #356851;
  --radius: 1rem;
  --page: 72rem;
  --shadow: 0 .5rem 1.5rem #55381714;
  --serif: "Songti SC", "Noto Serif CJK SC", "Noto Serif CJK TC", "Microsoft YaHei", Georgia, serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
  font: 100%/1.65 var(--sans);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 0; }
img, svg { display: block; max-width: 100%; }
img { height: auto; }
a { color: var(--green-deep); text-underline-offset: .2em; }
a:hover { color: var(--rust); }
button, input, select { font: inherit; }
button:enabled { cursor: pointer; }
button:disabled { cursor: default; opacity: .54; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
::selection { background: #d8e3cd; color: var(--green-deep); }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.24; }
h1, h2 { font-family: var(--serif); }
h1 { font-size: clamp(2.05rem, 5.4vw, 4.3rem); letter-spacing: -.035em; }
h2 { font-size: clamp(1.45rem, 3vw, 2.15rem); }
h3 { font-size: 1.13rem; }

.wrap { width: min(100% - clamp(2rem, 6vw, 6rem), var(--page)); margin-inline: auto; }
main.wrap { padding-block: clamp(1.4rem, 3.75vw, 3rem) clamp(2.5rem, 6vw, 5rem); }
.skip-link {
  position: absolute;
  inset: .625rem auto auto .625rem;
  z-index: 5;
  padding: .5rem .875rem;
  background: var(--surface);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner { display: flex; align-items: center; flex-wrap: wrap; gap: .15rem clamp(.7rem, 3vw, 2.5rem); min-height: 4.35rem; }
.brand, .site-nav a, .languages a { text-decoration: none; }
.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  min-height: 44px;
  font: 800 clamp(1.15rem, 2.5vw, 1.55rem)/1 var(--serif);
  letter-spacing: -.02em;
}
.brand svg, .brand img { width: 1.75rem; height: 1.75rem; }
.brand-mark { display: grid; place-items: center; width: 1.65em; aspect-ratio: 1; border-radius: 50%; background: var(--green); color: var(--surface); font-size: .75em; }
.site-nav, .languages { display: flex; align-items: center; flex-wrap: wrap; gap: 0 clamp(.65rem, 1.9vw, 1.35rem); }
.site-nav a, .languages a { display: inline-flex; align-items: center; min-height: 44px; }
.site-nav { font-size: .91rem; }
.site-nav [aria-current="page"] { font-weight: 750; color: var(--green-deep); text-decoration: underline; }
.languages { margin-inline-start: auto; gap: .625rem; font-size: .79rem; }
.languages [aria-current] { font-weight: 800; color: var(--rust); }

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  align-items: center;
  overflow: hidden;
  padding: clamp(1.3rem, 5vw, 4rem);
  min-height: 27rem;
  isolation: isolate;
  border: 1px solid var(--line);
  border-radius: 1.5rem;
  background: linear-gradient(115deg, #fff9ec 8%, #f6ebd7 62%, #e8dfc5);
}
.hero-copy { z-index: 1; display: grid; justify-items: start; gap: 1.08rem; }
.hero-copy h1 { max-inline-size: 12em; }
.hero-copy p { max-inline-size: 33rem; color: var(--muted); font-size: clamp(1rem, 1.5vw, 1.17rem); }
.eyebrow { color: var(--green); font-size: .82rem; font-weight: 750; letter-spacing: .11em; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.button, .game-controls button, .game-tools button, .puzzle button:not(.square), .game-setup button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .59rem .95rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: var(--surface);
  color: var(--green-deep);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
}
.button.primary { background: var(--green); border-color: var(--green); color: #fffdf7; }
.button.secondary { background: var(--surface); }
.button.quiet { background: transparent; border-color: transparent; text-decoration: underline; }
.button:hover, .game-controls button:enabled:hover, .game-tools button:enabled:hover, .puzzle button:not(.square):enabled:hover, .game-setup button:enabled:hover {
  background: var(--green-pale);
  color: var(--green-deep);
}
.button.primary:hover { background: var(--green-deep); color: #fffdf7; }
.hero-art {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: clamp(17rem, 30vw, 23rem);
  align-self: stretch;
}
.hero-art::before {
  position: absolute;
  z-index: -1;
  inset: 5% 5% 5% 8%;
  border-radius: 52% 48% 47% 53%;
  background: radial-gradient(ellipse at 52% 46%, #d5dbb7 18%, #e3e3c5 64%, transparent 72%);
  content: "";
}
.hero-cat {
  z-index: 1;
  width: min(53%, 13.5rem);
  height: auto;
  max-height: 21rem;
  object-fit: contain;
  align-self: end;
  margin-inline-start: -24%;
  filter: drop-shadow(0 .55rem .45rem #67452d33);
}
.hero-art > :only-child.hero-cat { margin-inline-start: 0; align-self: center; }
.hero-board, .hero-art > .board {
  position: absolute;
  inset: auto 1% .55rem auto;
  width: 57%;
  max-width: 15rem;
  z-index: 2;
  transform: rotate(9deg);
}
.hero-board > .board { width: 100%; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem 1rem; flex-wrap: wrap; margin-block: 2.55rem 1rem; }
.section-head p, .page-head p, .index-card p, .topic p, .reading .lead { color: var(--muted); }
.topic-grid, .index-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15.5rem), 1fr)); gap: .9rem; }
.topic, .index-card {
  display: grid;
  align-content: start;
  gap: .48rem;
  padding: 1.2rem;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.topic h2, .index-card h2 { font-size: 1.28rem; }
a.topic, a.index-card { color: var(--ink); text-decoration: none; }
a.topic:hover, a.index-card:hover { border-color: var(--green); }
a.topic:hover :is(h2, h3, strong), a.index-card:hover :is(h2, h3, strong) { text-decoration: underline; text-underline-offset: .18em; }
.topic > :first-child, .index-card > :first-child { color: var(--green-deep); }
.page-head { display: grid; gap: .55rem; margin-block: .3rem 1.8rem; }
.page-head h1 { font-size: clamp(1.95rem, 4.6vw, 3.5rem); }
.page-head p { max-width: 45rem; }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: .15rem .65rem; align-items: baseline; margin-block-end: .8rem; color: var(--muted); font-size: .86rem; }
.breadcrumbs ol { display: flex; flex-wrap: wrap; gap: .25rem .7rem; padding: 0; margin: 0; list-style: none; }
.breadcrumbs li + li::before { color: var(--muted); margin-inline-end: .6rem; content: "/"; }
.article-layout { display: grid; grid-template-columns: minmax(0, 45rem) minmax(12rem, 1fr); gap: clamp(1.1rem, 4vw, 4rem); align-items: start; }
.reading { display: grid; gap: 1.25rem; min-width: 0; overflow-wrap: anywhere; }
.reading .lead { font-size: 1.13rem; }
.reading h1 { font-size: clamp(1.95rem, 4.5vw, 3.55rem); }
.reading h2 { margin-block-end: .44rem; font-size: clamp(1.35rem, 2.6vw, 1.85rem); }
.reading section { scroll-margin-block-start: 1rem; }
.reading p + p { margin-block-start: .7rem; }
.reading :is(ul, ol) { padding-inline-start: 1.4rem; }
.related { display: grid; gap: .65rem; padding: 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.related h2 { font-size: 1.15rem; }
.related :is(ol, ul) { margin-block: 0; padding-inline-start: 1.2rem; }
.related a { display: inline-block; padding-block: .18rem; }
.site-footer { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.site-footer > .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem 1.4rem; padding-block: 1.25rem; font-size: .88rem; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }

/* SVG line coordinates, DOM buttons and static diagrams share the grid. */
.board {
  --board-ink: #654624;
  position: relative;
  isolation: isolate;
  width: 100%;
  aspect-ratio: 10 / 11;
  border: 1px solid #976534;
  border-radius: clamp(.45rem, 1.17vw, .85rem);
  background: repeating-linear-gradient(6deg, #7547170a 0 1px, transparent 2px 7px), linear-gradient(115deg, #f1ce98, #e9bb80 60%, #dca770);
  box-shadow: 0 .45rem 0 #a8784a, 0 .7rem 1.2rem #633d2538, inset 0 0 0 .23rem #fff3d64a;
  color: var(--board-ink);
}
.board-grid { position: absolute; z-index: 0; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.board-grid path { stroke: var(--board-ink); stroke-width: 1; }
.board-river {
  position: absolute;
  z-index: 1;
  inset: 50% 16% auto;
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 1rem;
  transform: translateY(-50%);
  color: var(--board-ink);
  font: 700 clamp(.7rem, 2vw, 1.25rem)/1 var(--serif);
  letter-spacing: .17em;
  pointer-events: none;
}
.square {
  position: absolute;
  z-index: 2;
  left: calc(10% + var(--col) * 10%);
  top: calc(8% + var(--row) * 9.333333%);
  display: grid;
  place-items: center;
  width: 10%;
  height: 9.333333%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  touch-action: manipulation;
}
.square::before { position: absolute; width: 88%; aspect-ratio: 1; border-radius: 50%; pointer-events: none; content: ""; }
button.square:focus-visible { z-index: 4; outline-offset: -2px; }
.square[data-last]:not([data-last="false"])::before { background: #61442d33; }
.square[data-selected]:not([data-selected="false"])::before { background: #344c39; outline: 2px solid #344c39; outline-offset: 1px; }
.square[data-hint]:not([data-hint="false"])::before { outline: 2px dashed #264f67; outline-offset: 1px; }
.square[data-legal]:not([data-legal="false"])::after {
  position: absolute;
  z-index: 3;
  width: 27%;
  aspect-ratio: 1;
  border: 1px solid #fff7d0;
  border-radius: 50%;
  background: #315a3f;
  pointer-events: none;
  content: "";
}
.square[data-legal]:not([data-legal="false"]):has(.piece)::after { width: 83%; border: 2px solid #315a3f; background: transparent; }
.piece {
  z-index: 1;
  display: grid;
  width: 84%;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid #966339;
  border-radius: 50%;
  background: radial-gradient(circle at 43% 35%, #fff6d9 0 58%, #ecd1a4 68% 100%);
  box-shadow: 0 .1em .125em #55301866, inset 0 0 0 .11em #b17c4c42;
  color: #35261a;
  font: 900 1.15rem/1 var(--serif);
  font-size: 5cqi;
  user-select: none;
  pointer-events: none;
}
.board { container-type: inline-size; }
.piece.red { color: #8e281f; border-color: #9e5c40; }
.diagram { margin: .1rem 0; max-width: 26rem; }
.diagram > .board, .puzzle .board { max-width: 26rem; }
.diagram figcaption { margin-block-start: 1rem; color: var(--muted); font-size: .92rem; }

.game-layout { display: grid; grid-template-columns: minmax(0, 34.5rem) minmax(14rem, 21rem); gap: clamp(1rem, 4.2vw, 3.5rem); align-items: start; }
.game-board { min-width: 0; padding-block-end: .55rem; }
.game-side { display: grid; gap: .85rem; min-width: 0; }
.cat-status {
  display: flex;
  gap: .85rem;
  align-items: center;
  min-height: 6.5rem;
  min-width: 0;
  padding: .55rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(125deg, var(--green-pale), #f4eddc);
}
.cat-status img { width: 4.15rem; height: 5.25rem; flex: 0 0 auto; object-fit: contain; transform-origin: 50% 83%; }
.cat-status p { color: var(--muted); font-size: .92rem; }
.cat-status[data-mood="start"] img { animation: cat-hello .58s ease-out both; }
.cat-status[data-mood="end"] img { animation: cat-finish .52s ease-in-out both; }
@keyframes cat-hello {
  0%, 100% { transform: rotate(0) translateY(0); }
  35% { transform: rotate(-8deg) translateY(-.35rem); }
  66% { transform: rotate(5deg) translateY(0); }
}
@keyframes cat-finish {
  0%, 100% { transform: rotate(0) scale(1); }
  45% { transform: rotate(7deg) scale(1.08); }
}
.game-controls, .game-tools, .puzzle-actions { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.game-controls .button, .game-tools .button { flex: 1 1 auto; }
.game-controls > p, .game-controls > .game-tools { flex-basis: 100%; }
.game-controls > p:empty { display: none; }
.game-more { margin-block-start: 1.3rem; }
.game-controls select, .game-setup select, .game-setup input { max-width: 100%; min-height: 44px; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: .4rem; background: var(--surface); color: var(--ink); }
.game-side > .status, .puzzle-status { min-height: 1.65em; color: var(--green-deep); font-weight: 720; }
.history {
  min-width: 0;
  padding: .7rem .9rem;
  border: 1px solid var(--line);
  border-radius: .7rem;
  background: var(--surface);
}
.history summary { cursor: pointer; font-weight: 720; }
.history :is(ol, ul) { max-height: 14rem; overflow-y: auto; padding-inline-start: 1.5rem; margin: .45rem 0; }
.history :is(ol, ul):empty { display: none; }
.history li { font-variant-numeric: tabular-nums; }
.history .move-steps { display: flex; flex-wrap: wrap; gap: .25rem; padding-inline-start: 0; list-style: none; }
.move-steps button { min-height: 44px; padding: .2rem .5rem; border: 1px solid var(--line); border-radius: .35rem; background: transparent; color: var(--ink); }
.move-steps button[aria-pressed="true"] { background: var(--green-pale); border-color: var(--green); }
.game-setup { max-width: min(28rem, 100% - 2rem); padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.game-setup::backdrop { background: #2e261d80; }
.game-setup form { display: grid; gap: .8rem; }
.game-setup label { display: grid; gap: .3rem; }
.puzzle { display: grid; gap: .8rem; }
.puzzle .board { margin-block-end: .45rem; }
.puzzle details { padding: .65rem .85rem; border: 1px solid var(--line); border-radius: .6rem; background: var(--surface); }
.puzzle summary { cursor: pointer; font-weight: 700; }

@media (max-width: 52rem) {
  .article-layout { grid-template-columns: minmax(0, 1fr); }
  .related { max-width: 43rem; }
}

@media (max-width: 43rem) {
  .header-inner { justify-content: space-between; padding-block: .24rem .15rem; }
  .site-nav { order: 2; flex: 1 0 100%; gap: 0 clamp(.65rem, 3.8vw, 1.35rem); border-top: 1px solid var(--line); }
  .site-nav a { font-size: .85rem; }
  .hero { grid-template-columns: minmax(0, 1fr); min-height: 0; gap: .4rem; }
  .hero-copy { gap: .7rem; }
  .hero-art { min-height: clamp(8.25rem, 43vw, 13.5rem); }
  .hero-art::before { inset: 4% 17% 0; }
  .hero-cat { width: min(38%, 7.5rem); max-height: 13rem; margin-inline-start: -21%; }
  .hero-board, .hero-art > .board { width: 36%; max-width: 9.4rem; inset: auto 17% .5rem auto; }
  .game-layout { display: flex; flex-direction: column; align-items: stretch; gap: .72rem; }
  .game-side { display: contents; }
  .game-board { order: 2; width: 100%; max-width: 31rem; align-self: center; }
  .cat-status { order: 0; min-height: 3.45rem; gap: .6rem; padding: .24rem .69rem; }
  .cat-status img { width: 2.25rem; height: 2.85rem; }
  .cat-status p { font-size: .83rem; }
  .game-side > .status { order: 1; }
  .game-side > :not(.cat-status, .status) { order: 3; }
  main.wrap:has(.game-layout) { display: flex; flex-direction: column; gap: .7rem; padding-block-start: .75rem; }
  .play-head { display: contents; }
  .play-head h1 { font-size: clamp(1.65rem, 6vw, 2.45rem); }
  .play-intro { order: 1; max-width: 45rem; color: var(--muted); }
  .game-more { order: 2; margin-block-start: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cat-status[data-mood] img { animation: none; }
}

@media (max-width: 43rem) and (max-height: 38rem) {
  main.wrap:has(.game-layout) { gap: .45rem; padding-block-start: .55rem; }
  .game-layout { gap: .4rem; }
  .cat-status { min-height: 2.9rem; }
  .cat-status img { width: 1.9rem; height: 2.4rem; }
}

/* Editorial paths stay compact; wood is the action color, green marks state. */
:root { --wood: #67452d; --wood-deep: #49301f; }
.button.primary { background: var(--wood); border-color: var(--wood); }
.button.primary:hover { background: var(--wood-deep); }
.brand-mark { background: var(--wood); }
.hero-copy .hero-trust { font-size: .84rem; }
.section-jumps { display: flex; flex-wrap: wrap; gap: .5rem; }
.section-jumps a { display: inline-flex; align-items: center; min-height: 44px; padding: .4rem .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 2rem; text-decoration: none; }
.context-note { margin-top: 1rem; max-width: 56rem; color: var(--muted); }
.index-card h3 { font-family: var(--serif); font-size: 1.25rem; }
.article-toc, .edition-links, .official-links, .next-step { padding: 1rem 1.1rem; border-left: 3px solid var(--wood); background: var(--cream); border-radius: .25rem .7rem .7rem .25rem; }
.article-toc { font-size: .92rem; }
.article-toc ul, .edition-links ul { margin: .4rem 0 0; }
.article-toc a, .edition-links a, .related li a { padding-block: .4rem; display: inline-block; }
.official-links p { margin-top: .75rem; font-size: .83rem; color: var(--muted); }
.puzzle-explanation, .rule-help { padding: .65rem .9rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); }
.puzzle-explanation summary, .rule-help summary, .history summary { min-height: 44px; align-content: center; cursor: pointer; font-weight: 700; }
.puzzle-explanation p, .rule-help p { margin-top: .5rem; }
.rule-help { font-size: .9rem; }
.rule-help ul { margin: .5rem 0; padding-left: 1.25rem; }
.rule-help a { display: inline-block; padding-block: .4rem; }
.first-move { padding: .7rem .9rem; border-left: 3px solid var(--green); background: var(--green-pale); font-size: .88rem; }
.guide-search { display: grid; gap: .5rem; max-width: 42rem; margin-bottom: 1.5rem; }
.guide-search label { font-weight: 700; }
.guide-search input { width: 100%; min-height: 48px; padding: .7rem; border: 1px solid var(--wood); border-radius: .5rem; background: var(--surface); color: var(--ink); }
.search-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.search-result { display: grid; align-content: start; gap: .4rem; padding: 1rem; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.search-result h2 { font-size: 1.3rem; }
.search-result p { color: var(--muted); }
.search-result:hover h2 { text-decoration: underline; }
@media (max-width: 43rem) {
  .site-nav { flex-wrap: nowrap; overflow-x: auto; gap: 1rem; }
  .site-nav a { flex-shrink: 0; }
  .header-inner > .site-nav { max-width: 100%; }
  .hero { padding: 1.25rem; }
  .hero-art { min-height: 9rem; }
  .section-head { margin-block-start: 1.75rem; }
  .index-card { padding: 1rem; box-shadow: none; }
  .game-side > .first-move { order: 3; }
  .game-tools { gap: .3rem; }
  .search-results { grid-template-columns: minmax(0, 1fr); }
}
.article-toc summary { min-height: 44px; align-content: center; cursor: pointer; font-weight: 700; }
.search-results { margin-top: 1rem; }
.opening-layout { display:grid; grid-template-columns:minmax(0,32rem) minmax(0,23rem); gap:2rem; align-items:start; }
.opening-board { padding-bottom:.7rem; }
.opening-controls { display:grid; gap:.8rem; min-width:0; }
.opening-controls select { min-height:44px; max-width:100%; background:var(--surface); color:var(--ink); border:1px solid var(--line); border-radius:.5rem; padding:.6rem; font:inherit; }
#opening-status { font-weight:750; color:var(--green); }
#opening-line { background:var(--cream); padding:.7rem; border-radius:.5rem; }
#opening-moves { overflow-wrap:anywhere; }
@media(max-width:43rem) { .opening-layout { grid-template-columns:minmax(0,1fr); gap:1rem; } .opening-board { max-width:31rem; width:100%; margin:auto; } }
.opening-board > #opening-status { margin-bottom:.65rem; }
