/* Root sizing: 1rem = 16px at the browser default, and still honours
   a user's own font-size preference. */
html {
  font-size: 100%;
}

/* Typography tokens — one modular scale: base 16px, ratio 1.414
   (Augmented Fourth). Every size is base × 1.414^n, rounded to the nearest
   pixel. The negative step lands near 11px, so the scale starts at body size
   and metadata shares it, separated by weight and ink instead of shrinking.
   Only the top of the scale is fluid; body copy stays fixed. */
:root {
  --font-display: "Marcellus", Georgia, "Times New Roman", serif;
  --font-body:
    "Nunito Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-body: 1rem; /* 16px — step  0: body, links, nav entries     */
  --text-meta: var(--text-body); /* 16px — metadata is read too: weight + ink */
  --text-lead: 1.4375rem; /* 23px — step +1: wordmark, sidebar labels     */
  /* The heading steps tighten to a 1.25 ratio on mobile and open up to
     1.414 on desktop. Body and labels above stay fixed at every width. */
  --text-title: clamp(1.9375rem, 1.629rem + 1.315vw, 2.8125rem); /* 31 → 45px */
  --text-display: clamp(2.4375rem, 1.888rem + 2.347vw, 4rem); /* 39 → 64px */
  /* The home name takes two steps above the display size, so the site's own
     identity outranks every page title. */
  --text-hero: clamp(3.8125rem, 2.344rem + 6.285vw, 8rem); /* 61 → 128px */

  /* Spacing system — a 4px base, and every step is at least 25% larger
     than the one before it, so adjacent values stay distinguishable:
       4 → 8 (100%) → 12 (50%) → 16 (33%) → 24 (50%) → 32 (33%)
       → 48 (50%) → 64 (33%) → 96 (50%).
     Related things sit one or two steps apart; separate sections sit
     three to five steps apart. Nothing below uses an arbitrary value. */
  --space-1: 0.25rem; /*  4px — labels to their controls, icon gaps   */
  --space-2: 0.5rem; /*  8px — items inside one group                 */
  --space-3: 0.75rem; /* 12px — tight internal padding                 */
  --space-4: 1rem; /* 16px — standard gap, card padding             */
  --space-5: 1.5rem; /* 24px — larger inner gaps, nav spacing         */
  --space-6: 2rem; /* 32px — section padding, between groups        */
  --space-7: 3rem; /* 48px — between page sections                  */
  --space-8: 4rem; /* 64px — top bar, generous page padding         */
  --space-9: 6rem; /* 96px — major page divisions                   */

  /* Body copy sits a step inward from the media edge, so prose and images
     read as two deliberate alignments instead of one ragged column. */
  --text-inset: 0;

  --top-bar-height: var(--space-8);

  /* Colour roles. Components reach for these names rather than raw values,
     so the dark block below only has to restate the palette. */
  color-scheme: light;
  --color-bg: #fff;
  --color-surface: #fff;
  --color-ink: #111;
  --color-ink-strong: #000;
  --color-ink-soft: #333;
  --color-ink-muted: #555;
  --color-link: #8762f3;
  /* Display glow: the title ink and the halo it casts. The shadow follows
     the cursor (see shadow.js). Named roles so the dark block can lift
     both against its own background. */
  --color-glow-ink: #afaead;
  --color-glow-shadow: #816afff7;
  --color-hamburger-bg: #333;
  --color-hamburger-ink: #fff;
  --color-draft: #c44;
  --color-draft-bg: #fff3cd;
  --color-draft-border: #ffc107;
  --color-draft-ink: #856404;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #141414;
  --color-surface: #1b1b1b;
  --color-ink: #e8e6e1;
  --color-ink-strong: #fff;
  --color-ink-soft: #cfcbc5;
  --color-ink-muted: #b8b4ae;
  --color-link: #8762f3;
  /* A lighter ink and a brighter halo keep the same soft glow on the dark
     canvas, where the violet needs more separation from the background. */
  --color-glow-ink: #cfcbc5;
  --color-glow-shadow: #9d88fff7;
  --color-hamburger-bg: #e8e6e1;
  --color-hamburger-ink: #141414;
  --color-draft: #ff9f9a;
  --color-draft-bg: #33280a;
  --color-draft-border: #8a6d00;
  --color-draft-ink: #ffe6a3;
}

