/*
 * DanTPro manual: one stylesheet for the index and every module page.
 * Plain CSS, no build step. The same files are shipped in the plugin (offline) and uploaded as-is
 * (online), so every link and asset path is relative.
 *
 * Follows the module panels: neutral greys, the DanT blue and yellow as accents, flat surfaces. Amber and red
 * appear only where the level meter's colours are named.
 * Written for desktop browsers (Rack's platforms); narrow windows still stack sensibly.
 */

/* Handwriting for the annotations (neat-annotations.css, MIT, see neat-annotations-LICENSE.txt). */
@font-face {
  font-family: "Shantell Sans";
  src: url("../fonts/ShantellSans.ttf") format("truetype");
  font-weight: 300 800;
  font-display: swap;
}
@font-face {
  font-family: "Stack Sans Headline";
  src: url("../fonts/StackSansHeadline-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Stack Sans Headline";
  src: url("../fonts/StackSansHeadline-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  /* The accents. */
  --blue: #00adec;
  --yellow: #ffc900;
  --amber: #ff9602;
  --red: #ff1f01;

  /* The page. */
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #e8e8e8;        /* Silver light */
  --text: #242424;             /* Charcoal dark */
  --text-muted: #5c5c5c;
  --border: #d2d2d2;           /* Silver */
  --header-bg: #383838;        /* Charcoal */
  --header-text: #e8e8e8;
  --link: #006f99;             /* the blue, dark enough for text */
  --link-hover: #008cc2;
  --chip-bg: #e8e8e8;
  --chip-text: #383838;
  --code-bg: #e8e8e8;
  --plate: #383838;            /* behind a panel, inverted, as the panel's output block is */

  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-heading: "Stack Sans Headline", var(--font-body);
  --font-mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;

  --measure: 46rem;
  --page: 62rem;
  color-scheme: light;
}

/* Dark: the system setting, unless the reader chose light; or the reader's choice (js/theme.js). The two blocks
   hold the same values, since CSS can't combine a media query with a selector in one list. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1b1b;
    --surface: #242424;
    --surface-2: #2e2e2e;
    --text: #e2e2e2;
    --text-muted: #a8a8a8;
    --border: #3d3d3d;
    --header-bg: #111111;
    --header-text: #e8e8e8;
    --link: #5cc8f2;
    --link-hover: #8fdafa;
    --chip-bg: #383838;
    --chip-text: #e2e2e2;
    --code-bg: #2e2e2e;
    --plate: #d2d2d2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1b1b;
  --surface: #242424;
  --surface-2: #2e2e2e;
  --text: #e2e2e2;
  --text-muted: #a8a8a8;
  --border: #3d3d3d;
  --header-bg: #111111;
  --header-text: #e8e8e8;
  --link: #5cc8f2;
  --link-hover: #8fdafa;
  --chip-bg: #383838;
  --chip-text: #e2e2e2;
  --code-bg: #2e2e2e;
  --plate: #d2d2d2;
  color-scheme: dark;
}

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

html { font-size: 106.25%; scroll-behavior: smooth; }  /* 17 px: every size below scales with it */
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

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

a { color: var(--link); text-underline-offset: 0.15em; }
a:hover { color: var(--link-hover); }

h1, h2, h3, h4 { font-family: var(--font-heading); font-weight: 700; line-height: 1.25; }
h1 { font-size: 2.6rem; margin: 0 0 0.25rem; letter-spacing: 0.01em; }
h3 { font-size: 1.2rem; margin: 2rem 0 0.5rem; }
h4 { font-size: 1.05rem; margin: 1.5rem 0 0.25rem; }
/* Room for the sticky header, so a contents link lands below it. */
h2, h3, h4, details[id], p[id] { scroll-margin-top: 4.5rem; }

/* Section headings: a plain bar in the blue. */
h2 {
  font-size: 1.6rem;
  margin: 3rem 0 0.9rem;
  padding: 0.1rem 0 0.1rem 0.8rem;
  border-left: 6px solid var(--blue);
}

p, ul, ol, dl, table { margin: 0 0 1rem; }
li { margin-bottom: 0.25rem; }

code, kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.05em 0.35em;
}
kbd { border: 1px solid var(--border); border-bottom-width: 2px; }

/* Numbers and values: every number in the text is wrapped in <span class="n"> (tools/manual-numbers.py
   does it), so values line up and read as values. */
.n {
  font-family: var(--font-mono);
  font-size: 0.92em;
  white-space: nowrap;
  background: var(--code-bg);   /* a light grey chip, so a value stands apart from the words around it */
  border-radius: 4px;
  padding: 0.05em 0.3em;
}
/* Inside a panel chip or a key badge the grey would clash; the monospace alone is enough there. */
.chip .n, .key-letters .n { background: none; padding: 0; }

/* ---- Site header and footer ---- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;  /* above the annotations */
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 4px solid var(--blue);
}
.site-header .inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
}
.site-header .brand {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--header-text);
  text-decoration: none;
}
.site-header nav { font-size: 0.95rem; }
.site-header nav a { color: var(--header-text); opacity: 0.85; }
.site-header nav a:hover { opacity: 1; color: var(--blue); }

