:root {
  --md-text-font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* Readable measure for a long-form text */
.md-typeset {
  font-size: 0.78rem;
  line-height: 1.7;
}

.md-typeset h1,
.md-typeset h2 {
  font-weight: 600;
  letter-spacing: -0.01em;
}

.md-typeset h2 {
  margin-top: 2.2em;
  padding-top: 0.4em;
  border-top: 1px solid var(--md-default-fg-color--lightest);
}

/* Figures */
.md-typeset figure {
  margin: 2em auto;
  max-width: 100%;
}

.md-typeset figure img {
  border-radius: 3px;
  border: 1px solid var(--md-default-fg-color--lightest);
  background: var(--md-default-bg-color);
}

.md-typeset figure.figure-lightbox-ready > img[role="button"],
.md-typeset figure.figure-lightbox-ready:not(.cp-embed) img[role="button"] {
  cursor: zoom-in;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.md-typeset figure.figure-lightbox-ready img[role="button"]:hover,
.md-typeset figure.figure-lightbox-ready img[role="button"]:focus-visible {
  border-color: var(--md-accent-fg-color);
  box-shadow: 0 8px 28px color-mix(in srgb, var(--md-default-fg-color) 18%, transparent);
  outline: none;
  transform: translateY(-1px);
}

.md-typeset figcaption {
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--md-default-fg-color--light);
  max-width: 46rem;
  margin: 0.7em auto 0;
  text-align: center;
}

/* Tables should breathe and never overflow the page */
.md-typeset table:not([class]) {
  font-size: 0.7rem;
  display: table;
}

.md-typeset__table {
  overflow-x: auto;
}

/* Frame-numbering diagrams rely on monospace alignment */
.md-typeset pre > code {
  font-size: 0.68rem;
}

/* Landing page cards */
.md-typeset .grid.cards > ul > li {
  border-radius: 4px;
}

/* Tighten the footnote block */
.md-typeset .footnote {
  font-size: 0.72rem;
}


/* Interactive chromaticity embeds (progressive enhancement over the static SVG).
   The static image shows by default (no-JS, print, or while/if the iframe fails);
   .cp-embed-live is added by color-plot-embed.js once the iframe actually loads. */
.cp-embed .cp-embed-mount {
  position: relative;
  display: block;
  max-width: 620px;
  margin: 0 auto;
  /* Match the embed's plot aspect (the fragment view width/height) so the plot
     canvas fills the iframe edge to edge. Any mismatch letterboxes, and the
     embed's page background is dark regardless of theme, so a mismatch shows as
     dark bars around a light plot. Per-figure override via --cp-embed-aspect. */
  aspect-ratio: var(--cp-embed-aspect, 900 / 820);
}

.figure-lightbox__expand {
  position: absolute;
  z-index: 3;
  top: .55rem;
  right: .55rem;
  display: grid;
  width: 2.1rem;
  height: 2.1rem;
  place-items: center;
  padding: 0;
  color: #fff;
  background: rgba(12, 12, 12, .76);
  border: 1px solid rgba(255, 255, 255, .36);
  border-radius: 6px;
  cursor: zoom-in;
  font: 1.1rem/1 sans-serif;
  opacity: .76;
  backdrop-filter: blur(5px);
  transition: opacity .15s ease, background .15s ease, transform .15s ease;
}

.figure-lightbox__expand:hover,
.figure-lightbox__expand:focus-visible {
  opacity: 1;
  background: rgba(12, 12, 12, .94);
  outline: 2px solid var(--md-accent-fg-color);
  outline-offset: 2px;
  transform: scale(1.04);
}

/* Full-screen figure lightbox */
.figure-lightbox {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: #fff;
  background: rgba(7, 7, 9, .96);
  border: 0;
}

.figure-lightbox::backdrop {
  background: rgba(0, 0, 0, .82);
  backdrop-filter: blur(8px);
}

.figure-lightbox__shell {
  position: relative;
  display: grid;
  grid-template: minmax(0, 1fr) auto / 4rem minmax(0, 1fr) 4rem;
  width: 100%;
  height: 100%;
}

.figure-lightbox__stage {
  grid-area: 1 / 2;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  padding: 0 .5rem;
}

.figure-lightbox__image {
  display: block;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  background: transparent;
  border: 0;
  border-radius: 4px;
  box-shadow: 0 18px 70px rgba(0, 0, 0, .55);
}

.figure-lightbox__frame {
  display: block;
  width: min(94vw, calc((100dvh - 9.5rem) * 1.25));
  max-width: 100%;
  height: min(82vh, 900px);
  max-height: calc(100dvh - 9.5rem);
  background: #111;
  border: 0;
  border-radius: 4px;
  box-shadow: 0 18px 70px rgba(0, 0, 0, .55);
}

.figure-lightbox__close,
.figure-lightbox__previous,
.figure-lightbox__next {
  appearance: none;
  color: #fff;
  background: rgba(255, 255, 255, .09);
  border: 1px solid rgba(255, 255, 255, .16);
  cursor: pointer;
}

.figure-lightbox__close:hover,
.figure-lightbox__previous:hover,
.figure-lightbox__next:hover,
.figure-lightbox__close:focus-visible,
.figure-lightbox__previous:focus-visible,
.figure-lightbox__next:focus-visible {
  color: #111;
  background: var(--md-accent-fg-color);
  outline: none;
}

.figure-lightbox__close {
  position: absolute;
  z-index: 2;
  top: .85rem;
  right: .85rem;
  display: grid;
  width: 2.55rem;
  height: 2.55rem;
  place-items: center;
  padding: 0;
  border-radius: 50%;
}

.figure-lightbox__close::before,
.figure-lightbox__close::after {
  position: absolute;
  width: 1.12rem;
  height: 2px;
  content: "";
  background: currentColor;
  border-radius: 999px;
}

.figure-lightbox__close::before {
  transform: rotate(45deg);
}

.figure-lightbox__close::after {
  transform: rotate(-45deg);
}

.figure-lightbox__previous,
.figure-lightbox__next {
  align-self: center;
  width: 2.8rem;
  height: 4.5rem;
  margin: .6rem;
  border-radius: 7px;
  font: 2.3rem/1 sans-serif;
}

.figure-lightbox__previous { grid-area: 1 / 1; }
.figure-lightbox__next { grid-area: 1 / 3; }

.figure-lightbox__footer {
  grid-area: 2 / 1 / 3 / 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  min-height: 3rem;
  padding: .4rem clamp(1rem, 5vw, 5rem);
  background: rgba(0, 0, 0, .35);
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.figure-lightbox__caption {
  max-width: 70rem;
  margin: 0;
  color: rgba(255, 255, 255, .84);
  font: .8rem/1.45 var(--md-text-font-family, sans-serif);
}

.figure-lightbox__meta {
  display: flex;
  gap: 1rem;
  align-items: center;
  white-space: nowrap;
  font: .72rem/1.3 var(--md-text-font-family, sans-serif);
}

.figure-lightbox__counter { color: rgba(255, 255, 255, .58); }
.figure-lightbox__original { color: #ffc44d; }

@media screen and (max-width: 44.9375em) {
  .figure-lightbox__shell {
    grid-template: minmax(0, 1fr) auto / minmax(0, 1fr);
  }
  .figure-lightbox__stage {
    grid-area: 1 / 1;
    padding: 0 .25rem;
  }
  .figure-lightbox__previous,
  .figure-lightbox__next {
    position: absolute;
    z-index: 2;
    top: 50%;
    width: 2.35rem;
    height: 3.8rem;
    margin: .3rem;
    transform: translateY(-50%);
  }
  .figure-lightbox__previous { left: 0; }
  .figure-lightbox__next { right: 0; }
  .figure-lightbox__footer {
    grid-area: 2 / 1;
    grid-template-columns: 1fr;
    gap: .45rem;
    padding: .7rem 1rem .9rem;
  }
  .figure-lightbox__meta { justify-content: space-between; }
  .figure-lightbox__frame { max-height: calc(100dvh - 11rem); }
}
/* The static SVG and the iframe both fill the aspect box, stacked. */
.cp-embed-static {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* Override the generic `figure img` white background/border: these plots are
     theme-specific SVGs that already carry their own background, so a forced
     white fill letterboxes as a bright halo in dark mode. */
  background: transparent;
  border: none;
  border-radius: 0;
}
/* The iframe overlays the static — never display:none (which would deadlock a
   lazy iframe's load event) — starting transparent and fading in once it loads.
   If it never loads (service down / no JS), the static shows through. */
.cp-embed-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 4px;
  background: transparent;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.cp-embed.cp-embed-live .cp-embed-frame { opacity: 1; }
.cp-embed-hint { color: var(--md-default-fg-color--light); }

/* Print never shows the iframe; keep the static figure. */
@media print {
  .cp-embed-frame { display: none !important; }
  .figure-lightbox,
  .figure-lightbox__expand { display: none !important; }
}

/* Frame-sequence diagrams — one colored cell per frame, so regions never
   visually overlap or share a boundary frame. Pure HTML/CSS: renders
   everywhere, no JS, and adapts to the theme. */
.md-typeset .fseq-fig { margin: 1.4em 0; }
.md-typeset .fseq {
  display: flex;
  flex-wrap: nowrap;               /* one continuous strip, never wraps */
  gap: 2px;
  overflow-x: auto;               /* scroll horizontally if it exceeds the column */
  max-width: 100%;
  padding-bottom: 3px;            /* room for the scrollbar */
  font-family: var(--md-code-font-family, monospace);
  font-size: 0.64rem;
  line-height: 1.2;
}
.md-typeset .fseq .fcell {
  flex: 0 0 auto;                 /* keep width; don't shrink or wrap */
  min-width: 2.6em;
  text-align: center;
  padding: 4px 5px;
  border-radius: 3px;
  border: 1px solid transparent;
  color: var(--md-default-fg-color);
}
.md-typeset .fseq .h { background: #e0912f26; border-color: #e0912f8c; }  /* handle */
.md-typeset .fseq .e { background: #4c7ef526; border-color: #4c7ef58c; }  /* edit   */
.md-typeset .fseq .s { background: #7a869544; border-color: #7a8695aa; }  /* slate  */
.md-typeset .fseq-key { margin: .5em 0 0; font-size: .64rem; color: var(--md-default-fg-color--light); }
.md-typeset .fseq-key .sw {
  display: inline-block; width: .8em; height: .8em; border-radius: 2px;
  vertical-align: -1px; margin: 0 .3em 0 .9em; border: 1px solid;
}
.md-typeset .fseq-key .sw:first-child { margin-left: 0; }

/* The di|vfx wordmark is solid black, and the header/nav drawer are black in BOTH
   themes (primary: black), so invert the logo to white everywhere it sits on them. */
.md-logo img,
.md-header__button.md-logo img,
.md-nav__button.md-logo img {
  filter: invert(1);
}

/* Drop the long site title from the primary navigation sidebar / drawer (the header
   still carries the logo and title). */
.md-nav--primary > .md-nav__title {
  display: none;
}

/* Mermaid workflow diagrams — Material themes the palette; these polish the
   geometry (rounder corners, slightly heavier links, tidier labels). */
.md-typeset .mermaid {
  margin: 1.6em 0;
  text-align: center;
}
.md-typeset .mermaid .node rect,
.md-typeset .mermaid .node path,
.md-typeset .mermaid .node polygon {
  rx: 8px;
  ry: 8px;
}
.md-typeset .mermaid .cluster rect {
  rx: 12px;
  ry: 12px;
}
.md-typeset .mermaid .flowchart-link {
  stroke-width: 1.6px;
}
.md-typeset .mermaid .edgeLabel {
  font-size: 0.68rem;
}
/* Caption paragraph immediately after a diagram */
.md-typeset .mermaid + p em {
  color: var(--md-default-fg-color--light);
  font-size: 0.72rem;
}

/* Contact form (Formspree) — theme-aware. The form is an elevated card so the
   page-coloured fields read as inset panels (they'd otherwise vanish against the
   body background), and the CTA uses the amber accent instead of the near-black
   primary that disappeared on the dark theme. */
.md-typeset .contact-form {
  max-width: 42rem; margin: 1.8em 0;
  padding: 1.6rem 1.6rem 1.5rem;
  background: color-mix(in srgb, var(--md-default-fg-color) 3.5%, var(--md-default-bg-color));
  border: 1px solid color-mix(in srgb, var(--md-default-fg-color) 12%, transparent);
  border-radius: 12px;
}
.md-typeset .contact-form .cf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.md-typeset .contact-form .cf-grid .cf-field { margin-bottom: 0; }
.md-typeset .contact-form .cf-field { display: block; margin-bottom: 1rem; }
.md-typeset .contact-form .cf-field > span {
  display: block; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--md-default-fg-color--light); margin-bottom: .45rem;
}
.md-typeset .contact-form input,
.md-typeset .contact-form textarea {
  width: 100%; box-sizing: border-box; padding: .65rem .8rem; font: inherit; font-size: .8rem; line-height: 1.5;
  color: var(--md-default-fg-color);
  background: var(--md-default-bg-color);
  border: 1px solid color-mix(in srgb, var(--md-default-fg-color) 20%, transparent);
  border-radius: 7px; transition: border-color .15s ease, box-shadow .15s ease;
}
.md-typeset .contact-form input::placeholder,
.md-typeset .contact-form textarea::placeholder { color: var(--md-default-fg-color--light); opacity: 1; }
.md-typeset .contact-form textarea { resize: vertical; min-height: 7rem; }
.md-typeset .contact-form input:hover,
.md-typeset .contact-form textarea:hover { border-color: color-mix(in srgb, var(--md-default-fg-color) 38%, transparent); }
.md-typeset .contact-form input:focus,
.md-typeset .contact-form textarea:focus {
  outline: none; border-color: var(--md-accent-fg-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-accent-fg-color) 25%, transparent);
}
.md-typeset .contact-form .cf-submit {
  appearance: none; cursor: pointer; margin-top: .4rem;
  padding: .7rem 1.7rem; font: inherit; font-size: .8rem; font-weight: 700; letter-spacing: .01em;
  color: #17130a; background: var(--md-accent-fg-color);
  border: none; border-radius: 7px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
  transition: filter .15s ease, transform .05s ease, box-shadow .15s ease;
}
.md-typeset .contact-form .cf-submit:hover { filter: brightness(1.07); box-shadow: 0 3px 10px color-mix(in srgb, var(--md-accent-fg-color) 40%, transparent); }
.md-typeset .contact-form .cf-submit:active { transform: translateY(1px); box-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.md-typeset .contact-form .cf-submit[disabled] { opacity: .6; cursor: default; filter: none; }
.md-typeset .contact-form .cf-success { margin: 0; font-weight: 700; color: var(--md-typeset-color); }
.md-typeset .contact-form .cf-error { margin: .6rem 0 0; font-size: .7rem; color: #c65a5a; }
@media screen and (max-width: 44.9375em) {
  .md-typeset .contact-form { padding: 1.2rem; }
  .md-typeset .contact-form .cf-grid { grid-template-columns: 1fr; gap: 0; }
  .md-typeset .contact-form .cf-grid .cf-field { margin-bottom: 1rem; }
}