/* Self-hosted fonts (SIL Open Font License, see assets/fonts/OFL-*.txt) */
@font-face {
  font-family: "Marcellus";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/marcellus-regular.woff2") format("woff2");
}

@font-face {
  font-family: "Nunito Sans";
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
  src: url("/assets/fonts/nunito-sans-roman.woff2") format("woff2");
}

@font-face {
  font-family: "Nunito Sans";
  font-style: italic;
  font-weight: 200 1000;
  font-display: swap;
  src: url("/assets/fonts/nunito-sans-italic.woff2") format("woff2");
}

/* Base styles */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-synthesis: none;
  line-height: 1.6;
}

/* Base link ink; navigation and titles below override it. */
a {
  color: var(--color-link);
}

/* Skip link: first focusable element, hidden until it receives focus. */
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 1001;
  padding: var(--space-2) var(--space-4);
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid currentColor;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}

/* Available to assistive technology, not visible on screen. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Even out line breaks: balance short headings and short copy, and keep
   running text from stranding a word on its own line. */
h1,
h2,
h3,
h4,
h5,
h6,
.site-title,
.page-title,
.entry-title,
blockquote,
figcaption,
dt {
  text-wrap: balance;
}

p,
li,
dd {
  text-wrap: pretty;
}

/* Monospace is reserved for technical content, never body copy. */
code,
pre,
kbd,
samp {
  font-family: var(--font-mono);
}

/* Top bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--top-bar-height);
  padding: 0 var(--space-5);
  background: transparent;
  z-index: 100;
}

.wordmark {
  font-family: var(--font-display);
  font-size: var(--text-lead);
  line-height: 1.2;
  color: var(--color-ink);
  text-decoration: none;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  margin-left: auto; /* Stay right-aligned when the wordmark is omitted on the homepage */
}

.top-link {
  font-family: var(--font-display);
  font-size: var(--text-body);
  line-height: 1.4;
  text-decoration: none;
  color: var(--color-ink-soft);
}

.top-link.active,
.sidebar-label.active,
.sidebar-link-category.active {
  color: var(--color-ink-strong);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* Site layout */
.site-layout {
  display: flex;
  margin-top: var(--top-bar-height); /* Account for fixed top bar */
  min-height: calc(100vh - var(--top-bar-height));
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: var(--top-bar-height); /* Match top bar height */
  width: 340px;
  height: calc(100vh - var(--top-bar-height));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: var(--space-5);
  background: transparent;
  flex-shrink: 0;
}

/* A zero-height flex item absorbs the free space and sits the nav against
   the bottom of the rail. Unlike a margin on the first section, this does
   not depend on which item is visible, and when the list outgrows the rail
   the spacer collapses so the list still scrolls from the top. */
.sidebar::before {
  content: "";
  margin-top: auto;
}

.sidebar > .sidebar-section:last-child {
  margin-bottom: 0;
}

.sidebar-section {
  margin-bottom: var(--space-5);
  flex-shrink: 0;
}

/* Home/About live in the top bar on desktop, so only show them in the mobile drawer */
.sidebar-mobile-only {
  display: none;
}

.sidebar-label {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-lead);
  line-height: 1.25;
  text-decoration: none;
  color: var(--color-ink-soft);
  margin-bottom: var(
    --space-1
  ); /* tight to its list, loose from next section */
}

.sidebar-entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-entries li {
  margin-bottom: 0;
}

.sidebar-link,
.sidebar-link-category {
  text-decoration: none;
  color: var(--color-ink-muted);
  display: block;
}

.sidebar-link:hover,
.sidebar-link-category:hover {
  color: var(--color-ink-strong);
}

.sidebar-link {
  font-size: var(--text-body);
  line-height: 1.3;
  padding: var(--space-1) 0;
}

