/* ===================================================================
   THE MARGINALIA — editorial stylesheet
   A quiet journal of design & letters
   =================================================================== */

:root {
  /* palette — warm paper & ink */
  --paper:      #f3ede2;
  --paper-2:    #ece4d6;
  --card:       #fbf7ef;
  --ink:        #211c18;
  --ink-soft:   #4a4039;
  --muted:      #8a7c6f;
  --rule:       #c9bca9;
  --rule-soft:  #ddd2c0;
  --accent:     #9c3b1b;   /* burnt sienna */
  --accent-2:   #c2691f;   /* amber */
  --accent-ink: #6a2712;
  --highlight:  rgba(194,105,31,.16);

  /* type — system font stack, no external requests */
  --f-display: Georgia, "Times New Roman", "DejaVu Serif", serif;
  --f-body:    Georgia, "Times New Roman", "DejaVu Serif", serif;
  --f-mono:    ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;

  /* measure */
  --measure: 68ch;
  --gutter: clamp(1.25rem, 5vw, 4rem);
  --maxw: 1240px;

  /* safe areas for notched devices */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--f-body);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  font-size: clamp(17px, 1.1vw, 19px);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
ol, ul { list-style: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
::selection { background: var(--accent); color: var(--paper); }

/* ---------- paper grain ---------- */
.grain {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  opacity: .035; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- reading progress ---------- */
.progress-rail {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 1000;
  background: transparent;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .1s linear;
}

/* ---------- utility ---------- */
.mono { font-family: var(--f-mono); font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.rule { width: 100%; border: 0; }
.rule.thin { border-top: 1px solid var(--rule); }
.rule.thick { border-top: 3px solid var(--ink); }
.divider { margin: clamp(2.5rem, 6vw, 5rem) 0; }

/* ===================================================================
   MASTHEAD
   =================================================================== */
.masthead { padding: 0 var(--gutter); }
.masthead-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: end; gap: 1rem;
  padding: clamp(1.5rem, 4vw, 2.5rem) 0 .9rem;
}
.masthead-meta-left { justify-self: start; }
.masthead-meta-right { justify-self: end; text-align: right; }

.wordmark {
  justify-self: center; text-align: center; line-height: .9;
  font-family: var(--f-display);
  font-weight: 600;
  font-variation-settings: "opsz" 144, "SOFT" 40, "WONK" 0;
  color: var(--ink);
  transition: color .3s ease;
}
.wordmark:hover { color: var(--accent); }
.wm-the {
  display: block;
  font-size: clamp(.7rem, 1.6vw, 1rem);
  font-style: italic;
  font-weight: 400;
  letter-spacing: .15em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .15em;
  font-variation-settings: "opsz" 14;
}
.wm-main {
  display: block;
  font-size: clamp(2rem, 6.5vw, 4.2rem);
  letter-spacing: -.02em;
  font-variation-settings: "opsz" 144, "SOFT" 50, "WONK" 1;
}

.masthead .rule.thick { margin-top: .35rem; }
.primary-nav { max-width: var(--maxw); margin: 0 auto; }
.primary-nav ul {
  display: flex; justify-content: center; gap: clamp(1.5rem, 4vw, 3rem);
  padding: .7rem 0;
}
.primary-nav a {
  font-family: var(--f-display);
  font-size: .95rem; font-weight: 500;
  letter-spacing: .02em;
  color: var(--ink-soft);
  position: relative; padding-bottom: 2px;
  transition: color .25s ease;
}
.primary-nav a::after {
  content: ""; position: absolute; left: 0; bottom: 0;
  width: 0; height: 1px; background: var(--accent);
  transition: width .3s ease;
}
.primary-nav a:hover, .primary-nav a.active { color: var(--accent); }
.primary-nav a:hover::after, .primary-nav a.active::after { width: 100%; }
.primary-nav .nav-sub { font-size: .68rem; opacity: .7; }

/* ---------- search bar ---------- */
.nav-search {
  display: flex;
  align-items: center;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  font-family: var(--f-body);
  font-size: .9rem;
  padding: .4rem 1rem .4rem 2rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--card);
  color: var(--ink);
  width: 180px;
  transition: width .3s ease, border-color .3s ease, box-shadow .3s ease;
  outline: none;
}

.search-input::placeholder {
  color: var(--muted);
  font-style: italic;
}

.search-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(156, 59, 27, .08);
  width: 220px;
}

