/*
  Indigo ink on cream paper, with an ochre stamp accent. A typewriter font is used only for small labels (stamps,
  captions, footer); everything you read is a plain sans-serif.
  Edit the variables below to retune the whole site.
*/
:root {
  color-scheme: light;
  --bg: #f6f1e2;
  --card: #fbf8ef;
  --soft: #fbf8ef;
  --ink: #1c2433;
  --muted: #4a5365;
  --line: #d6cdb4;
  --rule: #6b7390;
  --accent: #2b3a67;
  --accent-hover: #1f2b50;
  --on-accent: #fbf8ef;
  --link: #2b3a67;
  --highlight: #9a5a10;
  --mark: #e8d9a8;
  --warn-bg: #f6e7b8;
  --warn-line: #c9a13b;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .28 0 0 0 0 .15 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

:root { --type: "Courier New", Courier, "Liberation Mono", "Nimbus Mono PS", monospace; }

* { box-sizing: border-box; }
html { font-size: calc(clamp(106%, 0.95rem + 0.35vw, 122%) * var(--scale, 1)); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image: var(--grain);
  line-height: 1.65;
}
main { flex: 1 0 auto; padding: 2rem 0 3.5rem; }
header.site, footer.site { flex-shrink: 0; }

a { color: var(--link); }
a:hover { color: var(--highlight); }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 32px); }
.prose { max-width: 760px; }

/* Header: a typed double rule underneath */
header.site { border-bottom: 3px double var(--ink); background: var(--bg); }
/* The name and the text size buttons share one line, centred on each other. The tabs' bars sit
   on the header's rule, so the header has no padding underneath. */
header.site .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding-top: 10px; padding-bottom: 0; }
.brand { font-weight: 700; font-size: 1.15rem; line-height: 1.2; color: var(--ink); text-decoration: none; margin-right: auto; }
/* Links in the other menus: contents lists and breadcrumbs */
nav ul { list-style: none; display: flex; flex-wrap: wrap; gap: 2px 14px; margin: 0; padding: 0; }
nav a { text-decoration: none; color: var(--ink); font-size: 1rem; padding: 8px 0; border-bottom: 2px solid transparent; display: inline-block; }
nav a:hover { border-bottom-color: var(--highlight); color: var(--ink); }
/* The main menu: tabs in the page's own font. On a phone they share one full row under the
   site name; on wider screens they sit to the right of it. The site name is the way home. */
header.site nav ul { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; }
header.site nav a {
  display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 10px;
  font-size: 1rem; text-align: center; line-height: 1.2;
  color: var(--ink); text-decoration: none; border-top: 4px solid transparent; border-bottom: 4px solid transparent;
}
header.site nav a:hover { color: var(--highlight); border-bottom-color: var(--line); }
header.site nav a[aria-current="page"] { color: var(--highlight); font-weight: bold; border-bottom-color: var(--highlight); }

.tools { display: flex; align-items: center; gap: 6px; }
.tools button, button.btn {
  font: inherit; cursor: pointer;
}
.tools button {
  font-size: 0.95rem; color: var(--ink); background: var(--card);
  border: 1px solid var(--rule); border-radius: 3px; min-height: 40px; min-width: 40px; padding: 4px 10px;
}
.tools button:hover { border-color: var(--highlight); }
.tools { order: 2; }
header.site nav { order: 3; flex: 1 0 100%; }
/* Wide screens: the name, the menu and the text size buttons in one row. It never wraps: when
   space runs short (or the text is made larger), long labels break onto two lines in their tab. */
@media (min-width: 960px) {
  /* One row: tabs as tall as the header, the name and the buttons centred in it */
  header.site .wrap { flex-wrap: nowrap; padding-top: 0; }
  .brand, .tools { flex-shrink: 0; }
  header.site nav { order: 1; flex: 0 1 auto; min-width: 0; }
  /* Tabs as wide as their labels, so the space between labels is the same everywhere */
  header.site nav ul { display: flex; gap: 6px; }
  header.site nav a { min-height: 60px; padding: 8px 12px; }
}