.sidebar-link.active {
  color: var(--color-ink-strong);
}

.sidebar-link-category {
  font-family: var(--font-display);
  font-size: var(--text-lead);
  line-height: 1.25;
  padding: var(--space-1) 0;
}

/* Language switcher: matches the display titles but sits a step below them.
   The theme toggle sits on the same line, directly after the language link. */
.sidebar-lang-switcher {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.sidebar-lang-switcher a {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-body); /* 16px — a caption below the 23px labels */
  line-height: 1.25;
  color: var(--color-ink-soft);
  text-decoration: none;
}

.sidebar-lang-switcher a:hover {
  color: var(--color-ink-strong);
}

/* Icon-only theme switch: 32px target, 20px Phosphor glyph. The glyph
   rotates a half turn in dark mode so the filled half swaps sides. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--space-6);
  height: var(--space-6);
  flex-shrink: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--color-ink-soft);
  cursor: pointer;
}

.theme-toggle svg {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  transition: transform 0.25s ease;
}

.theme-toggle:hover {
  color: var(--color-ink-strong);
}

.theme-toggle:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

:root[data-theme="dark"] .theme-toggle svg {
  transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle svg {
    transition: none;
  }
}

/* Content area */
.content-area {
  flex: 1;
  padding: var(--space-7) var(--space-8);
  overflow-y: auto;
}

/* Display titles */
.site-title,
.page-title,
.entry-title {
  font-family: var(--font-display);
  font-weight: 400;
}

/* Home */
.site-title {
  font-size: var(--text-hero);
  line-height: 1.1;
  max-width: 20ch;
  margin: 0;
}

/* On desktop the homepage name sits at the bottom-right of the content area,
   away from the page title and close to the language switcher. */
@media (min-width: 769px) {
  .content-area:has(> .site-title) {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
  }

  /* The flex item shrinks when the name wraps, so both lines need to hug the
     right edge with it instead of sitting flush-left inside the box. */
  .content-area > .site-title {
    text-align: right;
  }
}

/* Category view: the sidebar already names the active category on desktop,
   so the heading is only visible in the mobile drawer. It stays in the
   accessibility tree on desktop instead of being removed with display: none,
   so the document keeps a real h1 at every viewport. */
.page-title {
  font-size: var(--text-display);
  line-height: 1.15;
  max-width: 24ch;
  margin: 0 0 var(--space-6);
}

@media (min-width: 769px) {
  .page-title {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }
}

/* Entry page */
.entry-title {
  font-size: var(--text-title);
  line-height: 1.15;
  max-width: 28ch;
  margin-top: 0;
  margin-bottom: var(--space-4);
}

/* Listing titles link to the full entry */
.entry-title a {
  color: inherit;
  text-decoration: none;
}

.entry-title a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.entry-body {
  margin-bottom: var(--space-6);
}

/* Prose keeps the readable measure; figures use the full content width,
   matching the images gallery. */
.entry-body > :not(figure) {
  max-width: 60ch; /* ~70 characters in Nunito Sans: inside the 45–75 range */
  text-align: justify;
}

/* Republished-article source note, set apart from the article itself. */
.entry-body .source-note {
  margin: 0 0 var(--space-6);
  padding: var(--space-2) var(--space-4);
  border-left: 3px solid var(--color-ink-muted);
  color: var(--color-ink-muted);
  font-style: italic;
}

/* Contact information is marked up as <address>; keep the body face upright. */
.entry-body address {
  font-style: normal;
}

/* On listing pages, entries are separate groups: give them more air than
   the paragraphs inside an entry. */
.entry + .entry {
  margin-top: var(--space-9);
}

/* Markdown headings inside an entry: each one sits below the entry title.
   h2 steps down the scale; h3 uses weight, not a smaller size. */
.entry-body h2 {
  font-family: var(--font-display);
  font-size: var(--text-lead);
  font-weight: 400;
  line-height: 1.25;
  margin: var(--space-6) 0 var(--space-3);
}

