/* ═══════════════════════════════════════════════════
   ET Book — self-hosted, woff only (woff2 not available from tufte-css)
   ═══════════════════════════════════════════════════ */

@font-face {
  font-family: 'ETBook';
  src: url('/fonts/et-book/et-book-roman-line-figures.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'ETBook';
  src: url('/fonts/et-book/et-book-display-italic-old-style-figures.woff') format('woff');
  font-weight: normal;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'ETBook';
  src: url('/fonts/et-book/et-book-bold-line-figures.woff') format('woff');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'ETBookOldStyle';
  src: url('/fonts/et-book/et-book-roman-old-style-figures.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ═══════════════════════════════════════════════════
   Custom properties — dark theme, WCAG AA verified
   ═══════════════════════════════════════════════════ */

:root {
  /* Backgrounds */
  --bg:        #0d0e10;
  --surface:   #141517;
  --border:    #27282c;
  --faint:     #1e1f22;

  /* Text — contrast ratios vs --bg
     --text:           #d6cfc0   →  9.8:1  ✓ AA + AAA
     --text-secondary: #9e9a93   →  5.1:1  ✓ AA
     --text-muted:     #6b6864   →  3.2:1  (large text / UI only)
     --accent:         #c8a46a   →  5.6:1  ✓ AA
     --link-hover:     #ddb87a   →  7.1:1  ✓ AA + AAA
  */
  --text:           #d6cfc0;
  --text-secondary: #9e9a93;
  --text-muted:     #6b6864;
  --accent:         #c8a46a;
  --accent-dim:     #7a6040;
  --link-hover:     #ddb87a;

  /* Typography */
  --font-serif: 'ETBook', 'Palatino Linotype', Palatino, Georgia, serif;
  --font-sans:  'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
  --font-mono:  Consolas, 'Liberation Mono', Menlo, Courier, monospace;

  /* Layout */
  --measure:    66ch;
  --margin-w:   340px;
}

/* ═══════════════════════════════════════════════════
   Reset and base
   ═══════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 15px;
}

@media (min-width: 760px) {
  html { font-size: 16px; }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.2rem;
  line-height: 2rem;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  counter-reset: sidenote-counter;
}

/* ═══════════════════════════════════════════════════
   Skip link (a11y)
   ═══════════════════════════════════════════════════ */

.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--accent);
  color: var(--bg);
  padding: 0.5rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 0 0 4px 4px;
  z-index: 100;
  transition: top 0.15s;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

/* ═══════════════════════════════════════════════════
   Focus ring (a11y)
   ═══════════════════════════════════════════════════ */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ═══════════════════════════════════════════════════
   Site header and navigation
   ═══════════════════════════════════════════════════ */

.site-header {
  padding: 1.4rem 1.8rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-name {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-decoration: none;
}

nav[aria-label] { display: flex; gap: 1.6rem; flex-wrap: wrap; }

nav a {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.18s;
}
nav a:hover { color: var(--text); }

/* ═══════════════════════════════════════════════════
   Main layout (Tufte two-column on wide screens)
   ═══════════════════════════════════════════════════ */

main {
  padding: 3rem 1.5rem 6rem;
}

article {
  position: relative;
  max-width: var(--measure);
  margin: 0 auto;
}

@media (min-width: 1000px) {
  article {
    max-width: calc(var(--measure) + var(--margin-w) + 3rem);
    padding-right: calc(var(--margin-w) + 3rem);
  }
}

section {
  padding-top: 1rem;
}

/* ═══════════════════════════════════════════════════
   Typography — headings
   ═══════════════════════════════════════════════════ */

h1 {
  font-family: var(--font-serif);
  font-weight: normal;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.2;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: 1.5rem;
}

p.subtitle {
  font-style: italic;
  font-size: 1.4rem;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  color: var(--text-secondary);
  display: block;
}

h2 {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 3rem;
  margin-bottom: 0.5rem;
  padding-left: 0.85rem;
  border-left: 2px solid var(--accent);
  line-height: 1.2;
}

h3 {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: normal;
  font-size: 1.2rem;
  color: var(--text);
  margin-top: 2rem;
  margin-bottom: 0;
}

/* ═══════════════════════════════════════════════════
   Prose
   ═══════════════════════════════════════════════════ */

p {
  margin-top: 1.4rem;
  margin-bottom: 0;
  vertical-align: baseline;
}

span.newthought {
  font-family: 'ETBookOldStyle', var(--font-serif);
  font-variant: small-caps;
  font-size: 1.1em;
  letter-spacing: 0.05em;
  color: var(--text);
}

.section-desc {
  font-style: italic;
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
  margin-bottom: 0.8rem;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--accent-dim);
  text-underline-offset: 3px;
  transition: text-decoration-color 0.18s;
}
a:hover { text-decoration-color: var(--accent); }

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

blockquote {
  border-left: none;
  padding: 0 0 0 2.5rem;
  margin: 1.5rem 0;
  font-style: italic;
}

blockquote footer {
  font-style: normal;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.4rem;
}

div.epigraph {
  margin: 3rem 0;
}
div.epigraph blockquote {
  margin-top: 0.5rem;
  padding-left: 3rem;
  padding-right: 2rem;
}
div.epigraph blockquote footer {
  width: 45%;
  text-align: right;
}

code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  padding: 0.1em 0.3em;
  border-radius: 2px;
}

pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.6;
  margin: 1.5rem 0;
}
pre code { background: none; padding: 0; font-size: inherit; }