/* Type */
h1 { font-size: clamp(1.7rem, 1.2rem + 2vw, 2.5rem); line-height: 1.2; margin: 0 0 0.6rem; text-wrap: balance; }
h2 { font-size: clamp(1.25rem, 1.1rem + 0.7vw, 1.6rem); line-height: 1.3; margin: 2.4rem 0 0.6rem; }
h3 { font-size: 1.1rem; margin: 1.4rem 0 0.4rem; }
.lead { font-size: 1.15rem; color: var(--muted); margin-bottom: 1.6rem; }
.eyebrow { font-family: var(--type); font-size: 0.9rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.4rem; }

/* Buttons */
.btn { display: inline-block; min-height: 44px; background: var(--accent); color: var(--on-accent); text-decoration: none; padding: 10px 20px; border-radius: 3px; font-weight: 600; border: 2px solid var(--accent); }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn.alt { background: var(--card); color: var(--accent); }
.btn.alt:hover { border-color: var(--highlight); color: var(--highlight); background: var(--card); }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 1.2rem 0 0.5rem; }
@media (max-width: 480px) { .btn-row .btn { flex: 1 1 100%; text-align: center; } }

/* Cards: a sheet of paper with a slightly thicker bottom edge, like a stack */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 16px; margin: 1rem 0; }
.card { border: 1px solid var(--line); border-bottom: 4px solid var(--line); border-radius: 2px; padding: 16px 18px; background: var(--card); }
.card h3 { margin-top: 0; }
.card h2 { font-size: 1.1rem; line-height: inherit; margin: 0 0 0.4rem; }
.card p { margin: 6px 0 0; font-size: 0.95rem; color: var(--muted); }
/* A release of free puzzles: always one row of three, even on a phone */
.release { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(8px, 2vw, 16px); margin: 0.4rem 0 1.6rem; }
.release .card { padding: clamp(8px, 2vw, 14px); }
.release .card h3 { font-size: clamp(0.85rem, 2.6vw, 1.05rem); margin: 0; overflow-wrap: anywhere; }
.release .card p { font-size: clamp(0.8rem, 2.4vw, 0.95rem); }
.release .thumb { aspect-ratio: 1 / 1; margin-bottom: 6px; }

/* Typewriter-style labels, such as the Draft tag on planned guides */
.tag { display: inline-block; font-family: var(--type); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.8rem; color: var(--highlight); border: 2px solid var(--highlight); border-radius: 3px; padding: 0 8px; margin-bottom: 6px; transform: rotate(-2deg); }

.thumb { aspect-ratio: 4 / 3; background: var(--bg); border: 1px dashed var(--rule); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; border-radius: 2px; }
.cover { aspect-ratio: 2 / 3; width: 160px; max-width: 100%; background: var(--bg); border: 1px dashed var(--rule); display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 0.85rem; border-radius: 2px; }
img.thumb, img.cover { display: block; width: 100%; height: auto; object-fit: contain; border-style: solid; }

/* Book cards: a small cover beside compact text, one card to a row */
.book-grid { display: grid; gap: 12px; }
.book { display: grid; grid-template-columns: 120px 1fr; gap: 18px; align-items: start; margin: 0; }
.rules { margin: -0.4rem 0 1rem; font-size: 0.9rem; }
/* The game tabs: choosing one shows only that game's books. On a narrow screen the row scrolls sideways,
   and its right edge fades while more tabs are hidden there. */
