/* Mate Room. Dark by default (data-theme on <html>, chosen in Settings). A chess-club table: the board sits on green baize under a pool of lamplight;
   everything around it is quiet paper, brass and Bodoni. Light and dark.
   The felt is the one bold thing; keep the rest calm. */
:root {
  --bg: #f4f0e7; --surface: #fffdf8; --ink: #1d1b16; --muted: #6a6457; --line: #ddd5c4; --chip: #ece5d6;
  --felt: #1e3a2e; --felt-ink: #efe8d6; --felt-muted: #aebcb1; --felt-line: rgba(239, 232, 214, .16);
  --accent: #9c6a1c; --accent-bright: #d9aa55; --on-accent: #fff; --accent-soft: rgba(196, 140, 40, .42);
  --good: #2e7a4f; --bad: #b8392f;
  --sq-light: #dce3ea; --sq-dark: #7d8fa8;
  --pc-white: #fbfaf6; --pc-white-edge: #1b2028; --pc-black: #1b2028; --pc-black-edge: #8c97a6;
  --f-display: "Bodoni Moda", "Didot", "Bodoni 72", Georgia, serif;
  --f-body: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;   /* chess notation only */
  --f-piece: "Noto Sans Symbols 2", "Segoe UI Symbol", "DejaVu Sans", serif;
  /* the kit's lobby and chat */
  --kit-bg: var(--surface); --kit-ink: var(--ink); --kit-muted: var(--muted); --kit-line: var(--line);
  --kit-accent: var(--accent); --kit-on-accent: var(--on-accent); --kit-ok: var(--good); --kit-warn: var(--bad);
  --kit-font: var(--f-body); --kit-display: var(--f-display);
  --kit-p0: #fbfaf6; --kit-p1: #1b2028;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f1512; --surface: #161e19; --ink: #e8ece6; --muted: #98a59c; --line: #27332c; --chip: #1f2a23;
  --felt: #173126; --accent: #d9aa55; --on-accent: #1b1306; --accent-soft: rgba(227, 164, 74, .45);
  --good: #5bbb88; --bad: #e46a62; --sq-light: #b9c4d1; --sq-dark: #5b6d86; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #0f1512; --surface: #161e19; --ink: #e8ece6; --muted: #98a59c; --line: #27332c; --chip: #1f2a23;
  --felt: #173126; --accent: #d9aa55; --on-accent: #1b1306; --accent-soft: rgba(227, 164, 74, .45);
  --good: #5bbb88; --bad: #e46a62; --sq-light: #b9c4d1; --sq-dark: #5b6d86; color-scheme: dark }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); -webkit-font-smoothing: antialiased; }
.wrap { --board-max: clamp(380px, calc(100vh - 150px), 680px); max-width: 1180px; margin: 0 auto; padding-block: 18px 72px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 22px; }
h2 { font-family: var(--f-display); font-weight: 500; font-size: 2rem; line-height: 1.1; margin: 2px 0 0; text-wrap: balance; letter-spacing: -.005em; }
h3 { font-family: var(--f-display); font-weight: 500; font-size: 1.2rem; line-height: 1.2; margin: 0 0 8px; }
a { color: var(--accent); }

/* ---- Header ---- */
header { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 40px; }
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand h1 { font-family: var(--f-display); font-weight: 700; font-size: 1.9rem; letter-spacing: -.015em; margin: 0; line-height: 1; white-space: nowrap; }
.brand span { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.home-btn { border-radius: 999px; padding: 7px 16px; flex: none; }

/* ---- The table: the board on green baize under a lamp ---- */
#puzzles, #play { display: flex; flex-direction: column; gap: 22px; }
.table { display: grid; grid-template-columns: minmax(0, var(--board-max)) minmax(300px, 1fr); gap: 34px; align-items: start; }
.felt, #tr-board, #pz-board, #rv-board, .board-col {
  background: radial-gradient(120% 75% at 50% -12%, rgba(255, 222, 160, .2), transparent 62%), var(--felt);
  border-radius: 20px; padding: clamp(10px, 2.2vw, 26px);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .28), inset 0 3px 34px rgba(0, 0, 0, .32);
  color: var(--felt-ink); }
.board-wrap { position: relative; width: 100%; max-width: var(--board-max); justify-self: center; }
.board-col { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: var(--board-max); justify-self: center; min-width: 0; }

