/* "How hard can it be?" — a reading-first stylesheet.
   Warm paper, soft ink, a muted sage accent, a serif at a comfortable size. */

:root {
  --paper: #f6f1e7;
  --paper-2: #efe8da;
  --card: #fbf8f1;
  --ink: #2f2a24;
  --ink-2: #5a5249;
  --ink-3: #857b6f;
  --rule: #e2d9c8;
  --accent: #4f7a63;         /* sage */
  --accent-soft: #e3ebe3;
  --link: #3f6b55;
  --mark: #f1e2b8;
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 10px 30px rgba(60, 45, 20, .08);
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1f1d1a;
    --paper-2: #26231f;
    --card: #2a2622;
    --ink: #e8e1d5;
    --ink-2: #c3b9aa;
    --ink-3: #988e80;
    --rule: #3a352f;
    --accent: #8fb79f;
    --accent-soft: #2c3830;
    --link: #9cc4ab;
    --mark: #4a4130;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .3);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 20px/1.72 var(--serif);
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

@media (max-width: 600px) { body { font-size: 18.5px; line-height: 1.68; } }

::selection { background: var(--mark); }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }

img { max-width: 100%; height: auto; display: block; }

.measure { max-width: 680px; margin: 0 auto; padding: 0 24px; }
.wide { max-width: 1040px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 480px) { .measure, .wide { padding: 0 16px; } }

/* ---------- top strip ---------- */

.strip { border-bottom: 1px solid var(--rule); font: 500 14px/1 var(--sans); }
.strip .wide { display: flex; justify-content: space-between; align-items: center; gap: 16px; height: 52px; }
.strip a { color: var(--ink-2); text-decoration: none; }
.strip a:hover { color: var(--ink); }
.strip .series { font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- headings ---------- */

.kicker {
  font: 700 13px/1 var(--sans);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 18px;
}

header.chapter { padding: 72px 0 24px; }
header.chapter h1 {
  font: 600 clamp(36px, 6vw, 52px)/1.1 var(--serif);
  letter-spacing: -.015em;
  margin: 0 0 18px;
  text-wrap: balance;
}
header.chapter .dek { font-size: 1.15em; color: var(--ink-2); margin: 0; font-style: italic; text-wrap: pretty; }
header.chapter .meta { font: 400 14px/1.4 var(--sans); color: var(--ink-3); margin-top: 22px; }

article { padding-bottom: 40px; }
article p { margin: 0 0 1.15em; text-wrap: pretty; hyphens: auto; }
article h2 {
  font: 600 1.45em/1.25 var(--serif);
  margin: 2.2em 0 .7em;
  letter-spacing: -.01em;
  text-wrap: balance;
}
article h3 { font: 700 .95em/1.3 var(--sans); margin: 1.8em 0 .5em; letter-spacing: .01em; }
article ul, article ol { padding-left: 1.3em; margin: 0 0 1.2em; }
article li { margin: 0 0 .45em; }
article li::marker { color: var(--accent); }
article strong { font-weight: 700; }
article code {
  font: .82em var(--mono);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: .1em .35em;
  white-space: nowrap;
}

article .lede::first-letter {
  float: left;
  font-size: 3.3em;
  line-height: .9;
  padding: .08em .1em 0 0;
  color: var(--accent);
  font-weight: 600;
}

hr { border: 0; text-align: center; margin: 2.4em 0; }
hr::before { content: "· · ·"; color: var(--ink-3); letter-spacing: .6em; }

blockquote {
  margin: 1.6em 0;
  padding: .2em 0 .2em 1.1em;
  border-left: 3px solid var(--accent);
  color: var(--ink-2);
  font-style: italic;
}

.aside {
  font: 400 16.5px/1.6 var(--sans);
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 18px 22px;
  margin: 1.8em 0;
  color: var(--ink);
}
.aside p:last-child { margin-bottom: 0; }
.aside strong:first-child { display: block; margin-bottom: 4px; }

/* numbers that deserve a beat */
.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 1.6em 0 1.8em; font-family: var(--sans); }
.figures div { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 14px 16px; }
.figures b { display: block; font: 600 28px/1.1 var(--serif); color: var(--accent); margin-bottom: 4px; }
.figures span { font-size: 14px; color: var(--ink-2); line-height: 1.4; display: block; }
@media (max-width: 600px) { .figures { grid-template-columns: 1fr; } }

/* ---------- figures (screenshots) ---------- */

figure.shot { margin: 2em 0 2.2em; }
figure.shot.bleed { margin-left: calc(50% - min(520px, 50vw - 16px)); margin-right: calc(50% - min(520px, 50vw - 16px)); }
figure.shot .frame {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  background: var(--card);
}
figure.shot figcaption {
  font: 400 14.5px/1.5 var(--sans);
  color: var(--ink-3);
  margin: 12px 4px 0;
  text-wrap: pretty;
}
figure.shot figcaption b { color: var(--ink-2); font-weight: 600; }

/* ---------- chapter list (landing) ---------- */

