:root {
  --bg: #ffffff; --ink: #111111; --muted: #555555; --line: #d4d4d4; --raise: #f5f5f5;
  --model: #2348a8; --good: #1d6b2f; --bad: #b0201a; --hl: #e9e9e9;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141414; --ink: #e8e8e8; --muted: #a0a0a0; --line: #343434; --raise: #1d1d1d;
    --model: #8fb0ff; --good: #7cc98e; --bad: #f27a6e; --hl: #2c2c2c;
  }
}
:root[data-theme="dark"] {
  --bg: #141414; --ink: #e8e8e8; --muted: #a0a0a0; --line: #343434; --raise: #1d1d1d;
  --model: #8fb0ff; --good: #7cc98e; --bad: #f27a6e; --hl: #2c2c2c;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 17px/1.55 var(--serif); }
a { color: inherit; text-underline-offset: 2px; }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px 40px; }

.top { display: flex; align-items: baseline; padding: 20px 0 32px; font: 13px/1 var(--mono); }
.brand { font-weight: 700; text-decoration: none; }

h1 { font-size: 34px; font-weight: 400; line-height: 1.1; letter-spacing: -.01em; margin: 0 0 10px; }
.lead { font-style: italic; margin: 0 0 28px; }
.foot { color: var(--muted); font-size: 13px; margin-top: 56px; padding-top: 12px; border-top: 1px solid var(--ink); }

.ls { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--ink); }
.ls li { display: grid; grid-template-columns: 12em 1fr auto; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ls .st { color: var(--muted); font-style: italic; }
.ls .st.live { color: var(--good); }
@media (max-width: 560px) { .ls li { grid-template-columns: 1fr auto; } .ls li span:nth-child(2) { grid-column: 1 / -1; order: 3; color: var(--muted); } }

.step { font-size: 17px; font-weight: 400; margin: 0 0 10px; }
.step b { display: inline-grid; place-items: center; width: 1.5em; height: 1.5em; margin-right: 6px; border: 1px solid var(--ink); border-radius: 50%; font: 700 12px/1 var(--mono); }

/* Both panels share the parent's three rows, so the two boards start at the same height. */
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 40px; }
.cols > .panel { display: grid; grid-row: span 3; grid-template-rows: subgrid; align-content: start; }
@media (max-width: 820px) { .cols { grid-template-columns: 1fr; } .cols > .panel + .panel { margin-top: 24px; } }
.head { padding-bottom: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

button, select { font: 13px/1 var(--mono); color: var(--ink); background: var(--bg); border: 1px solid var(--ink); border-radius: 0; padding: 6px 10px; cursor: pointer; }
button:hover { background: var(--ink); color: var(--bg); }
button.ghost, select { border-color: var(--line); }
button:disabled, input:disabled { opacity: .45; cursor: default; background: var(--bg); color: var(--ink); }

.status { font: 13px/1.5 var(--mono); color: var(--muted); margin-top: 8px; min-height: 1.5em; }
.bar { height: 2px; margin-top: 12px; background: var(--line); }
.bar > i { display: block; height: 100%; width: 0; background: var(--ink); }
.levels { display: flex; align-items: center; gap: 12px; }
.levels input { flex: 1; accent-color: var(--ink); }
.levels .lvl { color: var(--muted); min-width: 6em; text-align: right; }
button.primary { font-size: 15px; padding: 10px 22px; background: var(--ink); color: var(--bg); }
button.primary:hover { opacity: .85; }
.hint { font-size: 14px; font-style: italic; color: var(--muted); }
.hint.warn { color: var(--bad); font-style: normal; }
.bar[hidden] { display: none; }
.board.empty { position: relative; }
.board.empty::after { content: "press Solve"; position: absolute; inset: 0; display: grid; place-items: center; font-style: italic; color: var(--muted); background: color-mix(in srgb, var(--bg) 70%, transparent); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.legend i { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; margin-right: 6px; border: 1px solid var(--line); font-style: normal; color: var(--ink); vertical-align: middle; }
.legend i.clue { font-weight: 700; } .legend i.gen { color: var(--model); } .legend i.bad { color: var(--bad); } .legend i.changed { background: var(--hl); }
.stats .ok { color: var(--good); font-weight: 700; } .stats .no { color: var(--bad); font-weight: 700; }
.seg { margin-top: 10px; text-align: center; font-size: 14px; font-style: italic; color: var(--muted); }
.seg button { font-style: normal; margin-left: 6px; padding: 3px 8px; border-color: var(--line); color: var(--muted); }
.seg button + button { margin-left: -1px; }
.seg button.snd { margin-left: 14px; }
.seg button.snd[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); }
.seg button[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); position: relative; }
.seg button:hover { background: var(--raise); color: var(--ink); }

