/* ==========================================================================
   Notes from the Bottle — stylesheet

   Palette note: neutrals are biased blue-black (plotted ink), never mid-grey.
   The single bold gesture is the cold-to-hot "isotherm" gradient, standing in
   for the β sweep the writing is about. Amber is the accent; the cool blue is
   its cold-side counterpart and stays secondary.

   Theme tokens: bare :root carries the full dark palette, which is what every
   first-time visitor gets regardless of OS preference. Light is opt-in through
   the header toggle, which stamps data-theme="light" on <html> and persists the
   choice in localStorage. Components only ever read tokens, never raw colors.
   ========================================================================== */

:root {
  /* Dark — plotted ink. The default. */
  color-scheme: dark;

  --bg:         #0b0f14;
  --surface:    #121922;
  --ink:        #e8edf3;
  --ink-soft:   #c6cedb;
  --muted:      #8b96a6;
  --rule:       #212b37;
  --rule-soft:  #1a222c;

  --hot:        #f2a758;   /* accent */
  --hot-bright: #ffbc72;
  --cold:       #63c4e4;
  --accent-soft: rgba(242, 167, 88, 0.13);

  --code-bg:    #141c25;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 30px -18px rgba(0, 0, 0, 0.8);

  /* Type */
  --display-opsz: 8;    /* see the display-type rule below — lower = sturdier */
  --display-wght: 800;  /* needs the 400..900 variable range requested in <head> */
  --font-display: "Bodoni Moda", "Didot", "Bodoni MT", Georgia, serif;
  --font-body: "Source Serif 4", "Source Serif Pro", Charter, Georgia, Cambria, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Layout — one column width for everything: prose, plots, tables, code,
     header and footer all align to the same measure. */
  --measure: max(60vw, 48rem);
  --gutter: 1.5rem;
}

/* Bodoni Moda is a Didone: its hairlines thin out as the optical-size axis
   climbs, and `font-optical-sizing: auto` drives opsz toward the rendered size —
   so the largest headings ended up with the most fragile strokes, which dark
   mode's irradiation then eroded further. Pinning a text-range opsz keeps the
   sturdier cut at every display size. wght is restated because naming any axis
   in font-variation-settings can drop the font-weight mapping in some engines. */
.site-title,
.intro-title,
.post-item-title,
.post-title,
.post-content h2,
.post-content h3,
.post-content h4 {
  font-variation-settings: "opsz" var(--display-opsz), "wght" var(--display-wght);
}

/* Light — cool paper. Opt-in only, via the header toggle. */
:root[data-theme="light"] {
  color-scheme: light;

  --bg:         #f4f6f8;
  --surface:    #ffffff;
  --ink:        #12171f;
  --ink-soft:   #2c3542;
  --muted:      #5c6675;
  --rule:       #dde2e9;
  --rule-soft:  #e8ecf1;

  --hot:        #a3490f;
  --hot-bright: #c25c18;
  --cold:       #1d5c88;
  --accent-soft: rgba(163, 73, 15, 0.09);

  --code-bg:    #eef1f5;
  --shadow: 0 1px 2px rgba(18, 23, 31, 0.06), 0 8px 24px -16px rgba(18, 23, 31, 0.28);
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  /* Root scale: every rem below is relative to this, so one knob sizes the
     whole page. 100% of the 16px default = 16px base. */
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.72;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.shell {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

main {
  flex: 1 0 auto;
  padding-block: 3.5rem 5rem;
}

a { color: var(--hot); text-underline-offset: 0.18em; }
a:hover { color: var(--hot-bright); }

:focus-visible {
  outline: 2px solid var(--hot);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus {
  left: 1rem; top: 1rem; z-index: 20;
  background: var(--surface);
  color: var(--ink);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

/* Utility label register — mono, spaced, small caps feel. */
.post-meta,
.site-nav,
.read-more,
.tag-list li {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Header
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.5rem;
}

.site-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
}
.site-title:hover { color: var(--hot); }

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.4rem;
}
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--hot); }

/* The β sweep: cold to hot. */
.isotherm {
  height: 2px;
  background: linear-gradient(90deg,
    var(--cold) 0%,
    color-mix(in srgb, var(--cold) 45%, var(--hot)) 52%,
    var(--hot) 100%);
  opacity: 0.85;
}

/* Theme toggle ------------------------------------------------------------ */