.entry-body h3 {
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 700;
  line-height: 1.4;
  margin: var(--space-5) 0 var(--space-2);
}

.entry-images {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.entry-image {
  margin: 0;
}

.entry-image img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Inline article figures use the same full-width media edge as the gallery,
   breaking out of the prose inset on the left. */
.entry-body figure {
  width: calc(100% + var(--text-inset));
  margin: var(--space-6) 0 var(--space-6) calc(var(--text-inset) * -1);
}

.entry-body figure img {
  max-width: 100%;
  height: auto;
  display: block;
}

.entry-body figcaption {
  max-width: calc(90ch + var(--text-inset));
  margin-top: var(--space-2);
  padding-left: var(--text-inset);
  color: var(--color-ink-muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

.entry-external-link {
  margin-top: var(--space-6);
}

.entry-external-link a {
  text-decoration: underline;
  overflow-wrap: anywhere;
}

/* Body copy aligns one step in from the media edge. Titles and images keep
   the outer edge, so the two columns are visibly, intentionally offset. */
.entry-body,
.entry-external-link {
  margin-left: var(--text-inset);
}

/* Draft indicators (only visible in dev mode) */
.draft-label {
  font-family: var(--font-body);
  font-size: var(--text-meta);
  font-weight: 400;
  color: var(--color-draft);
  vertical-align: baseline;
  margin-left: 0.25em;
}

.draft-banner {
  font-family: var(--font-body);
  background: var(--color-draft-bg);
  border: 1px solid var(--color-draft-border);
  color: var(--color-draft-ink);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  font-size: var(--text-meta);
  line-height: 1.5;
  border-radius: 4px;
}

/* Menu toggle (hidden on desktop) */
.hamburger {
  display: none;
}

/* Overlay (hidden on desktop) */
.sidebar-overlay {
  display: none;
}

/* Mobile styles */
@media (max-width: 768px) {
  /* A smaller inset on narrow screens, where the outer padding is already tight. */
  :root {
    --text-inset: var(--space-4);
  }

  .top-bar {
    display: none;
  }

  .site-layout {
    margin-top: 0;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    background: var(--color-surface);
  }

  /* The drawer is opened on demand, so the menu starts at the top. */
  .sidebar::before {
    margin-top: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-mobile-only {
    display: block;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 998;
  }

  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .hamburger {
    display: grid;
    place-items: center;
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    width: 50px;
    height: 50px;
    background: var(--color-hamburger-bg);
    border: none;
    border-radius: 50%;
    color: var(--color-hamburger-ink);
    cursor: pointer;
    z-index: 1000;
    padding: 0;
  }

  .hamburger svg {
    display: block;
    width: 1.5rem;
    height: 1.5rem;
  }

  .content-area {
    padding: var(--space-5);
  }

  /* The sidebar is off-canvas here, so restore the category heading. */
  .page-title {
    display: block;
  }
}

/* Display glow — every Marcellus (--font-display) surface takes the glow ink
   with a violet shadow that follows the cursor (see shadow.js). Active/hover
   variants are listed so their own colours do not override it. */
.wordmark,
.top-link,
.top-link.active,
.sidebar-label,
.sidebar-label.active,
.sidebar-link-category,
.sidebar-link-category.active,
.sidebar-link-category:hover,
.sidebar-lang-switcher a,
.sidebar-lang-switcher a:hover,
.theme-toggle,
.theme-toggle:hover,
.site-title,
.page-title,
.entry-title,
.entry-title a,
.entry-body h2 {
  color: var(--color-glow-ink);
  text-shadow: var(--shadow-x, 0px) var(--shadow-y, 0px)
    var(--shadow-blur, 11px) var(--color-glow-shadow);
}

/* The toggle is an SVG, not text, so text-shadow cannot reach it. */
.theme-toggle svg {
  filter: drop-shadow(
    var(--shadow-x, 0px) var(--shadow-y, 0px) var(--shadow-blur, 11px)
      var(--color-glow-shadow)
  );
}
