/* Chess. Light and dark themes from the same tokens; every text colour meets WCAG 2.2 AA on its background, and the
   board's pieces and marks keep 3:1 against the squares they sit on (the white pieces have a dark outline, the black ones
   a light edge). The board itself is wood-toned in both themes. */
:root {
  --bg: #f6f1ea; --card: #ffffff; --ink: #1f1a14; --muted: #5b5146; --line: #e2d7c8;
  --brand: #7a4a1c; --brand-ink: #ffffff; --link: #6b3f14; --head: #3b2410; --head-ink: #ffffff; --head-soft: #f0dcc4;
  --danger: #b42318; --danger-ink: #ffffff; --focus: #1d4ed8;
  --ok-bg: #e6f4ea; --ok-ink: #14532d; --warn-bg: #fff3d4; --warn-ink: #5e4100; --err-bg: #fde8e6; --err-ink: #8a1c12;
  --tag-bg: #f3e9dc;
  --sq-light: #eed8b4; --sq-dark: #946339; --sq-on-light: #5c3b1e; --sq-on-dark: #ffffff;
  --pc-black: #141414; --pc-black-edge: #f6ead6; --pc-white: #ffffff; --pc-white-edge: #141414;
  --mark: #ffd23f; --mark-edge: #2a1d0f; --hint: #15803d; --check: #dc2626;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15110d; --card: #221b14; --ink: #f2ebe2; --muted: #c7b9a7; --line: #3a2f24;
    --brand: #e0b07a; --brand-ink: #2a1708; --link: #f0c592; --head: #0f0b07; --head-ink: #ffffff; --head-soft: #f0dcc4;
    --danger: #ff8f80; --danger-ink: #2a0905; --focus: #93c5fd;
    --ok-bg: #163a24; --ok-ink: #c8efd2; --warn-bg: #3a2e0c; --warn-ink: #ffe3a3; --err-bg: #3d1611; --err-ink: #ffd2cb;
    --tag-bg: #2d241b;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
a { color: var(--link); text-underline-offset: 2px; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 .6rem; }
h2 { font-size: 1.25rem; line-height: 1.25; margin: 1.2rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 16px 0 6px; }
.h-small { font-size: 1rem; margin: 16px 0 6px; }
.card > h2:first-child, .card > h1:first-child { margin-top: 0; }
p { margin: 0 0 .8rem; }
:is(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--card); color: var(--ink); padding: 8px 12px; z-index: 2000; }
.skip:focus { left: 8px; top: 8px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 16px; padding-bottom: 24px; }
main:focus { outline: none; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.lede { font-size: 1.08rem; color: var(--muted); }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap-row { flex-wrap: wrap; margin: 0 0 10px; }
ul.plain { list-style: none; padding: 0; margin: 0 0 12px; }

/* Header and footer */
.site-header { background: var(--head); color: var(--head-ink); }
.site-header .bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px; min-height: 56px; }
.brand { color: var(--head-ink); text-decoration: none; font-weight: 800; font-size: 1.2rem; padding: 8px 0; }
.brand span { margin-right: .3em; }
.top-nav { display: flex; flex-wrap: wrap; gap: 2px 18px; }
.top-nav a { color: var(--head-soft); text-decoration: none; padding: 8px 0; border-bottom: 3px solid transparent; }
.top-nav a:hover, .top-nav a[aria-current] { color: var(--head-ink); border-bottom-color: var(--head-soft); }
.site-footer { border-top: 1px solid var(--line); margin-top: 24px; padding: 16px 0 28px; color: var(--muted); font-size: .92rem; }
.site-footer a { color: var(--link); }

/* Cards, forms, buttons, alerts */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 0 0 16px; }
.card.narrow { max-width: 600px; margin: 24px auto; }
.card.inset { padding: 14px; margin: 10px 0; background: var(--tag-bg); }
.hero { margin: 8px 0 18px; }
.hero h1 { font-size: 2rem; }
.hero h1 span { margin-right: .3em; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; margin-bottom: 16px; }
.modes .card { margin: 0; }
.prose ul { padding-left: 1.3rem; }
.prose li { margin: 0 0 .35rem; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
.stack > label:first-child, .stack > div > label:first-child { margin-top: 0; }
input[type=text], input[type=email] { width: 100%; max-width: 420px; padding: 9px 11px; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--muted); border-radius: 8px; min-height: 44px; }
fieldset.choices { border: 0; padding: 0; margin: 12px 0; }
fieldset.choices legend { font-weight: 700; padding: 0; margin-bottom: 4px; }
label.choice { font-weight: 400; display: flex; gap: 8px; align-items: baseline; margin: 2px 0; padding: 6px 4px; min-height: 32px; cursor: pointer; border-radius: 6px; }
label.choice:hover { background: var(--tag-bg); }
label.choice.inline { display: inline-flex; margin-right: 12px; }
label.choice .muted { font-size: .88rem; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 8px 0; min-height: 32px; }
input[type=radio], input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--brand); color: var(--brand-ink); border: 2px solid var(--brand);
  border-radius: 8px; padding: 8px 16px; min-height: 44px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .92rem; }
