/* Leapfrog — reading edition
   Shared stylesheet for leapfrog-book.html and /read/*.html

   Light paper by default: this is long-form reading, not a landing page.
   Dark is available for readers who prefer it and follows the system
   setting automatically. The brand is unchanged — indigo becomes the ink
   and the masthead rather than the whole page. */

:root {
  --indigo:   #12163A;
  --cyan:     #34E0E0;
  --cyan-ink: #0E6E75;          /* cyan darkened enough to read on paper */
  --lavender: #AEBBE6;

  --surface:   #FBFAF7;
  --well:      #F2F1EC;
  --text:      #23252B;
  --text-soft: #5C5F6B;
  --accent:    var(--cyan-ink);
  --heading:   var(--indigo);
  --rule:      rgba(18, 22, 58, 0.14);

  --measure: 60ch;
  --display: "Poppins", system-ui, sans-serif;
  --reading: "Spectral", Georgia, serif;
  --mono:    "IBM Plex Mono", ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface:   #12163A;
    --well:      #0C0F2B;
    --text:      #EEF1FA;
    --text-soft: #AEBBE6;
    --accent:    var(--cyan);
    --heading:   #FFFFFF;
    --rule:      rgba(174, 187, 230, 0.20);
  }
}

:root[data-theme="dark"] {
  --surface:   #12163A;
  --well:      #0C0F2B;
  --text:      #EEF1FA;
  --text-soft: #AEBBE6;
  --accent:    var(--cyan);
  --heading:   #FFFFFF;
  --rule:      rgba(174, 187, 230, 0.20);
}

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

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

body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: var(--reading);
  font-size: 1.125rem;
  line-height: 1.72;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

/* ---- shell ---------------------------------------------------------- */

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.4rem;
}

/* The masthead keeps the brand indigo in both modes. It is the one place
   the dark identity belongs, and it anchors the page. */
.masthead {
  background: var(--indigo);
  padding: 0.85rem 0;
  font-family: var(--display);
  font-size: 0.8125rem;
}

.masthead .wrap { display: flex; align-items: center; gap: 1.35rem; }
.masthead a { color: var(--lavender); text-decoration: none; }
.masthead a:hover { color: var(--cyan); }
.masthead .home { font-weight: 600; color: #fff; margin-right: auto; }

.theme-toggle {
  background: none;
  border: 1px solid rgba(174, 187, 230, 0.3);
  border-radius: 4px;
  color: var(--lavender);
  font: inherit;
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--cyan); border-color: var(--cyan); }

/* ---- the arc: position in the book ---------------------------------- */

.arc { margin: 2.25rem 0 0.5rem; }

/* The caption is what turns the arc from ornament into navigation:
   it names the thing and says where you are. */
.arc-cap {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--display);
  font-size: 0.75rem;
  color: var(--text-soft);
  margin: 0 0 0.5rem;
}
.arc-cap span:first-child { font-weight: 500; }

.arc svg { width: 100%; height: auto; display: block; overflow: visible; }

.arc .bar   { fill: var(--rule); transition: fill 0.12s ease; }
.arc .bar.on { fill: var(--accent); }
.arc .lull  { fill: none; stroke: var(--rule); stroke-width: 2; transition: stroke 0.12s ease; }
.arc .lull.on { fill: var(--accent); stroke: var(--accent); }
.arc .curve { fill: none; stroke: var(--text-soft); stroke-width: 1.5; opacity: 0.35; }

.arc .pnum {
  fill: var(--text-soft);
  font-family: var(--mono);
  font-size: 8px;
  opacity: 0.75;
}

.arc a { cursor: pointer; }
.arc a:hover .bar  { fill: var(--text-soft); }
.arc a:hover .lull { stroke: var(--text-soft); }
.arc a:focus-visible { outline: none; }
.arc a:focus-visible .bar  { fill: var(--accent); }
.arc a:focus-visible .lull { stroke: var(--accent); }
.arc a:focus-visible .hit  { stroke: var(--accent); stroke-width: 1.5; rx: 4; }

/* ---- chapter opening ------------------------------------------------ */

.opener { padding: 0.75rem 0 2.5rem; }

.opener .part {
  font-family: var(--display);
  font-size: 0.875rem;
  color: var(--text-soft);
  margin: 0 0 0.6rem;
}