/* ═══════════════════════════════════════════════════
   Sidenotes and margin notes (core Tufte idiom)
   ═══════════════════════════════════════════════════ */

.sidenote-number { counter-increment: sidenote-counter; }

.sidenote-number::after,
.sidenote::before {
  font-family: 'ETBookOldStyle', var(--font-serif);
  position: relative;
  vertical-align: baseline;
  font-size: 0.7rem;
  color: var(--accent);
}

.sidenote-number::after {
  content: counter(sidenote-counter);
  top: -0.5rem;
  left: 0.1rem;
}

.sidenote::before {
  content: counter(sidenote-counter) " ";
  top: -0.5rem;
}

input.margin-toggle { display: none; }

label.sidenote-number { cursor: default; }
label.margin-toggle:not(.sidenote-number) {
  display: none;
  cursor: pointer;
  color: var(--accent);
  font-size: 1.2rem;
  line-height: 1;
}

.sidenote,
.marginnote {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-secondary);
  clear: right;
}

@media (min-width: 1000px) {
  .sidenote,
  .marginnote {
    float: right;
    clear: right;
    margin-right: calc(-1 * (var(--margin-w) + 3rem));
    width: var(--margin-w);
    margin-top: 0;
    margin-bottom: 1rem;
    vertical-align: baseline;
    position: relative;
  }

  label.margin-toggle:not(.sidenote-number) { display: none; }
  .margin-toggle:checked + .sidenote,
  .margin-toggle:checked + .marginnote { display: block; }
}

@media (max-width: 999px) {
  label.margin-toggle:not(.sidenote-number) { display: inline; }

  .sidenote,
  .marginnote {
    display: none;
    margin: 1rem 2.5%;
    width: 95%;
    background: var(--surface);
    border-left: 2px solid var(--border);
    padding: 0.6rem 0.8rem;
  }

  .margin-toggle:checked + .sidenote,
  .margin-toggle:checked + .marginnote {
    display: block;
  }
}

/* ═══════════════════════════════════════════════════
   Book lists (unordered lists in post content)
   ═══════════════════════════════════════════════════ */

.post-content ul {
  list-style: none;
  padding-left: 0;
  margin: 1rem 0 2rem;
}