/* ---- Board ---- */
.board { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: 100%; aspect-ratio: 1; max-width: 100%;
  border-radius: 6px; overflow: hidden; container-type: inline-size; touch-action: none; user-select: none; -webkit-user-select: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), 0 14px 30px -10px rgba(0, 0, 0, .55); }
.sq { position: relative; display: grid; place-items: center; min-height: 0; overflow: hidden; }
.sq.mine, .board:has(.sel) .sq { cursor: pointer; }
.sq.l { background: var(--sq-light); } .sq.d { background: var(--sq-dark); }
.sq.last::before, .sq.sel::before, .sq.hint::before, .sq.bad::before, .sq.chk::before { content: ""; position: absolute; inset: 0; }
.sq.last::before { background: rgba(214, 170, 60, .38); }
.sq.sel::before { background: var(--accent-soft); }
.sq.hint::before { box-shadow: inset 0 0 0 4px var(--accent-bright); }
.sq.bad::before { background: rgba(200, 50, 45, .5); }
.sq.chk::before { background: radial-gradient(circle, rgba(220, 40, 40, .85) 0%, rgba(220, 40, 40, .35) 45%, transparent 72%); }
.sq .dot { position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(20, 30, 45, .28); pointer-events: none; }
.sq .ring { position: absolute; inset: 4%; border-radius: 50%; box-shadow: inset 0 0 0 5px rgba(20, 30, 45, .28); pointer-events: none; }
.coord { position: absolute; font: 700 2.6cqi var(--f-body); pointer-events: none; line-height: 1; }
.coord.f { right: 5%; bottom: 2%; } .coord.r { left: 5%; top: 2%; }
.sq.l .coord { color: var(--sq-dark); } .sq.d .coord { color: var(--sq-light); }
.pc { font-family: var(--f-piece); font-size: 10.4cqi; line-height: 1; position: relative; pointer-events: none;
  paint-order: stroke fill; filter: drop-shadow(0 1px 1px rgba(0,0,0,.25)); }
.pc.w { color: var(--pc-white); -webkit-text-stroke: var(--stroke, .55cqi) var(--pc-white-edge); }
.pc.b { color: var(--pc-black); -webkit-text-stroke: var(--stroke, .3cqi) var(--pc-black-edge); }
.pc.lift { opacity: .25; }
.pc.arrive { animation: arrive .22s ease-out; }
.ghost { position: fixed; z-index: 50; transform: translate(-50%, -55%); display: grid; place-items: center; }
@keyframes arrive { from { transform: scale(.82); opacity: .4; } to { transform: none; opacity: 1; } }
.board.shake { animation: shake .32s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .pc.arrive, .board.shake { animation: none; } }
.promo { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 15, 12, .5); border-radius: inherit; z-index: 5; }
.promo-row { display: flex; gap: 8px; background: var(--surface); padding: 10px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.35); container-type: inline-size; width: min(80%, 340px); }
.promo button { flex: 1; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; background: var(--sq-light); cursor: pointer; display: grid; place-items: center; padding: 0; }
.promo button .pc { font-size: 17cqi; }

/* Player name bars, on the felt above and below the board */
.player { display: flex; align-items: center; gap: 10px; min-height: 30px; font-weight: 600; color: var(--felt-ink); }
.player em { font: 500 .78rem var(--f-body); font-style: normal; color: var(--felt-muted); }
.player em.tomove { color: #1b1306; background: var(--accent-bright); border-radius: 999px; padding: 1px 9px; }
/* Game clocks: one beside each player's name, the running one lit in brass, red when low */
.player .pclock { margin-left: auto; font: 650 1.05rem var(--f-body); font-variant-numeric: tabular-nums; letter-spacing: .02em;
  min-width: 4.6em; text-align: center; padding: 3px 10px; border-radius: 6px; color: var(--felt-muted);
  background: rgba(0, 0, 0, .28); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06); }
