/* viyan.live — built to be read.
 *
 * The reference is Medium, and the parts of Medium worth copying are not the
 * branding: a serif body at 20-21px, a line height near 1.6, a measure around
 * 680px, and a lot of air between paragraphs. That combination is what makes
 * a 1500-word piece feel finishable.
 *
 * NO WEB FONTS. A font file is 100-300KB fetched from someone else's server on
 * every first visit, and it blocks text from appearing while it arrives.
 * Charter ships with macOS and iOS, Sitka with Windows, and Georgia with
 * everything - so the serif stack below lands on a real book face almost
 * everywhere, instantly, with no request at all.
 */

:root {
  --ink: #1a1a19;        /* not black: pure black on white is harsh at length */
  --soft: #5f5f5a;
  --faint: #8a8a84;
  --line: #e6e4de;
  --bg: #ffffff;
  --panel: #f7f7f4;
  --accent: #2f6f4f;

  /* TWO WIDTHS, AND THEY ARE NOT THE SAME THING.
   *
   * `--measure` is the READING COLUMN: Medium sets its article at 680px
   * because long-form prose is read at 65-75 characters a line, and at 21px
   * that is what 680px gives. A theme may narrow it - kids does - because
   * fewer words per line is genuinely easier for a younger reader.
   *
   * `--frame` is the PAGE: the header, the nav, the footer, the lists. It is
   * the same on all four sites on purpose. When the chrome shared the
   * measure, the kids theme's shorter line moved the whole header with it, so
   * clicking from ai.viyan.live to kids.viyan.live made the menu jump sideways
   * - four sites that are meant to read as one masthead, each starting its
   * nav in a different place.
   */
  --measure: 42.5rem;
  --frame: 42.5rem;

  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* WHICH FACE READS THE PROSE, and which one carries the structure. Named
   * separately from the stacks above so a channel's theme can swap the ROLE
   * without restating the fallbacks: science takes its headings in the serif,
   * kids reads better set entirely in the sans. */
  --body-face: var(--serif);
  --head-face: var(--sans);

  /* The reading size, and the corner. Variables because they are the two
   * things a theme for nine-year-olds genuinely needs to change. */
  --read: 1.3rem;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9e7e0;
    --soft: #a7a59c;
    --faint: #78766e;
    --line: #2b2b28;
    --bg: #111110;
    --panel: #1a1a18;
    --accent: #7fbd9a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 1.5rem 5rem;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* The frame, not the measure - see above. */
main, .top, footer { max-width: var(--frame); margin: 0 auto; }

a { color: inherit; }

/* --- header ----------------------------------------------------------- */

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  /* Centred, not baseline: the brand carries the mark, and an SVG on a text
     baseline sits a few pixels low against the nav beside it. */
  align-items: center;
  padding: 1.75rem 0 1.25rem;
  border-bottom: 1px solid var(--line);
}

/* The wordmark keeps the serif in every theme. It is the one element that is
 * the same object on all four sites - a brand that changes face per section
 * is not a brand - so it is the one place `--body-face` is deliberately not
 * used. */
.brand {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.015em;
  text-decoration: none;
}

.top nav { display: flex; flex-wrap: wrap; gap: 1.1rem; }
.top nav a { color: var(--soft); text-decoration: none; font-size: 0.9rem; }
.top nav a:hover { color: var(--accent); }

/* --- index and channel lists ------------------------------------------ */

.lede { padding: 3rem 0 1.5rem; }
.lede h1 {
  font-family: var(--body-face);
  font-size: clamp(2rem, 6vw, 2.75rem);
  line-height: 1.15;
  letter-spacing: -0.022em;
  margin: 0 0 0.5rem;
}
.lede p { color: var(--soft); margin: 0; font-size: 1.05rem; }

.pieces { list-style: none; padding: 0; margin: 0; }
.pieces li { padding: 1.75rem 0; border-top: 1px solid var(--line); }
.pieces h2 {
  font-family: var(--body-face);
  font-size: 1.4rem;
  line-height: 1.25;
  letter-spacing: -0.012em;
  margin: 0.3rem 0 0.45rem;
}
.pieces h2 a { text-decoration: none; }
.pieces h2 a:hover { color: var(--accent); }
.pieces p { margin: 0 0 0.6rem; color: var(--soft); }