.search-icon {
  position: absolute;
  left: .6rem;
  color: var(--muted);
  pointer-events: none;
  transition: color .25s ease;
}

.search-input:focus + .search-icon,
.search-input:not(:placeholder-shown) + .search-icon {
  color: var(--accent);
}

/* ===================================================================
   APP LAYOUT
   =================================================================== */
.app {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 4rem) var(--gutter);
  min-height: 60vh;
}
.view { animation: fadeUp .6s cubic-bezier(.2,.7,.2,1) both; }
.view[hidden] { display: none; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
   FEATURED (hero)
   =================================================================== */
.featured {
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
  padding: clamp(1rem, 3vw, 2rem) 0;
}
.featured-visual {
  aspect-ratio: 4/5;
  background: var(--paper-2);
  position: relative; overflow: hidden;
  border: 1px solid var(--rule);
  box-shadow: 0 1px 0 var(--rule-soft), 0 30px 60px -40px rgba(33,28,24,.4);
}
.featured-visual::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(circle at 30% 20%, rgba(194,105,31,.22), transparent 55%),
    radial-gradient(circle at 80% 80%, rgba(156,59,27,.18), transparent 50%),
    linear-gradient(135deg, #e8dcc6, #d4c4a6);
}
.featured-visual .folio-num {
  position: absolute; top: 1.2rem; left: 1.2rem;
  font-family: var(--f-mono); font-size: .7rem; letter-spacing: .2em;
  color: var(--ink-soft);
}
.featured-visual .glyph {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--f-display);
  font-size: clamp(8rem, 22vw, 16rem);
  font-weight: 300;
  font-style: italic;
  font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1;
  color: var(--accent-ink);
  opacity: .85;
  line-height: 1;
  text-shadow: 0 2px 30px rgba(106,39,18,.15);
}
.featured-text .kicker {
  display: inline-block;
  font-family: var(--f-mono); font-size: .7rem; letter-spacing: .18em;
  text-transform: uppercase; color: var(--accent);
  border-bottom: 1.5px solid var(--accent);
  padding-bottom: 2px; margin-bottom: 1.2rem;
}
.featured-text h1 {
  font-family: var(--f-display);
  font-size: clamp(2rem, 4.5vw, 3.4rem);
  font-weight: 400;
  line-height: 1.04;
  letter-spacing: -.015em;
  font-variation-settings: "opsz" 144, "SOFT" 30;
  margin-bottom: 1.1rem;
}
.featured-text h1 em {
  font-style: italic; color: var(--accent-ink);
  font-variation-settings: "opsz" 144, "SOFT" 60, "WONK" 1;
}
.featured-text .dek {
  font-size: 1.12rem; line-height: 1.55; color: var(--ink-soft);
  max-width: 48ch; margin-bottom: 1.6rem;
}
.featured-meta {
  display: flex; align-items: center; gap: .9rem;
  margin-bottom: 1.6rem;
}
.featured-meta .by { font-family: var(--f-body); font-size: .9rem; color: var(--ink-soft); }
.featured-meta .by strong { font-weight: 600; color: var(--ink); }
.read-link {
  display: inline-flex; align-items: center; gap: .6rem;
  font-family: var(--f-display); font-size: 1rem; font-weight: 500;
  color: var(--accent);
  border-bottom: 1px solid var(--accent);
  padding-bottom: 3px;
  transition: gap .3s ease, color .3s ease;
}
.read-link:hover { gap: 1rem; color: var(--accent-ink); }
.read-link .arrow { transition: transform .3s ease; }
.read-link:hover .arrow { transform: translateX(3px); }

/* ===================================================================
   INDEX / POST LIST
   =================================================================== */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem;
  margin-bottom: 2rem;
}
.section-title {
  font-family: var(--f-display);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 500;
  font-variation-settings: "opsz" 100;
  letter-spacing: -.01em;
}

