/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * This file is linked *after* Bulma in the layout; see the comment there before reordering.
 *
 * Two layers live here. The public pages (masthead, home, blog, article, footer, and the About /
 * Contact / Privacy pages) are styled by the classes below and use almost no Bulma components;
 * the admin screens are still plain Bulma and only pick up the tokens, the masthead and the
 * footer. Keep it that way: a public-page rule should hang off one of these classes, never a
 * bare element selector that would leak into the admin forms and tables.
 */

/*
 * Design tokens. The palette comes from the hand-drawn snail on the home page: pencil graphite
 * for text, the paper it's drawn on for the page, and the green of the Erlenmeyer flask beside it
 * for links and the brand. Every text colour here meets 4.5:1 on both --paper and --wash.
 */
:root {
  --paper: #fbfbf9;        /* page background */
  --wash: #eaf3ee;         /* the masthead band */
  --ink: #1f2a2e;          /* body text and headings: graphite, not black */
  --muted: #5a6569;        /* dates, counts, secondary text (5.8:1 on --paper) */
  --line: #dfe4e0;         /* rules between entries and sections */
  --flask: #17694a;        /* links and brand text (6.4:1 on --paper) */
  --flask-deep: #0f4f37;   /* link hover */
  --flask-bright: #2e9e68; /* the masthead rule and focus rings only; too light for text */

  /* Source Serif 4 is loaded from jsDelivr in the layout. A serif rather than a sans because
     MathJax 4 typesets in New Computer Modern, a serif: inline maths sits naturally in a serif
     line and looks pasted in to a sans one. The fallbacks are the platforms' own book faces. */
  --serif: "Source Serif 4 Variable", "Iowan Old Style", Charter, "Bitstream Charter", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --column: 44rem;         /* ~75 characters of 19px Source Serif */
}

/*
 * Bulma overrides. Bulma 1.0 sets its variables in `:root` and *again* in
 * `.theme-light, [data-theme=light]`, which has the same (0,1,0) specificity as `:root` but comes
 * later in its file. Overriding `:root` alone would win on source order only, and would silently
 * stop working if the layout's hardcoded `data-theme="light"` changed, so every selector Bulma
 * uses is matched.
 *
 * Primary stays the light gray it was given when it coloured the old `hero is-primary` header;
 * it now only reaches the admin screens' `button is-primary`, where `--bulma-primary-invert-l`
 * (6% lightness, ~13:1 on this gray) is still right. Links take the flask green site-wide, so
 * admin links match the public pages.
 */
:root,
.theme-light,
[data-theme=light],
.theme-dark,
[data-theme=dark] {
  --bulma-primary-h: 0deg;
  --bulma-primary-s: 0%;
  --bulma-primary-l: 85%;

  --bulma-link-h: 157deg;
  --bulma-link-s: 64%;
  --bulma-link-l: 25%;

  --bulma-body-background-color: var(--paper);
  --bulma-scheme-main: var(--paper);
  --bulma-body-color: var(--ink);
  --bulma-text: var(--ink);
}

body {
  background-color: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--flask-bright);
  outline-offset: 2px;
}

/*
 * Sticky footer: hold the footer at the bottom of the viewport on short pages.
 *
 * `margin-top: auto` rather than a `flex: 1` content wrapper because the layout yields views
 * straight into <body> and the admin screens emit several top-level sections — there is no
 * single content element to grow. As the last flex item, the footer's auto top margin absorbs
 * whatever space is left over, and is inert once the content overflows. The <script> tags at
 * the end of <body> are display: none, so they never become flex items.
 *
 * 100dvh follows 100vh so browsers that understand it win: on mobile, 100vh is sized against
 * the *expanded* viewport behind a retractable URL bar, which parks the footer under the fold.
 */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

body > footer {
  margin-top: auto;
}

/* The one column every public page sits in, left-aligned so titles, entries and body text all
   share an edge. 1rem of gutter on phones. */
.site-container {
  width: 100%;
  max-width: calc(var(--column) + 2rem);
  margin-inline: auto;
  padding-inline: 1rem;
}

.page {
  padding-block: 2.5rem 4rem;
}

/* ---------------------------------------------------------------------------------------------
 * Masthead
 *
 * One row at every width: the wordmark, then the nav pushed to the right. Bulma's navbar is kept
 * for its burger (navbar_controller.js toggles it), but stripped of its white background and
 * 3.25rem minimum height so it sits on the band. The 3px rule underneath is the brand's one
 * flourish outside the home page.
 * ------------------------------------------------------------------------------------------- */
