/* ─── Design Tokens ─── */
:root {
  /* Palette */
  --bg-deep: #0a0a0c;
  --bg-surface: #111114;
  --bg-elevated: #1a1a1f;
  --border-subtle: #222228;

  --text-primary: #e8e6e3;
  --text-secondary: #9a9690;
  --text-muted: #5c5955;
  --text-accent: #c9a96e;
  --text-link: #8ba4c4;

  --quote-border: #c9a96e;
  --quote-bg: rgba(201, 169, 110, 0.04);

  /* Typography */
  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  /* Spacing */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2.5rem;
  --space-xl: 4rem;
  --space-xxl: 6rem;

  /* Widths */
  --content-width: 680px;
  --wide-width: 820px;


  /* Transitions */
  --transition-theme: background-color 0.4s ease, color 0.4s ease, border-color 0.4s ease;
}


/* ─── Reset & Base ─── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 18px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-weight: 400;
  line-height: 1.75;
  min-height: 100vh;
  position: relative;
  transition: var(--transition-theme);
}


/* ─── Film Grain Overlay ─── */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}


/* ─── Reader Controls ─── */
.reader-controls {
  position: relative;
  z-index: 10000;
}

.reader-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.reader-toggle:hover,
.reader-toggle.active {
  color: var(--text-accent);
  border-color: var(--text-accent);
  background: var(--bg-surface);
}

.reader-panel {
  position: absolute;
  top: calc(100% + 0.75rem);
  right: 0;
  width: 280px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.25rem;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(0.97);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.reader-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.reader-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.reader-label {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.reader-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 0.75rem 0;
}

/* Font Buttons */
.reader-font-options {
  display: flex;
  gap: 0.5rem;
}

.font-btn {
  flex: 1;
  height: 40px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.font-btn:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.font-btn.active {
  border-color: var(--text-accent);
  color: var(--text-accent);
  background: rgba(201, 169, 110, 0.08);
}

.font-name {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
}

/* Size Controls */
.reader-size-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.size-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-family: var(--font-sans);
  font-weight: 600;
}

.size-btn:hover:not(:disabled) {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.size-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.size-value {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  min-width: 2rem;
  text-align: center;
}

/* Theme Swatches */
.reader-theme-options {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

.theme-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  padding: 3px;
  transition: transform 0.2s ease;
}

.theme-btn:hover {
  transform: scale(1.1);
}

.theme-btn.active {
  transform: scale(1.15);
}

.theme-swatch {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid;
  transition: box-shadow 0.2s ease;
}

.theme-btn.active .theme-swatch {
  box-shadow: 0 0 0 2px var(--text-accent);
}


/* ─── Header ─── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-body);
  background: color-mix(in srgb, var(--bg-body) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: var(--transition-theme);
}

.header-inner {
  max-width: var(--wide-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

/* Left group: avatar + text column */
.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}

/* Scroll-revealed avatar — slides in from left, pushes text over */
.header-avatar {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: -56px;
  opacity: 0;
  transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.header-avatar.visible {
  margin-left: 0;
  opacity: 1;
}

/* Text column: title above home link */
.header-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

/* Scroll-revealed title — fades in above home link */
.header-title {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.header-title.visible {
  max-height: 1.5em;
  opacity: 1;
}

.site-header time {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}


/* ─── Article ─── */
article {
  max-width: var(--wide-width);
  margin: 0 auto;
  padding: 0 var(--space-md);
}


/* ─── Hero ─── */
.hero {
  padding: var(--space-xxl) 0 var(--space-xl);
  max-width: var(--content-width);
}

.hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2.8rem, 6vw, 4.5rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
}

.byline {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-accent);
  letter-spacing: 0.04em;
}

/* ─── Post Meta (avatar + author + date) ─── */
.post-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.post-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border-subtle);
}

.post-meta-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.post-author {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.post-meta-text time {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}


/* ─── Scroll Meta Elements ─── */
.sticky-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
}

.sticky-title {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  line-height: 1.2;
}


/* ─── Content Sections ─── */
.content {
  max-width: var(--content-width);
  margin-bottom: var(--space-xl);
}

.content h2 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
  padding-top: var(--space-lg);
  letter-spacing: -0.01em;
}

.content h3 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text-accent);
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
  font-style: italic;
}

.content p {
  margin-bottom: var(--space-md);
  color: var(--text-primary);
  font-optical-sizing: auto;
}

