/* style.css */
/* Define colors */
:root {
    --distill-gray: rgb(107, 114, 128);
    --distill-gray-light: rgb(185, 185, 185);
    --distill-gray-lighter: rgb(228, 228, 228);
    --distill-gray-lightest: rgb(245, 245, 245);
    --distill-blue: #007BFF;
}

/* Container for the controls */
[id^="plot-"] {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px; /* Adjust the gap between controls as needed */
}
[id^="plot-"] figure {
    margin-bottom: 0px;
    margin-top: 0px;
    padding: 0px;
}
.plotly_caption {
    font-style: italic;
    margin-top: 10px;
}

.plotly_controls {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 30px;
}


.plotly_input_container {
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 10px;
}

/* Style for the select dropdown */
.plotly_input_container > select {
    padding: 2px 4px;
    /* border: 1px solid #ccc; */
    line-height: 1.5em;
    text-align: center;
    border-radius: 4px;
    font-size: 12px;
    background-color: var(--distill-gray-lightest);
    outline: none;
}

/* Style for the range input */

.plotly_slider {
    display: flex;
    align-items: center;
    gap: 10px;
}

.plotly_slider > input[type="range"] {
    -webkit-appearance: none;
    height: 2px;
    background: var(--distill-gray-light);
    border-radius: 5px;
    outline: none;
}

.plotly_slider > span {
    font-size: 14px;
    line-height: 1.6em;
    min-width: 16px;
}

.plotly_slider > input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--distill-blue);
    cursor: pointer;
}

.plotly_slider > input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--distill-blue);
    cursor: pointer;
}

/* Style for the labels */
.plotly_input_container > label {
    font-size: 14px;
    font-weight: bold;
}

.main-plot-container {
    margin-top: 21px;
    margin-bottom: 35px;
}

.main-plot-container > figure {
    display: block !important;
    /* Let this be handled by graph-container */
    margin-bottom: 0px;
    margin-top: 0px;
}
.main-plot-container > div {
    display: none !important;
}


@media (min-width: 768px) {
    .main-plot-container > figure {
        display: none !important;
    }
    .main-plot-container > div {
        display: flex !important;
    }
}

d-byline .byline {
  grid-template-columns: 1fr;
  grid-column: text;
  font-size: 0.9rem;
  line-height: 1.8em;
}

@media (min-width: 768px) {
  d-byline .byline {
    grid-template-columns: 5fr 1fr 1fr;
  }
}

#title-plot {
    margin-top: 0px;
    margin-bottom: 0px;
}

d-contents > nav a.active {
    text-decoration: underline;
}

@media (max-width: 1199px) {
    d-contents {
        display: block;
        background: transparent;
        justify-self: start;
        align-self: start;
        padding-bottom: 0.5em;
        margin-bottom: 1.5em;
        padding-left: 0.25em;
        border-bottom: 1px solid var(--color-separator-subtle);
    }
}

d-contents a:hover {
    border-bottom: none;
}

toc-title {
    font-weight: bold;
    font-size: 1.2em;
    color: #333;
}

toggle-icon {
    transition: transform 0.3s;
}

toggle-icon.collapsed {
    transform: rotate(90deg);
}

.toc-content {
    margin-top: 15px;
    overflow: hidden;
    /* max-height: 1000px; */
    transition: max-height 0.3s ease-out;
}

.toc-content.collapsed {
    max-height: 0;
    margin-top: 0;
}

@media (min-width: 1200px) {
    d-article {
        /* Distill's bundled CSS sets contain: layout style on d-article.
         * contain: layout creates a new containing block that prevents
         * position: sticky from sticking to the viewport. Override it. */
        overflow: visible !important;
        contain: style !important;
    }

    d-contents {
        align-self: start;
        background: transparent;
        grid-column-start: 1 !important;
        grid-column-end: 4 !important;
        grid-row: auto / span 6;
        justify-self: end;
        margin-top: 0em;
        padding-right: 3em;
        padding-left: 2em;
        position: -webkit-sticky;
        position: sticky;
        top: 10px;
        overflow-y: auto;
        height: calc(100vh - 40px);
        scrollbar-width: none;
        z-index: 1;
    }
}

d-contents nav h3 {
    margin-top: 0;
    margin-bottom: 1em;
}

d-contents nav div div {
    color: rgba(0, 0, 0, 0.8);
    font-weight: bold;
}

