/* =========================================================================
   CORE — ships to production
   ========================================================================= */

/* ---------- Light theme tokens (default) ---------- */
:root {
  --paper:      #faf8f5;
  --paper-sunk: #f3efe7;
  --ink:        #1c1b18;
  --ink-muted:  #5b554d;
  --ink-faint:  #908778;
  --rule:       #e3ddd1;
  --rule-soft:  #ece6d9;

  --accent:     oklch(0.78 0.17 92);
  --accent-ink: oklch(0.62 0.16 92);
  --accent-wash: oklch(0.78 0.17 92 / 0.32);

  --serif: "Iowan Old Style", "Charter", "Source Serif Pro", "Source Serif 4",
           Cambria, Georgia, "Times New Roman", serif;
  --mono:  ui-monospace, "JetBrains Mono", "SF Mono", "Menlo",
           "Cascadia Mono", Consolas, monospace;

  --measure: 64ch;
  --gutter: clamp(1.25rem, 4vw, 2rem);

  --fs-body: clamp(1.0625rem, 0.95rem + 0.35vw, 1.1875rem);
  --lh-body: 1.72;
}

/* ---------- Dark theme tokens ----------
   Applied when [data-theme="dark"] is explicit, OR when no explicit
   preference is set and the OS reports dark mode. Order matters: the
   explicit override rule comes last so user choice always wins. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #0c0c0a;
    --paper-sunk: #161614;
    --ink:        #ece6d6;
    --ink-muted:  #978f7e;
    --ink-faint:  #5a544a;
    --rule:       #25231f;
    --rule-soft:  #1b1a17;

    --accent:     oklch(0.86 0.18 95);
    --accent-ink: oklch(0.92 0.14 95);
    --accent-wash: oklch(0.86 0.18 95 / 0.22);
  }
}
:root[data-theme="dark"] {
  --paper:      #0c0c0a;
  --paper-sunk: #161614;
  --ink:        #ece6d6;
  --ink-muted:  #978f7e;
  --ink-faint:  #5a544a;
  --rule:       #25231f;
  --rule-soft:  #1b1a17;

  --accent:     oklch(0.86 0.18 95);
  --accent-ink: oklch(0.92 0.14 95);
  --accent-wash: oklch(0.86 0.18 95 / 0.22);
}

/* ---------- Reset-ish ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--paper);
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 200ms ease, color 200ms ease;
}
::selection { background: var(--accent-wash); }

/* ---------- Page chrome ---------- */
.site-header {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(1.75rem, 5vw, 3rem) var(--gutter) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.site-header a { color: inherit; text-decoration: none; }
.site-header .wordmark {
  color: var(--ink);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
}
.site-header .wordmark::before {
  content: "";
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  margin-right: 0.55em;
  background: var(--accent);
  transform: translateY(-0.02em);
}

/* Theme toggle button */
.theme-toggle {
  appearance: none;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.4em 0.7em;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}
.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}
.theme-toggle .icon {
  width: 0.9em;
  height: 0.9em;
  display: inline-block;
  position: relative;
}
.theme-toggle .icon svg { width: 100%; height: 100%; display: block; }

/* ---------- Article container ---------- */
article {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 3.5rem) var(--gutter) 6rem;
}

/* ---------- Title block ---------- */
.post-meta {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}
.post-meta time { color: var(--ink-muted); }
.post-meta .sep { color: var(--rule); }

/* Draft badge — driven by `status: draft` in front-matter. */
.post-status {
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 0.18em 0.7em;
  border-radius: 999px;
}
.post-status--draft {
  color: var(--accent-ink);
  background: var(--accent-wash);
}

h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2rem, 1.4rem + 2.8vw, 3.25rem);
  line-height: 1.08;
  letter-spacing: -0.012em;
  margin: 0 0 2.5rem;
  text-wrap: balance;
}