.content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.content em {
  font-style: italic;
  color: var(--text-secondary);
}

/* Lede paragraph */
.lede p {
  font-size: 1.15rem;
  line-height: 1.8;
  color: var(--text-secondary);
}


/* ─── Blockquotes ─── */
blockquote {
  border-left: 3px solid var(--quote-border);
  background: var(--quote-bg);
  padding: var(--space-md) var(--space-lg);
  margin: var(--space-lg) 0;
  border-radius: 0 4px 4px 0;
  transition: var(--transition-theme);
}

blockquote p {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: var(--space-xs);
}

blockquote p:last-child {
  margin-bottom: 0;
}


/* ─── Lists ─── */
.content ul {
  list-style: none;
  margin: var(--space-md) 0 var(--space-lg);
  padding: 0;
}

.content ul li {
  position: relative;
  padding-left: 1.5rem;
  margin-bottom: var(--space-xs);
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
}

.content ul li::before {
  content: '—';
  position: absolute;
  left: 0;
  color: var(--text-muted);
}


/* ─── Pull Quote ─── */
.pullquote {
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 3.5vw, 1.9rem);
  font-weight: 500;
  font-style: italic;
  line-height: 1.5;
  color: var(--text-accent);
  text-align: center;
  padding: var(--space-xl) 0;
  max-width: 600px;
  margin: 0 auto;
}

.divider {
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  margin: var(--space-xl) 0;
  padding: var(--space-lg) 0;
  transition: var(--transition-theme);
}


/* ─── Closing Statement ─── */
.closing {
  font-size: 1.08rem;
  font-weight: 500;
  color: var(--text-primary);
  padding-top: var(--space-sm);
}


/* ─── Superscript Citations ─── */
sup {
  font-size: 0.65em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  top: -0.5em;
}

sup a {
  color: var(--text-accent);
  text-decoration: none;
  font-family: var(--font-sans);
  font-weight: 500;
  transition: color 0.2s ease;
}

sup a:hover {
  color: var(--text-primary);
}


/* ─── References ─── */
.references {
  max-width: var(--content-width);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-xxl);
  padding-top: var(--space-lg);
  padding-bottom: var(--space-xxl);
  transition: var(--transition-theme);
}