.player .pclock.running { color: #1b1306; background: var(--accent-bright); box-shadow: none; }
.player .pclock.low { color: #ffd9d2; background: #8f2f22; }
.player .pclock.running.low { color: #fff; background: #c2412f; }
.player .pclock.out { color: #fff; background: #c2412f; }
.pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-col .swatch { border-color: var(--felt-ink); } .board-col .swatch.b { border-color: var(--felt-muted); }

/* ---- Panel beside the board ---- */
.panel { display: flex; flex-direction: column; gap: 18px; min-width: 0; padding-top: 4px; }
.eyebrow { font-size: .88rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; }
.eyebrow b { color: var(--accent); font-weight: 600; }
.theme { color: var(--muted); margin: 4px 0 0; }
.turn { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.swatch { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.swatch.w { background: #fbfaf6; } .swatch.b { background: #1b2028; border-color: var(--muted); }
/* What just happened: a note with a coloured edge; a finished game or puzzle fills in. */
.status { min-height: 3em; padding: 12px 16px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  border-left: 4px solid var(--line); font-weight: 500; }
.status.good { border-left-color: var(--good); color: var(--good); }
.status.bad { border-left-color: var(--bad); color: var(--bad); }
.status.done { background: var(--good); border-color: var(--good); color: #fff; }
.status.lost { background: var(--bad); border-color: var(--bad); color: #fff; }
.clock { font: 600 1.15rem var(--f-body); font-variant-numeric: tabular-nums; color: var(--muted); }
.clock:empty { display: none; }
.clock.low { color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn { font: 500 .92rem var(--f-body); padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { border-color: var(--ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); align-self: flex-start; padding-inline: 0; text-decoration: underline; text-underline-offset: 3px; }
.btn:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; flex-basis: 100%; }
.confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--bad); border-radius: 10px; }
.confirm span { font-weight: 600; margin-right: auto; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; }
.error:empty { min-height: 0; }

.sheet { border-top: 1px solid var(--line); padding-top: 14px; }
.moves { font: .92rem var(--f-mono); display: grid; grid-template-columns: 2.6em 1fr 1fr; gap: 2px 8px; max-height: 240px; overflow-y: auto; font-variant-numeric: tabular-nums; }
.moves .n { color: var(--muted); }
.moves .empty { grid-column: 1 / -1; color: var(--muted); font-family: var(--f-body); }
.stats { display: flex; gap: 26px; font-variant-numeric: tabular-nums; border-top: 1px solid var(--line); padding-top: 14px; }
.stats div { display: flex; flex-direction: column; }
.stats strong { font-family: var(--f-display); font-size: 1.75rem; font-weight: 500; line-height: 1.05; }
.stats span { font-size: .8rem; color: var(--muted); }
.note { color: var(--muted); font-size: .86rem; margin: 0; max-width: 78ch; }

/* ---- Puzzle trainer ---- */
.modes { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.modes button { border: 0; background: transparent; color: var(--muted); font: 500 .98rem var(--f-body); padding: 8px 2px; margin-right: 20px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.modes button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.mode { display: flex; flex-direction: column; gap: 22px; }
.recent { display: flex; gap: 5px; align-items: center; min-height: 12px; }
.recent span { width: 10px; height: 10px; border-radius: 50%; }
.recent span.won { background: var(--good); } .recent span.lost { background: var(--bad); }
.recent em { color: var(--muted); font-size: .8rem; font-style: normal; }
.pick { display: flex; flex-direction: column; gap: 6px; }
.pick-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; }
.pick-head span:last-child { font-size: .82rem; font-variant-numeric: tabular-nums; }
.seg { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--ink); font: 500 .84rem var(--f-body); padding: 8px 2px; cursor: pointer; min-width: 0; }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.seg button:hover:not([aria-pressed="true"]) { background: var(--chip); }
.seg.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.theme-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--muted); font-size: .9rem; }
.theme-row b { color: var(--ink); font-weight: 600; }
.theme-row select { flex-basis: 100%; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent); font: 500 .9rem var(--f-body); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---- Mate classics: tiles coloured by mate length ---- */
.shelf { display: flex; flex-direction: column; gap: 12px; }
.shelf-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.shelf-head h3 { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filters button { font: 500 .84rem var(--f-body); padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 6px; }
.tile.n1, .key.n1 { --n: #3f8fc4; } .tile.n2, .key.n2 { --n: #c98a1e; } .tile.n3, .key.n3 { --n: #a0559e; }
.tile { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 .9rem var(--f-body);
  cursor: pointer; position: relative; font-variant-numeric: tabular-nums; padding: 0 0 10px; box-shadow: inset 0 -4px 0 var(--n, transparent); }
.tile:hover { border-color: var(--muted); }
.tile.solved { background: color-mix(in srgb, var(--good) 18%, var(--surface)); border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.tile.clean::after { content: ""; position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--good); }
.tile.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.tile small { position: absolute; left: 0; right: 0; bottom: 7px; font-size: .66rem; font-weight: 600; color: var(--n, var(--muted)); }
.key { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--n); margin-right: 6px; vertical-align: 1px; }

/* ---- Play menu and settings cards ---- */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.menu-grid .error { grid-column: 1 / -1; }
#menu .card { max-width: 460px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card h2 { font-size: 1.5rem; margin: 0; }
.card .btn { align-self: stretch; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); font-size: .9rem; }
input, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.field input, .field select { width: 58%; }
#joinForm { display: flex; gap: 8px; }
#joinForm input { flex: 1; text-transform: uppercase; letter-spacing: .15em; }
#lobby { max-width: 600px; }
.kit-lobby .kit-dot.p0 { box-shadow: 0 0 0 1px var(--ink); }
.credit { color: var(--muted); font-size: .8rem; margin: 0; }
.credit a { color: inherit; }

#settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 18px; align-items: start; }
.settings-card h2 { font-size: 1.4rem; margin: 0; }
#settings > .settings-card:first-child { grid-column: 1 / -1; }   /* Look, with the collection, gets the full width */
/* Link back to the website: same tab, at least 44 px tall to tap */
.home-link { margin: 0; }
#settings > .home-link { grid-column: 1 / -1; }
.moregames { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.moregames:hover { color: var(--ink); }
.look-menu { display: grid; gap: 12px; }
.look-row { display: grid; gap: 4px; color: var(--muted); font-size: .85rem; }
.look-preview { max-width: 400px; display: grid; grid-template-columns: repeat(4, 1fr); border-radius: 8px; overflow: hidden; container-type: inline-size; }
.look-preview .pc { aspect-ratio: 1; display: grid; place-items: center; font-size: 19cqi; width: 100%; height: auto; background-color: var(--sq-light); }
.look-preview .pc:nth-child(even) { background-color: var(--sq-dark); }
#setName { width: 100%; }

/* ---- Start page ---- */
#home { display: flex; flex-direction: column; gap: 30px; }
/* The hero is the table itself: your next puzzle, waiting on the felt. */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 22px 40px; align-items: center; padding: clamp(18px, 3.5vw, 40px); }
.hero h2 { font-size: clamp(1.9rem, 4.4vw, 3rem); line-height: 1.05; color: var(--felt-ink); margin: 0; max-width: 17ch; }
.hero p { color: var(--felt-muted); margin: 10px 0 0; max-width: 44ch; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 14px 30px; margin: 22px 0; }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats strong { font-family: var(--f-display); font-size: 1.8rem; font-weight: 500; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--felt-ink); }
.hero-stats strong small { font-size: .95rem; color: var(--felt-muted); }
.hero-stats span { font-size: .82rem; color: var(--felt-muted); }
.hero .btn.primary { background: var(--accent-bright); border-color: var(--accent-bright); color: #1b1306; font-weight: 600; padding: 11px 20px; }
.hero .btn.primary:hover { border-color: var(--felt-ink); }
.hero-board { width: clamp(200px, 26vw, 300px); display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.hero-board .board-wrap { max-width: none; }
.hero-board .board { pointer-events: none; }
.hero-board figcaption { font-size: .86rem; color: var(--felt-muted); text-align: center; }
.resume { align-self: flex-start; }

.home-sec { display: flex; flex-direction: column; gap: 12px; }
.home-sec > h2 { font-size: 1.6rem; margin: 0; }
.home-sub { font: 500 .92rem var(--f-body); color: var(--muted); margin: 8px 0 0; }
.home-grid { display: grid; gap: 12px; }
.home-grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.home-grid.fill { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.home-grid.four { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.choice, .resume { display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; min-width: 0; }
.choice:hover:not(:disabled), .resume:hover { border-color: var(--accent); }
.choice b, .resume b { display: block; font-family: var(--f-display); font-size: 1.25rem; font-weight: 500; line-height: 1.2; }
.choice small, .resume small { display: block; color: var(--muted); font-size: .87rem; margin-top: 3px; }
.choice em { font: 600 .74rem var(--f-body); font-style: normal; color: var(--accent); border: 1px solid currentColor; border-radius: 999px;
  padding: 0 8px; vertical-align: 3px; margin-left: 6px; white-space: nowrap; }
.choice.soon { cursor: default; opacity: .6; }
.choice .ic, .resume .ic { flex: none; width: 56px; height: 56px; border-radius: 10px; background: var(--sq-light) var(--i) center 80% / 92% no-repeat;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }
.resume { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); gap: 8px; }
.cats button { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; color: var(--ink); font: inherit; cursor: pointer; text-align: left; }
.cats button:hover { border-color: var(--accent); background: var(--surface); }
.cats b { font-weight: 500; font-size: .93rem; }
.cats small { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cats.mates { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 580px; }

/* ---- Picture boards (the wooden board and the collectible sets, all with the same frame width; pictures set in look.js) ---- */
:root[data-board-art] { --sq-light: #e6cfa2; --sq-dark: #5e3d27; }
:root[data-board-art] .board { background: var(--art-board) center / 100% 100% no-repeat; padding: 3.957%; border-radius: 4px;
  box-shadow: 0 16px 34px -12px rgba(0, 0, 0, .7), 0 2px 4px rgba(0, 0, 0, .35); }
:root[data-board-art] .sq { overflow: visible; }
:root[data-board-art] .sq.l, :root[data-board-art] .sq.d { background: transparent; }
:root[data-board-art] .sq.d .dot { background: rgba(255, 236, 205, .38); }
:root[data-board-art] .sq.d .ring { box-shadow: inset 0 0 0 5px rgba(255, 236, 205, .38); }
:root[data-board-art] .sq.l .dot { background: rgba(60, 35, 15, .32); }
:root[data-board-art] .sq.l .ring { box-shadow: inset 0 0 0 5px rgba(60, 35, 15, .32); }
:root[data-board-art] .sq.last::before { background: rgba(232, 178, 60, .42); }
/* Letters and numbers sit in the frame. The frame is 34.4% of a square (3.957% of the board / 11.51% per square). */
:root[data-board-art] .coord { color: var(--coord-ink, #f0dfbd); font-size: max(10px, 2.5cqi); text-shadow: 0 1px 1px var(--coord-shadow, rgba(0, 0, 0, .6)); display: grid; place-items: center; }
:root[data-board-art] .coord.f { left: 0; right: 0; bottom: -34.4%; height: 34.4%; }
:root[data-board-art] .coord.r { top: 0; bottom: 0; left: -34.4%; width: 34.4%; }

/* ---- Picture pieces (wood and the collectible sets; pictures set in look.js). The font glyph stays inside as a fallback. ---- */
:root[data-pieces-art] .pc { color: transparent; -webkit-text-stroke: 0; font-size: 0; width: 94%; height: 94%; display: block;
  background: center bottom / contain no-repeat; }
/* A thin rim (dark round light pieces, light round dark ones) keeps them readable on either square. */
:root[data-pieces-art] .pc.w { filter: drop-shadow(0 0 .14cqi rgba(40, 22, 8, .75)) drop-shadow(0 .35cqi .3cqi rgba(0, 0, 0, .4)); }
:root[data-pieces-art] .pc.b { filter: drop-shadow(0 0 .14cqi rgba(255, 238, 212, .6)) drop-shadow(0 .35cqi .3cqi rgba(0, 0, 0, .45)); }
/* Pale frames (jade, glass) get dark letters and numbers. */
:root[data-board-art="jade"], :root[data-board-art="glass"] { --coord-shadow: rgba(255, 255, 255, .5); }
/* Carved figures (koa) are slim, so the dark ones get a stronger light rim. */
:root[data-pieces-art="koa"] .pc.b { filter: drop-shadow(0 0 .22cqi rgba(255, 228, 190, .9)) drop-shadow(0 .35cqi .3cqi rgba(0, 0, 0, .45)); }
:root[data-pieces-art] .ghost.pc { filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .45)); }
:root[data-pieces-art] .promo button .pc { width: 86%; height: 86%; font-size: 0; }
:root[data-pieces-art] .look-preview .pc { width: 100%; height: auto; aspect-ratio: 1; background-size: 80%; background-position: center 70%; background-color: var(--sq-light); }
:root[data-pieces-art] .look-preview .pc:nth-child(even) { background-color: var(--sq-dark); }
:root[data-pieces-art] .pc.w.t-k { background-image: var(--pc-wk); } :root[data-pieces-art] .pc.b.t-k { background-image: var(--pc-bk); }
:root[data-pieces-art] .pc.w.t-q { background-image: var(--pc-wq); } :root[data-pieces-art] .pc.b.t-q { background-image: var(--pc-bq); }
:root[data-pieces-art] .pc.w.t-r { background-image: var(--pc-wr); } :root[data-pieces-art] .pc.b.t-r { background-image: var(--pc-br); }
:root[data-pieces-art] .pc.w.t-b { background-image: var(--pc-wb); } :root[data-pieces-art] .pc.b.t-b { background-image: var(--pc-bb); }
:root[data-pieces-art] .pc.w.t-n { background-image: var(--pc-wn); } :root[data-pieces-art] .pc.b.t-n { background-image: var(--pc-bn); }
:root[data-pieces-art] .pc.w.t-p { background-image: var(--pc-wp); } :root[data-pieces-art] .pc.b.t-p { background-image: var(--pc-bp); }

/* ---- Collection: sets in Settings, and the "New set earned" card (sets.js) ---- */
.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; margin-top: 4px; }
.set { display: grid; grid-template-columns: 84px 1fr; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.set-text { display: grid; gap: 2px; min-width: 0; }
.set-text b { font-weight: 600; font-size: .95rem; }
.set-text b em { white-space: nowrap; font-style: normal; font-weight: 500; font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; margin-left: 4px; vertical-align: 1px; }
.set-text small { color: var(--muted); font-size: .8rem; line-height: 1.35; }
.set-use { display: flex; gap: 6px; margin-top: 6px; }
.set-use button { flex: 1; font: 500 .8rem var(--f-body); padding: 5px 4px; border-radius: 6px; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; }
.set-use button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.set-use button:hover:not([aria-pressed="true"]) { background: var(--chip); }
.set-thumb { position: relative; aspect-ratio: 1; border-radius: 4px; background: center / 100% 100% no-repeat; box-shadow: 0 4px 10px -4px rgba(0, 0, 0, .55); }
.set-thumb .tp { position: absolute; bottom: 8%; width: 46%; height: 62%; background: center bottom / contain no-repeat; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .45)); }
.set-thumb .tp.w { left: 5%; } .set-thumb .tp.b { right: 5%; }
.set.locked .set-thumb { filter: grayscale(.6) brightness(.8); }
.set.locked .set-thumb::after { content: "🔒︎"; position: absolute; inset: auto 4px 4px auto; font-size: 13px; line-height: 1; padding: 4px; border-radius: 6px; background: rgba(0, 0, 0, .55); color: #fff; }
.set-progress { height: 5px; border-radius: 3px; background: var(--chip); overflow: hidden; margin-top: 6px; }
.set-progress i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.set-count { font-variant-numeric: tabular-nums; }
.earned-card { position: fixed; z-index: 60; left: 50%; bottom: max(16px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: min(440px, calc(100vw - 32px));
  display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; padding: 14px; border-radius: 14px;
  background: var(--felt); color: var(--felt-ink); border: 1px solid var(--accent-soft); box-shadow: 0 18px 40px -12px rgba(0, 0, 0, .7);
  animation: earned-in .35s ease-out; }
.earned-text { display: grid; gap: 3px; }
.earned-text small { color: var(--accent-bright); font-size: .8rem; }
.earned-text b { font-family: var(--f-display); font-weight: 500; font-size: 1.45rem; line-height: 1.1; }
.earned-text span { color: var(--felt-muted); font-size: .85rem; }
.earned-btns { display: flex; gap: 8px; margin-top: 8px; }
.earned-btns .btn:not(.primary) { background: transparent; color: var(--felt-ink); border-color: var(--felt-line); }
@keyframes earned-in { from { opacity: 0; transform: translate(-50%, 16px); } }
@media (prefers-reduced-motion: reduce) { .earned-card { animation: none; } }

/* ---- Tablets and phones ---- */
@media (max-width: 860px) {
  .table { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  /* Let the board fill the width, but keep it on screen. */
  .board-wrap, .board-col { max-width: min(100%, 76vh); }
  /* What just happened, and what to do next, right under the board. */
  .panel { gap: 14px; padding-top: 0; }
  .panel > .status { order: -2; }
  .panel > .actions { order: -1; }
  .panel > .coach { order: -1; }
  .hero { grid-template-columns: minmax(0, 1fr); }
  .hero-board { width: min(100%, 340px); justify-self: center; }
}
@media (max-width: 560px) {
  .brand h1 { font-size: 1.55rem; }
  .brand span { display: none; }
  .wrap { gap: 16px; padding-top: 12px; }
  .home-btn { padding: 6px 12px; }
  h2 { font-size: 1.7rem; }
  .felt, #tr-board, #pz-board, #rv-board, .board-col { border-radius: 14px; }
}

/* ---- Move planner (planner.js): a brass outline round the board and a bar beneath it ---- */
.board-wrap.planning .board { outline: 3px solid var(--accent-bright); outline-offset: 3px; }
.planbar { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; color: var(--felt-ink); }
.plan-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.plan-head b { font-family: var(--f-display); font-size: 1.25rem; font-weight: 500; color: var(--accent-bright); }
.plan-head span { color: var(--felt-muted); font-size: .9rem; }
.plan-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 4px; font: .95rem var(--f-mono); min-height: 1.6em; }
.plan-line .n { color: var(--felt-muted); margin-left: 6px; }
.plan-line .n:first-child { margin-left: 0; }
.plan-line .pm { font: inherit; color: var(--felt-ink); background: none; border: 0; border-radius: 5px; padding: 1px 5px; cursor: pointer; }
.plan-line .pm:hover { background: var(--felt-line); }
.plan-line .pm.now { background: var(--accent-bright); color: #1b1306; }
.plan-line .pm.later { color: var(--felt-muted); }
.plan-empty { font-family: var(--f-body); color: var(--felt-muted); font-size: .9rem; }
.plan-note { margin: 0; font-size: .88rem; color: #f3c27a; }
.plan-ctl { display: flex; flex-wrap: wrap; gap: 8px; }
.plan-ctl .btn { background: rgba(255, 255, 255, .06); border-color: var(--felt-line); color: var(--felt-ink); }
.plan-ctl .btn:hover:not(:disabled) { border-color: var(--felt-muted); }
.plan-ctl .btn.primary { background: var(--accent-bright); border-color: var(--accent-bright); color: #1b1306; margin-left: auto; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* ---- Review (review.js) and the mistake check after a game ---- */
.home-grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.choice em.due { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.modes .count { display: inline-block; min-width: 1.4em; margin-left: 4px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: .75rem; font-weight: 600; line-height: 1.5; text-align: center; vertical-align: 1px; }
.modes .count:empty { display: none; }
.mistake-note { padding: 10px 14px; border-radius: 10px; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  font-size: .92rem; }
.mistake-note .linkbtn { margin-left: 4px; }

/* ---- The coach: a short note in plain words under a finished puzzle or game (coach-ui.js) ---- */
.coach { padding: 12px 16px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); font-size: .95rem; line-height: 1.5; }
.coach:empty { display: none; }
.coach-head { display: flex; align-items: center; gap: 8px; font: 600 .8rem var(--f-body); color: var(--accent); letter-spacing: .02em; margin-bottom: 4px; }
.coach-ic { width: 16px; height: 16px; flex: none; background: var(--pc-wn) center / contain no-repeat; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35)); }
.coach h4 { margin: 10px 0 2px; font: 600 .85rem var(--f-body); color: var(--muted); }
.coach h4:first-of-type { margin-top: 4px; }
.coach p { margin: 0; }
.coach-wait { color: var(--muted); font-style: italic; }
.coach-offer { font-size: .9rem; }
.coach:has(.coach-offer) { padding: 8px 16px; border-left-width: 1px; }
.mistake-note .coach-game { margin-top: 10px; background: var(--surface); }
.coach-game ul { margin: 4px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.coach-game li b { font-family: var(--f-mono); font-weight: 500; margin-right: 4px; }

/* ---- Today's training (plan.js): the start page's card and the bar above the puzzles ---- */
.today { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 320px); gap: 18px 32px; align-items: center;
  padding: 20px 24px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.today h2 { font-size: 1.6rem; margin: 0; }
.today-sub { color: var(--muted); margin: 4px 0 12px; }
.today-steps { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.today-steps button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 500 .92rem var(--f-body); cursor: pointer; text-align: left; }
.today-steps button:hover { border-color: var(--accent); }
.today-steps small { color: var(--muted); font-size: .8rem; }
.today-steps li.next button { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.today-steps li.done button { color: var(--muted); }
.today-steps li.done b::before { content: "✓ "; color: var(--good); }
.today-chart { margin: 0; }
.today-chart figcaption { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-soft); opacity: .35; stroke: none; }
.chart circle { fill: var(--accent); }
.chart text { fill: var(--ink); font: 600 11px var(--f-body); }
.chart.empty line { stroke: var(--line); stroke-width: 2; stroke-dasharray: 4 6; }
@media (max-width: 720px) { .today { grid-template-columns: minmax(0, 1fr); padding: 16px; } }

.plan-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 14px; margin-bottom: 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); font-size: .92rem; }
.plan-bar .pb-text b { margin-right: 6px; }
.plan-bar .pb-meter { flex: 1 1 120px; height: 6px; border-radius: 999px; background: var(--chip); overflow: hidden; min-width: 80px; }
.plan-bar .pb-meter span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.plan-bar.complete { border-color: color-mix(in srgb, var(--good) 50%, var(--line)); }
.plan-bar.complete b { color: var(--good); }

/* ---- Puzzle Rush and the daily puzzle ---- */
.seg.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.modes { overflow-x: auto; scrollbar-width: none; }
.modes button { white-space: nowrap; }
.rush-live { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; padding: 12px 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); }
.rush-score strong { display: block; font: 500 2.2rem/1 var(--f-display); }
.rush-score span { color: var(--muted); font-size: .82rem; }
.rush-time { justify-self: center; font: 650 1.6rem var(--f-body); font-variant-numeric: tabular-nums; padding: 4px 14px; border-radius: 8px;
  background: var(--accent-bright); color: #1b1306; }
.rush-time.low { background: var(--bad); color: #fff; }
.rush-misses { display: flex; gap: 6px; }
.rush-misses span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); }
.rush-misses span.x { background: var(--bad); border-color: var(--bad); }
#ru-result h3 { font: 600 .9rem var(--f-body); color: var(--muted); margin: 0 0 6px; }
.rush-list { display: flex; flex-wrap: wrap; gap: 6px; }
.rush-list a { font: 500 .8rem var(--f-body); padding: 3px 8px; border-radius: 6px; text-decoration: none; color: #fff; font-variant-numeric: tabular-nums; }
.rush-list a.won { background: var(--good); }
.rush-list a.lost { background: var(--bad); }
.rush-list em { color: var(--muted); }
@media (max-width: 560px) { .modes button { margin-right: 10px; font-size: .9rem; } }

/* ---- Endgame school ---- */
#sc-home { display: flex; flex-direction: column; gap: 14px; }
.lead { font-size: 1.02rem; color: var(--muted); margin: 0; }
.school-list h3 { font-size: 1.3rem; margin: 10px 0 8px; }
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 10px; }
.lesson { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: left; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
.lesson:hover { border-color: var(--accent); }
.lesson b { font-family: var(--f-display); font-weight: 500; font-size: 1.15rem; }
.lesson small { grid-column: 1 / -1; color: var(--muted); font-size: .84rem; }
.lesson.mastered { border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.stars { color: var(--accent); letter-spacing: 2px; font-size: .95rem; white-space: nowrap; }
.how h3 { font: 600 .9rem var(--f-body); color: var(--muted); margin: 0 0 6px; }
.how ol { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; line-height: 1.45; }

/* ---- Famous games ---- */
#fm-list { margin-top: 12px; }
.players { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.score-line { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.story { display: grid; gap: 8px; max-height: 260px; overflow-y: auto; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); line-height: 1.45; font-size: .94rem; }
.story p { margin: 0; }
.story b { color: var(--accent); font-weight: 600; }
#fm-home .note { margin-top: 14px; }