.masthead {
  background-color: var(--wash);
  border-bottom: 3px solid var(--flask-bright);
}

.header-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: 4.5rem;
}

.wordmark {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 650;
  font-variation-settings: "opsz" 32;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--ink);
  white-space: nowrap;
}

.wordmark:hover {
  color: var(--flask-deep);
}

.masthead .navbar {
  margin-inline-start: auto;
  min-height: 0;
  background-color: transparent;
}

.masthead .navbar-brand {
  min-height: 0;
}

.masthead .navbar-item {
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink);
  background-color: transparent;
}

.masthead .navbar-item:hover,
.masthead .navbar-item:focus-visible {
  color: var(--flask);
  background-color: transparent;
}

/* The section you're in: the blog, on its page and on its articles; or About / Contact. */
.masthead .navbar-item[aria-current="page"] {
  color: var(--flask);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.4em;
}

.masthead .navbar-end {
  border-inline-start: 1px solid var(--line);
  margin-inline-start: 0.75rem;
  padding-inline-start: 0.75rem;
}

.masthead .navbar-end .navbar-item {
  color: var(--muted);
  font-weight: 400;
}

@media screen and (min-width: 1024px) {
  .masthead .navbar-menu {
    flex-grow: 0;
  }

  .masthead .navbar-start {
    margin-inline-end: 0;
  }

  .masthead .navbar-item {
    padding-inline: 0.625rem;
  }
}

/*
 * Mobile masthead, below Bulma's 1024px navbar breakpoint (the one that hides the burger and lays
 * the menu out as a row). The nav collapses to its burger at the end of the row, and the open
 * menu drops down as a panel under the band.
 *
 * The menu can't simply wrap onto the next line: it is a child of .navbar, not a flex item of
 * .header-bar. (`display: contents` on the nav would make it one, but it also drops the navigation
 * landmark from the accessibility tree.) So it is positioned absolutely against .masthead instead,
 * which means .navbar has to give up the `position: relative` Bulma gives it, or the panel would
 * be pinned to the burger's ~46px width. z-index matches Bulma's own --bulma-navbar-z.
 */
@media screen and (max-width: 1023px) {
  .masthead {
    position: relative;
  }

  .masthead .navbar {
    position: static;
  }

  .masthead .navbar-burger {
    color: var(--ink);
  }

  .masthead .navbar-menu.is-active {
    position: absolute;
    inset-inline: 0;
    top: calc(100% + 3px);
    z-index: 30;
    padding-block: 0.5rem;
    background-color: var(--paper);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 16px rgb(31 42 46 / 0.08);
  }

  .masthead .navbar-menu .navbar-item {
    padding: 0.625rem 1rem;
  }

  .masthead .navbar-end {
    border-inline-start: 0;
    border-top: 1px solid var(--line);
    margin: 0.5rem 0 0;
    padding: 0.5rem 0 0;
  }
}

/* ---------------------------------------------------------------------------------------------
 * Home page introduction: the drawing and two lines about the site.
 * ------------------------------------------------------------------------------------------- */
.intro {
  display: grid;
  grid-template-columns: minmax(0, 15rem) minmax(0, 1fr);
  align-items: center;
  gap: 2rem;
  padding-bottom: 2.5rem;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--line);
}

.intro-drawing {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.intro-lede {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-variation-settings: "opsz" 36;
  line-height: 1.3;
  letter-spacing: -0.005em;
  text-wrap: balance;
}

.intro-byline {
  margin-top: 0.75rem;
  font-family: var(--sans);
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--muted);
}

.intro-byline a {
  color: var(--flask);
  font-weight: 500;
  white-space: nowrap;
}

@media screen and (max-width: 600px) {
  .intro {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
  }

  .intro-lede {
    font-size: 1.3125rem;
  }
}

/* ---------------------------------------------------------------------------------------------
 * Page and section titles (home, blog pages, About / Contact / Privacy).
 * ------------------------------------------------------------------------------------------- */
