:root {
  --ground: #f5f6f8;
  --surface: #ffffff;
  --hairline: rgba(16, 20, 24, 0.1);
  --text: #10141a;
  --muted: #5b6472;
  --accent: #e05a1f;
  --accent-dim: rgba(224, 90, 31, 0.14);
  --shell-width: 72rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0b0f14;
    --surface: #131922;
    --hairline: rgba(237, 241, 245, 0.09);
    --text: #edf1f5;
    --muted: #7c8b9e;
    --accent: #ff7a33;
    --accent-dim: rgba(255, 122, 51, 0.16);
  }
}

:root[data-theme="dark"] {
  --ground: #0b0f14;
  --surface: #131922;
  --hairline: rgba(237, 241, 245, 0.09);
  --text: #edf1f5;
  --muted: #7c8b9e;
  --accent: #ff7a33;
  --accent-dim: rgba(255, 122, 51, 0.16);
}

:root[data-theme="light"] {
  --ground: #f5f6f8;
  --surface: #ffffff;
  --hairline: rgba(16, 20, 24, 0.1);
  --text: #10141a;
  --muted: #5b6472;
  --accent: #e05a1f;
  --accent-dim: rgba(224, 90, 31, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--ground);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
}

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

a:hover,
a:focus-visible {
  text-decoration-color: var(--accent);
}

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

code, .protocol {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--accent-dim);
  color: var(--text);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}

/* Top bar */
.topbar {
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}

.topbar-inner {
  max-width: var(--shell-width);
  margin: 0 auto;
  padding: 1.1rem 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.wordmark {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 1.3rem;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.wordmark .tally {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0.6rem var(--accent);
  flex-shrink: 0;
}

.wordmark:hover {
  text-decoration: none;
}

nav.help-nav {
  display: flex;
  gap: 1.25rem;
  font-size: 0.9rem;
}

nav.help-nav a {
  color: var(--muted);
  text-decoration: none;
}

nav.help-nav a:hover,
nav.help-nav a[aria-current="page"] {
  color: var(--text);
}

nav.help-nav a[aria-current="page"] {
  font-weight: 600;
}

/* Shell: sidebar + content, two columns on wide viewports */
.help-shell {
  max-width: var(--shell-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

@media (min-width: 64rem) {
  .help-shell {
    display: grid;
    grid-template-columns: 14rem minmax(0, 1fr);
    gap: 3rem;
    align-items: start;
  }
}

/* Sidebar — two real copies of the same nav in the DOM (see
   inc/sidebar.php), toggled by plain `display`, not by fighting a
   closed <details>'s native hiding — tried overriding that first and it
   didn't work in a real deployed test: modern browsers hide closed-
   details content via `content-visibility`, which a same-specificity
   `display` override doesn't undo. .help-sidebar-desktop is the
   always-visible plain copy (wide viewports only); .help-sidebar-mobile
   is the real collapsible "Contents" <details> disclosure (narrow
   viewports only, no JS). */
.help-sidebar {
  padding: 1.5rem 0;
  font-size: 0.9rem;
}

.help-sidebar-desktop {
  display: none;
}

@media (min-width: 64rem) {
  .help-sidebar {
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
  }
  .help-sidebar-desktop {
    display: block;
  }
  .help-sidebar-mobile {
    display: none;
  }
}

.help-sidebar-toggle summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  padding: 0.5rem 0;
  list-style: none;
}

.help-sidebar-toggle summary::-webkit-details-marker {
  display: none;
}

.help-sidebar-toggle summary::after {
  content: "▾";
  color: var(--muted);
  margin-left: 0.4rem;
  font-size: 0.75em;
}

.help-sidebar-toggle[open] summary::after {
  content: "▴";
}

.help-sidebar-groups {
  padding: 0.5rem 0 1rem;
}

.help-sidebar-toplink {
  display: block;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  padding: 0.3rem 0 1rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--hairline);
}

.help-sidebar-group {
  margin-bottom: 1.5rem;
}

.help-sidebar-group h3 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.5rem;
}

.help-sidebar-group a {
  display: block;
  color: var(--muted);
  text-decoration: none;
  padding: 0.3rem 0;
  font-size: 0.88rem;
}

.help-sidebar-group a:hover,
.help-sidebar-group a[aria-current="page"] {
  color: var(--text);
}

.help-sidebar-group a[aria-current="page"] {
  font-weight: 600;
}

/* Content */
main {
  max-width: 46rem;
  padding: 2.75rem 0 5rem;
}

main h1 {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-weight: 400;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  margin: 0 0 0.5rem;
  text-wrap: balance;
}

main .lede {
  font-size: 1.05rem;
  color: var(--muted);
  margin: 0 0 2.5rem;
  max-width: 38rem;
}

main h2 {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-weight: 400;
  font-size: 1.35rem;
  margin: 2.75rem 0 0.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hairline);
}