.post-list { display: flex; flex-direction: column; }
.post-item {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: clamp(1rem, 3vw, 2.5rem);
  align-items: baseline;
  padding: clamp(1.4rem, 3vw, 2rem) 0;
  border-top: 1px solid var(--rule-soft);
  transition: background .35s ease, padding .35s ease;
  position: relative;
}
.post-item:last-child { border-bottom: 1px solid var(--rule-soft); }
.post-item:hover { background: linear-gradient(90deg, transparent, rgba(194,105,31,.05) 30%, transparent); }
.post-item:hover .pi-title { color: var(--accent); }
.post-item:hover .pi-arrow { opacity: 1; transform: translateX(0); }

.pi-date {
  font-family: var(--f-mono); font-size: .72rem; letter-spacing: .08em;
  color: var(--muted); padding-top: .4em;
}
.pi-date .yr { display: block; color: var(--ink-soft); margin-top: 2px; }
.pi-body { min-width: 0; }
.pi-cat {
  font-family: var(--f-mono); font-size: .66rem; letter-spacing: .16em;
  text-transform: uppercase; color: var(--accent);
  margin-bottom: .4rem; display: block;
}
.pi-title {
  font-family: var(--f-display);
  font-size: clamp(1.25rem, 2.4vw, 1.7rem);
  font-weight: 450;
  line-height: 1.15;
  letter-spacing: -.01em;
  font-variation-settings: "opsz" 80;
  transition: color .3s ease;
  margin-bottom: .35rem;
}
.pi-excerpt {
  font-size: .98rem; color: var(--ink-soft); line-height: 1.5;
  max-width: 62ch;
}
.pi-arrow {
  font-family: var(--f-display); font-size: 1.5rem; color: var(--accent);
  opacity: 0; transform: translateX(-8px);
  transition: opacity .35s ease, transform .35s ease;
  align-self: center;
}

/* ===================================================================
   ARTICLE / POST VIEW
   =================================================================== */
.view-post { max-width: var(--measure); margin: 0 auto; }
.article-head { text-align: center; margin-bottom: 2.5rem; }
.article-cat {
  font-family: var(--f-mono); font-size: .7rem; letter-spacing: .18em;
  text-transform: uppercase; color: var(--accent);
  margin-bottom: 1.2rem; display: block;
}
.article-title {
  font-family: var(--f-display);
  font-size: clamp(2.2rem, 5.5vw, 3.6rem);
  font-weight: 450;
  line-height: 1.05;
  letter-spacing: -.02em;
  font-variation-settings: "opsz" 144, "SOFT" 40;
  margin-bottom: 1rem;
}
.article-title em {
  font-style: italic; color: var(--accent-ink);
  font-variation-settings: "opsz" 144, "SOFT" 70, "WONK" 1;
}
.article-dek {
  font-size: 1.15rem; font-style: italic; color: var(--ink-soft);
  line-height: 1.5; max-width: 52ch; margin: 0 auto 1.8rem;
}
.article-byline {
  display: inline-flex; align-items: center; gap: .8rem;
  font-family: var(--f-body); font-size: .9rem; color: var(--muted);
}
.article-byline strong { color: var(--ink-soft); font-weight: 600; }
.article-byline .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); }

.article-rule {
  display: flex; align-items: center; gap: 1rem; margin: 0 auto 2.5rem;
  color: var(--rule);
}
.article-rule::before, .article-rule::after {
  content: ""; flex: 1; height: 1px; background: var(--rule);
}
.article-rule span { font-family: var(--f-display); font-style: italic; color: var(--accent); font-size: 1.1rem; }