.btn.outline { background: transparent; color: var(--link); border-color: currentColor; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.stack .btn { margin-top: 14px; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--link); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; min-height: 24px; }
.alert { padding: 12px 14px; border-radius: 8px; margin: 0 0 14px; background: var(--tag-bg); }
.alert.ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert.warn { background: var(--warn-bg); color: var(--warn-ink); }
.alert p:last-child { margin-bottom: 0; }
.alert .btn { margin-top: 4px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* The game: board and panel */
.game { display: grid; grid-template-columns: minmax(0, 600px) minmax(260px, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .game { grid-template-columns: 1fr; } }
.board-wrap { max-width: 600px; width: 100%; position: relative; }
.board { container-type: inline-size; display: grid; grid-template-rows: repeat(8, 1fr); aspect-ratio: 1; width: 100%;
  border: 10px solid #4a2c12; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.25); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.brow { display: grid; grid-template-columns: repeat(8, 1fr); }
.cell { position: relative; cursor: pointer; }
.cell.light { background: var(--sq-light); }
.cell.dark { background: var(--sq-dark); }
.cell:focus { outline: none; }
/* Focus: a white ring with a blue one inside, so it shows on both the light and the dark squares (3:1 or better). */
.cell:focus-visible { outline: 3px solid #ffffff; outline-offset: -3px; box-shadow: inset 0 0 0 7px #1d4ed8; z-index: 2; }
.cell .rank, .cell .file { position: absolute; font-size: 2.2cqw; line-height: 1; font-weight: 700; pointer-events: none; }
.cell .rank { left: 4%; top: 4%; }
.cell .file { right: 5%; bottom: 4%; }
.cell.light :is(.rank, .file) { color: var(--sq-on-light); }
.cell.dark :is(.rank, .file) { color: var(--sq-on-dark); }
/* The pieces are the chess characters in a text font (not emoji), outlined so they show on either square. */
.pc { font-family: 'Segoe UI Symbol', 'Apple Symbols', 'Noto Sans Symbols 2', 'DejaVu Sans', 'Arial Unicode MS', serif; font-variant-emoji: text; line-height: 1; }
.cell .pc { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 10cqw; padding-bottom: .4cqw; }
.pc.pw { color: var(--pc-white); -webkit-text-stroke: .32cqw var(--pc-white-edge); paint-order: stroke fill;
  text-shadow: 0 .35cqw .5cqw rgba(0,0,0,.35); }
.pc.pb { color: var(--pc-black); -webkit-text-stroke: .22cqw var(--pc-black-edge); paint-order: stroke fill;
  text-shadow: 0 .35cqw .5cqw rgba(0,0,0,.35); }
.cell.last-from, .cell.last-to { box-shadow: inset 0 0 0 100cqw rgba(255, 210, 63, .32); }
.cell.sel { box-shadow: inset 0 0 0 .8cqw var(--mark), inset 0 0 0 1.1cqw var(--mark-edge), inset 0 0 0 100cqw rgba(255, 210, 63, .3); }
.cell.in-check { background-image: radial-gradient(circle, rgba(220, 38, 38, .95) 0, rgba(220, 38, 38, .7) 35%, rgba(220, 38, 38, 0) 72%); }
.cell.hinted { box-shadow: inset 0 0 0 .8cqw var(--hint), inset 0 0 0 1.1cqw #ffffff; }
.dot { position: absolute; left: 50%; top: 50%; width: 28%; height: 28%; transform: translate(-50%, -50%); border-radius: 50%;
  background: var(--mark); box-shadow: 0 0 0 .35cqw var(--mark-edge); pointer-events: none; }
.ring { position: absolute; inset: 4%; border-radius: 50%; border: .8cqw solid var(--mark); box-shadow: 0 0 0 .3cqw var(--mark-edge), inset 0 0 0 .3cqw var(--mark-edge); pointer-events: none; }
.board-help { margin-top: 8px; }
/* Which piece a pawn becomes: a box over the board. */
.promo { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 5; background: var(--card); color: var(--ink);
  border: 2px solid var(--brand); border-radius: var(--radius); padding: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.35); display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 92%; }
.promo p { width: 100%; margin: 0 0 4px; font-weight: 700; text-align: center; }
.promo .pc { font-size: 1.6rem; }
.promo .pc.pw { -webkit-text-stroke: 1.2px var(--pc-white-edge); text-shadow: none; }
.promo .pc.pb { -webkit-text-stroke: 0; text-shadow: none; }
.btn .pc.pb { color: var(--brand-ink); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.ch-status { font-size: 1.12rem; font-weight: 700; margin-bottom: 10px; }
.ch-counts li { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin: 3px 0; min-height: 28px; }
.ch-counts .took { font-size: 1.25rem; letter-spacing: -.08em; }
.ch-counts .took .pc.pw { -webkit-text-stroke: 1px var(--pc-white-edge); text-shadow: none; }
.ch-counts .took .pc.pb { color: var(--ink); -webkit-text-stroke: 0; text-shadow: none; }
.ch-counts .lead { color: var(--muted); font-weight: 700; }
.ch-type .row input { max-width: 200px; }
.ch-type-msg:empty { display: none; }
.ch-moves-box { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.ch-moves { margin: 0; padding-left: 2.2rem; font-variant-numeric: tabular-nums; white-space: pre; }
.ch-moves:empty::before { content: 'No moves yet.'; color: var(--muted); margin-left: -2rem; }
.ch-end { margin: 6px 0 10px; }

/* Stats */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 0 0 16px; }
.tiles li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-align: center; color: var(--muted); }
.tiles .big { display: block; font-size: 1.8rem; font-weight: 800; color: var(--ink); line-height: 1.1; }
.table-wrap { overflow-x: auto; margin: 0 0 8px; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
thead th { font-size: .88rem; color: var(--muted); }
td { font-variant-numeric: tabular-nums; }
dl.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 20px; margin: 0 0 8px; }
dl.facts dt { font-weight: 700; }
dl.facts dd { margin: 0; }

@media (prefers-reduced-motion: no-preference) { .btn { transition: filter .12s; } }
@media print { .site-header, .site-footer, .panel .btn, .ch-type, .board-help { display: none !important; } }