.post-content li {
  margin: 0;
  padding: 1.2rem 0;
  border-bottom: 1px solid var(--faint);
  line-height: 2rem;
  font-size: inherit;
  color: var(--text-secondary);
}

.post-content li:last-child {
  border-bottom: none;
}

.post-content li em {
  color: var(--text);
}

/* ═══════════════════════════════════════════════════
   Figures
   ═══════════════════════════════════════════════════ */

figure {
  margin: 2rem 0;
  padding: 0;
}

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

figcaption {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 0.6rem;
  line-height: 1.5;
  font-style: italic;
}

figure.fullwidth {
  max-width: none;
  width: 100%;
}

/* ═══════════════════════════════════════════════════
   Images (render hook compatibility)
   ═══════════════════════════════════════════════════ */

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

.image-figure {
  margin: 2.5rem 0;
  text-align: center;
}

.image-figure img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  border-radius: 2px;
}

.image-caption {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 0.5rem;
}

/* ═══════════════════════════════════════════════════
   Post header, share, nav
   ═══════════════════════════════════════════════════ */

.post-date {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 300;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
  display: block;
}

.post-share {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.post-next {
  margin-top: 2rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
}
.post-next a {
  color: var(--text-secondary);
  text-decoration: none;
}
.post-next a:hover { color: var(--text); }

/* Threads block */
.threads {
  border-left: 2px solid var(--faint);
  padding: 0.2rem 0 0.2rem 1.4rem;
  margin: 1.8rem 0;
}
.threads p { font-size: 1rem; margin-top: 0.8rem; }
.threads p:first-child { margin-top: 0; }
.threads strong {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  display: inline-block;
  margin-right: 0.35rem;
}

/* ═══════════════════════════════════════════════════
   Homepage sections
   ═══════════════════════════════════════════════════ */

.home-writing,
.home-lists {
  text-align: left;
  margin-top: 2rem;
}

.home-writing ul,
.home-lists ul {
  list-style: none;
  padding-left: 0;
  margin: 1rem 0 0 0;
}

.home-writing li,
.home-lists li {
  margin: 0.55rem 0;
}

/* ═══════════════════════════════════════════════════
   Lists section
   ═══════════════════════════════════════════════════ */

.list-article header h1 {
  margin-bottom: 0.25rem;
}

.list-article header .meta {
  display: block;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-secondary);
  font-weight: 300;
  margin-bottom: 1rem;
}

.list-article .list-body ul,
.list-article .list-body ol {
  list-style: none;
  padding-left: 0;
  margin: 1rem 0;
}

.list-article .list-body li {
  display: block;
  margin: 0.5rem 0;
  padding-left: 0;
}

.list-article .list-body li input[type="checkbox"] {
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════
   Archive layout
   ═══════════════════════════════════════════════════ */

.archive {
  text-align: left;
  margin-top: 0;
}

.archive-year {
  display: block;
  width: 100%;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.archive-year-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.archive-year-list li {
  display: block;
  margin: 0.5rem 0;
}

/* ═══════════════════════════════════════════════════
   About page social links
   ═══════════════════════════════════════════════════ */

.about-social-list {
  list-style: none;
  padding-left: 0;
}

.about-social-list li {
  margin: 0.4rem 0;
}

/* ═══════════════════════════════════════════════════
   External link note (render hook)
   ═══════════════════════════════════════════════════ */

.external-link-note {
  font-size: 0.8em;
  color: var(--text-secondary);
  font-style: italic;
}

/* ═══════════════════════════════════════════════════
   Media embeds
   ═══════════════════════════════════════════════════ */

video, iframe {
  max-width: 100%;
  display: block;
  margin: 1.5rem 0;
}

iframe {
  aspect-ratio: 16 / 9;
  height: auto;
  border: 0;
}

/* ═══════════════════════════════════════════════════
   Site footer
   ═══════════════════════════════════════════════════ */

.site-footer {
  text-align: center;
  padding: 1.8rem;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  letter-spacing: 0.04em;
}