/* ---------- rendered markdown ---------- */
.prose { font-size: 1.08rem; line-height: 1.78; color: var(--ink); }
.prose > * + * { margin-top: 1.3em; }
.prose p { max-width: none; }
.prose > p:first-of-type::first-letter {
  font-family: var(--f-display);
  font-size: 4.2em; line-height: .82; float: left;
  font-weight: 500; font-style: italic;
  font-variation-settings: "opsz" 144, "SOFT" 50, "WONK" 1;
  color: var(--accent);
  margin: .08em .12em 0 -.04em;
  padding-top: .04em;
}
.prose h2 {
  font-family: var(--f-display);
  font-size: 1.8rem; font-weight: 500;
  line-height: 1.2; letter-spacing: -.01em;
  font-variation-settings: "opsz" 100;
  margin-top: 2em; margin-bottom: .3em;
}
.prose h3 {
  font-family: var(--f-display);
  font-size: 1.35rem; font-weight: 500;
  margin-top: 1.6em; margin-bottom: .2em;
}
.prose a {
  color: var(--accent-ink);
  border-bottom: 1px solid var(--accent-2);
  transition: background .25s ease, color .25s ease;
}
.prose a:hover { background: var(--highlight); color: var(--accent); }
.prose strong { font-weight: 700; }
.prose em { font-style: italic; }
.prose blockquote {
  border-left: 3px solid var(--accent);
  padding: .4em 0 .4em 1.5em;
  margin: 1.8em 0;
  font-family: var(--f-display);
  font-size: 1.4rem; font-style: italic; font-weight: 400;
  line-height: 1.4; color: var(--ink-soft);
  font-variation-settings: "opsz" 80, "SOFT" 40;
}
.prose blockquote p { margin: 0; }
.prose ul, .prose ol { padding-left: 1.5em; }
.prose li { margin-top: .5em; }
.prose ul li::marker { color: var(--accent); }
.prose ol li::marker { font-family: var(--f-mono); font-size: .85em; color: var(--muted); }
.prose code {
  font-family: var(--f-mono); font-size: .85em;
  background: var(--paper-2); padding: .15em .4em; border-radius: 3px;
  color: var(--accent-ink);
}
.prose pre {
  background: #221d18; color: #e8dcc6;
  padding: 1.3em 1.5em; border-radius: 4px; overflow-x: auto;
  font-size: .9rem; line-height: 1.6;
  border: 1px solid #3a3128;
}
.prose pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5em auto; width: 30%; }
.prose img { border-radius: 3px; margin: 1.5em auto; border: 1px solid var(--rule-soft); }

/* ---------- article footer / nav ---------- */
.article-foot {
  margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--rule);
}
.tags { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 2rem; }
.tag {
  font-family: var(--f-mono); font-size: .68rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-soft);
  border: 1px solid var(--rule); padding: .35em .7em; border-radius: 2px;
  transition: border-color .25s, color .25s;
}
.tag:hover { border-color: var(--accent); color: var(--accent); }
.post-nav {
  display: flex; justify-content: space-between; gap: 1.5rem;
  flex-wrap: wrap;
}
.post-nav a {
  display: flex; flex-direction: column; gap: .3rem;
  max-width: 45%; transition: color .3s;
}
.post-nav a:hover { color: var(--accent); }
.post-nav .pn-label { font-family: var(--f-mono); font-size: .65rem; letter-spacing: .14em; color: var(--muted); text-transform: uppercase; }
.post-nav .pn-title { font-family: var(--f-display); font-size: 1.05rem; font-style: italic; }
.post-nav a.next { text-align: right; margin-left: auto; }

/* ===================================================================
   ABOUT
   =================================================================== */
.view-about { max-width: var(--measure); margin: 0 auto; }
.about-head { text-align: center; margin-bottom: 3rem; }
.about-head h1 {
  font-family: var(--f-display); font-size: clamp(2.5rem,6vw,4rem);
  font-weight: 400; font-variation-settings: "opsz" 144, "SOFT" 50;
  letter-spacing: -.02em; line-height: 1;
}
.about-head h1 em { font-style: italic; color: var(--accent-ink); font-variation-settings: "opsz" 144, "SOFT" 80, "WONK" 1; }

/* ===================================================================
   LOADER & ERROR
   =================================================================== */
.view-loading { display: grid; place-items: center; min-height: 40vh; }
.loader { display: flex; gap: .5rem; }
.loader span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: bounce 1s infinite ease-in-out;
}
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(.5); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

.view-error { text-align: center; padding: 4rem 0; }
.err-code { font-size: .85rem; color: var(--accent); margin-bottom: 1rem; }
.err-msg { font-family: var(--f-display); font-size: 1.6rem; font-style: italic; color: var(--ink-soft); max-width: 40ch; margin: 0 auto 2rem; }
.err-link { font-family: var(--f-display); color: var(--accent); border-bottom: 1px solid var(--accent); padding-bottom: 2px; }