.toc { list-style: none; padding: 0; margin: 2em 0; display: grid; gap: 12px; }
.toc li { margin: 0; }
.toc a {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 4px 18px;
  text-decoration: none;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 20px 22px;
  transition: border-color .15s, transform .15s;
}
.toc a:hover { border-color: var(--accent); transform: translateY(-1px); }
.toc .n { grid-row: span 2; font: 600 44px/1 var(--serif); color: var(--accent); }
.toc .t { font: 600 1.1em/1.3 var(--serif); }
.toc .d { font: 400 15.5px/1.5 var(--sans); color: var(--ink-2); }

/* ---------- prev / next ---------- */

nav.pager { border-top: 1px solid var(--rule); margin-top: 48px; padding-top: 28px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; font-family: var(--sans); }
nav.pager a { text-decoration: none; color: var(--ink); display: block; padding: 4px 0; }
nav.pager small { display: block; font-size: 13px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
nav.pager span { font: 600 18px/1.3 var(--serif); }
nav.pager a:hover span { color: var(--link); }
nav.pager .next { text-align: right; grid-column: 2; }

footer.end { font: 400 14px/1.5 var(--sans); color: var(--ink-3); padding: 40px 0 56px; }
footer.end a { color: var(--ink-2); }

/* ---------- layout with a contents sidebar ---------- */

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 48px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}
.layout > main { max-width: 680px; min-width: 0; }

.sidebar { position: sticky; top: 0; align-self: start; max-height: 100vh; overflow-y: auto; padding: 72px 0 32px; scrollbar-width: thin; }
.sidebar summary { display: none; }

.contents { font: 400 15px/1.35 var(--sans); }
.contents .nav-label,
.contents .ch {
  display: block;
  font: 600 11.5px/1.3 var(--sans);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-decoration: none;
  margin: 0 0 10px;
}
.contents .nav-label { margin-bottom: 14px; }
.contents .home {
  display: block;
  color: var(--ink);
  text-decoration: none;
  padding: 3px 0 3px 12px;
  border-left: 2px solid var(--accent);
  margin-bottom: 22px;
  font-weight: 500;
}
.contents .group { margin: 0 0 20px; }
.contents .ch:hover { color: var(--ink); }
.contents .group.current .ch { color: var(--accent); }
.contents .ch .num { display: inline-block; min-width: 1.4em; }

.contents ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
.contents li { margin: 0; }
.contents li a {
  display: block;
  padding: 4px 0 4px 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--ink-2);
  text-decoration: none;
}
.contents li a:hover { color: var(--ink); }
.contents li a.active { border-left-color: var(--accent); color: var(--ink); font-weight: 500; }
.contents .home.is-page { border-left-color: var(--accent); }

article h2[id] { scroll-margin-top: 24px; }

@media (max-width: 1000px) {
  .layout { display: block; padding: 0; }
  .layout > main { margin: 0 auto; padding: 0 24px; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    max-height: none;
    padding: 0;
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--rule);
  }
  .sidebar summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    list-style: none;
    padding: 0 24px;
    height: 48px;
    font: 600 14px/1 var(--sans);
    color: var(--ink-2);
  }
  .sidebar summary::-webkit-details-marker { display: none; }
  .sidebar summary::after { content: "▾"; color: var(--ink-3); }
  .sidebar details[open] summary::after { content: "▴"; }
  .sidebar .contents { padding: 8px 24px 20px; max-height: 70vh; overflow-y: auto; }
  .sidebar .contents .nav-label { display: none; }
}
@media (max-width: 480px) {
  .layout > main { padding: 0 16px; }
  .sidebar summary, .sidebar .contents { padding-left: 16px; padding-right: 16px; }
}

/* In the sidebar layout, text keeps its measure and wide figures fill the column
   (rather than bleeding left over the contents). */
.layout > main { max-width: none; }
.layout header.chapter,
.layout article > *,
.layout nav.pager,
.layout footer.end,
.layout .toc { max-width: 680px; }
.layout article > figure.shot { max-width: none; margin-left: 0; margin-right: 0; }
.strip .wide { max-width: 1120px; }

/* ---------- zoomable screenshots ---------- */

figure.shot img { cursor: zoom-in; }
figure.shot img:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.lightbox {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  background: transparent;
  display: none;
  cursor: zoom-out;
}
.lightbox[open] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px 24px;
  animation: lb-in .18s ease-out;
}
.lightbox::backdrop { background: rgba(24, 20, 16, .95); }
.lightbox img {
  max-width: min(100%, 1800px);
  max-height: calc(100dvh - 130px);
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  background: #fff;
}
.lightbox .lb-caption {
  margin: 0;
  max-width: 860px;
  font: 400 15px/1.5 var(--sans);
  color: #e8e1d5;
  text-align: center;
  cursor: default;
}
.lightbox .lb-caption b { color: #fff; }
.lightbox .lb-caption a { color: #9cc4ab; }
.lightbox .lb-close {
  position: fixed;
  top: 14px;
  right: 18px;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  font: 400 28px/1 var(--sans);
  cursor: pointer;
}
.lightbox .lb-close:hover { background: rgba(255, 255, 255, .22); }
html.lb-open { overflow: hidden; }
@keyframes lb-in { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .lightbox[open] { animation: none; } }
