:root {
  --maxw: 700px;
  --font-body: 'Newsreader Variable', Georgia, 'Times New Roman', serif;
  --font-display: 'Fraunces Variable', Georgia, serif;
  --font-mono: 'JetBrains Mono Variable', ui-monospace, "JetBrains Mono", monospace;

  /* Light theme (warm) */
  --bg: #faf8f5;
  --surface: #f1ece4;
  --text: #2b2722;
  --muted: #6b6358;
  --border: #e7e0d6;
  --accent: #b85c38;       /* warm terracotta */
  --accent-hover: #9c4a2b;
  --grain: 0.035;
}

:root[data-theme="dark"] {
  --bg: #14110e;
  --surface: #1d1813;
  --text: #e8e2d9;
  --muted: #9a9085;
  --border: #2a241e;
  --accent: #e0915f;
  --accent-hover: #eba874;
  --grain: 0.05;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  font-optical-sizing: auto;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.18rem;
  line-height: 1.72;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Warm radial glow layered over the base colour */
  background-color: var(--bg);
  background-image: radial-gradient(120% 65% at 50% -15%,
    color-mix(in oklab, var(--accent) 13%, transparent), transparent 55%);
  background-attachment: fixed;
  background-repeat: no-repeat;
  transition: background-color 0.5s ease, color 0.5s ease;
}

/* Fine film grain, behind content */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.25rem;
}

a { color: var(--accent); text-decoration: none; transition: color 0.25s ease; }
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

::selection { background: color-mix(in oklab, var(--accent) 26%, transparent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 560;
  line-height: 1.15;
  letter-spacing: -0.012em;
}
h1 { font-size: 2.2rem; }
h2 { font-size: 1.5rem; margin-top: 2.2rem; }

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface);
  padding: 0.15em 0.35em;
  border-radius: 4px;
}
pre {
  background: var(--surface);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
}
pre code { background: none; padding: 0; }

img { max-width: 100%; height: auto; }

hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* Site chrome */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.75rem 0 0.85rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 3rem;
  transition: border-color 0.5s ease;
}
.site-header nav { display: flex; align-items: center; gap: 1.4rem; }
.site-header nav a {
  color: var(--text);
  font-size: 1.06rem;
  background-image: linear-gradient(var(--accent), var(--accent));
  background-size: 0% 2px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 0.3s ease, color 0.25s ease;
}
.site-header nav a:hover { color: var(--accent); background-size: 100% 2px; text-decoration: none; }
.site-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.55rem;
  letter-spacing: -0.015em;
  color: var(--text);
}
.site-header .brand:hover { color: var(--accent); text-decoration: none; }
.logo-mark {
  display: block;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
}

@media (max-width: 560px) {
  .site-header { padding: 1.4rem 0 0.75rem; margin-bottom: 2.4rem; }
  .site-header .brand { font-size: 1.35rem; }
  .logo-mark { width: 38px; height: 38px; }
  .site-header nav { gap: 1.1rem; }
  .site-header nav a { font-size: 1rem; }
}

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding: 2rem 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-family: var(--font-mono);
  transition: border-color 0.5s ease;
}
.site-footer a { color: var(--muted); }
.footer-currently { margin: 0 0 1rem; line-height: 1.6; }
.footer-currently em { font-style: italic; font-family: var(--font-body); color: var(--text); }
.footer-meta { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.42rem;
  cursor: pointer;
  line-height: 0;
  transition: border-color 0.25s ease, color 0.25s ease;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.toggle-icon { display: block; }
.toggle-icon .sun,
.toggle-icon .rays,
.toggle-icon .moon-dot {
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.3s ease;
}
.toggle-icon .rays { transform-origin: 12px 12px; }
.toggle-icon .sun { transform-origin: 12px 12px; }
:root[data-theme="dark"] .toggle-icon .moon-dot { transform: translateX(-9px); }
:root[data-theme="dark"] .toggle-icon .rays { opacity: 0; transform: scale(0.4) rotate(45deg); }
:root[data-theme="dark"] .toggle-icon .sun { transform: scale(1.06); }

/* Reading-progress bar (fills only on post pages) */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 50;
  pointer-events: none;
  transition: width 0.1s linear;
}