d-contents nav a {
    color: rgba(0, 0, 0, 0.8);
    border-bottom: none;
    text-decoration: none;
}

d-contents li {
    list-style-type: none;
}

d-contents ul, d-article d-contents ul {
    padding-left: 1em;
}

d-contents nav ul li {
    margin-bottom: .25em;
}

d-contents nav a:hover {
    text-decoration: underline solid rgba(0, 0, 0, 0.6);
}

d-contents nav ul {
    margin-top: 0;
    margin-bottom: 6px;
}


d-contents nav > div {
    display: block;
    outline: none;
    margin-bottom: 0.5em;
}

d-contents nav > div > a {
    font-size: 13px;
    font-weight: 600;
}

d-article aside {
    margin-bottom: 1em;
}

d-article img {
    max-width: 100%;
}

@media (min-width: 768px) {
    d-article aside {
        margin-bottom: 0;
    }
}

d-contents nav > div > a:hover,
d-contents nav > ul > li > a:hover {
    text-decoration: none;
}

.note-box {
    background-color: #f6f8fa;
    border-left: 4px solid #444444;
    padding: 1rem;
    margin: 1rem 0;  /* Keep this modest margin */
    border-radius: 6px;
    /* Add this to ensure the box only takes up needed space */
    display: inline-block;
    width: 100%;
}

.note-box-title {
    margin: 0;
    color: #444444;
    font-weight: 600;
    font-size: 1em;
}

.note-box-content {
    margin-top: 0.5rem;
    margin-bottom: 0;  /* Ensure no bottom margin */
    color: #24292f;
    font-size: 0.9em;
    line-height: 1.5em;
}

/* For dark mode support */
@media (prefers-color-scheme: dark) {
    .note-box {
        background-color: #1c1c1c;
        border-left-color: #888888;
    }
    .note-box-title {
        color: #888888;
    }
    .note-box-content {
        color: #d4d4d4;
    }
}

d-article {
    font-size: 1.0em;
}

.figure-legend {
    font-size: 0.9em;
    font-style: italic;
    color: var(--distill-gray);
    line-height: 1.5em;
}

d-code {
    font-size: 12px;
}

.large-image-background {
        width: 100vw;
        padding-top: 10px;
        padding-bottom: 10px;
        margin-left: calc(-50vw + 50%);
        margin-right: calc(-50vw + 50%);
        background: transparent;
        height: fit-content; /* This will make it match the image height */
        display: flex;
        justify-content: center; /* This will center your image */
}

.large-image-background-transparent {
    /* width: 100vw; */
    padding-top: 10px;
    padding-bottom: 10px;
    /* margin-left: calc(-50vw + 50%); */
    margin-left:-100px;
    margin-right: -100px;
    /* margin-right: calc(-50vw + 50%); */
    /* background: white; */
    height: fit-content; /* This will make it match the image height */
    display: flex;
    justify-content: center; /* This will center your image */
}

.boxed-image {
    padding: 0.5rem;
    background: white;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

d-article li {
    margin-bottom: 0.0em;
}

d-article ul ul {
    margin-bottom: 0.0em;
}

d-article ol ol {
    margin-bottom: 0.0em;
}

d-article hr {
    grid-column: text;
}

/* Memory visualization */
#graph-all {
    min-width: 500px;
    margin-right: 10px;
    margin-bottom: 2rem;
    padding: 0.5rem;
    background: #f9fafb;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}


/* Main container styles */
#controls {
    max-width: 1200px;
    /* margin: 2rem auto; */
    margin-bottom: 2rem;
    margin-left: 10px;
    padding: 0.6rem;
    background: #f9fafb;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Grid layout */
#controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* gap: 2rem; */
}

/* Cell styles */
.cell {
    margin-bottom: 0.2rem;
}

/* Label styles */
label {
    display: block;
    /* margin-bottom: 0.5rem; */
    font-size: 0.8rem;
    font-weight: 500;
    color: #374151;
}

/* Input container for range + number combination */
.input-container {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* Range input styling */
input[type="range"] {
    flex: 1;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    appearance: none;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #2563eb;
}

/* Number input styling */
input[type="number"] {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #374151;
}

/* Select styling */
select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: white;
    font-size: 0.9rem;
    color: #374151;
    cursor: pointer;
}

/* Checkbox styling */
input[type="checkbox"] {
    width: 1.2rem;
    height: 1.2rem;
    margin-right: 0.5rem;
    border: 2px solid #e5e7eb;
    border-radius: 4px;
    cursor: pointer;
}