.theme-toggle {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.theme-toggle:hover {
  color: var(--hot);
  border-color: var(--hot);
  background: var(--accent-soft);
}
.theme-toggle svg {
  grid-area: 1 / 1;
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}
.icon-moon { fill: currentColor; stroke: none; }

/* Show the icon for the theme you would switch *to*. Keyed off the light stamp
   so the default (unstamped) state correctly reads as dark. */
:root[data-theme="light"] .icon-sun { display: none; }
:root:not([data-theme="light"]) .icon-moon { display: none; }

/* ==========================================================================
   Content column — everything shares the one measure, so figures and tables
   line up flush with the prose rather than breaking out past it.
   ========================================================================== */

.flow,
.post-content {
  display: flex;
  flex-direction: column;
  gap: 1.35em;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.flow > *,
.post-content > * { margin-block: 0; min-width: 0; }

/* ==========================================================================
   Home
   ========================================================================== */

.intro {
  max-width: var(--measure);
  margin: 0 auto 2.5rem;
  padding-inline: var(--gutter);
}

.intro-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2rem, 5.4vw, 2.6rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0;
  text-wrap: balance;
}

/* Sized to clear the column on one line; `pretty` keeps a lone word off the
   last line when it does wrap on narrow screens. */
.intro-tagline {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  font-style: italic;
  max-width: min(100%, 42rem);
  text-wrap: pretty;
}

.post-list {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
  display: flex;
  flex-direction: column;
}

.post-item {
  padding-block: 2.25rem;
  border-top: 1px solid var(--rule);
}
.post-item:first-child { border-top: none; padding-top: 0; }

.post-item--with-thumb {
  display: flex;
  gap: 1.9rem;
  align-items: stretch;   /* thumb column takes the full height of the text */
}
.post-item-body { min-width: 0; }  /* lets the excerpt truncate instead of forcing the row wider */

/* No card, no frame: the figures ship on a baked-in white canvas, so instead of
   boxing that white in, it is blended away — multiplied into the paper in light
   mode, inverted to the ink in dark mode. The plot then reads as if it were
   drawn straight onto the page. */
.post-item-thumb {
  flex: none;
  width: 18rem;
  display: flex;
  align-items: center;    /* figure sits centred in the full-height column */
  transition: transform 0.22s ease;
}
.post-item-thumb img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  /* Data figures, not photographs: cropping to fill the box cuts off the axes
     and legend and leaves an unreadable swatch. Fit the whole plot instead. */
  object-fit: contain;
  mix-blend-mode: multiply;
}
:root:not([data-theme="light"]) .post-item-thumb img {
  /* Deliberately NOT inverted. Inverting would hide the white canvas, but it
     also reverses perceptual colormaps — viridis encodes magnitude in lightness,
     so an inverted colorbar reads backwards. Dim it instead, matching the
     in-post figure treatment so the same plot looks the same in both places.
     The real fix is a dark-styled re-export of the figures. */
  filter: brightness(0.86) contrast(1.04);
  mix-blend-mode: normal;
}
.post-item:hover .post-item-thumb { transform: translateY(-3px); }

/* Below this, thumb-beside-text gets cramped; stack the thumb above instead. */
@media (max-width: 34rem) {
  .post-item--with-thumb { flex-direction: column; }
  .post-item-thumb { width: 100%; }
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
}

.post-item-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0.55rem 0 0;
  text-wrap: balance;
}
.post-item-title a { color: var(--ink); text-decoration: none; }
.post-item-title a:hover { color: var(--hot); }

.post-item-subtitle {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-style: italic;
  font-size: 0.97rem;
}

.post-item-excerpt {
  margin: 0.7rem 0 0;
  font-size: 0.95rem;
}

.read-more {
  display: inline-block;
  margin-top: 1rem;
  color: var(--hot);
  text-decoration: none;
}
.read-more:hover { text-decoration: underline; }

.empty { color: var(--muted); }

/* ==========================================================================
   Post
   ========================================================================== */

.post-header {
  max-width: var(--measure);
  margin: 0 auto 3rem;
  padding-inline: var(--gutter);
}

.post-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.1rem, 6vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0.6rem 0 0;
  text-wrap: balance;
}

.post-subtitle {
  margin: 0.9rem 0 0;
  color: var(--muted);
  font-size: 1.35rem;
  font-style: italic;
  line-height: 1.5;
}

/* Spans the measure and dissolves to the right, so it reads as a divider
   into the post list rather than a stub floating under the title. */
.title-rule {
  height: 1px;
  width: 100%;
  margin-top: 1.4rem;
  background: linear-gradient(90deg, var(--cold), var(--hot) 28%, transparent);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  list-style: none;
  margin: 1.4rem 0 0;
  padding: 0;
}
.tag-list li {
  color: var(--hot);
  background: var(--accent-soft);
  padding: 0.25rem 0.6rem;
  border-radius: 3px;
}