/* Home */
.intro { display: flex; gap: 1.6rem; align-items: center; margin-bottom: 0.6rem; }
.intro p { margin-bottom: 0; }
.portrait { width: 116px; height: 116px; border-radius: 50%; flex-shrink: 0; object-fit: cover; }
.hero-meta {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 2.6rem;
  font-variation-settings: 'opsz' 30, 'SOFT' 50;
}
.hero-meta time {
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.82em;
  font-feature-settings: "tnum";
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* Section heading — quiet kicker bar so post titles stay the focus */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 2.8rem 0 0.4rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.section-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
}
.section-kicker::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}
.section-kicker.no-tick::before { display: none; }
.section-more {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  color: var(--accent);
  white-space: nowrap;
}
.section-more:hover { color: var(--accent-hover); text-decoration: none; }

/* Post list */
.post-card { padding: 1.4rem 0; border-bottom: 1px solid var(--border); }
.post-card:last-of-type { border-bottom: none; }
.post-card time, .post-date {
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  letter-spacing: 0.02em;
}
.post-card h3 {
  margin: 0.4rem 0 0.5rem;
  font-size: 1.5rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
}
.post-card h3 a { color: var(--text); }
.post-card h3 a::after {
  content: "→";
  display: inline-block;
  margin-left: 0.4rem;
  color: var(--accent);
  opacity: 0;
  transform: translateX(-5px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.post-card h3 a:hover { color: var(--accent); }
.post-card h3 a:hover::after { opacity: 1; transform: translateX(0); }
.post-card p { margin: 0; color: var(--muted); font-size: 1.02rem; }

/* Contents-page blog index */
.contents { list-style: none; padding: 0; margin: 2rem 0 0; }
.contents-row { padding: 1.05rem 0; border-bottom: 1px solid var(--border); }
.contents-row:last-child { border-bottom: none; }
.contents-line { display: flex; align-items: baseline; gap: 0.7rem; }
.contents-num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  flex-shrink: 0;
  font-feature-settings: "tnum";
}
.contents-title {
  font-family: var(--font-display);
  font-weight: 540;
  font-size: 1.32rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.contents-title:hover { color: var(--accent); text-decoration: none; }
.contents-leader {
  flex: 1 1 auto;
  min-width: 1.5rem;
  align-self: stretch;
  border-bottom: 2px dotted var(--border);
  transform: translateY(-0.28em);
}
.contents-date {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
  font-feature-settings: "tnum";
}
.contents-desc {
  margin: 0.4rem 0 0;
  padding-left: calc(0.78rem + 0.7rem);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}
@media (max-width: 480px) {
  .contents-desc { padding-left: 0; }
}

/* Post body typography */
.post h1 { margin-bottom: 0.5rem; }
.standfirst {
  font-style: italic;
  font-size: 1.32rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 0 0.9rem;
  font-variation-settings: 'opsz' 40, 'SOFT' 50;
}
.post-meta {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 0 0 2.2rem;
}
.post-body > p:first-of-type::first-letter {
  float: left;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 3.5em;
  line-height: 0.74;
  padding: 0.04em 0.09em 0 0;
  color: var(--accent);
  font-variation-settings: 'opsz' 144, 'SOFT' 40, 'WONK' 1;
}
.post-back { margin-top: 2.6rem; }
.post p { margin: 0 0 1.25rem; }
.post a {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in oklab, var(--accent) 45%, transparent);
}
.post ul, .post ol { margin: 0 0 1.25rem; padding-left: 1.4rem; }
.post li { margin: 0.3rem 0; }
.post blockquote {
  margin: 1.4rem 0;
  padding: 0.3rem 0 0.3rem 1.1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: italic;
  transition: border-color 0.5s ease;
}
.post-end {
  margin: 2.6rem 0 0;
  text-align: center;
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: 0.5em;
  opacity: 0.7;
}

/* Static page prose (About, Work) — shares the post reading rhythm */
.prose p { margin: 0 0 1.25rem; }
.prose ul, .prose ol { margin: 0 0 1.25rem; padding-left: 1.4rem; }
.prose li { margin: 0.3rem 0; }
.prose a {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in oklab, var(--accent) 45%, transparent);
}

/* Photos */
.photo { margin: 1.5rem 0; }
.photo img { border-radius: 10px; }
.photo--wide {
  width: min(94vw, 1040px);
  max-width: none;
  margin-left: 50%;
  transform: translateX(-50%);
}
.photo--wide img { width: 100%; border-radius: 12px; }