/* ===================================================================
   COLOPHON / FOOTER
   =================================================================== */
.colophon { padding: 0 var(--gutter); margin-top: 4rem; }
.colophon-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1.5rem;
  padding: clamp(1.5rem, 4vw, 2.5rem) 0;
}
.colo-title { font-family: var(--f-display); font-size: 1.2rem; font-weight: 500; margin-bottom: .3rem; font-variation-settings: "opsz" 80; }
.colo-text { font-size: .9rem; color: var(--ink-soft); line-height: 1.55; max-width: 50ch; }
.colo-right { text-align: right; display: flex; flex-direction: column; gap: .5rem; justify-content: flex-end; }
.colo-rss { opacity: .7; }

/* ---------- back to top ---------- */
.back-to-top {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 100;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
  opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity .3s ease, transform .3s ease, background .3s ease;
}
.back-to-top.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.back-to-top:hover { background: var(--accent); }

/* ===================================================================
   STAGGER ENTRANCE
   =================================================================== */
.stagger > * { opacity: 0; animation: fadeUp .55s cubic-bezier(.2,.7,.2,1) forwards; }
.stagger > *:nth-child(1) { animation-delay: .05s; }
.stagger > *:nth-child(2) { animation-delay: .12s; }
.stagger > *:nth-child(3) { animation-delay: .19s; }
.stagger > *:nth-child(4) { animation-delay: .26s; }
.stagger > *:nth-child(5) { animation-delay: .33s; }
.stagger > *:nth-child(6) { animation-delay: .40s; }
.stagger > *:nth-child(7) { animation-delay: .47s; }
.stagger > *:nth-child(8) { animation-delay: .54s; }

/* ===================================================================
   RESPONSIVE — Tablet landscape (≤ 1024px)
   =================================================================== */
@media (max-width: 1024px) {
  .featured {
    grid-template-columns: 1fr 1fr;
    gap: clamp(1rem, 3vw, 2rem);
  }
  .featured-visual .glyph {
    font-size: clamp(6rem, 18vw, 10rem);
  }
  .featured-text h1 {
    font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  }
  .featured-text .dek {
    font-size: 1.05rem;
  }
  .post-item {
    grid-template-columns: 80px 1fr auto;
    gap: clamp(1rem, 2vw, 2rem);
  }
}

/* ===================================================================
   RESPONSIVE — Tablet portrait (≤ 860px)
   =================================================================== */