article > p:first-of-type {
  font-size: 1.125em;
  color: var(--ink);
  margin-top: 0;
}

/* ---------- Headings ---------- */
h2, h3 {
  font-family: var(--serif);
  color: var(--ink);
  text-wrap: balance;
}
h2 {
  font-size: clamp(1.35rem, 1.15rem + 0.9vw, 1.625rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.005em;
  margin: 3rem 0 0.9rem;
}
h3 {
  font-size: 1.0625em;
  font-weight: 600;
  line-height: 1.35;
  margin: 2rem 0 0.6rem;
}

/* ---------- Body text ---------- */
p { margin: 0 0 1.15rem; }
strong { font-weight: 600; color: var(--ink); }
em { font-style: italic; }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.18em;
  text-decoration-color: color-mix(in oklch, var(--accent) 50%, transparent);
  transition: color 120ms ease, text-decoration-color 120ms ease;
}
a:hover {
  color: var(--accent-ink);
  text-decoration-color: var(--accent-ink);
}

/* ---------- Lists ---------- */
ul, ol { margin: 0 0 1.25rem; padding-left: 1.4em; }
li { margin: 0.25rem 0; padding-left: 0.25em; }
li::marker { color: var(--ink-faint); }
ol { font-variant-numeric: tabular-nums; }
ul li::marker { content: "• "; }

/* ---------- Blockquote ---------- */
blockquote {
  margin: 2rem 0;
  padding: 0.25rem 0 0.25rem 1.4rem;
  border-left: 2px solid var(--accent);
  color: var(--ink);
  font-style: italic;
  font-size: 1.05em;
  line-height: 1.6;
}
blockquote p:last-child { margin-bottom: 0; }
blockquote cite {
  display: block;
  margin-top: 0.6rem;
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
blockquote cite::before { content: "— "; }

/* ---------- Code ---------- */
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--paper-sunk);
  padding: 0.12em 0.4em;
  border-radius: 3px;
  color: var(--ink);
  border: 1px solid var(--rule-soft);
}
pre {
  margin: 1.75rem 0;
  padding: 1.1rem 1.25rem;
  background: var(--paper-sunk);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.65;
  color: var(--ink);
  box-shadow: inset 2px 0 0 var(--rule);
}
pre code { background: transparent; border: 0; padding: 0; font-size: inherit; border-radius: 0; }
pre::-webkit-scrollbar { height: 8px; }
pre::-webkit-scrollbar-track { background: transparent; }
pre::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 4px; }

/* ---------- Figure (base) ---------- */
figure {
  margin: 2.25rem 0;
}
figure img,
figure svg.fig-art,
figure > video {
  display: block;
  width: 100%;
  height: auto;
  background: var(--paper-sunk);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
}
figcaption {
  margin-top: 0.7rem;
  font-style: italic;
  font-size: 0.92em;
  line-height: 1.55;
  color: var(--ink-muted);
  text-wrap: pretty;
}
figcaption::before {
  content: "Fig. ";
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.78em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 0.35em;
}

