* { box-sizing: border-box; }

html {
  font-size: calc(100% * var(--user-scale, 1));
  scroll-behavior: auto;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.125rem;
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
  transition: background var(--motion) ease, color var(--motion) ease;
  overflow-x: hidden;
}

.page { max-width: 42rem; margin: 0 auto; padding: 3rem 1.5rem 6rem; }

a { color: var(--inkwell); }
[data-underline="on"] a { text-decoration: underline; }

/* Skip link */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1rem;
  z-index: 200;
}
.skip-link:focus { left: 1rem; top: 1rem; }

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

/* ============================================
   READING PROGRESS BAR
   ============================================ */
#reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 100;
  transition: width var(--motion) linear;
}

/* ============================================
   MASTHEAD
   ============================================ */
.masthead { padding-bottom: 1.5rem; border-bottom: 3px double var(--ink); margin-bottom: 2.5rem; }
.masthead .kicker {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 0.4rem;
}
.masthead h1 { font-family: var(--font-display); font-weight: 800; font-size: 2.6rem; letter-spacing: -0.01em; margin: 0.1rem 0 0.5rem; }
.masthead h1 a { color: inherit; text-decoration: none; }
.masthead .dek { font-style: italic; color: var(--ink-soft); font-size: 1.02rem; max-width: 34rem; }
nav.topics { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin-top: 1.1rem; font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; }
nav.topics a { color: var(--ink-soft); text-decoration: none; }
nav.topics a:hover, nav.topics a.active { color: var(--accent); }
.back-link { display: inline-block; margin-bottom: 1.5rem; font-family: var(--font-mono); font-size: 0.78rem; text-decoration: none; color: var(--ink-soft); }
.back-link:hover { color: var(--accent); }

/* ============================================
   FEATURED POST + POST LIST (homepage)
   ============================================ */
.featured { margin-bottom: 3rem; padding-bottom: 2.5rem; border-bottom: 1px solid var(--rule); }
.featured .eyebrow { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.5rem; }
.featured h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.9rem; line-height: 1.15; margin: 0 0 0.6rem; }
.featured h2 a { color: var(--ink); text-decoration: none; }
.featured h2 a:hover { color: var(--accent); }
.featured p.excerpt { color: var(--ink-soft); margin: 0 0 0.8rem; max-width: 38rem; }

.meta { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-soft); }
.meta .tag { color: var(--inkwell); }
.meta .dot { margin: 0 0.4em; opacity: 0.5; }

.post-list { list-style: none; margin: 0; padding: 0; }
.post-item { padding: 1.6rem 0; border-bottom: 1px solid var(--rule); display: grid; grid-template-columns: 5.5rem 1fr; gap: 1.2rem; }
.post-item:last-child { border-bottom: none; }
.post-date { font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-soft); padding-top: 0.25rem; line-height: 1.4; }
.post-date .day { display: block; font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--ink); line-height: 1; margin-bottom: 0.15rem; }
.post-item h3 { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; line-height: 1.25; margin: 0 0 0.4rem; }
.post-item h3 a { color: var(--ink); text-decoration: none; }
.post-item h3 a:hover { color: var(--accent); }
.post-item p.excerpt { color: var(--ink-soft); font-size: 0.96rem; margin: 0 0 0.5rem; }
.empty-state { color: var(--ink-soft); font-style: italic; padding: 2rem 0; }

/* ============================================
   ARTICLE / CONTENT SYSTEM
   ============================================ */
.article :is(h2, h3, h4) { font-family: var(--font-display); font-weight: 700; color: var(--ink); line-height: 1.2; }
.article h2 { font-size: 1.75rem; margin: 2.6rem 0 1rem; padding-top: 0.6rem; border-top: 1px solid var(--rule); }
.article h3 { font-size: 1.3rem; margin: 2rem 0 0.75rem; color: var(--inkwell); }
.article h4 { font-size: 1.05rem; margin: 1.5rem 0 0.5rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; color: var(--ink-soft); }
.article p { margin: 0 0 var(--para-gap); }
.article > p:first-of-type::first-letter {
  font-family: var(--font-display); font-weight: 800; font-size: 3.4rem; float: left;
  line-height: 0.85; padding: 0.05em 0.08em 0 0; color: var(--accent);
}
[data-theme="ereader"] .article > p:first-of-type::first-letter,
[data-contrast="high"] .article > p:first-of-type::first-letter { color: var(--ink); }

.note {
  position: relative; margin: 1.75rem 0; padding: 1rem 1.2rem 1rem 1.4rem;
  background: var(--paper-raised); border-left: 3px solid var(--accent); border-radius: 0 3px 3px 0; font-size: 0.96rem;
}
.note::before {
  content: attr(data-label); display: block; font-family: var(--font-mono); font-size: 0.66rem;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.4rem;
}
.note p:last-child { margin-bottom: 0; }
.note.warning { border-left-color: var(--gold); } .note.warning::before { color: var(--gold); }
.note.quote { border-left-color: var(--inkwell); font-style: italic; } .note.quote::before { color: var(--inkwell); }
.note.source { border-left-style: dashed; border-left-color: var(--ink-soft); font-family: var(--font-mono); font-size: 0.82rem; } .note.source::before { color: var(--ink-soft); }

code { font-family: var(--font-mono); font-size: 0.85em; background: var(--paper-raised); padding: 0.12em 0.4em; border-radius: 3px; color: var(--inkwell); }
pre { background: var(--code-bg); color: var(--code-fg); padding: 1.1rem 1.2rem; border-radius: 5px; overflow-x: auto; font-size: 0.85rem; line-height: 1.55; margin: 1.75rem 0; }
pre code { background: none; color: inherit; padding: 0; font-size: 1em; }