.section-title {
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  font-family: var(--serif);
  font-size: 2.25rem;
  font-weight: 650;
  font-variation-settings: "opsz" 48;
  line-height: 1.15;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.page-subtitle {
  margin-top: 0.375rem;
  font-family: var(--sans);
  font-size: 0.9375rem;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------------------------
 * Article lists: welcome/_article_card inside an ol.entries.
 * ------------------------------------------------------------------------------------------- */
.entries {
  list-style: none;
  margin: 0;
  padding: 0;
}

.entries > li {
  padding-block: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.entries > li:first-child {
  padding-top: 1rem;
}

.entries > li:last-child {
  border-bottom: 0;
}

.entry-title {
  font-family: var(--serif);
  font-size: 1.4375rem;
  font-weight: 620;
  font-variation-settings: "opsz" 28;
  line-height: 1.25;
  letter-spacing: -0.005em;
  text-wrap: balance;
}

.entry-title a {
  color: var(--ink);
}

.entry-title a:hover {
  color: var(--flask);
}

.entry-meta {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.4em;
  margin-top: 0.375rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--muted);
}

.entry-meta a {
  color: var(--flask);
}

.entry-meta a:hover {
  color: var(--flask-deep);
  text-decoration: underline;
}

.entry-summary {
  margin-top: 0.5rem;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: #3a464b;
  /* Descriptions are excerpts cut at ~190 characters with "..."; three lines is all of one. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

/* ---------------------------------------------------------------------------------------------
 * Article page
 * ------------------------------------------------------------------------------------------- */
.article-header {
  padding-bottom: 1.75rem;
  margin-bottom: 2.25rem;
  border-bottom: 1px solid var(--line);
}

.article-blog {
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
}

.article-blog a {
  color: var(--flask);
}

.article-blog a:hover {
  color: var(--flask-deep);
}

.article-title {
  margin-top: 0.5rem;
  font-family: var(--serif);
  font-size: 2.625rem;
  font-weight: 650;
  font-variation-settings: "opsz" 60;
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
  color: var(--ink);
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  column-gap: 1.25rem;
  row-gap: 0.25rem;
  margin-top: 1.25rem;
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--muted);
}

.article-meta a {
  color: var(--flask);
}

@media screen and (max-width: 600px) {
  .page {
    padding-top: 1.75rem;
  }

  .article-title {
    font-size: 2rem;
  }

  .page-title {
    font-size: 1.875rem;
  }
}

/* "More in <blog>" under the article. */
.related {
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 2px solid var(--ink);
}

.related-title {
  font-family: var(--serif);
  font-size: 1.375rem;
  font-weight: 650;
  font-variation-settings: "opsz" 28;
}

.related .entries > li:last-child {
  border-bottom: 1px solid var(--line);
}

.related-all {
  display: inline-block;
  margin-top: 1.25rem;
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--flask);
}

/* ---------------------------------------------------------------------------------------------
 * Prose: an article body (the Markdown parser's output, wrapped in a <section>) and the About,
 * Contact and Privacy pages. The parser only emits p, h1–h3, ul/ol/li, em, strong, a, img and a
 * <code data-language> block, plus whatever raw HTML a body contains (u, br, sub/sup); maths
 * arrives as $…$ / $$…$$ text and becomes mjx-container elements in the browser.
 * ------------------------------------------------------------------------------------------- */
.prose {
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.65;
  color: var(--ink);
  overflow-wrap: break-word;
}

.prose > .page-title {
  margin-bottom: 1.5rem;
}

.prose p,
.prose ul,
.prose ol {
  margin-bottom: 1.25em;
}

/* Inline maths can't wrap where it has no operators to break at, and one over-wide formula
   would make the whole page scroll sideways on a phone. This is inert until a paragraph's
   content really is wider than the column; then that paragraph scrolls instead. Not applied to
   li, where it would clip the outside list marker. */
.prose p {
  overflow-x: auto;
}

.prose h1,
.prose h2,
.prose h3 {
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
  text-wrap: balance;
  color: var(--ink);
}

.prose h1:not(.page-title),
.prose h2 {
  margin: 2.25em 0 0.75em;
  font-size: 1.625rem;
  font-variation-settings: "opsz" 36;
}

.prose h3 {
  margin: 1.75em 0 0.5em;
  font-size: 1.3125rem;
  font-variation-settings: "opsz" 28;
}

.prose section > :is(h1, h2, h3):first-child {
  margin-top: 0;
}

.prose a {
  color: var(--flask);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

.prose a:hover {
  color: var(--flask-deep);
  text-decoration-thickness: 2px;
}

.prose strong {
  font-weight: 650;
  color: inherit;
}

.prose ul {
  list-style: disc;
  padding-left: 1.5em;
}

.prose ol {
  list-style: decimal;
  padding-left: 1.5em;
}

.prose li + li {
  margin-top: 0.375em;
}

.prose li::marker {
  color: var(--muted);
}

/* Figures: plots, spectra, structures and typeset formulas, usually alone in their paragraph.
   The parser's "=600" width argument arrives as an inline max-width, which this leaves alone.

   Nearly all of them were exported on a pure white background, which shows as a pale box
   against --paper. Multiply blends white to the paper colour and leaves everything darker
   effectively untouched (--paper is 98.5% white, so a photo darkens by ~1.5%). */
.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.75rem auto;
  mix-blend-mode: multiply;
}

.prose code {
  font-size: 0.85em;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background-color: #eef1ee;
  color: var(--ink);
}

.prose code[data-language] {
  display: block;
  margin-bottom: 1.25em;
  padding: 1rem;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.5;
}

/* Display maths scrolls sideways on a phone rather than overflowing the page. */
.prose mjx-container[display="true"] {
  margin: 1.5em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

/* ---------------------------------------------------------------------------------------------
 * Footer
 * ------------------------------------------------------------------------------------------- */
.site-footer {
  padding-block: 2rem 3rem;
  border-top: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--muted);
}

.site-footer-name {
  font-family: var(--serif);
  font-size: 1.0625rem;
  font-weight: 650;
  color: var(--ink);
}

.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin-block: 0.625rem;
  list-style: none;
  padding: 0;
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--flask);
  text-decoration: underline;
}