/* Column specific styles */
.column-1 {
    padding-right: 0.5rem;
}

.column-2 {
    padding-left: 0.5rem;
}

/* Checkbox container */
.checkbox-container {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

/* Memory visualization styles */
.memory-block {
    background: #fff;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.memory-title {
    font-size: 1.1rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.5rem;
}

.memory-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: #3b82f6;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #controls {
        grid-template-columns: 1fr;
        padding: 1rem;
    }

    .column-1, .column-2 {
        padding: 0;
    }
}

/* Hover states and transitions */
input:hover, select:hover {
    border-color: #3b82f6;
}

input:focus, select:focus {
    border-color: #2563eb;
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Add smooth transitions */
input, select, button {
    transition: all 0.15s ease;
}

/* Preset dropdown special styling */
select[name="presets"] {
    background-color: #f3f4f6;
    font-weight: 500;
}

/* Memory graph enhancements */
.activation-memory {
    background: #dbeafe;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.gradient-memory {
    background: #ede9fe;
    padding: 1rem;
    border-radius: 8px;
}


/* ============================================================
 * sdan design system — overrides + additions
 * Lifted from ~/Developer/suryad/styles/new.css.
 * Loaded after Distill's defaults so these take precedence.
 * ============================================================ */

/* No bundled web fonts. We use the system stack (matches sdan.io):
 *   -apple-system / BlinkMacSystemFont resolve to San Francisco on Apple,
 *   then Helvetica Neue → Helvetica → Arial elsewhere.
 * Zero font payload, instant first paint, no FOIT/FOUT. */

:root {
  --background-color: #fafaf9;
  --text-color: rgb(22, 23, 26);
  --border-color: #edf2f7;
  --link-color: #000;
  --code-background: rgb(236, 237, 238);
  --text-primary: var(--text-color);
  --text-muted: color-mix(in srgb, var(--text-color) 70%, transparent);
  --text-faint: color-mix(in srgb, var(--text-color) 45%, transparent);

  --color-success: #22c55e;
  --color-error: #ef4444;
  --color-separator: rgba(128, 128, 128, 0.10);
  --color-separator-subtle: rgba(128, 128, 128, 0.06);
  --color-separator-form: rgba(128, 128, 128, 0.18);

  --feed-row-hover: color-mix(in srgb, var(--text-color) 4.5%, transparent);
  --feed-row-active: color-mix(in srgb, var(--text-color) 7.5%, transparent);
  --feed-row-inset: clamp(0.7rem, 1.6vw, 0.9rem);
  --feed-row-radius: clamp(0.625rem, 1.2vw, 0.85rem);
  --feed-row-y-pad: clamp(0.56rem, 1vw, 0.78rem);
  --feed-row-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset;
  --feed-row-shadow-active: 0 1px 0 rgba(255, 255, 255, 0.18) inset;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --space-xl: 1.5rem;
  --space-2xl: 2rem;
  --space-3xl: 2.5rem;
  --space-4xl: 3rem;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Helvetica Neue',
               Helvetica, Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, 'Helvetica Neue',
                  Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas,
               'Liberation Mono', monospace;

  --content-width: 720px;
  --page-width: 880px;
}

[data-theme='dark'],
:root.dark {
  --background-color: #1a1818;
  --text-color: #d4d4d4;
  --border-color: #333;
  --link-color: #ededed;
  --code-background: #2f2c2c;
  --code-border: #3a3636;
  --text-muted: color-mix(in srgb, var(--text-color) 70%, transparent);
  --text-faint: color-mix(in srgb, var(--text-color) 45%, transparent);
  /* Hairlines need more weight on a dark background — 6% gray reads as
   * "missing." Bumping each tier so dividers remain perceptible. */
  --color-separator: rgba(180, 180, 180, 0.18);
  --color-separator-subtle: rgba(180, 180, 180, 0.12);
  --color-separator-form: rgba(180, 180, 180, 0.26);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --background-color: #1a1818;
    --text-color: #d4d4d4;
    --border-color: #333;
    --link-color: #ededed;
    --code-background: #2f2c2c;
    --code-border: #3a3636;
    --text-muted: color-mix(in srgb, var(--text-color) 70%, transparent);
    --text-faint: color-mix(in srgb, var(--text-color) 45%, transparent);
    --color-separator: rgba(180, 180, 180, 0.18);
    --color-separator-subtle: rgba(180, 180, 180, 0.12);
    --color-separator-form: rgba(180, 180, 180, 0.26);
  }
}