/* ---------- Table ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
  font-variant-numeric: tabular-nums;
  margin: 1.75rem 0;
}
th, td {
  text-align: left;
  padding: 0.65rem 0.9rem 0.65rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
th {
  font-weight: 600;
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding-top: 0;
}
tr:last-child td { border-bottom: 0; }

/* ---------- Gallery (slideshow figure) ----------
   Markup pattern (write this directly in your .md, Parsedown passes it):

     <figure class="gallery">
       <video src="clip-a.mp4" muted loop playsinline></video>
       <video src="clip-b.mp4" muted loop playsinline></video>
       <img src="still.jpg" alt="">
       <figcaption>Caption here.</figcaption>
     </figure>

   Orientation auto-detects from the first item; override with
   data-orientation="portrait" on the figure if needed.
*/
.gallery { margin: 2.25rem 0; }
.gallery .stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--paper-sunk);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  overflow: hidden;
}
.gallery[data-orientation="portrait"] .stage {
  aspect-ratio: 4 / 5;
  max-width: 28rem;
  margin-inline: auto;
}
.gallery .stage > img,
.gallery .stage > video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
  border: 0;
  border-radius: 0;
  opacity: 0;
  transition: opacity 240ms ease;
  pointer-events: none;
}
.gallery .stage > .is-active {
  opacity: 1;
  pointer-events: auto;
}
.gallery .controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.75rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.gallery .counter { font-variant-numeric: tabular-nums; }
.gallery .dots {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}
.gallery .dot {
  appearance: none;
  width: 7px;
  height: 7px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--rule);
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}
.gallery .dot:hover { background: var(--ink-faint); }
.gallery .dot[aria-current="true"] {
  background: var(--accent);
  transform: scale(1.15);
}
.gallery .nav {
  display: flex;
  gap: 0.4rem;
}
.gallery .nav button {
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease;
}
.gallery .nav button:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}
.gallery .nav button:disabled {
  opacity: 0.35;
  cursor: default;
}
.gallery .nav svg { width: 10px; height: 10px; display: block; margin: auto; }
.gallery figcaption { margin-top: 0.6rem; }

[data-img-width="wide"] .gallery { margin-inline: clamp(-6rem, calc((var(--measure) - 100%) * 0.5), 0px); }
@media (min-width: 1100px) {
  [data-img-width="wide"] .gallery { margin-inline: -6rem; }
}

/* ---------- Size modifier for a single figure ----------
   Use on any <figure> to cap its width and center it inside the column.
   Default cap is 28rem (~448px), matching the gallery's portrait variant.
   Override per-figure with `style="max-width: 20rem"` if needed.
*/
figure.figure-narrow {
  max-width: 28rem;
  margin-inline: auto;
}

/* ---------- Side-by-side image/video pair ----------
   Markup:
     <figure class="figure-pair">
       <div class="pair">
         <img src="/assets/a.jpg" alt="…">
         <img src="/assets/b.jpg" alt="…">
       </div>
       <figcaption>Caption here.</figcaption>
     </figure>
   Drops to a single column on narrow screens.
*/
.figure-pair > .pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.figure-pair > .pair > img,
.figure-pair > .pair > video {
  display: block;
  width: 100%;
  height: auto;
}
@media (max-width: 600px) {
  .figure-pair > .pair { grid-template-columns: 1fr; }
}

/* ---------- Horizontal rule ---------- */
hr {
  border: 0;
  margin: 3rem auto;
  text-align: center;
  height: 1rem;
}
hr::before {
  content: "· · ·";
  color: var(--ink-faint);
  font-family: var(--serif);
  letter-spacing: 0.5em;
  font-size: 1rem;
}