/* Code blocks — warm Shiki dual theme switched by data-theme */
.astro-code { background-color: var(--shiki-light-bg); color: var(--shiki-light); }
.astro-code span { color: var(--shiki-light); }
:root[data-theme="dark"] .astro-code { background-color: var(--shiki-dark-bg); color: var(--shiki-dark); }
:root[data-theme="dark"] .astro-code span { color: var(--shiki-dark); }
.photo figcaption {
  color: var(--muted);
  font-size: 0.84rem;
  font-family: var(--font-mono);
  margin-top: 0.5rem;
}

@media (max-width: 480px) {
  .intro { flex-direction: column; text-align: center; }
  h1 { font-size: 1.95rem; }
}

/* Motion — one orchestrated page-load reveal, opt-out respected */
@media (prefers-reduced-motion: no-preference) {
  .reveal {
    opacity: 0;
    transform: translateY(14px);
    animation: reveal 1.1s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  }
  .reveal-2 { animation-delay: 0.12s; }
  .reveal-3 { animation-delay: 0.24s; }
  .reveal-4 { animation-delay: 0.36s; }

  .post-card, .contents-row { opacity: 0; animation: reveal 0.95s ease forwards; }
  .post-card:nth-child(1), .contents-row:nth-child(1) { animation-delay: 0.30s; }
  .post-card:nth-child(2), .contents-row:nth-child(2) { animation-delay: 0.42s; }
  .post-card:nth-child(3), .contents-row:nth-child(3) { animation-delay: 0.54s; }
  .post-card:nth-child(4), .contents-row:nth-child(4) { animation-delay: 0.66s; }
  .post-card:nth-child(5), .contents-row:nth-child(5) { animation-delay: 0.78s; }
  .post-card:nth-child(n + 6), .contents-row:nth-child(n + 6) { animation-delay: 0.86s; }
}

@keyframes reveal {
  to { opacity: 1; transform: none; }
}

/* ── Tufte sidenotes ───────────────────────────────────────────────────── */
.post-body { counter-reset: sidenote-counter; }

/* Focusable but visually-hidden toggle (drives the mobile collapse). */
.margin-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  opacity: 0;
  clip: rect(0 0 0 0);
}

/* Inline superscript marker; also the tap target on narrow screens. */
.sidenote-number {
  counter-increment: sidenote-counter;
  cursor: pointer;
}
.sidenote-number::after {
  content: counter(sidenote-counter);
  font-size: 0.68em;
  vertical-align: super;
  line-height: 0;
  margin-left: 1px;
  color: var(--accent);
}
/* Visible focus ring on the marker when its hidden checkbox is focused. */
.margin-toggle:focus-visible + .sidenote-number::after {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.sidenote {
  font-family: var(--font-body);
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--muted);
}
.sidenote::before {
  content: counter(sidenote-counter) " ";
  color: var(--accent);
}

/* Narrow screens: collapsed until the marker is tapped, then inline. */
@media (max-width: 1199px) {
  .sidenote { display: none; }
  .margin-toggle:checked ~ .sidenote {
    display: block;
    margin: 0.6rem 0 0.9rem;
    padding-left: 1rem;
    border-left: 2px solid var(--border);
  }
}

/* Wide screens: float into the right-hand whitespace, only when present. */
@media (min-width: 1200px) {
  .post:has(.sidenote) .sidenote {
    float: right;
    clear: right;
    width: 200px;
    margin-right: -228px;
    margin-top: 0.25rem;
    margin-bottom: 0.6rem;
    position: relative;
  }
}

/* Self-hosted web fonts (replaces the former @fontsource npm imports). The
   family names match the existing --font-* custom properties exactly. */
@font-face {
  font-family: 'Fraunces Variable';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/fraunces-latin-opsz-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Newsreader Variable';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('/fonts/newsreader-latin-opsz-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Newsreader Variable';
  font-style: italic;
  font-weight: 200 800;
  font-display: swap;
  src: url('/fonts/newsreader-latin-opsz-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono Variable';
  font-style: normal;
  font-weight: 100 800;
  font-display: swap;
  src: url('/fonts/jetbrains-mono-latin-wght-normal.woff2') format('woff2');
}

/* Cross-document view transitions (Chromium). Browsers without support fall
   back to normal instant navigation — nothing breaks. */
@view-transition {
  navigation: auto;
}
