:root {
  --bg: #f7f1e8;
  --card: #fffaf2;
  --text: #2b2118;
  --muted: #5c4d3e;
  --accent: #9b3e1d;
  --accent-hover: #7d3015;
  --gold: #e0a03a;
  --line: #e4d9c8;
  --light: #f0d9b5;
  --dark: #b58863;
  --select: #2f7d4f;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .08);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --piece-font: 'Segoe UI Symbol', 'Apple Symbols', 'Noto Sans Symbols 2', 'DejaVu Sans', serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 17px/1.6 var(--font-body); }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }

.site-header { border-bottom: 1px solid var(--line); background: var(--card); }
.header-inner { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.logo { font: 700 18px/1.2 var(--font-display); text-decoration: none; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.logo-mark { font-family: var(--piece-font); color: var(--accent); font-size: 22px; }
.site-nav { display: flex; gap: 20px; font-size: 14px; font-weight: 600; }
.site-nav a { text-decoration: none; color: var(--muted); }
.site-nav a:hover { color: var(--accent); }

.site-footer { border-top: 1px solid var(--line); margin-top: 64px; padding: 32px 0 48px; color: var(--muted); font-size: 14px; text-align: center; }
.footer-nav { display: flex; gap: 24px; justify-content: center; margin-bottom: 12px; }

.hero { padding-top: 24px; }
h1 { font: 700 40px/1.2 var(--font-display); margin: 0 0 16px; text-align: center; }
h2 { font: 700 28px/1.2 var(--font-display); margin: 0 0 16px; }
h3 { font: 700 22px/1.25 var(--font-display); margin: 32px 0 12px; }
p { max-width: 70ch; margin: 0 0 16px; }

.tool { max-width: 560px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; background: var(--line); padding: 4px; border-radius: var(--radius); flex: 1; min-width: 0; }
.tab {
  flex: 1; border: 0; background: transparent; min-height: 44px; padding: 8px 4px; border-radius: 7px;
  font: 600 14px/1.2 var(--font-body); color: var(--text); cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
.btn {
  border: 1px solid var(--accent); background: var(--accent); color: var(--card); border-radius: var(--radius);
  min-height: 44px; padding: 10px 16px; font: 600 15px/1.2 var(--font-body); cursor: pointer;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:focus-visible, .tab:focus-visible, .sq:focus-visible, .spare:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn.ghost { background: var(--card); color: var(--accent); padding: 8px 14px; }
.btn.ghost:hover { background: var(--bg); }


.board, .wt-board {
  container-type: inline-size;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 1 / 1; width: 100%;
  border: 2px solid var(--text); border-radius: 6px; overflow: hidden; user-select: none; -webkit-user-select: none;
  touch-action: manipulation; box-shadow: var(--shadow-md);
}
.sq, .wt-sq {
  position: relative; border: 0; padding: 0; margin: 0; display: flex; align-items: center; justify-content: center;
  min-width: 0; min-height: 0;
}
.sq { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sq.light, .wt-sq.light { background: var(--light); }
.sq.dark, .wt-sq.dark { background: var(--dark); }
.sq.selected, .wt-sq.hi { box-shadow: inset 0 0 0 4px var(--select); background-image: linear-gradient(rgba(47, 125, 79, .32), rgba(47, 125, 79, .32)); }
.coord { position: absolute; font: 700 2.2cqw/1 var(--font-body); pointer-events: none; }
.coord.rank { top: 3px; left: 3px; }
.coord.file { bottom: 2px; right: 4px; }
.sq.light .coord, .wt-sq.light .coord { color: var(--dark); }
.sq.dark .coord, .wt-sq.dark .coord { color: var(--light); }

.piece { font-family: var(--piece-font); line-height: 1; font-size: 10cqw; cursor: grab; }
.piece.w { color: var(--card); -webkit-text-stroke: 0.06em var(--text); paint-order: stroke fill; text-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
.piece.b { color: var(--text); text-shadow: 0 1px 0 rgba(255, 255, 255, .25); }

.rule-line { text-align: center; font-size: 14px; color: var(--muted); margin: 12px auto 0; font-weight: 600; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.spares { display: grid; grid-template-columns: repeat(13, 1fr); gap: 4px; margin-top: 12px; container-type: inline-size; }
.spare {
  aspect-ratio: 1 / 1; border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 4cqw; color: var(--muted);
}
.spare .piece { font-size: 5.6cqw; }
.spare.selected { border-color: var(--select); box-shadow: 0 0 0 2px var(--select); background: var(--bg); }
.status { text-align: center; font-size: 14px; color: var(--muted); margin: 8px auto 0; min-height: 1.5em; }

.content { padding-top: 48px; max-width: 820px; }
.steps { padding-left: 24px; max-width: 70ch; }
.steps li { margin-bottom: 12px; }
.table-wrap { overflow-x: auto; margin: 16px 0; }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 15px; box-shadow: var(--shadow-sm); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { background: var(--bg); }
.note { color: var(--muted); font-size: 13px; }
.small { font-size: 14px; color: var(--muted); }

.walkthrough-box { margin: 24px 0 32px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.wt-stage { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 24px; padding: 20px; align-items: center; }
.wt-badge { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--accent); background: var(--bg); padding: 4px 10px; border-radius: 999px; margin-bottom: 10px; }
.wt-title { font-size: 20px; margin: 0 0 8px; }
.wt-body { font-size: 15px; color: var(--muted); margin: 0 0 12px; }
.wt-caption { font-size: 14px; font-weight: 600; background: var(--bg); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 4px; margin: 0 0 14px; }
.wt-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.wt-progress { display: flex; align-items: center; gap: 12px; }
.wt-bar { flex: 1; height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.wt-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }
.wt-time { font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.walkthrough-box figcaption { padding: 12px 20px; font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); background: var(--bg); }

.diagram { margin: 20px 0; text-align: center; }
.diagram img { max-width: 100%; height: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.diagram figcaption { font-size: 14px; color: var(--muted); margin-top: 8px; }

.openings { padding-left: 20px; max-width: 70ch; }
.openings li { margin-bottom: 12px; }
code.move { font: 700 0.92em/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; color: var(--accent); }

.faq details { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.faq summary { font-weight: 600; cursor: pointer; }
.faq details p { margin: 10px 0 0; }

.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cards li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards li.is-soon { background: var(--bg); border-style: dashed; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.badge-soon { font-size: 12px; color: var(--text); background: var(--line); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.card-text { font-size: 15px; color: var(--muted); }

.page { padding-top: 32px; max-width: 780px; }
.prose h2 { margin-top: 28px; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  h1 { font-size: 30px; }
  .wrap { padding: 0 12px; }
  .site-nav { gap: 12px; font-size: 13px; }
  .tab { font-size: 13px; padding: 8px 2px; }
  .btn { font-size: 14px; padding: 10px 8px; }
  .actions { grid-template-columns: 1fr; }
  .spares { grid-template-columns: repeat(7, 1fr); }
  .spare { font-size: 7cqw; }
  .spare .piece { font-size: 10cqw; }
  .wt-stage { grid-template-columns: 1fr; padding: 14px; }
  .wt-controls .btn { flex: 1 1 45%; }
}

@media print {
  body { background: var(--card); }
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; padding: 10mm; }
  .board { max-width: 170mm; margin: 0 auto; box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sq.selected { box-shadow: none; background-image: none; }
}


/* ---------- guide pages ---------- */
.crumbs { font-size: 14px; color: var(--muted); padding-top: 22px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.crumbs a { text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }
.crumb-sep { color: var(--line); }
.guide { max-width: 840px; }
.guide-head { padding: 14px 0 6px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
.guide-head h1 { text-align: left; margin: 0 0 14px; }
.lede { font-size: 19px; line-height: 1.5; color: var(--muted); max-width: 64ch; margin: 0; }
.toc { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 22px; margin: 28px 0 4px; box-shadow: var(--shadow-sm); }
.toc-title { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.toc ol { margin: 0; padding-left: 20px; font-size: 15px; }
.toc li { margin: 3px 0; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }
.prose { overflow-wrap: break-word; }
.prose h2 { margin: 44px 0 14px; padding-top: 14px; border-top: 1px solid var(--line); scroll-margin-top: 16px; }
.prose h2:first-child { border-top: 0; padding-top: 0; margin-top: 32px; }
.prose h3 { font-size: 20px; margin: 28px 0 10px; }
.prose ul, .prose ol { max-width: 70ch; padding-left: 22px; }
.prose li { margin-bottom: 8px; }
.prose ol.checks { list-style: none; padding-left: 0; }
.prose ol.checks li { padding-left: 30px; position: relative; }
.prose ol.checks li::before { content: attr(data-step); position: absolute; left: 0; top: 2px; font: 700 13px/1.4 var(--font-body); color: var(--accent); background: var(--card); border: 1px solid var(--line); border-radius: 999px; width: 21px; height: 21px; text-align: center; }
.prose blockquote { margin: 20px 0; padding: 12px 18px; background: var(--card); border-left: 3px solid var(--gold); border-radius: 4px; color: var(--muted); font-size: 16px; }
.prose blockquote p { margin: 0; }
.prose .callout { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin: 20px 0; box-shadow: var(--shadow-sm); font-size: 16px; }
.prose .callout p { margin: 0 0 8px; }
.prose .callout p:last-child { margin: 0; }
.prose strong { font-weight: 700; }
.faq-section { margin-top: 52px; scroll-margin-top: 16px; }
.related { margin-top: 52px; }
.related h2 { margin-bottom: 16px; }
.card-link { display: block; font-weight: 700; color: var(--text); text-decoration: none; margin-bottom: 4px; }
.card-link:hover { color: var(--accent); text-decoration: underline; }
.cards li .card-text { display: block; }
@media (max-width: 640px) {
  .guide-head h1 { font-size: 29px; }
  .lede { font-size: 17px; }
  .prose h2 { margin-top: 34px; }
}


/* ---- polish pass: mobile header, controls, tables, rhythm ---- */
.site-nav a { white-space: nowrap; }
.header-inner { flex-wrap: wrap; row-gap: 4px; }
.logo { white-space: nowrap; }

.tab, .btn, .btn.ghost, .card-link, .wt-controls .btn { border-radius: var(--radius); }
.actions { flex-wrap: wrap; gap: 12px; }
.actions .btn { flex: 0 1 auto; }

.spares { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 100%; }
.spares > * { flex: 0 0 auto; }

.prose p, .content > p { margin: 0 0 20px; }
.prose p:last-child, .content > p:last-child { margin-bottom: 0; }
.prose h2, .content > h2 { margin: 48px 0 16px; }
.prose h3, .content > h3 { margin: 32px 0 12px; }
.prose ul, .prose ol { margin: 0 0 20px; padding-left: 22px; }
.prose li { margin-bottom: 8px; }

.table-wrap { overflow-x: auto; margin: 0 0 24px; }
.table-wrap table, .content table { border-collapse: collapse; width: 100%; font-size: 16px; }
.table-wrap th, .table-wrap td, .content th, .content td { border: 1px solid #d8cbb8; padding: 10px 14px; vertical-align: top; }
.table-wrap thead th, .content thead th { background: #f4ece0; font-weight: 700; text-align: left; }
.table-wrap tbody tr:nth-child(even), .content tbody tr:nth-child(even) { background: rgba(43, 33, 24, .025); }

.status { font-size: 14px; font-weight: 600; color: var(--muted); }
.small { font-size: 14px; color: var(--muted); }

@media (max-width: 720px) {
  .site-header { padding: 6px 0; }
  .header-inner { padding: 6px 0; gap: 8px 14px; }
  .site-nav { gap: 14px; font-size: 13px; flex-wrap: wrap; }
  .hero { padding-top: 32px; }
  .board, .tool { max-width: 100%; }
  .actions { justify-content: center; }
  .actions .btn { padding: 0 16px; }
  .table-wrap table, .content table { font-size: 15px; }
  .table-wrap th, .table-wrap td, .content th, .content td { padding: 8px 10px; }
}


/* mobile first-screen polish */
@media (max-width: 720px) {
  h1 { font-size: 30px; line-height: 1.22; margin-bottom: 18px; }
  .hero h1 { max-width: 22ch; margin-left: auto; margin-right: auto; }
  .spares { padding: 0 12px; }
  .guide-head h1 { font-size: 32px; }
}


/* guide column + toc weight + link affordance */
.guide { max-width: 800px; margin-left: auto; margin-right: auto; }
.guide-head h1 { font-size: clamp(30px, 4vw, 40px); }
.toc { background: #fbf6ee; border: 1px solid rgba(43, 33, 24, .10); border-radius: 8px; box-shadow: none; padding: 16px 20px; }
.toc-title { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.eyebrow { letter-spacing: .1em; font-size: 12px; text-transform: uppercase; }
.prose a, .guide a { text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.crumbs a, .site-nav a, .footer-nav a, .card-link, .logo, .related a { text-decoration: none; }
.crumbs { font-size: 14px; color: var(--muted); }
@media (max-width: 720px) {
  .guide-head h1 { font-size: clamp(26px, 8vw, 32px); }
  .guide { padding-left: 18px; padding-right: 18px; }
  .toc { padding: 12px 14px; }
  .site-nav { gap: 12px; font-size: 13px; }
}
