/* Article layout modelled on Distill (distill.pub): a narrow text column, figures that break out
   to the wider "page" column, side notes in a right-hand gutter, a title block with a byline grid,
   and an appendix. Light by default, with a dark theme toggle. */
:root {
  font-family: var(--font-sans);
  font-size: 17px;
  font-feature-settings: "cv01", "ss03";
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  color: var(--foreground);
  background: var(--background);
  line-height: 1.7;
}
* { box-sizing: border-box; }
body { margin: 0; }

/* --- grid: screen | page | text | gutter | page | screen --- */
.grid {
  display: grid;
  grid-template-columns:
    [screen-start] minmax(16px, 1fr) [page-start] minmax(0, 96px)
    [text-start] minmax(0, 680px) [text-end gutter-start] minmax(0, 200px) [gutter-end page-end]
    minmax(16px, 1fr) [screen-end];
  column-gap: 28px;
}
.grid > * { grid-column: text; min-width: 0; }
.grid > .l-page { grid-column: page; }
.grid > .l-body-outset { grid-column: page-start / gutter-start; }
.grid > .l-gutter { grid-column: gutter; }
.grid > .l-screen { grid-column: screen; }
@media (max-width: 1000px) {
  .grid { grid-template-columns: [screen-start page-start] 20px [text-start] minmax(0, 1fr) [text-end gutter-start gutter-end] 20px [page-end screen-end]; column-gap: 0; }
  .grid > .l-page, .grid > .l-body-outset { grid-column: text; }
  .grid > .l-gutter { grid-column: text; }
}

/* --- top bar --- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 0; color: var(--muted-foreground); font-size: var(--text-small); }
.topbar #theme-toggle { margin-left: auto; }

/* --- title block --- */
.title { padding-top: 40px; }
h1 {
  font-size: clamp(36px, 5vw, 50px);
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 14px;
  text-wrap: balance;
}
.subtitle { font-size: 1.2rem; line-height: 1.55; font-weight: 300; color: var(--secondary-foreground); margin: 0 0 28px; text-wrap: pretty; }
.byline {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 24px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 16px 0; margin: 28px 0 8px; font-size: var(--text-small); line-height: 1.5;
}
.byline .label { margin: 0 0 4px; font-size: var(--text-mini); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-foreground); font-weight: var(--font-weight-medium); }
.byline p { margin: 0; color: var(--foreground); }
@media (max-width: 640px) { .byline { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* --- article text --- */
article { padding-bottom: 24px; }
article p { margin: 0 0 1.1em; text-wrap: pretty; }
article h2 {
  font-size: 28px; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em;
  margin: 2.6rem 0 1.2rem; padding-bottom: 0.8rem; border-bottom: 1px solid var(--border);
  text-wrap: balance;
}
article h3 { font-size: 20px; line-height: 1.35; font-weight: 600; margin: 1.8rem 0 0.6rem; }
article ul, article ol { padding-left: 1.2em; margin: 0 0 1.1em; }
article li { margin-bottom: 0.35em; }
a { color: var(--primary); text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 4px; }
cite.ref { font-style: normal; font-size: 0.8em; vertical-align: super; line-height: 0; }
cite.ref a { text-decoration: none; }

/* side notes: in the gutter on wide screens, inline boxes on narrow ones */
.l-gutter.note {
  font-size: var(--text-small); line-height: 1.5; color: var(--muted-foreground);
  align-self: start; margin-bottom: 1em; border-left: 2px solid var(--border); padding-left: 10px;
}

/* --- appendix --- */
.appendix { border-top: 1px solid var(--border); margin-top: 32px; padding-top: 24px; font-size: var(--text-body); line-height: 1.6; color: var(--secondary-foreground); }
.appendix h2 { font-size: var(--text-heading); border: none; margin: 1.6rem 0 0.6rem; padding: 0; }
.appendix ol.references { padding-left: 1.4em; }
.appendix ol.references li { margin-bottom: 0.6em; }
footer.bottom { padding: 24px 0 48px; color: var(--muted-foreground); font-size: var(--text-mini); }

/* --- theme toggle --- */
#theme-toggle {
  display: grid; place-items: center; width: 36px; height: 36px; padding: 8px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--secondary-foreground);
}
#theme-toggle svg { width: 18px; height: 18px; grid-area: 1/1; }
.theme-moon { display: none; }
[data-theme="light"] .theme-sun { display: none; }
[data-theme="light"] .theme-moon { display: block; }
