:root {
  color-scheme: light;
  --paper: #f5f4ec;
  --surface: #fffef8;
  --ink: #203b32;
  --muted: #50665a;
  --primary: #174d3a;
  --primary-hover: #103d2d;
  --line: #cbd2c5;
  --board-line: #354e42;
  --soft: #e7eee2;
  --error: #942f27;
  --focus: #155abe;
  --A: #bfdaeb;
  --B: #f2c8a7;
  --C: #cddfbb;
  --D: #dbcce3;
  --E: #eddfa2;
  --gutter: clamp(16px, 3vw, 40px);
  --axis: 22px;
  --max-width: 1080px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, a, summary { -webkit-tap-highlight-color: transparent; }
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { color: #66756c; cursor: default; }
button:active:not(:disabled) { filter: brightness(.94); }
:where(button, a, summary):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
a { color: inherit; }
svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
[hidden] { display: none !important; }
.skip {
  position: absolute;
  top: -120px;
  left: var(--gutter);
  z-index: 5;
  padding: 15px;
  background: var(--surface);
}
.skip:focus { top: 8px; }

.site-header, main, footer {
  width: min(100%, var(--max-width));
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.site-header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.brand > svg {
  width: 36px;
  height: 36px;
  padding: 5px;
  color: var(--surface);
  background: var(--primary);
  border-radius: 10px;
}
.brand > span {
  display: inline-flex;
  align-items: center;
  gap: 15px;
  font: 34px/.96 Georgia, "Times New Roman", serif;
  letter-spacing: -1.6px;
}
.brand-note {
  padding-left: 14px;
  border-left: 1px solid #a9b7aa;
  font: 600 14px/1.2 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif;
  letter-spacing: .04em;
}
.edition {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 13px;
  color: var(--muted);
  text-underline-offset: 4px;
}
.intro { padding: 20px 0 12px; }
.eyebrow {
  color: var(--primary);
  font-size: 13px;
  font-weight: 650;
}
h1, h2, h3, p { overflow-wrap: break-word; }
h1 {
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1.35;
  margin: 0;
}
.subline { margin: 7px 0 0; color: var(--muted); line-height: 1.6; }

.journey {
  display: flex;
  border-block: 1px solid #b8c4b8;
  padding: 4px 0;
  margin: 0 0 22px;
}
.journey button {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 6px clamp(6px, 1.3vw, 16px);
  background: transparent;
  border: 0;
  border-radius: 7px;
  text-align: start;
  color: var(--muted);
}
.journey button + button:before {
  content: "";
  position: absolute;
  left: -1px;
  height: 20px;
  border-left: 1px solid var(--line);
}
.journey .current {
  background: var(--primary);
  color: var(--surface);
}
.journey .current:before,
.journey .current + button:before { display: none; }
.step-num {
  display: inline-grid;
  place-items: center;
  min-width: 25px;
  min-height: 25px;
  font: 600 12px/1 Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  border: 1px solid #8a9b8e;
  border-radius: 50%;
}
.current .step-num { border-color: #b9ceba; }
.journey strong { display: block; font-size: 15px; font-weight: 650; }
.journey small { display: block; margin-top: 3px; font-size: 12px; }
.step-status { font-size: 11px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, .88fr);
  gap: clamp(22px, 4vw, 52px);
  align-items: start;
}
.play-area {
  min-width: 0;
  padding: clamp(18px, 2.1vw, 26px);
  background: var(--surface);
  border: 1px solid #cbd2c3;
  border-radius: 16px;
}
.board-heading {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 10px;
  justify-content: space-between;
}
.board-heading h1, .board-heading h2 {
  margin: 0;
  font-size: clamp(18px, 2.05vw, 25px);
  font-weight: 650;
  line-height: 1.35;
}
#queen-count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.board-rule {
  margin: 5px 0 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
/* Keep the current instruction and its action in sight while making a move. */
.board-guide {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 8px;
  padding: 5px 5px 5px 11px;
  border-left: 3px solid var(--primary);
  border-radius: 0 7px 7px 0;
  background: var(--soft);
}
#board-prompt {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 550;
  line-height: 1.55;
}
#board-action {
  flex: 0 0 auto;
  max-width: 42%;
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid #a5b8a8;
  border-radius: 5px;
  background: var(--surface);
  color: var(--primary);
  font-size: 13px;
  font-weight: 650;
}
#board-action:empty { display: none; }
.board-shell {
  position: relative;
  margin-inline: auto;
  width: min(100%, 452px);
  padding: var(--axis) 0 0 var(--axis);
}
.column-labels, .row-labels {
  position: absolute;
  display: grid;
  place-items: center;
  color: var(--muted);
  font: 600 12px/1 Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
.column-labels {
  top: 0;
  right: 0;
  left: var(--axis);
  height: var(--axis);
  grid-template-columns: repeat(5, 1fr);
}
.row-labels {
  top: var(--axis);
  bottom: 0;
  left: 0;
  width: var(--axis);
  grid-template-rows: repeat(5, 1fr);
}
#board {
  display: grid;
  grid-template: repeat(5, minmax(0, 1fr)) / repeat(5, minmax(0, 1fr));
  aspect-ratio: 1;
  border: 2px solid var(--board-line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--board-line);
  box-shadow: 0 3px 0 #a9b6a8;
}
#board[data-draw="true"] { touch-action: none; }
#board[data-draw="true"] .cell { touch-action: none; }
.grid-row { display: contents; }
.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-inline-end: 1px solid #41554355;
  border-bottom: 1px solid #41554355;
  border-radius: 0;
  background: var(--region);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}
