/* The Second Time Is a Bug: microsite styles.
   Colours and type come from the book cover (tools/cover/cover.html).
   Red means "the guard" and nothing else, as in the book's figures. */

@font-face { font-family: "Source Serif 4"; font-weight: 400; font-style: normal; font-display: swap; src: url("/assets/fonts/source-serif-4-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-weight: 400; font-style: italic; font-display: swap; src: url("/assets/fonts/source-serif-4-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-weight: 600; font-style: normal; font-display: swap; src: url("/assets/fonts/source-serif-4-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-weight: 700; font-style: normal; font-display: swap; src: url("/assets/fonts/source-serif-4-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("/assets/fonts/inter-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("/assets/fonts/inter-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("/assets/fonts/inter-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url("/assets/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }

:root {
  --ink: #12161f;
  --ink-2: #1c2230;
  --paper: #f3efe6;
  --card: #fbf8f1;
  --text: #1d2230;
  --slate: #555c6b;
  --muted: #aab1bf;
  --line: #d9d1c1;
  --line-ink: #2c3342;
  --guard: #e0452f;
  --guard-text: #b8322a;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --gutter: clamp(1rem, 4vw, 2.5rem);
  --section: clamp(3.5rem, 6vw, 5.5rem);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0 0 1.1em; text-wrap: pretty; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; border-radius: 2px; }
code { font-family: var(--mono); font-size: 0.82em; font-variant-numeric: normal; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 10;
  background: var(--paper); color: var(--ink);
  padding: 0.6rem 1rem; font-family: var(--sans); font-weight: 600;
}
.skip:focus { top: 1rem; }

.wrap { width: 100%; max-width: 72rem; margin: 0 auto; padding: 0 var(--gutter); }

.paper { background: var(--paper); color: var(--text); }
.ink { background: var(--ink); color: var(--paper); }
section { padding: var(--section) 0; }
.paper + .paper { padding-top: 0; }
/* A hairline between consecutive paper sections, as wide as the content. */
.paper + .paper::before {
  content: ""; display: block;
  width: calc(min(100%, 72rem) - 2 * var(--gutter));
  margin: 0 auto var(--section);
  border-top: 1px solid var(--line);
}

/* The layout of every section after the hero: a rail on the left for the
   heading (or the cover), the body on the right. One grid, so every
   section lines up with the next. */
.row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem 4.5rem; }
.rail h2 { margin-bottom: 0.4em; }
.rail-note { color: var(--slate); font-size: 1.05rem; margin: 0; }
.ink .rail-note { color: var(--muted); }
.body > :last-child { margin-bottom: 0; }
@media (max-width: 59.99rem) { .rail:empty { display: none; } }
@media (min-width: 60rem) {
  .row { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
  .rail { align-self: start; position: sticky; top: 2.5rem; }
  .rail h2 { font-size: clamp(1.9rem, 1rem + 1.6vw, 2.5rem); }
}

h2 {
  font-weight: 600;
  font-size: clamp(1.9rem, 1.2rem + 2.6vw, 2.9rem);
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin-bottom: 0.7em;
}
h3 { font-family: var(--sans); font-weight: 600; font-size: 1rem; line-height: 1.4; }

/* ---------- Hero ---------- */

.hero {
  background: var(--ink);
  color: var(--paper);
  min-height: min(100svh, 62rem);
  display: flex;
  align-items: center;
  padding: clamp(3rem, 8vw, 6rem) 0;
}
.hero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(2.5rem, 6vw, 4rem);
  align-items: center;
}
.hero-motif { width: min(100%, 26rem); }
.hero-motif svg { overflow: visible; }
.hero-motif .loop, .closing .mini path {
  fill: none; stroke: var(--paper); stroke-width: 8;
  stroke-linecap: round; stroke-linejoin: round;
}
.hero-motif .head, .closing .mini polygon { fill: var(--paper); }
.hero-motif .guard, .closing .mini line { stroke: var(--guard); stroke-width: 9; }

.title {
  font-weight: 700;
  font-size: clamp(3rem, 0.9rem + 8.6vw, 6.6rem);
  line-height: 0.98;
  letter-spacing: -0.015em;
  font-variant-numeric: normal;
}
.title span { display: block; white-space: nowrap; }
.rule { width: 7.5rem; height: 0.4rem; background: var(--guard); margin: clamp(1.75rem, 4vw, 2.5rem) 0 1.5rem; }
.subtitle {
  font-family: var(--sans); font-weight: 400;
  font-size: clamp(1.15rem, 0.9rem + 1vw, 1.5rem);
  line-height: 1.35; color: var(--muted); max-width: 22em; margin-bottom: 1.25rem;
}
.byline {
  font-family: var(--sans); font-weight: 600; font-size: 0.95rem;
  letter-spacing: 0.16em; text-transform: uppercase; margin-bottom: 2.5rem;
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.75rem; font-family: var(--sans); font-size: 1rem; }
.actions p { margin: 0; }
.btn {
  display: inline-block; font-family: var(--sans); font-weight: 600; font-size: 1rem;
  padding: 0.85rem 1.4rem; border-radius: 3px; text-decoration: none;
}
.btn-light { background: var(--paper); color: var(--ink); }
.btn-light:hover { background: #fff; }
.link-light { color: var(--paper); }
.soon { color: var(--paper); font-weight: 500; }
.note { color: var(--muted); flex-basis: 100%; font-size: 0.95rem; }

@media (min-width: 56rem) {
  .hero-grid { grid-template-columns: 1.25fr 1fr; }
  .hero-motif { order: 2; width: 100%; justify-self: end; }
}

/* The page's one moment: the loop comes round a second time and the guard stops it. */
@media (prefers-reduced-motion: no-preference) {
  .hero-motif .loop { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.7s cubic-bezier(.55,.1,.35,1) 0.25s forwards; }
  .hero-motif .head { opacity: 0; animation: appear 0.2s ease-out 1.85s forwards; }
  .hero-motif .guard { transform-box: fill-box; transform-origin: center; transform: scaleY(0); animation: stop 0.35s cubic-bezier(.2,.8,.2,1.2) 2.05s forwards; }
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes appear { to { opacity: 1; } }
@keyframes stop { to { transform: scaleY(1); } }

/* ---------- Problem ---------- */

.lede { font-size: clamp(1.25rem, 1.05rem + 0.7vw, 1.5rem); line-height: 1.5; }
.turn { font-size: clamp(1.25rem, 1.05rem + 0.7vw, 1.5rem); font-style: italic; margin: 1.6em 0 0; }

/* ---------- Thesis ---------- */

.thesis blockquote { margin: 0; max-width: 56rem; }
.thesis blockquote p {
  font-weight: 600;
  font-size: clamp(1.9rem, 1rem + 3.4vw, 3.6rem);
  line-height: 1.12; letter-spacing: -0.012em; margin: 0;
}
.thesis-note { color: var(--muted); margin: 2.5rem 0 0; font-size: 1.15rem; max-width: 44rem; }

/* ---------- Exhibit ---------- */

.panels { display: grid; grid-template-columns: 1fr; gap: 2rem; margin: 3rem 0 0; }
@media (min-width: 64rem) { .panels { grid-template-columns: 1fr 1.15fr; align-items: stretch; } }
.panel { margin: 0; min-width: 0; display: flex; flex-direction: column; }
.panel .code { flex: 1 1 auto; }
.panel figcaption { font-family: var(--sans); font-size: 0.95rem; line-height: 1.5; color: var(--slate); margin-bottom: 0.75rem; }
.panel figcaption strong { color: var(--text); font-weight: 600; }
.code {
  margin: 0; background: var(--ink); color: #dfe3ea;
  font-family: var(--mono); font-size: 0.8rem; line-height: 1.65;
  padding: 1.25rem 1.4rem; border-radius: 4px;
  overflow-x: auto; white-space: pre; tab-size: 2;
  font-variant-numeric: normal;
}
.code code { font-size: inherit; }
.code .del { color: var(--muted); }
.code .add { color: #f3efe6; }
.code .cmd { color: var(--muted); }
.code .fail { color: #ff7a63; font-weight: 400; }
.panel-guard { position: relative; }
/* Phones get the same lines rewrapped to 40 columns, so nothing hides off the side. */
.code-phone, .phone-note { display: none; }
@media (max-width: 40rem) {
  .code-wide { display: none; }
  .code-phone { display: block; font-size: 0.76rem; padding: 1rem 1.1rem; }
  .phone-note { display: inline; }
}
.panel-guard .code { border-left: 6px solid var(--guard); }
.after { color: var(--text); }

/* ---------- Method ---------- */

.steps { list-style: none; counter-reset: step; padding: 0; margin: 0; }
.steps li:first-child { border-top: 0; padding-top: 0; }
.steps li {
  counter-increment: step;
  display: grid; grid-template-columns: 3rem 1fr; column-gap: 1rem;
  padding: 1.25rem 0; border-top: 1px solid var(--line);
}
.steps li::before {
  content: counter(step);
  grid-row: span 2;
  font-family: var(--serif); font-weight: 600; font-size: 2rem; line-height: 1;
  color: var(--slate); font-variant-numeric: lining-nums;
}
.steps h3 { font-family: var(--serif); font-size: 1.3rem; font-weight: 600; margin-bottom: 0.3rem; }
.steps p { margin: 0; color: var(--text); }

.exception { margin: 2rem 0 0; padding: 1.1rem 1.25rem; border-left: 4px solid var(--guard); background: var(--card); }

/* ---------- Pattern card ---------- */

.pcard {
  background: var(--card);
  border: 1px solid #cbc2b0;
  outline: 1px dashed #b9b09e; outline-offset: 0.7rem;
  margin: 0.7rem;
  padding: 1.5rem 1.6rem 0.5rem;
  font-size: 1rem; line-height: 1.55;
}
.pcard header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding-bottom: 0.9rem; border-bottom: 2px solid var(--text); }
.pcard h3 { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.pid { font-family: var(--mono); font-size: 0.85rem; color: var(--slate); }
.pcard dl { margin: 0; }
.pcard dl > div { display: grid; grid-template-columns: 1fr; padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
.pcard dl > div:last-child { border-bottom: 0; }
.pcard dt { font-family: var(--sans); font-weight: 600; font-size: 0.85rem; color: var(--slate); }
.pcard dd { margin: 0; }
@media (min-width: 36rem) {
  .pcard dl > div { grid-template-columns: 7rem 1fr; column-gap: 1rem; }
  .pcard dt { padding-top: 0.15rem; }
}

/* ---------- Drills ---------- */

.drills h2 { color: var(--paper); }
.drills p { color: var(--muted); }
.mistakes {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: 1fr; column-gap: 3rem;
}
@media (min-width: 48rem) { .mistakes { grid-template-columns: 1fr 1fr; } }
.mistakes li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1.5rem;
  padding: 1rem 0; border-bottom: 1px solid var(--line-ink);
  font-size: 1.1rem; line-height: 1.45;
}
.mistakes li > code { color: var(--muted); font-size: 0.8rem; flex: none; }
.mistakes li span code { color: var(--paper); font-size: 0.85em; }

/* ---------- What you get ---------- */

.cover { display: block; width: min(60vw, 15rem); margin-top: 1.5rem; }
.cover img {
  width: 100%; height: auto;
  box-shadow: 0 1px 2px rgba(18,22,31,.25), 0 18px 40px -12px rgba(18,22,31,.45);
  border-radius: 2px 4px 4px 2px;
}
.facts { list-style: none; padding: 0; margin: 0 0 2rem; }
.facts li:first-child { padding-top: 0; border-top: 0; }
.facts li { padding: 0.9rem 0; border-top: 1px solid var(--line); }
.facts li:last-child { border-bottom: 1px solid var(--line); }
.facts strong { font-weight: 600; }

/* ---------- Contents ---------- */

.toc { display: grid; grid-template-columns: 1fr; gap: 2rem 3rem; }
@media (min-width: 40rem) { .toc { grid-template-columns: 1fr 1fr; } }
.toc h3 { color: var(--slate); font-size: 0.9rem; margin-bottom: 0.5rem; }
.toc ol { margin: 0; padding-left: 1.6rem; }
.toc li { padding: 0.15rem 0; font-size: 1.15rem; font-variant-numeric: lining-nums; }
.toc li::marker { color: var(--slate); font-family: var(--sans); font-size: 0.85rem; }
.appx { margin: 2.5rem 0 0; color: var(--slate); font-family: var(--sans); font-size: 0.95rem; }

/* ---------- Audience ---------- */

.two { display: grid; grid-template-columns: 1fr; gap: 2rem 3rem; align-content: start; }
@media (min-width: 48rem) { .two { grid-template-columns: 1fr 1fr; } }
.two h3 { color: var(--slate); font-size: 0.9rem; margin-bottom: 0.5rem; }
.two ul { list-style: none; margin: 0; padding: 0; }
.two li { padding: 0.75rem 0; border-top: 1px solid var(--line); }
.needs { grid-column: 1 / -1; margin: 0; font-style: italic; }

/* ---------- Author ---------- */

.links { display: flex; gap: 1.5rem; font-family: var(--sans); font-size: 1rem; margin: 1.5rem 0 0; }

/* ---------- Closing ---------- */

.closing .mini { width: 9rem; margin: 0.6rem 0 0; overflow: visible; }
.closing .mini path { stroke-width: 11; }
.closing .mini line { stroke-width: 12; }
.closing h2 { font-size: clamp(2.2rem, 1.2rem + 3vw, 3.6rem); margin-bottom: 2rem; }

/* ---------- Footer ---------- */

.foot {
  background: var(--ink); color: var(--muted);
  font-family: var(--sans); font-size: 0.85rem; line-height: 1.6;
  padding: 2.5rem 0 3rem; border-top: 1px solid var(--line-ink);
}
.foot p { margin: 0 0 0.4rem; max-width: 48rem; }

/* ---------- 404 ---------- */

.lost { min-height: 100svh; display: flex; align-items: center; }
.lost h1 { font-size: clamp(2.4rem, 1.4rem + 4vw, 4.5rem); line-height: 1.05; font-weight: 700; margin-bottom: 1.5rem; }
.lost p { color: var(--muted); font-family: var(--sans); }

/* ---------- Questions ---------- */

.faq-list { display: grid; grid-template-columns: 1fr; gap: 0; }
.qa { padding: 1.25rem 0; border-bottom: 1px solid var(--line); }
.qa:first-child { padding-top: 0; }
.qa:last-child { border-bottom: 0; padding-bottom: 0; }
.qa h3 { font-family: var(--serif); font-size: 1.2rem; font-weight: 600; margin-bottom: 0.35rem; }
.qa p { margin: 0; }