/* The light and dark switch: shows the theme it changes to. */
.theme-toggle {
  margin-left: auto;
  align-self: center;
  display: flex;
  padding: 0.3rem;
  color: var(--header-text);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle:hover { color: var(--blue); }
.theme-toggle:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.icon-sun { display: none; }

/* A view that shows a panel comes in light and dark, and follows the page. */
img.for-dark { display: none !important; }
:root[data-theme="dark"] img.for-dark { display: block !important; }
:root[data-theme="dark"] img.for-light { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) img.for-dark { display: block !important; }
  :root:not([data-theme="light"]) img.for-light { display: none !important; }
}

:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

.site-footer {
  max-width: var(--page);
  margin: 4rem auto 0;
  padding: 1.5rem 1rem 3rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
}

main {
  max-width: var(--page);
  margin: 0 auto;
  padding: 2rem 1rem 0;
}

/* ---- Module page: hero with the panel beside the intro ---- */

.module-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2rem;
  align-items: start;
}
.module-hero .panel { width: fit-content; margin: 0; }
.plate { padding: 12px; background: var(--plate); border-radius: 8px; }
.module-hero .panel img { display: block; border-radius: 0; }
.module-hero .tagline { color: var(--text-muted); font-size: 1.1rem; margin-bottom: 1.25rem; }
.library-links { margin: -0.75rem 0 1rem; font-size: 0.95rem; }

/* Fact pills. */
.facts { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0; list-style: none; }
.facts li {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.75rem;
  font-size: 0.9rem;
}

/* Body text keeps a readable line length; figures and tables may use the full page. */
.content > p, .content > ul, .content > ol, .content > dl, .content > .callout, .content > h3, .content > h4,
.content > details, .control { max-width: var(--measure); }

/* ---- Table of contents ---- */

nav.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--blue);
  border-radius: 8px;
  padding: 1rem 1.25rem 0.5rem;
  margin: 2rem 0;
}
nav.toc h2 { border: 0; background: none; margin: 0 0 0.5rem; padding: 0; font-size: 1.15rem; }
nav.toc ol { columns: 3 14rem; column-gap: 2.5rem; margin: 0 0 0.5rem; padding-left: 1.6rem; }
nav.toc li { break-inside: avoid; margin-bottom: 0.1rem; }
nav.toc li::marker { color: var(--text-muted); font-family: var(--font-mono); font-weight: 600; }

/* ---- Panel labels, bold and uppercase as on the module ---- */

.chip {
  display: inline-block;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.78em;
  letter-spacing: 0.03em;
  line-height: 1.5;
  padding: 0 0.45em;
  border-radius: 4px;
  background: var(--chip-bg);
  color: var(--chip-text);
  vertical-align: 0.1em;
  white-space: nowrap;
}

/* ---- A control's entry: heading with its chip, then a line of specs ---- */

.control {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  margin: 1.25rem 0;
}
.control h4 { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; margin-top: 0; }
.specs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
  padding: 0;
  list-style: none;
}
.specs li { margin: 0; }
.specs b { color: var(--text); font-weight: 600; }

/* ---- Callouts ---- */

.callout {
  border-left: 4px solid var(--blue);
  background: var(--surface-2);
  border-radius: 0 6px 6px 0;
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}
.callout > :last-child { margin-bottom: 0; }
.callout .title { display: block; font-family: var(--font-heading); font-weight: 700; margin-bottom: 0.25rem; }
.callout.warn { border-left-color: var(--yellow); }

/* ---- Figures ---- */

figure { margin: 1.5rem 0; }
figure img { display: block; border-radius: 6px; }
figcaption { font-size: 0.9rem; color: var(--text-muted); margin-top: 0.5rem; max-width: var(--measure); }

/* Text then the screenshot it describes, the screenshot framed as a panel under the text. */
.split { margin: 1rem 0 1.5rem; }
.split > div > :first-child { margin-top: 0; }
.split > div, .split > p { max-width: var(--measure); }
.split > figure {
  width: fit-content;
  max-width: 100%;
  margin: 1rem 0 2rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.split > figure img { border-radius: 6px; }
.split > figure figcaption { margin-top: 0.6rem; }

/* Several figures side by side, wrapping in a narrow window; .reactions holds the wider low/high pairs. */
.figure-grid, .reactions { display: grid; gap: 1rem 1.25rem; margin: 1.5rem 0; }
.figure-grid { grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.figure-grid.two { grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr)); }
.reactions { grid-template-columns: repeat(auto-fill, minmax(24rem, 1fr)); }
.figure-grid figure, .reactions figure { margin: 0; }
.figure-grid img, .reactions img { width: 100%; }

/* The grid light's layouts: each light enlarged, with its channel count under it. */
.grid-states { display: grid; grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr)); gap: 1rem; margin: 1rem 0 1.5rem; max-width: var(--measure); }
.grid-states figure { margin: 0; text-align: center; }
.grid-states img { box-sizing: content-box; width: 84px; margin: 0 auto; padding: 6px; background: var(--plate); }