.opener h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(2rem, 6.5vw, 2.75rem);
  line-height: 1.1;
  letter-spacing: -0.021em;
  color: var(--heading);
  margin: 0 0 0.85rem;
}

.opener .standfirst {
  color: var(--text-soft);
  font-size: 1.1875rem;
  line-height: 1.55;
  margin: 0;
}

/* ---- reading matter ------------------------------------------------- */

.prose h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.375rem;
  line-height: 1.25;
  letter-spacing: -0.012em;
  color: var(--heading);
  margin: 2.9rem 0 0.8rem;
}

.prose h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.0625rem;
  color: var(--text-soft);
  margin: 2.1rem 0 0.55rem;
}

.prose p { margin: 0 0 1.4rem; }

.prose a { color: var(--accent); text-underline-offset: 3px; }

.prose blockquote {
  margin: 2.1rem 0;
  padding-left: 1.3rem;
  border-left: 2px solid var(--accent);
  border-radius: 0;
  color: var(--text-soft);
  font-style: italic;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.8125em;
  background: var(--well);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

.prose pre {
  background: var(--well);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.8125rem;
  line-height: 1.6;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }

/* ---- experiments panel ---------------------------------------------- */

.experiments {
  background: var(--well);
  border-radius: 8px;
  padding: 1.6rem 1.5rem 0.6rem;
  margin: 3.2rem 0 0;
}

.experiments h2 {
  font-family: var(--display);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 0.3rem;
}

.experiments .lede {
  color: var(--text-soft);
  font-size: 0.9375rem;
  margin: 0 0 1.25rem;
}

.experiments ol { margin: 0; padding-left: 1.2rem; }
.experiments li { margin-bottom: 1.15rem; font-size: 1rem; line-height: 1.65; }
.experiments li::marker { color: var(--text-soft); font-size: 0.875rem; }
.experiments li strong { font-family: var(--display); font-weight: 600; color: var(--heading); }

/* ---- chapter to chapter --------------------------------------------- */

.turn {
  display: flex;
  gap: 0.85rem;
  margin: 3.2rem 0 0;
  border-top: 1px solid var(--rule);
  padding-top: 1.6rem;
}

.turn a {
  flex: 1;
  text-decoration: none;
  color: var(--heading);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.9rem 1rem;
  font-family: var(--display);
  font-size: 0.9375rem;
  line-height: 1.35;
}
.turn a:hover { border-color: var(--accent); }
.turn a span {
  display: block;
  font-family: var(--display);
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-soft);
  margin-bottom: 0.25rem;
}
.turn a.next { text-align: right; }

/* ---- contents ------------------------------------------------------- */

.part-head {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--heading);
  margin: 3rem 0 0.2rem;
}
.part-head + .part-note {
  color: var(--text-soft);
  font-size: 0.9375rem;
  margin: 0 0 1.2rem;
}

.toc { list-style: none; margin: 0; padding: 0; }
.toc li { border-top: 1px solid var(--rule); }
.toc li:last-child { border-bottom: 1px solid var(--rule); }

.toc a {
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  gap: 0.75rem;
  align-items: baseline;
  padding: 1rem 0;
  text-decoration: none;
  color: var(--heading);
}
.toc a:hover .title { color: var(--accent); }

.toc .num { font-family: var(--mono); font-size: 0.8125rem; color: var(--text-soft); }
.toc .title { font-family: var(--display); font-weight: 500; font-size: 1.0625rem; }
.toc .blurb {
  grid-column: 2;
  font-size: 0.9688rem;
  color: var(--text-soft);
  line-height: 1.5;
  margin-top: 0.2rem;
}

/* ---- licence and colophon ------------------------------------------- */

.colophon {
  border-top: 1px solid var(--rule);
  margin-top: 3.5rem;
  padding: 1.8rem 0 4rem;
  font-family: var(--display);
  font-size: 0.875rem;
  color: var(--text-soft);
  line-height: 1.65;
}
.colophon a { color: var(--accent); }
.colophon p { margin: 0 0 0.8rem; }
.colophon .whole { font-size: 0.9375rem; color: var(--text); }

/* ---- floor ---------------------------------------------------------- */

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}

::selection { background: var(--cyan); color: var(--indigo); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 30rem) {
  body { font-size: 1.0625rem; }
  .turn { flex-direction: column; }
  .turn a.next { text-align: left; }
}

@media print {
  .masthead, .turn, .arc, .theme-toggle { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .wrap { max-width: none; }
}