.ch { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em;
      color: var(--faint); }
.ch a { color: inherit; text-decoration: none; }
.ch a:hover { color: var(--accent); }

time { font-size: 0.85rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.empty { color: var(--soft); padding: 2.5rem 0; }

/* --- the article ------------------------------------------------------- */

/* The prose column is the one that narrows, and only it. */
article { padding: 3rem 0 0; max-width: var(--measure); }

article h1 {
  font-family: var(--body-face);
  font-size: clamp(2.1rem, 7vw, 2.9rem);
  line-height: 1.14;
  letter-spacing: -0.024em;
  font-weight: 700;
  margin: 0.5rem 0 0.7rem;
}

.summary {
  font-family: var(--body-face);
  font-size: 1.25rem;
  line-height: 1.45;
  color: var(--soft);
  margin: 0 0 1.4rem;
}

/* Channel · date · reading time, the one line Medium puts under every title.
 * The reading time is the part that earns its place: these pieces run
 * 900-2000 words, so "how long is this" is a real question. */
.byline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--faint);
}
.byline .dot { opacity: 0.5; }

/* The body, and the whole point of the file. */
.body {
  font-family: var(--body-face);
  font-size: var(--read);     /* ~21px by default */
  line-height: 1.62;
  letter-spacing: -0.003em;
  margin-top: 2.25rem;
}

.body p { margin: 0 0 1.6rem; }

/* Headings go SANS against a serif body. The contrast is what makes them read
 * as structure at a glance rather than as a slightly bigger sentence. */
.body h2 {
  font-family: var(--head-face);
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.015em;
  margin: 3rem 0 0.9rem;
}
.body h3 {
  font-family: var(--head-face);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 2.25rem 0 0.7rem;
}

/* Underlined, in the text colour: a link in the middle of a paragraph should
 * be findable without recolouring the sentence around it. */
.body a { color: inherit; text-decoration: underline; text-underline-offset: 3px;
          text-decoration-thickness: 1px; text-decoration-color: var(--faint); }
.body a:hover { color: var(--accent); text-decoration-color: var(--accent); }

.body ul, .body ol { padding-left: 1.4rem; margin: 0 0 1.6rem; }
.body li { margin-bottom: 0.65rem; }

.body blockquote {
  margin: 2rem 0;
  padding-left: 1.4rem;
  border-left: 3px solid var(--ink);
  font-style: italic;
  color: var(--soft);
}
.body blockquote p:last-child { margin-bottom: 0; }

.body hr { border: 0; border-top: 1px solid var(--line); margin: 3rem 0; }

.body strong { font-weight: 700; }

/* Code and tables drop back to sans/mono at a smaller size: they are not
 * prose, and setting them in the reading face at reading size makes a page of
 * numbers look like a page of argument. */
.body code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--panel);
  padding: 0.12em 0.36em;
  border-radius: 4px;
}

.body pre {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.1rem;
  /* Code, tables and diagrams are the only things allowed wider than the
   * measure, and they scroll inside themselves so the PAGE never does. */
  overflow-x: auto;
  font-size: 0.95rem;
}
.body pre code { background: none; padding: 0; font-size: 0.88rem; }

/* Tables are set further down, with the rest of what a comparison table
 * needs. They were styled here first, as a boxed grid on a block-level table -
 * both of which the later rules replace, so the two must not coexist: a
 * `border: 1px` here and a `border-bottom` there leaves the vertical hairlines
 * of the first showing through the second, which is a grid nobody chose. */

.body img { max-width: 100%; height: auto; border-radius: 6px; }

/* --- diagrams ---------------------------------------------------------- */
/* Mermaid, unrendered on purpose - see `_diagram_fence`. Framed and labelled
 * so it reads as a diagram in source form rather than as a page that failed to
 * load something. */