/* An image with lettered callouts baked in (tools/annotate.py), and the key beneath it. */
figure.annotated img { border-radius: 0; }
.key { list-style: none; padding: 0; }
.key li { margin-bottom: 0.4rem; }
.key-letters {
  display: inline-block;
  min-width: 4.4em;
  text-align: center;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.85em;
  padding: 0 0.5em;
  margin-right: 0.3em;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
}
.key-letters.yellow { background: var(--yellow); color: #242424; }
.key-letters.ink { background: #383838; }

/* A word in the colour it names (the level meter's colours). */
.swatch { font-weight: 600; }
.swatch::before {
  content: "";
  display: inline-block;
  width: 0.75em;
  height: 0.75em;
  margin-right: 0.3em;
  border-radius: 2px;
  vertical-align: -0.05em;
  background: currentColor;
}
.swatch.blue { color: var(--blue); }
.swatch.amber { color: var(--amber); }
.swatch.red { color: var(--red); }

/* ---- Annotations (neat-annotations.css): a hand-drawn arrow and note on a technical term, where it's
   first explained. One colour: the blue, darker on light pages and lighter on dark pages. ---- */

.ann { --ann-font: "Shantell Sans", cursive; --ann-label-max-width: 170px; --ann-color: light-dark(#006f99, #5cc8f2); --ann-mark: transparent; }
.ann::after { font-size: 0.95rem; font-weight: 500; }
h2 .ann, h3 .ann { --ann-label-max-width: 22rem; }  /* a heading's note stays on one line */

/* The signal flow with notes above and below each stage: one row, with room for the notes. */
/* Fits its content; the padding is the room the notes need (up to 3 lines plus the arrow) above and below,
   and at the sides for notes wider than the first and last boxes. */
.flow.noted {
  width: fit-content;
  max-width: 100%;
  gap: 1.5rem 0.6rem;
  padding: 8.5rem 2rem 8.5rem;
  margin: 1.25rem 0 2rem;
}
/* Two rows of four equal boxes (the .break item ends the first row), wide enough for the notes above the
   first row and below the second. */
.flow.noted li:not(.arrow):not(.break) { width: 11.5rem; min-height: 3.2rem; white-space: nowrap;
  display: flex; flex-direction: column; justify-content: center; }
.flow.noted li.break { flex-basis: 100%; height: 0; padding: 0; margin: 0; border: 0; background: none; }
.flow.noted .ann { display: block; --ann-label-max-width: 11rem; --ann-rotate: -1.5deg; }
.flow.noted .ann::after { font-size: 1rem; font-weight: 600; line-height: 1.15; }
.flow.noted li { font-size: 0.86rem; padding: 0.4rem 0.6rem; }
.flow.noted li.arrow { font-size: 1rem; }

/* ---- Tables ---- */

.table-wrap { overflow-x: auto; margin: 0 0 1.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; background: var(--surface); }
caption { text-align: left; font-family: var(--font-heading); font-weight: 700; padding: 0 0 0.4rem; }
th, td { text-align: left; vertical-align: top; padding: 0.45rem 0.7rem; border: 1px solid var(--border); }
th { background: var(--surface-2); font-weight: 600; }
td:first-child { white-space: nowrap; font-weight: 600; }
.ports td:first-child { white-space: normal; }  /* grouped port names wrap */
.table-note { font-size: 0.92rem; color: var(--text-muted); margin: 0.5rem 0 0; }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }

/* ---- Signal flow (plain HTML boxes, no image); the output stage is inverted, like the panel's output block ---- */

.flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem;
  margin: 1rem 0 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  list-style: none;
}
.flow li {
  margin: 0;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border-bottom: 3px solid var(--blue);
  background: var(--surface-2);
  font-size: 0.9rem;
  line-height: 1.3;
  text-align: center;
}
.flow li small { display: block; color: var(--text-muted); font-size: 0.8rem; }
.flow li.arrow { background: none; border: 0; padding: 0; color: var(--text-muted); font-size: 1.2rem; }
.flow li.out { background: #383838; color: #e8e8e8; border-bottom-color: #383838; }

/* ---- FAQ ---- */

details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin: 0 0 0.6rem;
}
details summary { cursor: pointer; font-weight: 600; }
details summary::marker { color: var(--blue); }
details[open] summary { margin-bottom: 0.5rem; }
details > :last-child { margin-bottom: 0; }

/* ---- Index: module cards ---- */

.intro { max-width: var(--measure); }
.modules {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 1.25rem;
  padding: 0;
  list-style: none;
  margin: 2rem 0;
}
.modules li { margin: 0; }
.card {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--blue);
  border-radius: 10px;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--blue); transform: translateY(-2px); color: inherit; }
.card .thumb { background: var(--plate); padding: 1rem; text-align: center; }
.card .thumb img { max-height: 220px; width: auto; margin: 0 auto; }
.card .body { padding: 0.9rem 1rem 1.1rem; }
.card h2 { border: 0; background: none; margin: 0 0 0.25rem; padding: 0; font-size: 1.3rem; }
.card .meta { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.card p { margin: 0; }

.back-to-top { font-size: 0.9rem; }
