@font-face {
  font-family: 'Archivo Black';
  src: url('/fonts/archivo-black.ttf') format('truetype');
  font-style: normal;
  font-weight: 900;
  font-display: swap;
}
:root {
  --paper: #f2edf8;
  --surface: #fffdf9;
  --ink: #292139;
  --primary: #503080;
  --primary-hover: #382058;
  --accent: #f8ce54;
  --muted: #61556e;
  --line: #b9acc5;
  --board-line: #30233d;
  --soft: #e6dbf4;
  --error: #9c1b3d;
  --focus: #2540a4;
  --A: #ffd46a;
  --B: #aebdf5;
  --C: #91dab6;
  --D: #f5a5a0;
  --E: #c8a5ed;
  --display: 'Archivo Black','Arial Black','PingFang SC','Hiragino Sans','Microsoft YaHei',system-ui,sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Consolas, monospace;
  --max-width: 1224px;
  --gutter: clamp(16px,3.8vw,54px);
  font-family: system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
body { min-height: 100vh; background: var(--paper); }
main:focus { outline: none; }
.masthead { color: var(--surface); background: var(--ink); }
.masthead-inner {
  display: flex; align-items: center; gap: clamp(26px,5.5vw,88px);
  max-width: var(--max-width); padding: 9px var(--gutter); margin: auto;
}
.wordmark {
  display: inline-flex; align-items: center; gap: 9px;
  color: var(--surface); text-decoration: none;
  font: 900 35px/.98 var(--display); letter-spacing: -.075em;
}
.wordmark small { display: block; margin-top: 2px; font: 700 12px/1 var(--display); letter-spacing: .035em; }
.wordmark img { width: 39px; height: 39px; }
.primary-nav { display: flex; align-items: center; gap: 5px; }
.primary-nav a {
  display: inline-flex; align-items: center; min-height: 44px;
  padding: 0 clamp(10px,1.3vw,20px); text-decoration: none;
  color: #eee8f8; font-size: 14px; font-weight: 670;
}
.primary-nav a[aria-current] { color: var(--accent); box-shadow: inset 0 -3px var(--accent); }
.primary-nav a:hover { background: #43374f; }
.masthead .language-control { margin-inline-start: auto; }
.masthead .language-control svg { left: 11px; }
.masthead select {
  color: var(--surface); background: var(--ink);
  min-height: 44px; border: 1px solid #84778f; border-radius: 22px; padding-inline: 34px 9px;
}
.masthead :focus-visible { outline-color: var(--accent); }
.game-layout { padding-block: clamp(24px,4.1vw,58px) 36px; }
.practice-workspace {
  display: grid;
  grid-template-columns: minmax(270px,.81fr) minmax(390px,1.19fr);
  grid-template-rows: auto auto 1fr;
  grid-template-areas: "brief mat" "hint mat" "lesson mat";
  align-items: start; gap: 26px clamp(40px,6.8vw,106px);
}
.puzzle-brief { grid-area: brief; min-width: 0; }
.practice-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 7px 12px; color: var(--muted); font: 650 12px/1.5 var(--mono); }
#practice-number:not(:empty) { color: var(--ink); border: 1.5px solid var(--ink); background: var(--accent); padding: 3px 8px; }
.puzzle-brief h1 {
  margin: clamp(14px,2vw,27px) 0 12px; max-width: 10ch; color: var(--ink);
  font: 900 clamp(46px,5.15vw,80px)/.98 var(--display);
  letter-spacing: -.07em; text-wrap: balance; scroll-margin-top: 12px;
}
:lang(zh) .puzzle-brief h1, :lang(ja) .puzzle-brief h1 { line-height: 1.12; letter-spacing: -.055em; }
.puzzle-brief .board-rule { max-width: 35ch; margin: 0; font-size: clamp(15px,1.25vw,18px); line-height: 1.55; color: var(--ink); }
.practice-workspace .puzzle-mat {
  --edge: clamp(16px,2.9vw,40px);
  grid-area: mat; width: 100%; position: relative;
  padding: 16px var(--edge) 11px; border: 2px solid var(--ink); border-radius: 20px;
  background-color: #ddd1ee;
  background-image: radial-gradient(#b6a6c8 .75px,transparent .85px);
  background-size: 9px 9px; box-shadow: 0 6px 0 var(--ink);
}
.puzzle-mat::before,.puzzle-mat::after {
  content: ''; position: absolute; width: 6px; height: 6px; top: 15px;
  background: var(--ink); border-radius: 50%; pointer-events: none;
}
.puzzle-mat::before { left: 14px; }
.puzzle-mat::after { right: 14px; }
.mat-chrome { width: min(100%,488px); margin: 0 auto; padding-inline-start: var(--axis); }
.mat-chrome .queen-progress { display: flex; justify-content: space-between; width: 100%; }
.mat-chrome #queen-count { font: 700 13px/1.4 var(--mono); color: var(--ink); }
.practice-workspace .board-shell { width: min(100%,488px); }
.column-labels, .row-labels { font: 750 12px/1 var(--mono); color: #51445e; }
#board { border: 3px solid var(--board-line); border-radius: 5px; box-shadow: 0 3px 0 var(--board-line); }
.cell { border-color: #67577675; }
.cell .region-letter { font-family: var(--mono); color: #42364c; }
.cell.hint-focus:before { border-color: var(--primary); }
.cell.target:after { border-color: var(--ink); }
.cell.stroke-preview { box-shadow: inset 0 0 0 3px var(--primary); }
#board:empty { background: repeating-linear-gradient(90deg,transparent 0 calc(20% - 1px),var(--line) calc(20% - 1px) 20%),repeating-linear-gradient(0deg,var(--soft) 0 calc(20% - 1px),var(--line) calc(20% - 1px) 20%); }
.mode-tools {
  padding: 0; gap: 0; background: var(--surface); border: 2px solid var(--ink);
  border-radius: 8px; box-shadow: 0 3px 0 var(--ink);
}
.puzzle-mat .mode-tools { max-width: 488px; margin-top: 16px; }
.mode-tools button { min-height: 46px; padding: 5px 7px; font-weight: 700; color: var(--ink); border-radius: 0; }
.mode-tools button:first-child { border-radius: 5px 0 0 5px; }
.mode-tools button:last-child { border-radius: 0 5px 5px 0; }
.mode-tools button + button { border-inline-start: 1px solid var(--ink); }
.mode-tools button[aria-pressed=true] { background: var(--ink); color: var(--surface); }
.mode-tools button[data-mode=erase]::before {
  content: ''; display: inline-block; width: 11px; height: 8px; border: 1.6px solid currentColor;
  border-radius: 2px; transform: rotate(-42deg); background: linear-gradient(90deg,currentColor 0 42%,transparent 42%);
}
.control-note { color: #53455d; margin: 10px 0 0; line-height: 1.4; }
.board-actions { gap: 4px 18px; margin-top: 0; }
.quiet,.text-button { border-radius: 4px; color: var(--primary); font-weight: 650; }
.quiet:disabled { color: #6a5d76; }
.quiet:disabled,.mode-tools button:disabled { cursor: default; }
.feedback { color: var(--ink); background: var(--surface); border-inline-start: 3px solid var(--primary); text-align: start; }
.feedback[data-tone="error"] { border-color: var(--error); }
.practice-panel {
  grid-area: hint; padding: 17px 0 0; border: 0; border-top: 2px solid var(--ink);
}
.hint-heading { display: flex; align-items: center; gap: 7px 16px; flex-wrap: wrap; justify-content: space-between; }
.hint-heading h2,.learn-card h3,.practice-library h2 {
  margin: 0; font: 900 clamp(23px,2.1vw,32px)/1.15 var(--display); letter-spacing: -.045em;
}
.hint-heading .eyebrow { color: var(--primary); font: 700 12px/1.4 var(--mono); }
.practice-panel > #practice-status { font-size: 15px; line-height: 1.5; color: var(--muted); margin: 8px 0 12px; }
.practice-panel-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 13px; }
.practice-panel-actions .primary,.practice-panel-actions .secondary,.site-button {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  width: auto; min-height: 46px; margin: 0; border: 2px solid var(--ink); border-radius: 6px;
  color: var(--ink); background: var(--accent); box-shadow: 0 3px 0 var(--ink);
  padding: 8px 17px; font-size: 15px; font-weight: 750; text-decoration: none; line-height: 1.35;
}
.practice-panel-actions .secondary { border-color: transparent; background: transparent; box-shadow: none; padding-inline: 3px; color: var(--primary); }
.practice-panel-actions .secondary::after,.practice-tutorial::after { content: '→'; margin-inline-start: .45em; }
.practice-panel .hint-block { margin-bottom: 12px; padding: 8px 12px; border-inline-start: 4px solid var(--primary); background: var(--surface); }
.practice-panel .hint-block + .hint-block { border-top: 0; }
.practice-panel .hint-block p { margin: 0; font-size: 15px; line-height: 1.55; }
.practice-panel .hint-block .hint-label { color: var(--primary); font-size: 13px; }
#practice-hint-target { display: none; }
.practice-panel button:disabled { background: #e0d8e8; color: #63566d; box-shadow: none; }
.learn-card {
  grid-area: lesson; display: grid; grid-template-columns: minmax(105px,.78fr) minmax(144px,1.22fr);
  align-items: center; column-gap: 18px; padding: 17px 0 0; border-top: 1px dashed #a397b0;
}
.learn-card h3 { grid-column: 2; font-size: clamp(17px,1.4vw,22px); line-height: 1.23; }
.lock-diagram {
  grid-row: 1 / span 2; grid-column: 1; display: grid; grid-template-columns: repeat(5,minmax(0,1fr));
  overflow: hidden; border: 2px solid var(--ink); border-radius: 4px; box-shadow: 0 2px 0 var(--ink);
}
.example-cell { position: relative; display: grid; place-items: center; min-width: 0; aspect-ratio: .83; color: var(--ink); background: var(--region); font: 650 clamp(16px,1.6vw,21px)/1 var(--mono); }
.example-cell + .example-cell { border-left: 1px solid #61556e80; }
.example-cell:nth-child(2),.example-cell:nth-child(4) { border-left: 2px solid var(--ink); }
.example-cell small { position: absolute; inset: 2px auto auto 2px; font: 700 8px/1 var(--mono); }
.example-cell i { width: 4px; height: 4px; border-radius: 50%; background: var(--ink); }
.practice-tutorial { grid-column: 2; display: inline-flex; min-height: 44px; align-items: center; color: var(--primary); font-size: 14px; font-weight: 700; text-underline-offset: 3px; }

.practice-library { border-top: 3px solid var(--ink); margin-top: clamp(40px,4.7vw,70px); padding-top: clamp(18px,2.3vw,32px); scroll-margin-top: 12px; }
.practice-library h2 { font-size: clamp(29px,3.2vw,48px); }
#library-title + p { max-width: 75ch; margin: 8px 0 16px; line-height: 1.55; color: var(--muted); }
.library-filters { display: flex; flex-wrap: wrap; gap: 5px 8px; margin-bottom: 19px; }
.library-filters button { min-height: 44px; padding: 6px 14px; color: var(--primary); background: transparent; border: 1px solid #9a88ae; border-radius: 24px; font: inherit; font-size: 14px; font-weight: 650; }
.library-filters button[aria-pressed=true] { color: white; background: var(--primary); border-color: var(--primary); }
.library-cards { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 11px; }
.library-card { display: flex; align-items: center; gap: clamp(9px,1.2vw,18px); min-width: 0; padding: 12px; border: 1px solid var(--line); border-bottom: 3px solid var(--line); border-radius: 5px; background: var(--surface); text-decoration: none; }
.library-card[aria-current] { border-color: var(--ink); background: #fff4d1; }
.library-thumb { display: grid; grid-template: repeat(5,1fr) / repeat(5,1fr); flex: none; width: clamp(52px,5vw,72px); aspect-ratio: 1; border: 1.5px solid var(--ink); border-radius: 2px; overflow: hidden; }
.library-thumb span { background: var(--region); }
.library-card-info { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.library-number { font: 900 clamp(14px,1.2vw,18px)/1.2 var(--display); letter-spacing: -.035em; }
.library-technique,.library-state { font-size: 12px; line-height: 1.3; color: var(--muted); overflow-wrap: anywhere; }
.library-card:is([data-status=best],[data-status=help]) .library-state { font-weight: 700; color: var(--primary); }
.local-note { margin-top: 12px; }
.site-foot { border-top: 1px solid var(--line); padding-block: 18px 26px; }
.site-foot a:hover { text-decoration: underline; }
.lang-directory { min-width: 88px; }
.lang-directory summary { min-height: 44px; align-content: center; cursor: pointer; font-weight: 650; }
.lang-directory ul { list-style: none; padding: 0; margin: 0; }
.lang-directory a[aria-current] { font-weight: 700; text-decoration: underline; }
.tutorial-heading { margin-bottom: 16px; }
.tutorial-heading h1 { margin: 0 0 8px; }
.tutorial-heading p { margin: 0; color: var(--muted); }
.tutorial-heading > a + a { margin-inline-start: 1rem; }
.page-tutorial .play-area { background: #e4d9f0; border: 2px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); }
.page-tutorial .board-guide { border-color: var(--primary); background: var(--surface); }
.page-tutorial #board-action { border-color: var(--ink); background: var(--accent); color: var(--ink); }
.tutorial-finish { margin-top: 14px; }
.worked-board { border-collapse: collapse; margin: 16px 0; table-layout: fixed; }
.worked-board caption { caption-side: bottom; text-align: start; line-height: 1.5; }
.worked-board th { font: 700 12px/1 var(--mono); }
.worked-board th:first-child { width: 22px; }
.worked-board th[scope=col] { padding-bottom: 6px; }
.worked-board td { height: clamp(33px,6vw,48px); text-align: center; background: var(--region); border: 1px solid var(--line); font-family: var(--mono); }
.worked-board .edge-r { border-right: 3px solid var(--ink); }
.worked-board .edge-b { border-bottom: 3px solid var(--ink); }
#feedback-form { display: grid; align-items: start; }
#feedback-form :is(input,textarea) { width: 100%; min-height: 44px; font: inherit; }
#feedback-form textarea { resize: vertical; }
#feedback-form button { justify-self: start; }
#feedback-form output { overflow-wrap: anywhere; }

@media (hover: hover) {
  .practice-panel .primary:enabled:hover,.practice-panel a.primary:hover { background: #ffdc78; }
  .library-card:hover { border-color: var(--primary); }
  .quiet:enabled:hover,.text-button:hover,.mode-tools button[aria-pressed=false]:enabled:hover,.library-filters button:not([aria-pressed=true]):hover { background: var(--soft); }
}
@media (max-width: 960px) {
  .practice-workspace { gap: 20px 32px; grid-template-columns: minmax(246px,.8fr) minmax(340px,1.2fr); }
  .library-cards { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (min-width: 761px) and (max-width: 960px) {
  .masthead-inner { display: grid; grid-template-columns: 1fr auto; gap: 1px 12px; padding-block: 6px 0; }
  .masthead .language-control { grid-row: 1; grid-column: 2; }
  .primary-nav { grid-row: 2; grid-column: 1 / -1; flex-wrap: wrap; }
  .primary-nav a:first-child { padding-inline-start: 0; }
}
@media (max-width: 760px) {
  :root { --gutter: clamp(13px,4vw,24px); --axis: 18px; }
  .masthead-inner { gap: 0 8px; flex-wrap: wrap; justify-content: space-between; padding-block: 4px 0; }
  .wordmark { font-size: 28px; }
  .wordmark img { width: 31px; height: 31px; }
  .primary-nav { order: 3; width: 100%; gap: 0; justify-content: space-between; }
  .primary-nav a { justify-content: center; min-height: 44px; padding: 0 7px; font-size: 13px; }
  .masthead select { font-size: 12px; max-width: 166px; }
  .game-layout { padding-block: 12px 26px; }
  .practice-workspace { max-width: 540px; margin-inline: auto; grid-template: "brief" auto "mat" auto "hint" auto "lesson" auto / minmax(0,1fr); gap: 16px; }
  .puzzle-brief h1 { max-width: none; margin: 8px 0 4px; font-size: clamp(33px,8vw,46px); line-height: 1.04; }
  .puzzle-brief .board-rule { font-size: 14px; line-height: 1.4; max-width: 50ch; }
  .practice-meta { font-size: 11px; }
  .practice-workspace .puzzle-mat { --edge: 8px; width: calc(100% + 10px); margin-inline: -5px; padding: 6px var(--edge) 2px; border-radius: 14px; box-shadow: 0 4px 0 var(--ink); }
  .mat-chrome { padding-inline: var(--axis) 4px; }
  .mat-chrome #queen-count { font-size: 11px; }
  .puzzle-mat::before,.puzzle-mat::after { top: 12px; width: 4px; height: 4px; }
  .puzzle-mat::before { left: 9px; } .puzzle-mat::after { right: 7px; }
  .puzzle-mat .mode-tools { margin-top: 10px; }
  .puzzle-mat .control-note { margin: 7px 0 0; font-size: 12px; }
  .mode-tools button { min-height: 44px; font-size: 13px; }
  .board-actions { gap: 0 5px; }
  .practice-panel {
    display: grid; grid-template-columns: minmax(0,1fr) auto;
    align-items: center; gap: 0 10px; padding: 10px 0 0;
  }
  .practice-panel .hint-heading { grid-column: 1; grid-row: 1; display: grid; gap: 3px; }
  .practice-panel-actions { display: contents; }
  #practice-hint { grid-column: 2; grid-row: 1; justify-self: end; }
  .practice-panel > #practice-status { grid-column: 1 / -1; grid-row: 2; font-size: 14px; margin: 8px 0 0; }
  .practice-workspace .cell.target:focus { outline: 3px solid var(--focus); outline-offset: -4px; z-index: 1; }
  .practice-hint-result { grid-column: 1 / -1; grid-row: 3; }
  #practice-hint-target:not([hidden]) {
    display: inline-flex; align-items: center; min-height: 44px; max-width: 100%;
    margin-bottom: 8px; padding: 7px 14px; border: 2px solid var(--primary); border-radius: 6px;
    background: var(--surface); color: var(--primary); font-weight: 700; overflow-wrap: anywhere;
  }
  #practice-hint-text:not(:empty) { margin-top: 7px; }
  #hide-hint { grid-column: 1; grid-row: 4; justify-self: start; }
  #practice-next { grid-column: 2; grid-row: 4; justify-self: end; }
  .practice-panel:has(#practice-hint[hidden]) #practice-next { grid-row: 1; }
  .learn-card { column-gap: 16px; padding-top: 12px; }
  .practice-library { margin-top: 29px; }
  .library-cards { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; }
  .library-filters { gap: 4px; }
  .library-filters button { padding-inline: 10px; font-size: 13px; }
}
@media (max-width: 420px) {
  .library-card { gap: 7px; padding: 8px 6px; }
  .library-thumb { width: 43px; }
  .library-technique,.library-state { font-size: 11px; }
}
@media (max-width: 360px) {
  .primary-nav a { padding: 0 3px; font-size: 12px; }
  .practice-panel-actions { gap: 4px 8px; }
  .library-cards { grid-template-columns: minmax(0,1fr); }
  .library-thumb { width: 52px; }
}
