/* Spot the Mate. Board colours and mate-map marks follow the books (render.py / render_epub.py). */
:root {
  --ink: #1d2433;
  --muted: #5b6475;
  --bg: #faf8f4;
  --card: #ffffff;
  --line: #e4dfd5;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --good: #1f7a3a;
  --bad: #b3261e;
  --light: #f2ede4;
  --dark: #c9bfae;
  --gold: #f2cf63;
  --mk-green: #1f7a3a;
  --mk-red: #b3261e;
  --mxp: #f3b9b3;
  --mblk: #c3cad6;
  --board: min(92vw, 520px);
  color-scheme: light;
}
* { 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 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
a { color: var(--accent); }
main { max-width: 980px; margin: 0 auto; padding: 0 16px 48px; }
.top {
  max-width: 980px; margin: 0 auto; padding: 14px 16px; display: flex; flex-wrap: wrap;
  gap: 10px 20px; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px;
  color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.top nav { display: flex; gap: 16px; flex-wrap: wrap; }
.top nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.top nav a:hover { color: var(--ink); }
.foot { text-align: center; color: var(--muted); font-size: 14px; padding: 24px 16px 40px; }

.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-size: clamp(28px, 6vw, 42px); line-height: 1.1; margin: 0 0 8px; letter-spacing: -0.02em; }
.lede { color: var(--muted); margin: 0 auto; max-width: 560px; font-size: 18px; }
.date { font-weight: 700; margin: 10px 0 0; }
.note { color: var(--muted); text-align: center; }

/* ladder */
.ladder { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 18px 0 22px; }
.rung .short { display: none; }
@media (max-width: 720px) {
  .ladder { gap: 6px; margin: 12px 0 14px; }
  .rung { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 6px 4px; gap: 0; }
  .rung .step { grid-row: auto; font-size: 20px; width: auto; }
  .rung .meta, .rung .src { display: none; }
  .rung .short { display: block; font-size: 11px; color: var(--muted); }
  .rung .rating { font-size: 12px; }
  .rung .tick { top: 2px; left: 5px; right: auto; font-size: 12px; }
  .hero { padding: 8px 0 0; }
  .hero h1 { font-size: 26px; margin-bottom: 4px; }
  .lede { font-size: 15px; }
  .date { margin-top: 4px; font-size: 14px; }
}
.rung {
  position: relative; display: grid; grid-template-columns: auto 1fr; gap: 0 10px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  text-decoration: none; color: var(--ink); min-width: 0;
}
.rung:hover { border-color: var(--accent); }
.rung.cur { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.rung .step { grid-row: span 3; font-size: 26px; font-weight: 800; color: var(--accent); width: 1.4em; text-align: center; }
.rung .meta { font-weight: 600; font-size: 14px; }
.rung .rating { font-size: 13px; color: var(--muted); }
.rung .src { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rung .tick { position: absolute; top: 6px; right: 10px; color: var(--good); font-weight: 800; }
.rung.done { background: #f1f7f2; }

/* solver */
.solver { display: grid; justify-items: center; gap: 12px; }
.prompt { text-align: center; display: grid; gap: 2px; }
.prompt .pn, .prompt .pr { color: var(--muted); font-size: 14px; }
.prompt strong { font-size: 20px; }
.board-wrap { position: relative; }
.bd {
  width: var(--board); aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, 1fr);
  border: 4px solid #2b2b2b; border-radius: 4px; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.sq { position: relative; aspect-ratio: 1; cursor: pointer; }
.bd.mapped .sq { cursor: default; }
.sq.lt { background: var(--light); }
.sq.dk { background: var(--dark); }
.sq img.pc { position: absolute; inset: 4%; width: 92%; height: 92%; pointer-events: none; }
.sq .crd { position: absolute; font-size: clamp(9px, 2.2vw, 12px); font-weight: 700; color: rgba(29,36,51,.55); line-height: 1; pointer-events: none; z-index: 2; }
.sq .crd-r { top: 3px; left: 3px; }
.sq .crd-f { bottom: 2px; right: 4px; }
.sq.lm { box-shadow: inset 0 0 0 999px rgba(242, 207, 99, .45); }
.sq.sel { box-shadow: inset 0 0 0 999px rgba(15, 118, 110, .35); }
.sq.tgt::after { content: ""; position: absolute; inset: 37%; border-radius: 50%; background: rgba(15, 118, 110, .55); }
.sq.tgt-cap::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: 4px solid rgba(15, 118, 110, .6); }
.bd.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* mate map — same shapes as the books */
.sq.mfrom { background: var(--gold); }
.sq.mxp { background: var(--mxp); }
.sq.mblk { background: var(--mblk); }
.sq.mto::after, .sq.mking::after { content: ""; position: absolute; inset: 5%; border: solid; border-width: clamp(3px, 0.9vw, 5px); pointer-events: none; }
.sq.mto::after { border-color: var(--mk-green); border-radius: 50%; }
.sq.mking::after { border-color: var(--mk-red); border-radius: 18%; }
.sq.mto img.pc, .sq.mking img.pc { inset: 13%; width: 74%; height: 74%; }

.promo { position: absolute; inset: 0; margin: auto; width: max-content; height: max-content; display: flex; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.promo button { width: 64px; height: 64px; border: 1px solid var(--line); border-radius: 8px; background: var(--light); cursor: pointer; }
.promo img { width: 100%; height: 100%; }

.status { min-height: 1.6em; font-weight: 600; text-align: center; }
.status.good { color: var(--good); }
.status.bad { color: var(--bad); }
.moves { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); min-height: 1.4em; text-align: center; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
button { font: inherit; }
.actions button {
  border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; cursor: pointer;
}
.actions button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.actions button.ghost { color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; font-size: 14px; color: var(--muted); max-width: 620px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend img { width: 20px; height: 20px; }
.legend .sw { display: inline-block; width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); }
.sw-xp { background: var(--mxp); }
.sw-blk { background: var(--mblk); }

.bookcard { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; max-width: 560px; width: 100%; }
.bookcard img { border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.15); flex: none; height: auto; }
.bookcard .from { margin: 0; color: var(--muted); font-size: 14px; }
.bookcard h3 { margin: 2px 0; font-size: 18px; }
.bookcard h3 a { color: var(--ink); text-decoration: none; }
.bookcard .sub { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.bookcard .links { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 0; }
a.buy { display: inline-block; background: var(--accent); color: var(--accent-ink); text-decoration: none; font-weight: 700;
  padding: 8px 14px; border-radius: 10px; }

/* books */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; margin-top: 18px; }
.bk { display: grid; gap: 4px; text-decoration: none; color: var(--ink); }
.bk img { width: 100%; height: auto; border-radius: 4px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.bk .t { font-weight: 700; }
.bk .s { font-size: 13px; color: var(--muted); }
.book-head { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; margin-top: 18px; }
.book-head .cover { width: min(240px, 60vw); height: auto; border-radius: 4px; box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.book-head h1 { margin: 0 0 4px; line-height: 1.15; }
.book-head .sub, .book-head .series, .book-head .by { margin: 0 0 6px; color: var(--muted); }
.desc { max-width: 680px; }
.samples { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 18px; }
.sample { margin: 0; }
.sample .bd { width: 100%; }
.sample .sq { cursor: default; }
.sample figcaption { font-size: 14px; color: var(--muted); margin-top: 6px; }
.prose { max-width: 680px; margin: 18px auto 0; }
.archive { max-width: 680px; margin: 0 auto; }
.archive ul { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.archive li a { display: block; padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; text-decoration: none; }