.game-filter { margin: 0 0 1.5rem; border-bottom: 2px solid var(--line); }
.game-tabs { position: relative; display: flex; justify-content: safe center; overflow-x: auto; scrollbar-width: none; }
.game-tabs::-webkit-scrollbar { display: none; }
.game-tabs.more { mask-image: linear-gradient(to right, #000 85%, transparent); }
.game-tabs a { flex: none; padding: 10px 8px; margin-bottom: -2px; border-bottom: 4px solid transparent; font-size: 0.88rem; color: var(--muted); text-decoration: none; }
.game-tabs a:hover { color: var(--highlight); border-bottom-color: var(--line); }
.game-tabs a[aria-current="true"] { color: var(--highlight); font-weight: bold; border-bottom-color: var(--highlight); }
.book .cover { width: 100%; }
.book-body > :first-child { margin-top: 0; }
.book .book-title { font-size: 1.2rem; line-height: 1.25; margin: -0.25em 0 0; }
.book .book-meta { font-size: 0.85rem; color: var(--muted); margin: 2px 0 24px; }
.nowrap { white-space: nowrap; }
.book-buy { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.book-buy .btn { min-height: 36px; padding: 6px 14px; font-size: 0.85rem; }
.book-stores { flex-basis: 100%; margin-bottom: -0.3em; font-size: 0.8rem; color: var(--muted); }
/* A dot between the links that are shown; amazon.js chooses which. */
.book-stores a { white-space: nowrap; }
.book-stores a:not([hidden]) ~ a:not([hidden])::before { content: "\00b7  "; display: inline-block; white-space: pre; color: var(--muted); }
/* Desktop: the spare height beside the cover splits 1 : 2 : 1, above the title, between the
   details and the buttons, and below the store links. The negative margins remove the space
   above the capitals and below the underlines, so the parts are measured from the ink. */
@media (min-width: 561px) {
  .book-body { align-self: stretch; display: flex; flex-direction: column; }
  .book-body::before, .book-body::after { content: ""; flex-grow: 1; }
  .book .book-meta { flex-grow: 2; margin-bottom: -0.3em; }
}
/* This week's puzzle: picture beside the download button, hints and solution */
.weekly { display: grid; grid-template-columns: minmax(0, 340px) 1fr; gap: 24px; align-items: start; }
.weekly .thumb { aspect-ratio: 1 / 1; margin: 0; }
.weekly h3 { margin-top: 1rem; }

@media (max-width: 560px) {
  .weekly { grid-template-columns: 1fr; }
  /* Phone: cover beside the title, the buttons on a full-width row under both */
  .book { grid-template-columns: 80px 1fr; gap: 6px 14px; }
  .book-body { display: contents; }
  .book .cover { grid-row: span 4; }
  .book-buy { grid-column: 1 / -1; }
  .book-buy .btn { flex: 1 1 0; text-align: center; padding: 6px 4px; font-size: 0.8rem; white-space: nowrap; }
}

.note { background: var(--card); border-left: 4px solid var(--highlight); padding: 12px 16px; margin: 1.5rem 0; }
.todo { background: var(--warn-bg); border: 1px dashed var(--warn-line); padding: 2px 6px; border-radius: 3px; font-size: 0.9em; }

/* Puzzle grids */
figure { margin: 1rem 0; }

/* Puzzle diagrams drawn by lib/grids.js */
svg.pz { display: block; max-width: 100%; height: auto; margin: 12px 0; }
.pz text { font-family: var(--type); font-weight: 700; }
.pz .pz-num { fill: var(--ink); }
.pz .pz-new { fill: var(--highlight); }
.pz .pz-muted { fill: var(--muted); font-weight: 400; }
.pz .pz-cell { fill: var(--soft); }
.pz .pz-hl { fill: var(--mark); }
.pz .pz-ring-ink { fill: none; stroke: var(--ink); stroke-width: 2.2; }
.pz .pz-ring-new { fill: none; stroke: var(--highlight); stroke-width: 2.6; }
.pz .pz-stroke { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pz .pz-mark { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.pz .pz-mark-new { stroke: var(--highlight); stroke-width: 2.6; stroke-linecap: round; }
.pz .pz-clue { fill: var(--line); }
.pz .pz-kline { stroke: var(--ink); stroke-width: 1; }
.pz .pz-dots { stroke: var(--rule); stroke-width: 1.4; stroke-dasharray: 0 4.5; stroke-linecap: round; opacity: 0.7; }
.pz .pz-thin { stroke: var(--ink); stroke-width: 0.6; stroke-opacity: 0.55; }
.pz .pz-bold { stroke: var(--ink); stroke-width: 2.4; stroke-linecap: square; }
.pz .pz-frame { fill: none; stroke: var(--ink); stroke-width: 2.4; }
.pz .pz-ring { fill: none; stroke: var(--highlight); stroke-width: 3; }
.pz .pz-ink-fill { fill: var(--ink); }
.pz .pz-new-fill { fill: var(--highlight); }
.pz .pz-island { stroke: var(--ink); stroke-width: 2; }
.pz .pz-bridge { stroke: var(--ink); stroke-width: 2.4; }
.pz .pz-bridge-new { stroke: var(--highlight); stroke-width: 2.8; }
.pz .pz-loop { stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
.pz .pz-loop-new { stroke: var(--highlight); stroke-width: 4.5; stroke-linecap: round; }
.step-grid svg.pz, .pair svg.pz { margin: 0; }
figcaption { font-family: var(--type); font-size: 0.9rem; color: var(--muted); }

details { border: 1px solid var(--line); border-bottom: 4px solid var(--line); border-radius: 2px; padding: 8px 14px; margin: 10px 0; background: var(--card); }
summary { cursor: pointer; font-weight: 600; }
code { font-family: var(--type); background: var(--card); padding: 1px 5px; border-radius: 3px; }

/* Footer: sits at the bottom of the window on short pages, after the content on long ones */
footer.site { border-top: 3px double var(--ink); background: var(--bg); padding: 20px 0; font-family: var(--type); font-size: 0.9rem; color: var(--muted); }
footer.site a { color: var(--muted); }
footer.site a:hover { color: var(--highlight); }

/* Contents lists, breadcrumbs and guide layout */
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
[id] { scroll-margin-top: 1rem; }

.toc { background: var(--card); border: 1px solid var(--line); border-bottom: 4px solid var(--line); border-radius: 2px; padding: 14px 18px 8px; margin: 1.5rem 0; }
.toc h2 { font-family: var(--type); font-size: 0.95rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.toc ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 0 20px; }
.toc li a { display: block; padding: 9px 0; min-height: 44px; border-bottom: 1px dotted var(--rule); text-decoration: none; color: var(--link); font-weight: 600; }
.toc li a:hover { color: var(--highlight); }
.to-top { margin: 0.8rem 0 0; font-size: 0.95rem; }

.breadcrumb ol { list-style: none; display: block; margin: 0 0 1rem; padding: 0; line-height: 1.6; font-family: var(--type); font-size: 0.9rem; color: var(--muted); }
.breadcrumb li { display: inline; }
.breadcrumb li + li::before { content: "\203A"; margin: 0 8px; }
.breadcrumb a { color: var(--muted); }
.meta-line { font-family: var(--type); font-size: 0.9rem; color: var(--muted); margin: 0 0 1rem; }

.steps { list-style: none; counter-reset: step; padding: 0; margin: 1rem 0; }
.steps > li { counter-increment: step; border-top: 1px dotted var(--rule); padding: 1rem 0; }
.step { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; }
.step-text { flex: 1 1 300px; }
.step-text p { margin: 0; }
.step-text p::before { content: "Step " counter(step); display: block; font-family: var(--type); font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--highlight); }
.step-grid { flex: 0 0 auto; }
.pair { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.pair .arrow { font-size: 1.4rem; color: var(--muted); }

@media print {
  header.site, footer.site, .btn-row, .tools, .js-print, .toc, .game-filter, .breadcrumb { display: none; }
  :root { color-scheme: light; --bg: #fff; --card: #fff; --soft: #fff; --ink: #000; --line: #999; --mark: #ddd; --grain: none; }
  body { background-image: none; }
}
