/* Desktop surfaces. The media attribute in index.html keeps the compact layout independent. */
:root {
  --paper: #fbfaf6;
  --ink: #262f2a;
  --green: #284f40;
  --muted: #596158;
  --line: #d8d8ce;
  --green-light: #e6ece2;
  --shadow: none;
  --radius: 5px;
  --gutter: clamp(24px, 3vw, 48px);
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --control-height: 38px;
  --board-paper: #f8efd9;
}

::selection { background: #e3e8d9; color: #203d30; }

.brand { padding: 2px 0; }
.brand img { width: 136px; }
.sidebar .nav-label, .local-note { display: none; }
.sidebar .category-nav, .sidebar-utilities {
  display: grid;
  border: 1px solid var(--sidebar-divider);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.sidebar .category-nav { margin-block: 30px 20px; }
.sidebar :is(.nav-item, .settings-link, .landing-return-link) {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  min-height: 46px;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: 0;
  font-size: 14px;
}
.sidebar .nav-item { grid-template-columns: 20px minmax(0, 1fr) 9px; }
.sidebar .nav-item + .nav-item, .sidebar .sidebar-utilities button + button { border-top: 1px solid var(--sidebar-divider); }
.sidebar :is(.nav-item, .settings-link, .landing-return-link) > span { color: inherit; display: inline-flex; justify-content: center; }
.sidebar .nav-item::after { margin: 0; justify-self: end; }
.sidebar :is(.nav-item, .settings-link, .landing-return-link):focus-visible { outline-offset: -3px; }

.topbar { min-height: 40px; justify-content: space-between; background: transparent; padding-block: 4px; }
.breadcrumb > span, body:not(:has(#view-games:not([hidden]) #game-picker[inert])) .breadcrumb { visibility: hidden; }
.breadcrumb > span { display: none; }
.service-status :is(span, #engine-status) { background: transparent; border: 0; border-radius: 0; }
#engine-status { text-decoration: underline; text-underline-offset: 4px; }

main { padding-top: 16px; }
.page-heading { margin-bottom: 14px; }
h1 { font-size: clamp(28px, 2.35vw, 34px); margin-bottom: 2px; }
.page-heading p { font-size: 13px; }

.button, .icon-button, select, input:not([type]), input[type="text"], textarea {
  border-radius: 4px;
  min-height: var(--control-height);
}
.button { padding: 6px 12px; }
.text-button { min-height: 32px; border-radius: 4px; }
.text-button:hover:not(:disabled) { background: var(--green-light); }
.import-options, .game-select-row, .coach-actions, .game-perspective { gap: var(--space-1); }

.lesson-strip > label,
.game-board-card .board-heading strong { display: none; }
.training-progress { border: 0; background: transparent; padding: 0; flex-basis: 144px; }
.training-progress strong { font-size: 17px; }
.lesson-strip { flex: 1 1 270px; max-width: 31rem; padding-block: 7px; }
.course-tabs { padding: 0; background: transparent; }
.training-layout { gap: 14px clamp(22px, 3vw, 44px); }
.hint-list li { border: 1px solid #d7e0d2; background: #f3f6ef; padding: 9px 12px; border-radius: var(--radius); }
.coach-reflection { background: #fff; border-color: #d3d7cd; min-height: 68px; margin: 6px 0 12px; }
.coach-card h2, .plain-card h2, .item-card h2 { font-family: var(--heading-font); }
.coach-card .coach-actions > * { flex: 0 1 auto; }

.board-card { border: 1px solid #d5d6cb; background: #fffefb; }
.board-toolbar { min-height: 44px; padding: 4px var(--space-2); background: #faf9f3; }
.board-toolbar .icon-button { background: #fffefb; border-color: #d8d9ce; }
.turn-badge { background: #faeee9; border: 1px solid #ebd2c7; padding: 2px 10px; border-radius: 999px; }
.turn-badge.black { background: #e8eeea; border-color: #cddbd1; color: #2b3f35; }
.turn-badge.complete { background: var(--green-light); border-color: #c2d6c4; color: var(--green); }
.board-wrap, .training-layout .board-wrap, .game-board-card .board-wrap:not([data-mate]) {
  background: var(--board-paper);
  padding-block: 10px;
}
:is(#chessboard, #game-board) {
  width: min(100%, 482px);
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}
.board-footer, .feedback, .coordinate-guide { padding-inline: var(--space-2); }
.feedback { background: #f8f8f2; color: var(--muted); }
.feedback.success { background: #eaf4e9; color: #275c3c; }
.feedback.error { background: #fdf0ea; color: #963f2d; }

#game-title { color: var(--ink); font-size: 16px; font-weight: 700; }
#game-content:is([data-layout="wide"], [data-layout="triple"]) :is(#game-analysis, #game-coach) {
  padding-inline: var(--space-1);
}
#game-content[data-layout="wide"] #game-coach {
  padding-inline: 0;
}
.game-picker-toggle { margin: 0 0 var(--space-2); }
.game-library > .field-label { margin-top: 0; }
#game-library-status { margin-top: var(--space-1); }
#game-analysis > .import-options { margin-block: var(--space-2); }
.game-coach-message { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 4px 0 12px; }
#game-coach-content { max-width: 68ch; }
#game-tabs { gap: 12px; padding-inline: var(--space-2); }
#game-tabs button { border-radius: 0; }
#game-tabs button[aria-pressed="true"] { background: transparent; box-shadow: inset 0 -2px var(--green); }

:is(.plain-card, .report-panel) {
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: var(--space-2) 0;
}
.import-layout { column-gap: clamp(24px, 3vw, 48px); }
.import-original {
  padding-top: var(--space-2);
}
#position-image-empty {
  min-height: 320px;
  margin-top: 8px;
}
#position-board-turn {
  font-weight: 600;
  color: var(--ink);
}
.import-status {
  padding: 8px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  margin-top: var(--space-2);
}
#view-coach > .plain-card { max-width: 52rem; }
#view-coach > .plain-card > label[for="coach-style-list"] {
  display: block;
  margin-bottom: 6px;
  font-weight: var(--control-weight);
}
#coach-style-list {
  width: min(100%, 24rem);
  margin-bottom: 6px;
}
#coach-preferences .learner-fields:has(> :nth-child(3):last-child) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
#coach-preferences :is(fieldset, details) {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  padding: 12px 0 var(--space-1);
}
#coach-preferences legend { padding: 0 12px 0 0; }
#view-coach :is(input, select, textarea) { background-color: white; }
.item-grid { gap: 0 36px; }
.item-card {
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  border-radius: 0;
  padding: 18px 0;
}
.item-card p { line-height: 1.8; }
.empty-state { background: transparent; border: 0; border-block: 1px solid var(--line); border-radius: 0; }
.empty-state .empty-icon { display: none; }
.empty-state p { color: var(--muted); }
dialog { border-radius: 8px; }


/* Keep headings, reading text and control labels distinct across desktop pages. */
:root {
  --reading-size: 0.9375rem;
  --control-size: 0.875rem;
  --note-size: 0.8125rem;
  --control-weight: 500;
}
body {
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: var(--reading-size);
  line-height: 1.65;
}
h1 { line-height: 1.24; }
:is(h1, h2, h3) { text-wrap: balance; }
h2 { margin-bottom: 8px; line-height: 1.4; }
h3 { line-height: 1.4; }
.button, .text-button, .nav-item, .settings-link {
  font-size: var(--control-size);
  font-weight: var(--control-weight);
  line-height: 1.4;
}
.nav-item.active { font-weight: 600; }
:where(.view, dialog) :is(label, select, textarea, input:not([type="checkbox"], [type="file"])) {
  font-size: var(--control-size);
  line-height: 1.5;
}
.view :is(.field-label, .import-options label) { font-weight: var(--control-weight); }
:is(.view, dialog) :is(.caption, .small, .import-status),
.page-heading p, .board-footer, .service-status :is(span, #engine-status) {
  font-size: var(--note-size);
  line-height: 1.55;
}
.service-status :is(.ready, .offline, .warning) { background: transparent; }
:is(.view, dialog) :is(p, textarea)::placeholder { color: var(--muted); }
.feedback { font-size: var(--control-size); }

.goal-card #objective {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.48;
  text-wrap: pretty;
}
#coach-focus, .hint-list li { font-size: var(--reading-size); line-height: 1.65; }
#hint-counter { font-size: var(--note-size); font-weight: 400; color: var(--muted); }
.coach-card :is(#hint-note, #ai-caption) { margin-top: 5px; }
#ai-caption { overflow-wrap: anywhere; }

#position-report:not([hidden]) { display: flex; flex-direction: column; }
#position-conclusion {
  order: -1;
  margin: 10px 0 4px;
  font-size: 1.25rem;
  line-height: 1.4;
  font-weight: 700;
}
#position-report-origin, #game-coach-context, .game-coach-message > .caption {
  margin: 0 0 6px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.analysis-origin-perspective { display: inline; }
#game-coach-context { margin-top: 8px; }
#position-recommendation { margin: 4px 0 0; font-size: var(--reading-size); }
#position-reference-title { margin-bottom: 4px; }
.game-actions .text-button { font-weight: 400; font-size: var(--note-size); }
.game-coach-message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.6;
}
.game-coach-message > strong { margin-bottom: 4px; font-size: var(--control-size); }
.game-coach-message .game-coach-verdict {
  order: -1;
  margin: 0 0 4px;
  font-weight: 650;
  font-size: 1.0625rem;
  line-height: 1.45;
}
.game-coach-message .game-coach-answer {
  width: 100%;
  margin: 0;
  font-size: var(--reading-size);
  font-weight: 400;
  line-height: 1.65;
  white-space: normal;
}
.game-coach-answer span {
  display: block;
  margin-block: 0 6px;
  white-space: pre-line;
  text-wrap: pretty;
}
.game-coach-answer span:last-child { margin-bottom: 0; }
.game-coach-message > p:empty { display: none; }

#knowledge-list .rule-scope { display: none; }
:is(#knowledge-list, #mistake-list) .item-card h2 {
  margin-bottom: 4px;
  font-size: 1.25rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
:is(#knowledge-list .rule-text, #mistake-list .mistake-objective) {
  margin: 0 0 4px;
  color: var(--ink);
  font-size: var(--reading-size);
  line-height: 1.6;
  text-wrap: pretty;
}
#knowledge-list :is(.caption, .entry-action) { margin-inline-end: 12px; }
#knowledge-list br { display: none; }
:is(#knowledge-list, #mistake-list) .entry-action {
  margin-top: 2px;
  padding: 4px 6px;
  min-height: 36px;
  border-color: transparent;
  background: transparent;
}
:is(#knowledge-list, #mistake-list) .entry-action:hover { background: var(--green-light); }
#mistake-list .mistake-heading {
  flex-direction: row;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 10px;
  margin-bottom: 4px;
}
#mistake-list .mistake-heading h2 { margin: 0; }
#mistake-list .mistake-status {
  order: 0;
  margin: 0;
  font-size: var(--note-size);
  letter-spacing: normal;
  line-height: 1.55;
}
#mistake-list .mistake-status[data-resolved="false"] { color: var(--red); font-weight: 600; }
#mistake-list .mistake-record {
  margin: 0 0 2px;
  font-size: var(--note-size);
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
}


/* Put the question and the coach's reply on distinct reading lines. */
.game-coach-message[data-action="question"] {
  align-items: stretch;
}
.game-coach-message[data-action="question"] > strong {
  order: -2;
  color: var(--muted);
  font-size: var(--note-size);
  font-weight: 500;
}
.game-coach-message > .game-coach-question-text {
  order: -1;
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.5;
  font-weight: 600;
}
.game-coach-reply { margin-top: 8px; }
.game-coach-reply .game-coach-reply-label {
  display: block;
  margin: 0 0 4px;
  color: var(--green);
  font-size: var(--note-size);
  font-weight: 600;
}
.game-coach-reply-desktop { display: block; }
.game-coach-reply-original { display: none; }
.game-coach-overview { margin: 0; padding-inline-start: 1.35em; }
.game-coach-overview li + li { margin-top: 4px; }
.game-coach-reply-detail { margin-top: 8px; }
.game-coach-reply-detail > summary {
  min-height: 32px;
  font-size: var(--control-size);
}
.game-coach-reply-detail[open] > .game-coach-answer { margin-top: 6px; }


/* Only the stone moves. Its square stays fixed for focus and hit testing. */
:is(#chessboard, #game-board) .board-cell:focus { outline: none; }
:is(#chessboard, #game-board) .board-stone { transform-box: view-box; transform-origin: 0 0; }
#report-panel { scroll-margin-top: 24px; }
.walkthrough { margin: 16px 0; }
.walkthrough-nav { max-width: 680px; margin-bottom: 16px; }
.walkthrough-nav select { min-height: var(--control-height); padding: 6px 10px; }
.walkthrough:has(.reference-board-panel) {
  display: grid;
  grid-template-columns: minmax(320px, 460px) minmax(240px, 1fr);
  grid-template-rows: auto auto auto 1fr;
  gap: 14px 28px;
  align-items: start;
}
.walkthrough:has(.reference-board-panel) > p.caption,
.walkthrough:has(.reference-board-panel) > .walkthrough-nav {
  grid-column: 1 / -1;
  margin-bottom: 0;
}
.walkthrough:has(.reference-board-panel) > .reference-board-panel {
  grid-column: 1;
  grid-row: 3 / span 2;
  margin: 0;
  max-width: none;
  background: var(--board-paper);
  border-color: #ddd2bc;
  border-radius: var(--radius);
}
.walkthrough:has(.reference-board-panel) > .position-line {
  grid-column: 2;
  grid-row: 3;
  margin: 0;
  padding-left: 22px;
}
.walkthrough:has(.reference-board-panel) > .button {
  grid-column: 2;
  grid-row: 4;
  justify-self: start;
  align-self: start;
}
.study-board-panel {
  background: var(--board-paper);
  border-color: #ddd2bc;
  border-radius: var(--radius);
}
.study-board-panel > strong {
  min-height: auto;
  margin-bottom: 8px;
  font-size: var(--control-size);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
#report-title:focus {
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-underline-offset: 6px;
}

@media (prefers-reduced-motion: no-preference) {
  :is(#chessboard, #game-board) .board-stone-lifted {
    transform: translateY(-3px) scale(1.045);
    animation: board-stone-lift 105ms cubic-bezier(0.16, 1, 0.3, 1);
  }
}

@keyframes board-stone-lift {
  from { transform: translateY(0) scale(1); }
  to { transform: translateY(-3px) scale(1.045); }
}


/* Keep the question and answer together. Position context follows the answer. */
#game-coach-context,
.game-coach-message > .game-coach-compact-meta,
.game-coach-message > .game-coach-verdict {
  display: none;
}
.game-coach-message { align-items: stretch; }
.game-coach-message > .game-coach-question-text { margin-bottom: 2px; }
.game-coach-message .game-coach-origin {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: var(--note-size);
  font-weight: 400;
}
.game-coach-reply-detail .caption { margin: 4px 0; }
.game-coach-reply-detail { margin-top: 3px; }


/* Reserve both outside columns before checkmate so the last move keeps its place. */
.game-board-card .game-board-stage {
  --mate-gutter: clamp(35px, 10%, 68px);
  --mate-ink: #26332c;
  --mate-seal: #32483e;
  --mate-paper: #fff8e9;
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(512px, calc(100% - var(--mate-gutter) - var(--mate-gutter))) minmax(0, 1fr);
  align-items: center;
  background: var(--board-paper);
}
.game-board-stage[data-mate="red"] { --mate-seal: #a63e2e; }
.game-board-stage #game-board { grid-area: 1 / 2; width: 100%; }
.game-board-stage[data-mate] .game-mate-label {
  grid-row: 1;
  justify-self: center;
  display: grid;
  justify-items: center;
  font-family: KaiTi, "Kaiti SC", STKaiti, "Noto Serif CJK SC", SimSun, serif;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}
.game-mate-title {
  grid-column: 1;
  gap: 0.09em;
  color: var(--mate-ink);
  font-size: clamp(28px, 8.1cqw, 64px);
  font-weight: 400;
  -webkit-text-stroke: 0.012em currentColor;
}
#game-mate-winner {
  grid-column: 3;
  gap: 0.23em;
  padding: 0.37em 0.25em;
  border: 1px solid var(--mate-seal);
  outline: 1px solid #fff8e999;
  outline-offset: -4px;
  background: var(--mate-seal);
  color: var(--mate-paper);
  font-size: clamp(20px, 4.9cqw, 41px);
  font-weight: 700;
}

@media (prefers-reduced-motion: no-preference) {
  /* Match the stone's 160 ms travel before revealing the result. */
  .game-board-stage[data-mate-animation] .game-mate-title {
    animation: mate-ink-reveal 130ms ease-out 160ms both;
  }
  .game-board-stage[data-mate-animation] #game-mate-winner {
    animation: mate-seal-press 175ms cubic-bezier(0.18, 0.75, 0.34, 1) 310ms both;
  }
}

@keyframes mate-ink-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes mate-seal-press {
  from { opacity: 0; transform: translateY(-8px) scale(1.08); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