html {
  background: var(--background-color);
  color: var(--text-color);
}

body {
  margin: 0;
  background: var(--background-color);
  color: var(--text-color);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--link-color);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 120ms ease;
}
a:hover { text-decoration-color: currentColor; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  letter-spacing: -0.015em;
  color: var(--text-color);
}

code, pre, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.92em;
}
code:not(pre code) {
  background: var(--code-background);
  padding: 0.12em 0.32em;
  border-radius: 4px;
}

/* ------------------------------------------------------------
 * Theme toggle button (works on listing + posts)
 * ------------------------------------------------------------ */
.theme-toggle {
  appearance: none;
  background: transparent;
  border: none;
  width: 28px; height: 28px;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms ease, color 120ms ease;
  padding: 0;
  opacity: 0.5;
}
.theme-toggle:hover {
  background: var(--feed-row-hover);
  color: var(--text-color);
  opacity: 1;
}
.theme-toggle svg { width: 14px; height: 14px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline; }
[data-theme='dark'] .theme-toggle .icon-sun { display: inline; }
[data-theme='dark'] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme='light']) .theme-toggle .icon-moon { display: none; }
}

/* ------------------------------------------------------------
 * Listing page (homepage)
 * ------------------------------------------------------------ */
body.listing {
  font-family: var(--font-sans);
  max-width: var(--page-width);
  margin: 0 auto;
  padding: var(--space-3xl) var(--space-2xl);
}

.listing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4xl);
}
.listing-title {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}
.listing-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}
.listing-home {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
}
.listing-home:hover { color: var(--text-color); }

.listing-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

/* Featured tier: hero (left, 2/3) + stack of 2 medium cards (right, 1/3).
 * The grid row height is set by the hero's aspect ratio. The card-stack
 * fills that same height and splits evenly between its two children. */
.listing-tier--featured {
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr;
  gap: var(--space-lg);
}
@media (max-width: 720px) {
  .listing-tier--featured { grid-template-columns: 1fr; grid-template-rows: auto; }
}

.listing-card-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  /* Fill the grid row so both mediums split the hero's height */
  min-height: 0;
}

.listing-card {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 14px;
  background-color: var(--code-background);
  background-size: cover;
  background-position: center;
  text-decoration: none;
  color: #fff;
  isolation: isolate;
  transition: transform 200ms ease;
}
.listing-card:hover { transform: translateY(-2px); }

/* Hero fills its grid cell entirely — aspect ratio driven by the 2fr width */
.listing-card--hero {
  aspect-ratio: 16 / 11;
}

/* Medium cards each take exactly half the stack (minus the gap) */
.listing-card--medium {
  flex: 1;
  min-height: 0;
}
@media (max-width: 720px) {
  .listing-card--hero { aspect-ratio: 16 / 10; }
  .listing-card--medium { aspect-ratio: 16 / 9; }
}

.listing-card-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0) 30%,
    rgba(0, 0, 0, 0.7) 100%
  );
  z-index: 1;
}
.listing-card-meta {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: var(--space-xl);
  z-index: 2;
}
.listing-card-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-xs) 0;
  color: #fff;
  line-height: 1.2;
}
.listing-card--hero .listing-card-title { font-size: 1.875rem; }
.listing-card-date {
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.78);
}

/* archive (text-only rows) */
.listing-archive {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--color-separator-subtle);
}
.listing-archive-row {
  border-bottom: 1px solid var(--color-separator-subtle);
}
.listing-archive-link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-lg);
  padding: var(--feed-row-y-pad) var(--feed-row-inset);
  margin: 0 calc(var(--feed-row-inset) * -1);
  text-decoration: none;
  color: var(--text-color);
  border-radius: var(--feed-row-radius);
  transition: background 120ms ease, box-shadow 120ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .listing-archive-link:hover {
    background: var(--feed-row-hover);
    box-shadow: var(--feed-row-shadow);
  }
}
.listing-archive-link:active {
  background: var(--feed-row-active);
  box-shadow: var(--feed-row-shadow-active);
}
.listing-archive-title {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.listing-archive-date {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.listing-footer {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-separator-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-md);
  color: var(--text-muted);
}
.listing-footer-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}
.listing-footer-icon:hover {
  background: var(--feed-row-hover);
  color: var(--text-color);
}
.listing-footer-icon svg {
  width: 16px;
  height: 16px;
}