.references h2 {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

.references ol {
  list-style: none;
  counter-reset: ref-counter;
  padding: 0;
}

.references ol li {
  counter-increment: ref-counter;
  padding-left: 2rem;
  position: relative;
  margin-bottom: var(--space-sm);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.references ol li::before {
  content: counter(ref-counter) ".";
  position: absolute;
  left: 0;
  color: var(--text-muted);
  font-weight: 500;
}

.references ol li em {
  font-style: italic;
  color: var(--text-secondary);
}

.references ol li a {
  color: var(--text-link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.references ol li a:hover {
  border-bottom-color: var(--text-link);
}


/* ─── Site Footer ─── */
.site-footer {
  border-top: 1px solid var(--border-subtle);
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  transition: var(--transition-theme);
}

.site-footer p {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}


/* ─── Selection ─── */
::selection {
  background: rgba(201, 169, 110, 0.25);
  color: var(--text-primary);
}


/* ─── Home Link ─── */
.site-home {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

.site-home:hover {
  color: var(--text-accent);
}


/* ─── Blog Index ─── */
.blog-index .hero {
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: var(--space-lg);
  margin-bottom: var(--space-lg);
  text-align: center;
}

.avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: var(--space-md);
  border: 2px solid var(--border-subtle);
  box-shadow: 0 0 24px rgba(255, 255, 255, 0.06);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.avatar:hover {
  border-color: var(--text-accent);
  box-shadow: 0 0 32px rgba(255, 255, 255, 0.1);
}

.social-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  margin-top: var(--space-sm);
  transition: color 0.2s ease;
}

.social-link:hover {
  color: var(--text-accent);
}

.social-icon {
  border-radius: 4px;
  vertical-align: middle;
}

.footer-social {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-decoration: none;
  margin-top: var(--space-xs);
  transition: color 0.2s ease;
}

.footer-social:hover {
  color: var(--text-accent);
}

.post-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.post-card {
  display: block;
  text-decoration: none;
  padding: var(--space-lg) 0;
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.2s ease;
}

.post-card:first-child {
  padding-top: 0;
}

.post-card:hover {
  background-color: var(--bg-surface);
}

.post-card time {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.post-card h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: var(--space-xs) 0;
  letter-spacing: -0.01em;
  line-height: 1.3;
  transition: color 0.2s ease;
}

.post-card:hover h2 {
  color: var(--text-accent);
}

.post-excerpt {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
}


/* ─── Markdown Horizontal Rules ─── */
.content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: var(--space-xl) auto;
  max-width: 120px;
}


/* ─── Footnote Backrefs ─── */
.footnote-backref {
  font-family: var(--font-sans);
  color: var(--text-accent);
  text-decoration: none;
  margin-left: 0.25rem;
  font-size: 0.85em;
}

.footnote-backref:hover {
  color: var(--text-primary);
}


/* ══════════════════════════════════════════════════
   THEME OVERRIDES
   ══════════════════════════════════════════════════ */

/* ─── Ember (warm dark) ─── */
.theme-ember {
  --bg-deep: #110e0b;
  --bg-surface: #1a1510;
  --bg-elevated: #231c14;
  --border-subtle: #322820;

  --text-primary: #e8ddd0;
  --text-secondary: #a09080;
  --text-muted: #685848;
  --text-accent: #d4956a;
  --text-link: #c4916a;

  --quote-border: #d4956a;
  --quote-bg: rgba(212, 149, 106, 0.05);
}

/* ─── Parchment (warm light) ─── */
.theme-parchment {
  --bg-deep: #f0e6d3;
  --bg-surface: #e8dcc8;
  --bg-elevated: #e0d4be;
  --border-subtle: #c9b99a;

  --text-primary: #2c2418;
  --text-secondary: #5c4d38;
  --text-muted: #8a7a62;
  --text-accent: #8b5e3c;
  --text-link: #6b4c32;

  --quote-border: #8b5e3c;
  --quote-bg: rgba(139, 94, 60, 0.06);
}

.theme-parchment .grain {
  opacity: 0.015;
}

.theme-parchment ::selection {
  background: rgba(139, 94, 60, 0.2);
  color: var(--text-primary);
}

.theme-parchment .reader-toggle {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.theme-parchment .reader-panel {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

/* ─── Daylight (cool light) ─── */
.theme-daylight {
  --bg-deep: #fafaf8;
  --bg-surface: #f2f2ee;
  --bg-elevated: #eaeae5;
  --border-subtle: #d0d0cc;

  --text-primary: #1a1a18;
  --text-secondary: #52524e;
  --text-muted: #8a8a85;
  --text-accent: #3a6ea5;
  --text-link: #2a5a8a;

  --quote-border: #3a6ea5;
  --quote-bg: rgba(58, 110, 165, 0.04);
}

.theme-daylight .grain {
  opacity: 0.01;
}

.theme-daylight ::selection {
  background: rgba(58, 110, 165, 0.15);
  color: var(--text-primary);
}

.theme-daylight .reader-toggle {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.theme-daylight .reader-panel {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
}


/* ══════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════ */

@media (max-width: 720px) {
  .hero {
    padding: var(--space-xl) 0 var(--space-lg);
  }

  blockquote {
    padding: var(--space-sm) var(--space-md);
    margin: var(--space-md) 0;
  }

  .pullquote {
    padding: var(--space-lg) 0;
  }

  .divider {
    margin: var(--space-lg) 0;
    padding: var(--space-md) 0;
  }

  .reader-controls {
    top: 0.75rem;
    right: 0.75rem;
  }

  .reader-panel {
    width: 260px;
  }
}

@media (max-width: 480px) {
  article {
    padding: 0 var(--space-sm);
  }

  .hero h1 {
    font-size: 2.2rem;
  }

  .pullquote {
    font-size: 1.2rem;
  }

  .reader-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  .reader-panel.open {
    transform: translateY(0);
  }

  .reader-font-options {
    gap: 0.4rem;
  }
}

@media (max-width: 360px) {
  .hero h1 {
    font-size: 1.9rem;
  }

  .content h2 {
    font-size: 1.3rem;
  }

  blockquote {
    padding: var(--space-xs) var(--space-sm);
  }
}


/* ─── Reduced Motion ─── */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition: none !important;
  }
}


/* ─── Print ─── */
@media print {

  .grain,
  .reader-controls {
    display: none;
  }

  body {
    background: white;
    color: #111;
  }

  .site-header,
  .site-footer {
    border-color: #ccc;
  }

  a {
    color: inherit;
  }

  blockquote {
    border-left-color: #999;
    background: transparent;
  }

  .pullquote {
    color: #333;
  }
}