.cell:last-child { border-inline-end: 0; }
.grid-row:last-child .cell { border-bottom: 0; }
.cell.boundary-r { border-inline-end: 3px solid var(--board-line); }
.cell.boundary-b { border-bottom: 3px solid var(--board-line); }
.cell .region-letter {
  position: absolute;
  top: 5px;
  left: 6px;
  font: 650 clamp(11px, 1vw, 13px)/1.1 Arial, sans-serif;
  color: #3e5147;
}
.cell .mark {
  font-family: Arial, sans-serif;
  font-size: clamp(25px, 2.4vw, 34px);
  font-weight: 600;
  line-height: 1;
}
.cell.auto .mark { font-size: clamp(18px, 1.8vw, 24px); font-weight: 400; color: #556559; }
.cell svg {
  width: 50%;
  height: 50%;
  fill: #294f3e;
  stroke: #193b2c;
}
.cell.hint-focus:before, .cell.target:after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 4px;
}
.cell.hint-focus:before { inset: 2px; border: 2px solid #174d3a; }
.cell.target:after { inset: 6px; border: 2px dashed #213f32; }
.cell.stroke-preview {
  box-shadow: inset 0 0 0 3px #345a47;
  background-image:
    linear-gradient(45deg, transparent 43%, #345a47 43% 56%, transparent 56%),
    linear-gradient(-45deg, transparent 43%, #345a47 43% 56%, transparent 56%);
  background-repeat: no-repeat;
  background-size: 16px 16px;
  background-position: center;
}
.cell.stroke-erase { box-shadow: inset 0 0 0 2px #476353; background-image: none; }
.cell.stroke-erase .mark { opacity: .18; }
.cell.conflict {
  background: repeating-linear-gradient(135deg, #f3bdba, #f3bdba 6px, #f9d4ca 6px, #f9d4ca 13px);
}
.cell.conflict svg { fill: var(--error); stroke: #702219; }
.cell:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -4px;
  z-index: 1;
}

.mode-tools {
  display: flex;
  gap: 4px;
  margin: 17px auto 0;
  padding: 4px;
  border: 1px solid #c7d0c4;
  border-radius: 10px;
  background: #eaf0e5;
}
.mode-tools button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 14px;
  font-weight: 550;
}
.mode-tools button[aria-pressed="true"] { background: var(--primary); color: #fff; }
.mode-tools button > span[aria-hidden] { font-size: 21px; line-height: 1; }
.mode-tools button > svg { width: 20px; height: 20px; }
.control-note, .feedback, .lesson-footnote, .rule-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.control-note { margin: 8px 0 0; text-align: center; }
.feedback { margin: 7px 0 0; padding: 7px 10px; background: #edf0e8; border-radius: 5px; }
.feedback:empty { display: none; }
.feedback[data-tone="error"], .play-area:has(.cell.conflict) .feedback {
  color: var(--error);
  background: #fbebe4;
}
.board-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 4px;
}
.quiet, .text-button {
  min-height: 44px;
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}
.text-button { text-decoration: underline; text-underline-offset: 4px; }
.quiet:disabled { color: #89948b; }
.lesson {
  min-width: 0;
  padding: 1.4rem 0 1rem;
  border-top: 3px solid var(--primary);
}
.lesson-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.lesson-top .eyebrow { margin: 0; font-weight: 650; }
.pill {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}
.lesson h2 {
  margin: 0 0 12px;
  font: 650 clamp(21px, 2.4vw, 29px)/1.45 "Songti SC", "STSong", Georgia, serif;
  text-wrap: balance;
}
.lesson p { font-size: 16px; line-height: 1.8; margin: 0 0 13px; }
.lesson .callout {
  margin-top: 12px;
  padding: 13px 16px;
  background: #e4ece0;
  border-left: 3px solid var(--primary);
  border-radius: 0 6px 6px 0;
  font-size: 15px;
  line-height: 1.75;
}
.hint-block { padding: 0 0 3px; }
.hint-block + .hint-block { padding-top: 12px; border-top: 1px solid var(--line); }
.lesson .hint-label { font-size: 13px; font-weight: 650; color: var(--primary); margin-bottom: 3px; }
.lesson .lesson-footnote { margin: 12px 0 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.primary, .secondary {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--primary);
  border-radius: 7px;
  font-weight: 650;
  font-size: 15px;
  margin-top: 12px;
}
.primary { background: var(--primary); color: #fff; }
.secondary { background: var(--surface); color: var(--primary); }
.primary:disabled, .secondary:disabled { border-color: var(--line); background: #e7ece3; }
.success-symbol {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 12px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 24px;
}
#debrief {
  margin-top: 14px;
  padding: 14px 14px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.lesson #debrief-question { font-size: 15px; font-weight: 650; }
.reason-options { display: grid; gap: 7px; }
.reason-options button {
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid #a8b6a9;
  border-radius: 5px;
  background: var(--surface);
  text-align: start;
  font-size: 14px;
  line-height: 1.55;
}
.reason-options button[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--soft);
  box-shadow: inset 3px 0 var(--primary);
}
.lesson #reason-result { margin: 8px 0 2px; font-size: 14px; }
#reason-result:empty { display: none; }
.rules { border-block: 1px solid var(--line); margin-top: 22px; }
.rules summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 53px;
  font-size: 15px;
  font-weight: 600;
}
.rules summary::-webkit-details-marker { display: none; }
.rules summary .disclosure-icon { font-size: 19px; }
.rules[open] summary .disclosure-icon { transform: rotate(45deg); }
.rule-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.rule-grid p, .rule-note {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}
.rule-grid b { display: block; margin-bottom: 3px; color: var(--ink); }
.local-note { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 13px; color: var(--muted); }
footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-block: 14px; font-size: 13px; color: var(--muted); }
footer nav { display: flex; gap: 16px; }
footer a { display: inline-flex; min-height: 44px; align-items: center; text-decoration: none; }
.document { width: min(100%, 750px); margin-block: 35px; }
.document h1 { font-size: 30px; }
.document h2 { margin: 26px 0 10px; font-size: 20px; }
.document p, .document li { font-size: 16px; line-height: 1.85; }
.document .back { display: inline-block; margin: 16px 0; }

@media (hover: hover) {
  .journey button:not(.current):enabled:hover, .quiet:enabled:hover, .text-button:hover { background: #e5ebdf; }
  .primary:enabled:hover { background: var(--primary-hover); }
  .secondary:enabled:hover { background: #e5ebdf; }
  .mode-tools button[aria-pressed="false"]:enabled:hover { background: #dbe5d6; }
  .cell:hover { filter: brightness(.95); }
  footer a:hover { text-decoration: underline; }
}

@media (max-width: 720px) {
  :root { --gutter: clamp(12px, 4vw, 20px); --axis: 19px; }
  .site-header { min-height: 52px; }
  .brand > svg { width: 29px; height: 29px; border-radius: 7px; }
  .brand > span { font-size: 28px; gap: 10px; }
  .brand-note { padding-left: 10px; font-size: 13px; }
  .edition { font-size: 12px; }
  .journey { margin-bottom: 13px; padding-block: 3px; }
  .journey button { min-height: 44px; padding: 5px; gap: 6px; }
  .journey strong { font-size: 13px; }
  .journey small, .step-status { display: none; }
  .step-num { min-width: 21px; min-height: 21px; font-size: 11px; }
  .workspace { max-width: 495px; grid-template-columns: minmax(0, 1fr); margin-inline: auto; gap: 16px; }
  .play-area { padding: 13px clamp(8px, 2vw, 14px) 4px; border-radius: 11px; }
  .board-heading { padding-inline: 4px; }
  .board-heading h1, .board-heading h2 { font-size: 18px; }
  #queen-count { font-size: 12px; }
  .board-rule { margin: 5px 4px; font-size: 12px; }
  .board-guide { margin: 6px 0 5px; gap: 6px; padding: 3px 3px 3px 8px; }
  #board-prompt { font-size: 13px; line-height: 1.5; }
  #board-action { max-width: 37%; font-size: 12px; padding-inline: 6px; }
  .board-shell { width: min(100%, 390px); }
  .mode-tools { margin-top: 11px; }
  .control-note { margin-top: 5px; font-size: 12px; }
  .mode-tools button { font-size: 13px; }
  .board-actions { margin-top: 0; }
  .lesson { padding: 15px 2px 4px; }
  .lesson-top { margin-bottom: 8px; }
  .lesson h2 { font-size: 22px; margin-bottom: 8px; }
  .lesson .lesson-footnote { margin-top: 8px; }
  .rules { margin-top: 18px; }
  .rule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 14px; }
  footer { font-size: 12px; }
}
@media (max-width: 365px) {
  .edition { font-size: 11px; }
  .journey button { gap: 4px; }
  .journey strong { font-size: 12px; }
  .mode-tools button { font-size: 12px; }
}
@media (min-width: 721px) and (max-height: 650px) {
  .site-header { min-height: 48px; }
  .journey button { min-height: 44px; }
  .board-shell { width: min(100%, max(270px, 58vh)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after { scroll-behavior: auto !important; transition-duration: 0s !important; }
}

/* Keep the language control visible beside the rules and on each document. */
.header-tools, .document-tools, .language-control {
  display: flex;
  align-items: center;
}
.header-tools { gap: clamp(8px, 2vw, 22px); }
.document-tools { justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.language-control { position: relative; min-width: 0; }
.language-control svg {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  pointer-events: none;
}
.language-control select {
  min-height: 44px;
  max-width: 15rem;
  padding: 6px 5px 6px 30px;
  border: 1px solid #a8b6a9;
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  line-height: 1.35;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.language-control select:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.journey button > span:nth-child(2) { min-width: 0; overflow-wrap: anywhere; }
.mode-tools button svg { flex-shrink: 0; }
.mode-tools button span[data-i18n], #board-action { overflow-wrap: anywhere; }
footer, footer nav { flex-wrap: wrap; }
@media (max-width: 720px) {
  .site-header { flex-wrap: wrap; gap: 2px 8px; padding-block: 5px; }
  .brand-note { display: none; }
  .header-tools { margin-inline-start: auto; }
  .language-control select { max-width: 165px; }
}
@media (max-width: 365px) {
  .brand { gap: 4px; }
  .header-tools { gap: 6px; }
  .language-control select { max-width: 155px; font-size: 12px; }
}