@media (max-width: 860px) {
  /* Masthead: stack vertically, centered */
  .masthead-inner {
    grid-template-columns: 1fr;
    text-align: center;
    gap: .6rem;
  }
  .masthead-meta-left,
  .masthead-meta-right {
    justify-self: center;
    text-align: center;
  }
  .masthead-meta-right {
    order: 3;
  }

  /* Nav: tighter spacing */
  .primary-nav ul {
    gap: 1.2rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Search: smaller width */
  .search-input {
    width: 160px;
  }
  .search-input:focus {
    width: 180px;
  }

  /* Featured: single column, visual on top */
  .featured {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  .featured-visual {
    aspect-ratio: 16/10;
    order: -1;
  }
  .featured-text .dek {
    max-width: none;
  }

  /* Post list: simplify grid */
  .post-item {
    grid-template-columns: 1fr;
    gap: .4rem;
    padding: clamp(1.2rem, 3vw, 1.8rem) 0;
  }
  .pi-date {
    order: 2;
    padding-top: 0;
  }
  .pi-arrow {
    display: none;
  }
  .pi-excerpt {
    max-width: none;
  }

  /* Section head: stack on smaller screens */
  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: .3rem;
  }

  /* Footer: stack */
  .colophon-inner {
    flex-direction: column;
    gap: 1.5rem;
  }
  .colo-right {
    text-align: left;
  }
  .colo-text {
    max-width: none;
  }
}

/* ===================================================================
   RESPONSIVE — Large phone (≤ 640px)
   =================================================================== */
@media (max-width: 640px) {
  body {
    font-size: clamp(15px, 4vw, 17px);
  }

  /* Masthead: smaller wordmark */
  .wm-main {
    font-size: clamp(1.8rem, 10vw, 2.8rem);
  }
  .wm-the {
    font-size: clamp(.6rem, 2.5vw, .8rem);
  }

  /* Featured: smaller hero */
  .featured-visual {
    aspect-ratio: 3/2;
  }
  .featured-visual .glyph {
    font-size: clamp(5rem, 20vw, 8rem);
  }
  .featured-text h1 {
    font-size: clamp(1.6rem, 6vw, 2.2rem);
  }
  .featured-text .dek {
    font-size: 1rem;
  }
  .featured-meta {
    flex-wrap: wrap;
    gap: .5rem;
  }

  /* Article */
  .article-title {
    font-size: clamp(1.8rem, 7vw, 2.6rem);
  }
  .article-dek {
    font-size: 1.05rem;
  }

  /* Prose: smaller drop cap */
  .prose > p:first-of-type::first-letter {
    font-size: 3.6em;
  }
  .prose h2 {
    font-size: 1.5rem;
  }
  .prose h3 {
    font-size: 1.2rem;
  }
  .prose blockquote {
    font-size: 1.2rem;
  }
  .prose pre {
    padding: 1em;
    font-size: .85rem;
  }

  /* About */
  .about-head h1 {
    font-size: clamp(2rem, 8vw, 3rem);
  }

  /* Back to top: smaller */
  .back-to-top {
    width: 38px;
    height: 38px;
    bottom: 1rem;
    right: 1rem;
  }
}

/* ===================================================================
   RESPONSIVE — Small phone (≤ 520px)
   =================================================================== */
@media (max-width: 520px) {
  :root {
    --gutter: 1rem;
  }

  /* Masthead */
  .masthead {
    padding-left: calc(var(--gutter) + var(--safe-left));
    padding-right: calc(var(--gutter) + var(--safe-right));
  }
  .masthead-inner {
    padding-top: 1.2rem;
    padding-bottom: .7rem;
  }

  /* Nav: smaller font, tighter */
  .primary-nav ul {
    gap: .8rem;
    padding: .5rem 0;
  }
  .primary-nav a {
    font-size: .85rem;
  }
  .primary-nav .nav-sub {
    font-size: .62rem;
  }

  /* Search: compact on small screens */
  .nav-search {
    width: 100%;
    order: 4;
    margin-top: .3rem;
  }
  .search-wrapper {
    width: 100%;
  }
  .search-input {
    width: 100%;
    font-size: .85rem;
  }
  .search-input:focus {
    width: 100%;
  }

  /* Featured */
  .featured {
    padding: .5rem 0;
  }
  .featured-visual .folio-num {
    top: .8rem;
    left: .8rem;
    font-size: .6rem;
  }
  .featured-text .kicker {
    font-size: .62rem;
    margin-bottom: .8rem;
  }
  .featured-text h1 {
    font-size: clamp(1.4rem, 7vw, 2rem);
    margin-bottom: .8rem;
  }
  .featured-text .dek {
    font-size: .95rem;
    margin-bottom: 1.2rem;
  }
  .featured-meta {
    margin-bottom: 1.2rem;
  }

  /* Post list */
  .section-title {
    font-size: 1.4rem;
  }
  .post-item {
    padding: 1.2rem 0;
  }
  .pi-cat {
    font-size: .6rem;
  }
  .pi-title {
    font-size: 1.15rem;
  }
  .pi-excerpt {
    font-size: .9rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Article */
  .article-cat {
    font-size: .62rem;
  }
  .article-title {
    font-size: clamp(1.6rem, 8vw, 2.2rem);
    margin-bottom: .8rem;
  }
  .article-dek {
    font-size: .98rem;
    margin-bottom: 1.4rem;
  }
  .article-byline {
    font-size: .8rem;
    flex-wrap: wrap;
    gap: .4rem;
  }

  /* Prose */
  .prose {
    font-size: 1rem;
    line-height: 1.7;
  }
  .prose > p:first-of-type::first-letter {
    font-size: 3.2em;
  }
  .prose h2 {
    font-size: 1.35rem;
    margin-top: 1.6em;
  }
  .prose h3 {
    font-size: 1.1rem;
  }
  .prose blockquote {
    font-size: 1.1rem;
    padding-left: 1em;
    margin: 1.4em 0;
  }
  .prose pre {
    padding: .8rem;
    font-size: .8rem;
    border-radius: 3px;
    margin-left: calc(var(--gutter) * -0.5);
    margin-right: calc(var(--gutter) * -0.5);
  }
  .prose img {
    margin-left: calc(var(--gutter) * -0.5);
    margin-right: calc(var(--gutter) * -0.5);
    max-width: calc(100% + var(--gutter));
  }

  /* Post nav: stack vertically */
  .post-nav {
    flex-direction: column;
    gap: 1rem;
  }
  .post-nav a {
    max-width: 100%;
  }
  .post-nav a.next {
    text-align: left;
    margin-left: 0;
  }

  /* Tags */
  .tags {
    gap: .4rem;
  }
  .tag {
    font-size: .62rem;
    padding: .3em .5em;
  }

  /* Footer */
  .colophon {
    padding-left: calc(var(--gutter) + var(--safe-left));
    padding-right: calc(var(--gutter) + var(--safe-right));
  }
  .colo-title {
    font-size: 1.05rem;
  }
  .colo-text {
    font-size: .85rem;
  }

  /* Error */
  .view-error {
    padding: 2.5rem 0;
  }
  .err-msg {
    font-size: 1.3rem;
  }
}

/* ===================================================================
   RESPONSIVE — Extra small phone (≤ 380px)
   =================================================================== */
@media (max-width: 380px) {
  :root {
    --gutter: .75rem;
  }

  .wm-main {
    font-size: 1.6rem;
  }
  .wm-the {
    font-size: .55rem;
  }

  .primary-nav ul {
    gap: .6rem;
  }
  .primary-nav a {
    font-size: .78rem;
  }

  .featured-text h1 {
    font-size: 1.3rem;
  }
  .featured-text .dek {
    font-size: .88rem;
  }
  .featured-meta .by {
    font-size: .8rem;
  }

  .article-title {
    font-size: 1.4rem;
  }
  .article-dek {
    font-size: .9rem;
  }

  .prose {
    font-size: .95rem;
    line-height: 1.65;
  }
  .prose > p:first-of-type::first-letter {
    font-size: 2.8em;
  }
  .prose pre {
    font-size: .75rem;
    padding: .6rem;
  }

  .section-title {
    font-size: 1.2rem;
  }
  .pi-title {
    font-size: 1.05rem;
  }
}

/* ===================================================================
   RESPONSIVE — Touch device improvements
   =================================================================== */
@media (pointer: coarse) {
  /* Larger touch targets */
  .primary-nav a {
    padding: .5rem .3rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .post-item {
    padding: 1.4rem 0;
  }
  .back-to-top {
    width: 48px;
    height: 48px;
  }
  .tag {
    padding: .5em .7em;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }
  .read-link {
    padding-bottom: .4rem;
    min-height: 44px;
  }
}

/* ===================================================================
   RESPONSIVE — Hover-capable devices (restore hover effects)
   =================================================================== */
@media (hover: none) {
  /* Remove hover-only UI cues on touch devices */
  .post-item:hover {
    background: none;
  }
  .post-item:hover .pi-title {
    color: inherit;
  }
  .post-item:hover .pi-arrow {
    opacity: 0;
  }
}

/* ===================================================================
   RESPONSIVE — Landscape phones
   =================================================================== */
@media (max-height: 500px) and (orientation: landscape) {
  .masthead-inner {
    padding-top: 1rem;
    padding-bottom: .5rem;
  }
  .featured-visual {
    aspect-ratio: 2/1;
  }
  .view-loading {
    min-height: 30vh;
  }
  .back-to-top {
    bottom: .5rem;
    right: .5rem;
  }
}

/* ===================================================================
   Safe area padding for body
   =================================================================== */
body {
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ===================================================================
   RESPONSIVE — Reduced motion
   =================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .stagger > * { opacity: 1; }
}