.board { display: grid; grid-template-columns: repeat(9, 1fr); width: 100%; max-width: 380px; aspect-ratio: 1; border: 2px solid var(--ink); margin: 0 auto; }
.cell { display: flex; align-items: center; justify-content: center; font-size: clamp(14px, 3.8vw, 19px); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.bx { border-right-color: var(--ink); }
.cell.by { border-bottom-color: var(--ink); }
.cell.clue { font-weight: 700; }
.cell.gen { color: var(--model); }
.cell.changed { background: var(--hl); }
.cell.bad { color: var(--bad); }
.cell input { width: 100%; height: 100%; border: 0; background: transparent; color: inherit; font: inherit; text-align: center; outline: none; }
.cell input:focus { background: var(--hl); }
.stats { text-align: center; color: var(--muted); margin-top: 12px; }
.stats b { color: var(--ink); font-weight: 400; }

.stack > .panel + .panel { margin-top: 28px; }
.stack .levels { margin: 4px 0 14px; }
.row .seg { margin-top: 0; }
.stack .seg { text-align: left; }
.stack .legend { justify-content: flex-start; }
.opts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 16px; align-items: center; }
.opts > span { font-size: 15px; }
.opts .seg { margin: 0; }
.opts .seg button:first-child { margin-left: 0; }
@media (max-width: 560px) { .opts { grid-template-columns: 1fr; gap: 4px; } .opts .seg { margin-bottom: 8px; } }
.legend u { text-underline-offset: 3px; margin-right: 6px; color: var(--ink); }
.story u { text-decoration-thickness: 2px; text-underline-offset: 4px; }
.story { white-space: pre-wrap; font-size: 19px; line-height: 1.7; min-height: 13em; padding: 14px 18px; border: 1px solid var(--line); }
.story .new { background: color-mix(in srgb, var(--hl) 55%, transparent); }
.story.empty { display: grid; place-items: center; color: var(--muted); font-style: italic; }
.story.empty::after { content: "press Write a story"; }

.about { margin-top: 48px; padding-top: 4px; border-top: 1px solid var(--line); }
.prose h2 { font-size: 20px; font-weight: 400; margin: 28px 0 6px; }
.prose p { margin: 0 0 12px; }

.hero { display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: start; margin: 8px 0 36px; }
.hero > a { text-decoration: none; color: inherit; }
.hero .board { max-width: 300px; }
.hero .cell { font-size: 15px; }
.story.mini { font-size: 16px; line-height: 1.6; min-height: 0; height: 300px; overflow: hidden; mask-image: linear-gradient(#000 85%, transparent); }
.cap { grid-column: 1 / -1; font-size: 14px; font-style: italic; color: var(--muted); }
.cap::before { content: "Figure. "; font-style: normal; font-weight: 700; color: var(--ink); }
.ls i { display: block; font-size: 14px; color: var(--muted); }
.next { font-size: 15px; font-style: italic; color: var(--muted); margin: 18px 0 0; }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; } .hero .board { margin: 0 auto; } .story.mini { height: 17em; } }