.body .diagram {
  margin: 2.25rem 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.body .diagram figcaption {
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.body .diagram pre {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: none;
  padding: 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
  overflow-x: auto;
}

/* --- sources and footer ------------------------------------------------ */

.sources {
  margin-top: 3.5rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.95rem;
}
.sources h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  margin: 0 0 0.8rem;
  font-weight: 600;
}
.sources ul { padding-left: 1.2rem; margin: 0; }
.sources li { margin-bottom: 0.4rem; }
.sources a { color: var(--accent); }

footer {
  margin-top: 4.5rem;
  padding-top: 1.75rem;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.88rem;
}
footer p { margin: 0 0 0.5rem; }
footer a { color: var(--accent); }

/* --- the apex: a way in, not a second copy of the channels -------------- */

.channels { list-style: none; padding: 0; margin: 2rem 0 3.5rem; display: grid; gap: 0.75rem; }
/* THE CARD LINK ONLY - `>` both times, deliberately. `.channels a` also
 * matches the headline link inside `.newest`, which then drew itself as a
 * second card nested inside the first. */
.channels > li > a {
  display: block;
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  transition: border-color .12s ease;
}
.channels > li > a:hover { border-color: var(--accent); }
.channels h2 { font-family: var(--body-face); font-size: 1.25rem; margin: 0 0 0.15rem;
               letter-spacing: -0.012em; }
.channels p { margin: 0; color: var(--faint); font-size: 0.88rem; }

h2.section {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.top nav a.on { color: var(--ink); font-weight: 600; }

/* Which site answered. Small print on the 404 on purpose: a reader does not
 * need it, and it is the one fact that makes a domain attached to the wrong
 * Firebase site visible from a browser instead of from the console. */
.whoami { color: var(--faint); font-size: 0.8rem; margin-top: 3rem; }
.whoami code { font-family: var(--mono); font-size: 0.95em; }

/* --- one publication per subdomain -------------------------------------
 *
 * A subdomain here is not a section of one magazine, it is a magazine:
 * ai.viyan.live explains a training run to an adult, kids.viyan.live explains
 * why the sky is blue to a nine-year-old. Served in the same palette they were
 * the same page with different words in it.
 *
 * ALL FOUR LOOKS LIVE IN THIS ONE FILE, selected by `<html data-theme>` from a
 * name on the channel's row. The alternative - a stylesheet per channel - is a
 * deploy per channel and four files that drift apart at the first change to
 * the type scale. This way the skeleton stays shared, so a fix to the measure
 * or the heading contrast lands everywhere at once, and only the palette, the
 * faces and the reading size are per publication.
 *
 * WHY EACH BLOCK IS WRITTEN TWICE. `:root` and `[data-theme=x]` have equal
 * specificity, so the later rule wins - which means a theme's light values
 * would also apply in dark mode unless the dark values are restated after the
 * dark `:root` block. Hence a light block and a dark block per theme, each
 * setting every variable it touches.
 *
 * An unknown theme name matches nothing here and the page renders in the
 * default look, so a typo in a seed file costs the theme and never the page.
 */

/* The way in. Neutral on purpose: it is a directory, and the three
 * publications are what should have the colour. */
[data-theme="index"] {
  --accent: #40506e;
  --panel: #f6f6f4;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="index"] {
    --accent: #93a4c8;
    --panel: #191a1c;
  }
}

/* AI: cool, technical, close to the default. The subject is already dense, so
 * the page stays out of the way - one cold accent and a slightly cooler rule
 * than the paper themes. */
[data-theme="ai"] {
  --accent: #1f6f7a;
  --line: #e2e6e6;
  --panel: #f4f7f7;
  --ink: #16191a;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="ai"] {
    --accent: #6fc3ce;
    --line: #262c2d;
    --panel: #161a1b;
    --ink: #e6eaea;
  }
}

/* Science: paper and ink. Warm ground, indigo accent, and the headings in the
 * SERIF - a journal sets its structure in the reading face, and next to the AI
 * channel's sans headings that alone says "different publication" before a
 * word is read. */
[data-theme="science"] {
  --accent: #34489b;
  --head-face: var(--serif);
  --bg: #fbfaf6;
  --panel: #f3f1ea;
  --line: #e4e0d5;
  --ink: #1b1a17;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="science"] {
    --accent: #9aaaf0;
    --head-face: var(--serif);
    --bg: #12120f;
    --panel: #1c1c18;
    --line: #2e2d27;
    --ink: #ebe8df;
  }
}