/*
 * The admin dashboard's traffic chart (admin/_traffic_chart, plans/007_traffic_logging.md). Admin
 * only, so it hangs off .traffic-chart like the public rules hang off theirs. The two series
 * colours are the first two slots of a colour-blind-checked categorical palette (protan ΔE 24.7
 * between them, both ≥ 3:1 on white); every piece of text stays in ink colours, never a series
 * colour, and the legend and tooltip key each series with a short stroke of its colour.
 */
.traffic-chart {
  --series-hits: #2a78d6;
  --series-visitors: #eb6834;
  --chart-grid: #ececec;
  --chart-axis: #c9c9c9;
  --chart-surface: var(--bulma-scheme-main, #ffffff); /* the box behind it, for the dot rings */
  margin-bottom: 1.5rem;
}

.traffic-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--ink);
}

.traffic-chart-legend li {
  display: flex;
  align-items: center;
}

.traffic-chart-note {
  color: var(--muted);
}

.traffic-chart-key {
  display: inline-block;
  width: 14px;
  height: 2px;
  margin-right: 0.4rem;
  border-radius: 1px;
  vertical-align: middle;
}

.traffic-chart-key-hits { background: var(--series-hits); }
.traffic-chart-key-visitors { background: var(--series-visitors); }

.traffic-chart-frame {
  position: relative;
}

.traffic-chart-frame svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  touch-action: pan-y;
}

.traffic-chart-frame svg:focus-visible {
  outline: 2px solid var(--series-hits);
  outline-offset: 4px;
  border-radius: 2px;
}

.traffic-chart-grid line {
  stroke: var(--chart-grid);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.traffic-chart-grid line.traffic-chart-baseline {
  stroke: var(--chart-axis);
}

.traffic-chart-grid text {
  font-family: var(--sans);
  font-size: 11px;
  fill: var(--muted);
  font-variant-numeric: tabular-nums;
}

.traffic-chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.traffic-chart-line-hits { stroke: var(--series-hits); }
.traffic-chart-line-visitors { stroke: var(--series-visitors); }

/* The segment into the current, incomplete bucket. */
.traffic-chart-line-current { stroke-dasharray: 3 4; }

/* A wash under hits, so the hits series stays visible where the visitors line lies on top of it. */
.traffic-chart-area {
  fill: var(--series-hits);
  fill-opacity: 0.1;
}

/* Filled dots with a surface ring, so they stay legible where the two lines cross. */
.traffic-chart-dot {
  stroke: var(--chart-surface);
  stroke-width: 2;
}

.traffic-chart-dot-hits { fill: var(--series-hits); }
.traffic-chart-dot-visitors { fill: var(--series-visitors); }

.traffic-chart-crosshair {
  stroke: var(--muted);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.traffic-chart-tooltip {
  position: absolute;
  top: 0;
  z-index: 1;
  padding: 0.5rem 0.75rem;
  background: var(--chart-surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.08);
  font-size: 0.8125rem;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
}

.traffic-chart-tooltip[hidden] {
  display: none;
}

.traffic-chart-tooltip strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.traffic-chart-tooltip-label {
  margin-bottom: 0.25rem;
  color: var(--muted);
}

.traffic-chart-table summary {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
  cursor: pointer;
}