/* Prose ------------------------------------------------------------------- */

.post-content h2,
.post-content h3,
.post-content h4 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
  margin-top: 1em;   /* sits on top of the column gap */
}
.post-content h2 { font-size: 2.08rem; }
.post-content h3 { font-size: 1.52rem; }
.post-content h4 { font-size: 1.24rem; font-family: var(--font-body); }

.post-content strong { color: var(--ink); font-weight: 600; }
.post-content em { font-style: italic; }

.post-content ul,
.post-content ol { padding-left: 1.35rem; }
.post-content li + li { margin-top: 0.4rem; }
.post-content li::marker { color: var(--muted); }

.post-content blockquote {
  padding: 0.1rem 0 0.1rem 1.25rem;
  border-left: 2px solid var(--hot);
  color: var(--muted);
  font-style: italic;
}

.post-content hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin-block: 1.5em;
}

/* Code -------------------------------------------------------------------- */

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.86em; }

.post-content :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
  padding: 0.1em 0.34em;
}

.post-content pre,
.post-content .highlight {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  line-height: 1.6;
}
.post-content pre code {
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
}

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

.post-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

/* Matplotlib exports sit on a white canvas — take the glare off in dark mode. */
:root:not([data-theme="light"]) .post-content img {
  filter: brightness(0.88) contrast(1.04);
  transition: filter 0.2s ease;
}
:root:not([data-theme="light"]) .post-content img:hover { filter: none; }

.post-content figure { margin: 0; }
.post-content figcaption,
.post-content p:has(> img:only-child) + p > em:only-child {
  display: block;
  margin-top: 0.7rem;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  line-height: 1.55;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-align: center;
  font-style: normal;
}

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

.post-content table {
  border-collapse: collapse;
  font-size: 1.07rem;
  display: block;
  /* Without an explicit width, a block-level table stretches to fill the
     column. A narrow table (few columns, short cells) then leaves dead space
     to the right of its own left-aligned content, reading as flush-left
     instead of centered. Shrink to content and center the box instead; wide
     tables still cap at the column and scroll via overflow-x below. */
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
  overflow-x: auto;
}
.post-content th,
.post-content td {
  border-bottom: 1px solid var(--rule);
  padding: 0.6rem 0.9rem;
  text-align: left;
  vertical-align: top;
}
.post-content th {
  font-family: var(--font-mono);
  font-size: 0.79rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 1px solid var(--muted);
  white-space: nowrap;
}
.post-content th .katex {
  letter-spacing: normal;
  text-transform: none;
}
/* Unwrappable math cells take their full width and crush prose columns into
   sliver-thin, very tall ones; floor the text cells and let the table scroll. */
.post-content td:not(:has(.katex)) { min-width: 12rem; }
.post-content tbody tr:hover { background: var(--accent-soft); }

/* Math -------------------------------------------------------------------- */

/* Math is pre-rendered to HTML + MathML at build time, so there is no loading
   state to style around and no raw TeX ever reaches the reader. */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding-block: 0.35rem;
  max-width: 100%;
}
/* KaTeX lays \tag'd equations out as a 100%-wide table, which forces the box
   to the column width instead of letting a long equation scroll inside it. */
.katex-display > .katex { max-width: 100%; }
.katex { color: var(--ink); }

/* The MathML twin is what parsers and screen readers consume; it must stay in
   the DOM but must never paint on top of the visual HTML rendering. */
.katex-mathml {
  position: absolute;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 0;
  border: 0;
  height: 1px;
  width: 1px;
  overflow: hidden;
}

/* Footnotes & post footer -------------------------------------------------- */

.footnotes {
  font-size: 1.03rem;
  color: var(--muted);
  border-top: 1px solid var(--rule);
  padding-top: 1.25rem;
}

/* Kramdown's default back-reference glyph (an underlined, accent-colored
   "↩" glued to the end of each footnote) fights the citation links inside
   the same footnote for the same color. Mute it to a quiet affordance and
   only bring back the accent on hover/focus. */
.footnotes .reversefootnote {
  margin-left: 0.4em;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85em;
  transition: color 0.15s ease;
}
.footnotes .reversefootnote:hover,
.footnotes .reversefootnote:focus-visible {
  color: var(--hot);
}

.post-footer {
  max-width: var(--measure);
  margin: 4rem auto 0;
  padding: 1.5rem var(--gutter) 0;
  border-top: 1px solid var(--rule);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  border-top: 1px solid var(--rule);
  padding-block: 1.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  justify-content: space-between;
}

/* ==========================================================================
   Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