main h2:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

main h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
}

main p {
  margin: 0 0 1rem;
  max-width: 38rem;
}

main ul, main ol {
  max-width: 38rem;
  padding-left: 1.25rem;
}

main li {
  margin-bottom: 0.4rem;
}

.card-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2rem;
}

.card-links a {
  display: block;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  text-decoration: none;
  color: var(--text);
  flex: 1 1 14rem;
}

.card-links a:hover {
  border-color: var(--accent);
}

.card-links strong {
  display: block;
  margin-bottom: 0.2rem;
}

.card-links span {
  color: var(--muted);
  font-size: 0.88rem;
}

.callout {
  background: var(--accent-dim);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  margin: 1rem 0 1.5rem;
  max-width: 38rem;
  font-size: 0.92rem;
}

.callout p:last-child {
  margin-bottom: 0;
}

footer.help-footer {
  border-top: 1px solid var(--hairline);
  margin-top: 3rem;
}

footer.help-footer .topbar-inner {
  padding: 1.25rem 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Screenshots */
main figure {
  margin: 1rem 0 1.75rem;
  max-width: 38rem;
}

main figure img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--hairline);
  border-radius: 12px;
}

main figcaption {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

/* Print — used both for an actual browser print and as the source Chrome
   headless renders manual.php through for the PDF download. Hides all
   navigation chrome; the manual's own section headings are the only
   wayfinding a printed/PDF copy needs. */
@media print {
  .topbar,
  .help-sidebar,
  footer.help-footer {
    display: none;
  }

  .help-shell {
    display: block;
    max-width: none;
    padding: 0;
  }

  main {
    max-width: none;
    padding: 0;
  }

  main p, main ul, main ol, main .lede {
    max-width: none;
  }

  /* Breaks before each topic (h1 — manual.php has one per section), not
     every h2 subsection — one h2 break per topic on a standalone page
     would be fine, but manual.php has ~40 h2s across all topics
     combined, and breaking on every one of those would bloat the PDF
     with lots of near-empty pages. */
  main h1 {
    break-before: page;
  }

  /* :first-of-type is scoped per-parent, not per-document — since
     manual.php wraps every topic's h1 in its own <section>, EVERY h1 is
     "first-of-type" among its own section's children, which silently
     cancelled the page break above for every topic, not just the first
     (confirmed in a real generated PDF: no break appeared between
     topics at all). main > h1 covers a standalone topic page (h1 is a
     direct child of main there, no <section> wrapper); main >
     section:first-child > h1 covers manual.php's actual first topic. */
  main > h1,
  main > section:first-child > h1 {
    break-before: avoid;
  }

  /* Keeps a subsection heading attached to what follows it, rather than
     landing as the last line on a page with its own content starting
     fresh on the next one. */
  main h2 {
    break-after: avoid;
  }

  a {
    color: var(--text);
    text-decoration: none;
  }

  /* Screenshots are full-resolution iPhone captures (tall, ~0.46
     aspect ratio) — at the on-screen 38rem width they render taller
     than a whole printable page, so every one split across two pages.
     Shrinking them plus break-inside: avoid keeps each figure, image
     and caption together, whole, on one page. */
  main figure {
    max-width: 3.2in;
    break-inside: avoid;
  }

  main figure img {
    max-width: 100%;
  }
}