/* ------------------------------------------------------------
 * Post pages (Distill <d-article> overrides)
 * ------------------------------------------------------------ */
body.post {
  background: var(--background-color);
  color: var(--text-color);
  overflow-x: hidden;
}

d-title h1 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.025em;
}
d-title .post-description,
d-title p {
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-size: 1.125rem;
}

d-article p,
d-article li {
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.7;
}
d-article h2 {
  margin-top: var(--space-4xl);
  font-size: 1.5rem;
}
d-article h3 {
  margin-top: var(--space-3xl);
  font-size: 1.1875rem;
}

d-article a {
  color: var(--link-color);
}

d-article aside {
  font-family: var(--font-sans);
  color: var(--text-muted);
  border-left: 2px solid var(--color-separator-form);
  padding-left: var(--space-md);
}

d-article figure {
  margin: var(--space-2xl) 0;
}
d-article figcaption {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: var(--space-sm);
  line-height: 1.5;
}

/* Heading anchor link (added by anchor-headings.js) */
.heading-anchor {
  margin-left: 0.4em;
  opacity: 0;
  text-decoration: none;
  color: var(--text-faint);
  font-weight: 400;
  transition: opacity 120ms ease;
}
:is(h1, h2, h3, h4):hover .heading-anchor { opacity: 1; }

/* Code block copy button */
d-code, pre {
  position: relative;
}
.code-copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  appearance: none;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--color-separator);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease, background 120ms ease;
}
:is(d-code, pre):hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { background: rgba(0, 0, 0, 0.1); }

/* ------------------------------------------------------------
 * Byline "Copy page" button (replaces Distill's PDF download icon).
 * The icon swap happens in src/components/byline-copy.js.
 * ------------------------------------------------------------ */
.byline-copy-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--color-separator);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  margin-top: 4px;
}
.byline-copy-btn:hover {
  background: var(--feed-row-hover);
  color: var(--text-color);
  border-color: var(--color-separator-form);
}
.byline-copy-btn svg { width: 14px; height: 14px; }

/* The Copy column has no <h3> heading. Distill's other columns use a 0.6rem
 * uppercase heading (~14px line height with margin); push the button down
 * slightly so it sits on the same baseline as the values in those columns. */
d-byline .side.pdf-download { padding-top: 1.4em; }
.post-actions-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--color-separator);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.post-actions-btn:hover {
  background: var(--feed-row-hover);
  color: var(--text-color);
  border-color: var(--color-separator-form);
}
.post-actions-btn svg { width: 14px; height: 14px; }

/* ------------------------------------------------------------
 * Post appendix — citation + BibTeX block (Distill <d-appendix>)
 * ------------------------------------------------------------ */
d-appendix {
  background: transparent;
  border-top: 1px solid var(--color-separator-subtle);
  margin-top: var(--space-4xl);
  padding-top: var(--space-2xl);
  color: var(--text-muted);
  font-size: 0.875rem;
}
d-appendix h3 {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-color);
  margin: var(--space-xl) 0 var(--space-sm) 0;
  letter-spacing: -0.01em;
}
d-appendix h3:first-of-type { margin-top: 0; }
d-appendix p {
  margin: 0 0 var(--space-sm) 0;
  font-size: 0.875rem;
}
d-appendix pre.citation {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  background: var(--code-background);
  border: 1px solid var(--color-separator-subtle);
  border-radius: 8px;
  padding: var(--space-md) var(--space-lg);
  margin: 0 0 var(--space-lg) 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text-color);
  overflow-x: auto;
}

/* ------------------------------------------------------------
 * Post masthead — thin top strip (sdan wordmark + theme toggle).
 * Modeled on distill.pub's <distill-header>: small, non-sticky,
 * disappears as you read.
 * ------------------------------------------------------------ */
.post-masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: var(--space-lg) var(--space-2xl);
  border-bottom: 1px solid var(--color-separator-subtle);
  font-size: 0.875rem;
}
.post-masthead-home {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-color);
  text-decoration: none;
}
.post-masthead-home {
  text-decoration: none;
}
.post-masthead-home:hover {
  text-decoration: underline;
  text-decoration-skip-ink: none;
}

/* No post-coda. Posts end on <d-appendix> — distill.pub convention. */