/* ---------- Footer ---------- */
.site-footer {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2rem var(--gutter) 4rem;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.site-footer a { color: var(--ink-muted); text-decoration: none; }
.site-footer a:hover { color: var(--ink); }

/* ---------- Responsive nudges ---------- */
@media (max-width: 480px) {
  :root { --lh-body: 1.65; }
  h1 { margin-bottom: 1.75rem; }
  h2 { margin-top: 2.25rem; }
  blockquote { padding-left: 1rem; }
  pre { padding: 0.9rem 1rem; font-size: 0.82rem; }
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; color: #000; }
  .site-header, .site-footer, .theme-toggle { display: none; }
  a { color: #000; text-decoration: underline; }
  pre, code { background: #f5f5f5; border-color: #ddd; }
}

/* =========================================================================
   IMAGE VARIANTS — driven by data-attrs on <html>
   Defaults (no data attr): inset width, border style, italic caption.
   ========================================================================= */

/* Width */
[data-img-width="wide"] figure {
  margin-inline: clamp(-6rem, calc((var(--measure) - 100%) * 0.5), 0px);
}
@media (min-width: 1100px) {
  [data-img-width="wide"] figure { margin-inline: -6rem; }
}
[data-img-width="bleed"] figure {
  margin-inline: calc(50% - 50vw);
  width: 100vw;
  max-width: 100vw;
}
[data-img-width="bleed"] figure img,
[data-img-width="bleed"] figure svg.fig-art {
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}
[data-img-width="bleed"] figcaption {
  max-width: var(--measure);
  margin-left: auto;
  margin-right: auto;
  padding: 0.7rem var(--gutter) 0;
}

/* Treatment */
[data-img-style="plain"] figure img,
[data-img-style="plain"] figure svg.fig-art,
[data-img-style="plain"] figure > video {
  border: 0;
  background: transparent;
}
[data-img-style="framed"] figure {
  background: var(--paper-sunk);
  padding: clamp(0.75rem, 2vw, 1.5rem);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
}
[data-img-style="framed"] figure img,
[data-img-style="framed"] figure svg.fig-art {
  border: 0;
  border-radius: 2px;
}
[data-img-style="framed"] figcaption {
  margin-left: 0.1rem;
}
[data-img-width="bleed"][data-img-style="framed"] figure {
  margin-inline: 0;
  width: auto;
  max-width: 100%;
}

/* Caption */
[data-cap="caps"] figcaption {
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
[data-cap="caps"] figcaption::before {
  content: counter(figcap, decimal-leading-zero) " · ";
  margin-right: 0;
}
body { counter-reset: figcap; }
[data-cap="caps"] figure { counter-increment: figcap; }

/* =========================================================================
   ACCENT PALETTE OVERRIDES — driven by [data-accent] on <html>
   ========================================================================= */
[data-accent="yellow"] {
  --accent: oklch(0.78 0.17 92);
  --accent-ink: oklch(0.62 0.16 92);
  --accent-wash: oklch(0.78 0.17 92 / 0.32);
}
[data-accent="terracotta"] {
  --accent: oklch(0.55 0.11 40);
  --accent-ink: oklch(0.42 0.10 40);
  --accent-wash: oklch(0.55 0.11 40 / 0.18);
}
[data-accent="indigo"] {
  --accent: oklch(0.45 0.12 270);
  --accent-ink: oklch(0.35 0.11 270);
  --accent-wash: oklch(0.45 0.12 270 / 0.18);
}
[data-accent="forest"] {
  --accent: oklch(0.45 0.09 160);
  --accent-ink: oklch(0.35 0.08 160);
  --accent-wash: oklch(0.45 0.09 160 / 0.18);
}
:root[data-theme="dark"][data-accent="yellow"]     { --accent: oklch(0.86 0.18 95);  --accent-ink: oklch(0.92 0.14 95); }
:root[data-theme="dark"][data-accent="terracotta"] { --accent: oklch(0.74 0.12 40);  --accent-ink: oklch(0.82 0.10 40); }
:root[data-theme="dark"][data-accent="indigo"]    { --accent: oklch(0.70 0.13 270); --accent-ink: oklch(0.78 0.10 270); }
:root[data-theme="dark"][data-accent="forest"]    { --accent: oklch(0.70 0.10 160); --accent-ink: oklch(0.78 0.09 160); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"])[data-accent="yellow"]     { --accent: oklch(0.86 0.18 95);  --accent-ink: oklch(0.92 0.14 95); }
  :root:not([data-theme="light"])[data-accent="terracotta"] { --accent: oklch(0.74 0.12 40);  --accent-ink: oklch(0.82 0.10 40); }
  :root:not([data-theme="light"])[data-accent="indigo"]    { --accent: oklch(0.70 0.13 270); --accent-ink: oklch(0.78 0.10 270); }
  :root:not([data-theme="light"])[data-accent="forest"]    { --accent: oklch(0.70 0.10 160); --accent-ink: oklch(0.78 0.09 160); }
}