blockquote { margin: 2rem 0; padding: 0 0 0 1.3rem; border-left: 2px solid var(--ink); font-family: var(--font-display); font-style: italic; font-size: 1.2rem; color: var(--ink-soft); }
blockquote cite { display: block; margin-top: 0.5rem; font-family: var(--font-mono); font-style: normal; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
blockquote cite::before { content: "— "; }

table { width: 100%; border-collapse: collapse; margin: 1.75rem 0; font-size: 0.92rem; }
th, td { padding: 0.55rem 0.7rem; text-align: left; border-bottom: 1px solid var(--rule); }
th { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); border-bottom: 2px solid var(--ink); }
tbody tr:nth-child(odd) { background: color-mix(in srgb, var(--accent) 5%, transparent); }

figure { margin: 2rem 0; }
figcaption { margin-top: 0.6rem; font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-soft); font-style: italic; }

.asterism { text-align: center; color: var(--accent); letter-spacing: 0.5em; margin: 2.5rem 0; font-size: 0.9rem; }

sup.footnote-ref a { color: var(--accent); text-decoration: none; font-weight: 600; }
.footnotes { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-size: 0.85rem; color: var(--ink-soft); }
.footnotes ol { padding-left: 1.2rem; }
.footnotes li { margin-bottom: 0.4rem; }

.aside-note { margin: 3rem 0; padding: 1rem 1.2rem; background: var(--paper-raised); border-left: 3px solid var(--gold); border-radius: 0 3px 3px 0; font-size: 0.92rem; color: var(--ink-soft); }
.aside-note strong { color: var(--ink); }

footer.site-footer { margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-soft); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }

.widgets-row { display: grid; grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 2.5rem; min-width: 0; }
.widget { background: var(--paper-raised); border: 1px solid var(--rule); border-radius: 8px; padding: 1.25rem 1.4rem; min-width: 0; }
.widget h2 {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-soft); margin: 0 0 1rem; display: flex; justify-content: space-between; align-items: center;
}

/* Recent posts slider */
.slider-wrap { position: relative; min-width: 0; }
.slider-track {
  display: flex; gap: 1rem; overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 0.4rem; scrollbar-width: thin; min-width: 0;
}
.slider-track::-webkit-scrollbar { height: 6px; }
.slider-track::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 3px; }
.slider-card {
  flex: 0 0 14rem; scroll-snap-align: start; background: var(--paper); border: 1px solid var(--rule);
  border-radius: 6px; padding: 0.9rem 1rem; display: flex; flex-direction: column;
}
.slider-card .slider-date { font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.4rem; }
.slider-card h3 { font-family: var(--font-display); font-size: 1rem; line-height: 1.25; margin: 0 0 0.4rem; }
.slider-card h3 a { color: var(--ink); text-decoration: none; }
.slider-card h3 a:hover { color: var(--accent); }
.slider-card p { font-size: 0.85rem; color: var(--ink-soft); margin: 0; flex-grow: 1; }
.slider-nav { display: flex; gap: 0.4rem; }
.slider-nav button {
  width: 1.9rem; height: 1.9rem; border-radius: 50%; border: 1px solid var(--rule); background: var(--paper);
  color: var(--ink); cursor: pointer; font-family: var(--font-mono); font-size: 0.9rem; line-height: 1;
}
.slider-nav button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Tag cloud widget */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tag-cloud a {
  font-family: var(--font-mono); font-size: 0.78rem; padding: 0.35rem 0.7rem; border: 1px solid var(--rule);
  border-radius: 999px; color: var(--ink-soft); text-decoration: none;
}
.tag-cloud a:hover { color: var(--accent); border-color: var(--accent); }
.tag-cloud a .count { color: var(--ink-soft); opacity: 0.6; margin-left: 0.3em; }

@media (min-width: 640px) {
  .widgets-row { grid-template-columns: 2fr 1fr; }
}


.a11y-toggle {
  position: fixed; bottom: 1.25rem; right: 1.25rem; z-index: 150;
  width: 3.1rem; height: 3.1rem; border-radius: 50%;
  background: var(--ink); color: var(--paper); border: none;
  font-family: var(--font-display); font-weight: 700; font-size: 1.05rem;
  cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}
.a11y-toggle:hover { background: var(--accent); }

.a11y-panel {
  position: fixed; bottom: 5rem; right: 1.25rem; z-index: 150;
  width: min(20rem, calc(100vw - 2.5rem)); max-height: 75vh; overflow-y: auto;
  background: var(--paper-raised); color: var(--ink); border: 1px solid var(--rule);
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  padding: 1.25rem;
}
.a11y-panel[hidden] { display: none; }
.a11y-panel h2 { font-family: var(--font-display); font-size: 1.1rem; margin: 0 0 1rem; }
.a11y-panel section { margin-bottom: 1.1rem; }
.a11y-panel h3 { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); margin: 0 0 0.5rem; }
.a11y-row { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.a11y-panel button {
  font-family: var(--font-mono); font-size: 0.78rem; padding: 0.4rem 0.7rem;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 4px; color: var(--ink); cursor: pointer;
}
.a11y-panel button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.a11y-panel label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; cursor: pointer; }
#a11y-reset { width: 100%; margin-top: 0.5rem; }

@media (max-width: 480px) {
  .masthead h1 { font-size: 2.1rem; }
  .article > p:first-of-type::first-letter { font-size: 2.6rem; }
  .post-item { grid-template-columns: 3.5rem 1fr; gap: 0.8rem; }
  .post-date .day { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}