/* ============================================================
 * Dark-mode override layer for Distill's bundled CSS.
 *
 * distill.js inlines ~1300 lines of CSS for d-* components, all
 * with hardcoded rgba(0,0,0,X) colors that assume a white page.
 * This block re-binds those colors to var(--text-*) tokens when
 * dark mode is active. Two triggers:
 *   1. [data-theme='dark'] (explicit user toggle, persisted)
 *   2. prefers-color-scheme: dark on a fresh visit
 *
 * Anything we add later (KaTeX math, prism syntax, new d-*
 * components) needs a corresponding rule here. Add to the bottom.
 * ============================================================ */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    /* duplicated from above so the @media block can reach Distill selectors */
  }
}

/* Use a shared selector list pattern: the explicit dark theme OR the
 * prefers-color-scheme dark *without* a light override. Each rule below
 * needs both contexts so the toggle and OS auto-detection both work. */

[data-theme='dark'] d-title h1,
[data-theme='dark'] d-title p,
[data-theme='dark'] d-article,
[data-theme='dark'] d-article p,
[data-theme='dark'] d-article ul,
[data-theme='dark'] d-article ol,
[data-theme='dark'] d-article li,
[data-theme='dark'] d-article h2,
[data-theme='dark'] d-article h3,
[data-theme='dark'] d-article h4,
[data-theme='dark'] d-article strong,
[data-theme='dark'] d-article em,
[data-theme='dark'] d-byline,
[data-theme='dark'] d-byline p,
[data-theme='dark'] d-appendix,
[data-theme='dark'] d-appendix p {
  color: var(--text-color);
}

[data-theme='dark'] d-byline h3,
[data-theme='dark'] d-appendix h3,
[data-theme='dark'] .figcaption,
[data-theme='dark'] figcaption,
[data-theme='dark'] .kicker,
[data-theme='dark'] .marker,
[data-theme='dark'] d-article aside,
[data-theme='dark'] d-article blockquote,
[data-theme='dark'] d-article figcaption,
[data-theme='dark'] d-article figcaption a {
  color: var(--text-muted);
}

[data-theme='dark'] d-article a,
[data-theme='dark'] d-byline a,
[data-theme='dark'] d-article d-byline a,
[data-theme='dark'] d-article d-cite,
[data-theme='dark'] d-article .citation {
  color: var(--link-color);
}

[data-theme='dark'] d-article a {
  border-bottom-color: color-mix(in srgb, var(--text-color) 35%, transparent);
}
[data-theme='dark'] d-article a:hover {
  border-bottom-color: var(--text-color);
}

[data-theme='dark'] d-article hr,
[data-theme='dark'] d-byline,
[data-theme='dark'] d-article,
[data-theme='dark'] d-article h2 {
  border-color: var(--color-separator);
}

[data-theme='dark'] d-article table,
[data-theme='dark'] d-article table th,
[data-theme='dark'] d-article table td,
[data-theme='dark'] table thead {
  border-color: var(--color-separator);
}

[data-theme='dark'] d-article blockquote {
  border-left-color: var(--color-separator-form);
}

/* TOC */
[data-theme='dark'] d-contents,
[data-theme='dark'] d-contents nav a,
[data-theme='dark'] d-contents nav h3,
[data-theme='dark'] .toc-title {
  color: var(--text-color);
}
[data-theme='dark'] d-contents > nav a.active {
  color: var(--text-color);
}

/* KaTeX math — Distill's bundled CSS hardcodes span.katex color: rgba(0,0,0,0.8).
 * KaTeX renders many descendant spans (.mord, .mrel, .mop, .msupsub, etc.) so
 * we hit the entire subtree to make sure every glyph picks up the right color. */
[data-theme='dark'] span.katex,
[data-theme='dark'] .katex,
[data-theme='dark'] .katex *,
[data-theme='dark'] .katex-display,
[data-theme='dark'] .katex-display *,
[data-theme='dark'] d-math,
[data-theme='dark'] d-math * {
  color: var(--text-color);
}

/* Code blocks (Prism syntax tokens are colorful — leave them, but flip
 * the base text + background) */
[data-theme='dark'] code[class*="language-"],
[data-theme='dark'] pre[class*="language-"] {
  color: var(--text-color);
  text-shadow: none;
  background: var(--code-background);
}
[data-theme='dark'] :not(pre) > code[class*="language-"],
[data-theme='dark'] pre[class*="language-"] {
  background: var(--code-background);
}
[data-theme='dark'] d-code,
[data-theme='dark'] d-article pre {
  background: var(--code-background);
  color: var(--text-color);
}