/* Kids: SET ENTIRELY IN THE SANS, bigger, on a shorter line.
 *
 * Not decoration. A serif at 21px on a 680px measure is tuned for an adult
 * reading 1500 words; a younger reader does better with a plainer letterform,
 * more of it, and fewer words per line to lose their place in. So the body
 * face becomes the sans, the reading size goes up, the measure comes in, and
 * the corners round off - which is the one purely cheerful part. */
[data-theme="kids"] {
  --accent: #b8460e;
  --body-face: var(--sans);
  --head-face: var(--sans);
  --read: 1.38rem;
  --measure: 37rem;   /* the prose only; --frame stays put, so the nav does */
  --radius: 16px;
  --bg: #fffdf8;
  --panel: #fff4e2;
  --line: #f0e3cf;
  --ink: #201c16;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="kids"] {
    --accent: #ffab6b;
    --body-face: var(--sans);
    --head-face: var(--sans);
    --read: 1.38rem;
    --measure: 37rem;
    --radius: 16px;
    --bg: #14120f;
    --panel: #23201a;
    --line: #332e26;
    --ink: #f2eee6;
  }
}

/* The three things that read as a corner, so `--radius` actually means
 * something. Kids gets soft edges; everything else is unchanged at 8px. */
[data-theme] .body pre,
[data-theme] .body .diagram,
[data-theme] .channels > li > a { border-radius: var(--radius); }

/* Headings a shade heavier when they are set in the reading face, so a serif
 * h2 still reads as structure rather than as a slightly larger sentence - the
 * contrast the sans was providing has to come from somewhere. */
[data-theme="science"] .body h2 { letter-spacing: -0.02em; }

/* The apex's newest-headline line: one piece of proof that a publication is
 * running, under each card. */
.newest {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  margin: 0.5rem 0 1.6rem;
  padding-left: 1.25rem;
  color: var(--faint);
  font-size: 0.9rem;
}
.newest a { color: var(--accent); text-decoration: none; }
.newest a:hover { text-decoration: underline; }
.newest time { color: var(--faint); }

/* --- the mark, and the glyphs beside words ------------------------------
 *
 * Inline SVG inheriting `currentColor`, so every glyph is already the right
 * colour in every theme with no second asset. The spark in the mark is the
 * one place the channel's accent appears in the chrome.
 */

.brand { display: inline-flex; align-items: center; gap: 0.45rem; }
.mark { flex: none; transform: translateY(0.02em); }

/* Glyph and words as one unit: the gap never collapses, and the pair wraps as
 * a whole rather than leaving an orphaned icon at the end of a line. */
.withicon { display: inline-flex; align-items: center; gap: 0.35rem; }
.withicon svg { flex: none; opacity: 0.75; }

/* --- tables -------------------------------------------------------------
 *
 * WORTH REAL STYLING, because the formats ask for one in every piece and the
 * critic blocks a draft without one. Ruled rather than boxed: a grid of
 * borders makes four numbers look like a spreadsheet, while one rule under
 * the head and hairlines between rows let the eye run across a row - which is
 * what a comparison table is read for.
 *
 * `.scroll` is added by the renderer (see `_table_open`). The table keeps its
 * own layout inside it, so columns still size against each other; the wrapper
 * is what scrolls on a phone, so the PAGE never does.
 */

.body .scroll {
  overflow-x: auto;
  margin: 2.25rem 0;
  /* Room for the shadow of the scroll on iOS, and for the last row's rule. */
  padding-bottom: 0.25rem;
}

.body table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.45;
  margin: 0;
}

.body thead th {
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 0 0.9rem 0.55rem;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
}

.body tbody td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

/* The first column is the row's name - it carries the comparison, so it reads
 * as a heading rather than as another value. */
.body tbody td:first-child { font-weight: 600; color: var(--ink); }
.body tbody tr:last-child td { border-bottom: 0; }
.body tbody tr:hover td { background: var(--panel); }

/* --- and the small print ----------------------------------------------- */

.body s { color: var(--faint); }
.body mark { background: var(--panel); padding: 0.05em 0.25em; border-radius: 3px; }