/* Citation/BibTeX block in <d-appendix> */
[data-theme='dark'] d-appendix pre.citation {
  background: var(--code-background);
  border-color: var(--color-separator);
  color: var(--text-color);
}

/* Listing chrome already uses tokens — just confirm hover wash works */
[data-theme='dark'] .listing-archive-link:hover {
  background: var(--feed-row-hover);
  box-shadow: var(--feed-row-shadow-active);
}

/* Mirror everything for prefers-color-scheme: dark when no explicit toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) d-title h1,
  :root:not([data-theme='light']) d-title p,
  :root:not([data-theme='light']) d-article,
  :root:not([data-theme='light']) d-article p,
  :root:not([data-theme='light']) d-article ul,
  :root:not([data-theme='light']) d-article ol,
  :root:not([data-theme='light']) d-article li,
  :root:not([data-theme='light']) d-article h2,
  :root:not([data-theme='light']) d-article h3,
  :root:not([data-theme='light']) d-article h4,
  :root:not([data-theme='light']) d-article strong,
  :root:not([data-theme='light']) d-article em,
  :root:not([data-theme='light']) d-byline,
  :root:not([data-theme='light']) d-byline p,
  :root:not([data-theme='light']) d-appendix,
  :root:not([data-theme='light']) d-appendix p {
    color: var(--text-color);
  }
  :root:not([data-theme='light']) d-byline h3,
  :root:not([data-theme='light']) d-appendix h3,
  :root:not([data-theme='light']) .figcaption,
  :root:not([data-theme='light']) figcaption,
  :root:not([data-theme='light']) .kicker,
  :root:not([data-theme='light']) .marker,
  :root:not([data-theme='light']) d-article aside,
  :root:not([data-theme='light']) d-article blockquote,
  :root:not([data-theme='light']) d-article figcaption,
  :root:not([data-theme='light']) d-article figcaption a {
    color: var(--text-muted);
  }
  :root:not([data-theme='light']) d-article a,
  :root:not([data-theme='light']) d-byline a,
  :root:not([data-theme='light']) d-article d-byline a,
  :root:not([data-theme='light']) d-article d-cite,
  :root:not([data-theme='light']) d-article .citation {
    color: var(--link-color);
  }
  :root:not([data-theme='light']) d-article a {
    border-bottom-color: color-mix(in srgb, var(--text-color) 35%, transparent);
  }
  :root:not([data-theme='light']) d-article a:hover {
    border-bottom-color: var(--text-color);
  }
  :root:not([data-theme='light']) d-article hr,
  :root:not([data-theme='light']) d-byline,
  :root:not([data-theme='light']) d-article,
  :root:not([data-theme='light']) d-article h2 {
    border-color: var(--color-separator);
  }
  :root:not([data-theme='light']) d-article table,
  :root:not([data-theme='light']) d-article table th,
  :root:not([data-theme='light']) d-article table td,
  :root:not([data-theme='light']) table thead {
    border-color: var(--color-separator);
  }
  :root:not([data-theme='light']) d-article blockquote {
    border-left-color: var(--color-separator-form);
  }
  :root:not([data-theme='light']) d-contents,
  :root:not([data-theme='light']) d-contents nav a,
  :root:not([data-theme='light']) d-contents nav h3,
  :root:not([data-theme='light']) .toc-title {
    color: var(--text-color);
  }
  :root:not([data-theme='light']) span.katex,
  :root:not([data-theme='light']) .katex,
  :root:not([data-theme='light']) .katex *,
  :root:not([data-theme='light']) .katex-display,
  :root:not([data-theme='light']) .katex-display *,
  :root:not([data-theme='light']) d-math,
  :root:not([data-theme='light']) d-math * {
    color: var(--text-color);
  }
  :root:not([data-theme='light']) code[class*="language-"],
  :root:not([data-theme='light']) pre[class*="language-"] {
    color: var(--text-color);
    text-shadow: none;
    background: var(--code-background);
  }
  :root:not([data-theme='light']) d-code,
  :root:not([data-theme='light']) d-article pre {
    background: var(--code-background);
    color: var(--text-color);
  }
  :root:not([data-theme='light']) d-appendix pre.citation {
    background: var(--code-background);
    border-color: var(--color-separator);
    color: var(--text-color);
  }
}
