/* ============================================================
   IF AND WHEN — main.css
   Design system for ifandwhen.org
   ============================================================ */

/* ── CUSTOM PROPERTIES ───────────────────────────────────── */
:root {
  --ink: #1a1a18;
  --paper: #f5f2eb;
  --rule: #c8c0b0;
  --accent: #b5341a;
  --muted: #635850;
  --aside-bg: #eeeae0;
  --col-width: 680px;
  --margin: clamp(1.5rem, 5vw, 4rem);
}

/* ── DARK THEME ─────────────────────────────────────────── */
[data-theme="dark"] {
  --ink: #e8e4dd;
  --paper: #1a1a18;
  --rule: #3a3832;
  --accent: #d4563e;
  --muted: #a09888;
  --aside-bg: #252520;
}

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

/* ── BASE ────────────────────────────────────────────────── */
html {
  font-size: 18px;
  scroll-behavior: smooth;
}

body {
  background-color: var(--paper);
  color: var(--ink);
  font-family: 'Libre Baskerville', Georgia, serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

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

a {
  color: inherit;
}

/* ── PROGRESS BAR ────────────────────────────────────────── */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  width: 0%;
  z-index: 200;
  transition: width 0.05s linear;
  pointer-events: none;
}

/* ── MASTHEAD ────────────────────────────────────────────── */
.masthead {
  border-bottom: 3px solid var(--ink);
  padding: 1.4rem var(--margin);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  background: var(--paper);
  z-index: 100;
}

.masthead-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}

.masthead-title .accent { color: var(--accent); }

.masthead-nav {
  display: flex;
  gap: 1.8rem;
  list-style: none;
}

.masthead-nav a {
  font-family: 'Barlow', sans-serif;
  font-weight: 400;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

.masthead-nav a:hover { color: var(--ink); }

/* ── THEME TOGGLE ───────────────────────────────────────── */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-left: 1.8rem;
  color: var(--muted);
  transition: color 0.15s;
  display: flex;
  align-items: center;
}

.theme-toggle:hover { color: var(--ink); }

.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.theme-toggle .icon-moon { display: block; }
.theme-toggle .icon-sun  { display: none; }

[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }

/* ── FOOTER ──────────────────────────────────────────────── */
.site-footer {
  border-top: 3px solid var(--ink);
  padding: 2rem var(--margin);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.footer-brand {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink);
}

.footer-brand .accent { color: var(--accent); }

.footer-copy {
  font-family: 'Barlow', sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.footer-links {
  display: flex;
  gap: 1.4rem;
  list-style: none;
}

.footer-links a {
  font-family: 'Barlow', sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover { color: var(--ink); }

/* ── HOME PAGE ───────────────────────────────────────────── */
.home-header {
  max-width: calc(var(--col-width) + 2 * var(--margin));
  margin: 0 auto;
  padding: 5rem var(--margin) 3.5rem;
  border-bottom: 1px solid var(--rule);
}

.home-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-weight: 700;
  font-size: clamp(2rem, 4.5vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
}

.home-desc {
  font-family: 'Barlow', sans-serif;
  font-weight: 300;
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--muted);
  max-width: 52ch;
}

.post-list {
  max-width: calc(var(--col-width) + 2 * var(--margin));
  margin: 0 auto;
  padding: 0 var(--margin) 6rem;
  list-style: none;
}

.post-list-item {
  border-bottom: 1px solid var(--rule);
  padding: 2.5rem 0;
}

.post-list-item:first-child {
  padding-top: 3rem;
}

.post-kicker {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.post-kicker::after {
  content: '';
  display: block;
  height: 1px;
  width: 2rem;
  background: var(--accent);
}

.pinned-indicator {
  color: var(--muted);
  margin-right: 0.4em;
}

.post-list-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-weight: 700;
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin-bottom: 0.6rem;
}

.post-list-title a {
  text-decoration: none;
  color: var(--ink);
  transition: color 0.15s;
}

.post-list-title a:hover { color: var(--accent); }

.post-list-excerpt {
  font-family: 'Barlow', sans-serif;
  font-weight: 300;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--muted);
  max-width: 60ch;
  margin-bottom: 1rem;
}

.post-list-meta {
  font-family: 'Barlow', sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.post-list-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--rule);
  display: inline-block;
}

.read-more {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.15s;
}

.read-more:hover { opacity: 0.7; }

/* ── ESSAY HEADER ────────────────────────────────────────── */
.essay-header {
  max-width: calc(var(--col-width) + 2 * var(--margin));
  margin: 0 auto;
  padding: 5rem var(--margin) 3rem;
  border-bottom: 1px solid var(--rule);
}

.essay-kicker {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.4rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.essay-kicker::after {
  content: '';
  display: block;
  height: 1px;
  width: 3rem;
  background: var(--accent);
}

.essay-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-weight: 700;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin-bottom: 1.8rem;
}

.essay-lede {
  font-family: 'Barlow', sans-serif;
  font-weight: 300;
  font-size: 1.2rem;
  line-height: 1.65;
  color: var(--muted);
  max-width: 56ch;
  margin-bottom: 2.4rem;
}

.essay-meta {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  font-family: 'Barlow', sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  flex-wrap: wrap;
}

.essay-meta .byline { color: var(--ink); font-weight: 500; }

.essay-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--rule);
  display: inline-block;
}

/* ── ESSAY BODY ──────────────────────────────────────────── */
.essay-body {
  max-width: calc(var(--col-width) + 2 * var(--margin));
  margin: 0 auto;
  padding: 3.5rem var(--margin) 6rem;
}

.essay-body p {
  font-size: 1.05rem;
  line-height: 1.82;
  margin-bottom: 1.6rem;
  color: var(--ink);
  max-width: 66ch;
}

/* Drop cap on first paragraph */
.essay-body > p:first-child::first-letter {
  float: left;
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 4.2rem;
  line-height: 0.82;
  margin-right: 0.1em;
  margin-top: 0.08em;
  color: var(--accent);
  font-weight: 700;
}

.essay-body h2 {
  font-family: 'Libre Baskerville', serif;
  font-weight: 700;
  font-size: 1.3rem;
  line-height: 1.3;
  margin: 2.5rem 0 1rem;
  max-width: 66ch;
}

.essay-body h3 {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2rem 0 0.8rem;
}

.essay-body ul,
.essay-body ol {
  padding-left: 1.5rem;
  margin-bottom: 1.6rem;
  max-width: 62ch;
}

.essay-body li {
  font-size: 1.05rem;
  line-height: 1.75;
  margin-bottom: 0.4rem;
}

.essay-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: opacity 0.15s;
}

.essay-body a:hover { opacity: 0.75; }

.essay-body em { font-style: italic; }
.essay-body strong { font-weight: 700; }

.essay-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 2.5rem 0 2.5rem -2rem;
  padding: 0.4rem 0 0.4rem 2rem;
}

.essay-body blockquote p {
  font-style: italic;
  font-size: 1.25rem !important;
  line-height: 1.55 !important;
  margin-bottom: 0 !important;
}

/* ── SECTION BREAK ───────────────────────────────────────── */
.section-break {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 2.8rem 0;
  color: var(--rule);
  max-width: 66ch;
}

.section-break span {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.65rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-break::before,
.section-break::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* Native Markdown <hr> becomes section break */
.essay-body hr {
  border: none;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 2.8rem 0;
  max-width: 66ch;
}

.essay-body hr::before,
.essay-body hr::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* ── PULL QUOTE INCLUDE ───────────────────────────────────── */
.pull-quote {
  border-left: 3px solid var(--accent);
  margin: 2.5rem 0 2.5rem -2rem;
  padding: 0.4rem 0 0.4rem 2rem;
}

.pull-quote p {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-style: italic;
  font-size: 1.25rem;
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: 0;
  max-width: 52ch;
}

.pull-quote p::first-letter {
  font-size: 4.2rem;
  float: left;
  font-weight: 700;
  font-style: normal;
  line-height: 0.82;
  margin-right: 0.1em;
  margin-top: 0.08em;
  color: var(--accent);
}

/* ── COMPARISON BOX ──────────────────────────────────────── */
.comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 2.5rem 0 2.5rem -2rem;
  width: calc(100% + 4rem);
}

.comparison-item {
  padding: 1.5rem 1.8rem;
  background: var(--aside-bg);
  border-top: 2px solid var(--rule);
}

.comparison-item:first-child {
  border-right: 1px solid var(--rule);
  border-top-color: var(--muted);
}

.comparison-item:last-child {
  border-top-color: var(--accent);
}

.comparison-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.comparison-phrase {
  font-family: 'Libre Baskerville', serif;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 0.7rem;
}

.comparison-item:last-child .comparison-phrase {
  color: var(--accent);
}

.comparison-desc {
  font-family: 'Barlow', sans-serif;
  font-weight: 300;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
}

/* ── CALLOUT ────────────────────────────────────────────── */

.callout {
  background: var(--aside-bg);
  border-top: 2px solid var(--rule);
  padding: 1.5rem 1.8rem;
  margin: 2.5rem 0;
}

.callout-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.callout p {
  font-family: 'Barlow', sans-serif;
  font-weight: 300;
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--ink);
  margin: 0;
}

/* ── RELATED ESSAYS ──────────────────────────────────────── */
.related {
  background: var(--aside-bg);
  border-top: 1px solid var(--rule);
  padding: 3rem var(--margin);
}

.related-inner {
  max-width: calc(var(--col-width) + 2 * var(--margin));
  margin: 0 auto;
}

.related-label {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2rem;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
}

.related-card {
  border-top: 2px solid var(--rule);
  padding-top: 1rem;
  text-decoration: none;
  display: block;
  transition: border-color 0.15s;
}

.related-card:hover { border-top-color: var(--accent); }

.related-card-kicker {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.related-card-title {
  font-family: 'Libre Baskerville', serif;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.related-card-desc {
  font-family: 'Barlow', sans-serif;
  font-weight: 300;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--muted);
}

/* ── NOTE LAYOUT ─────────────────────────────────────────── */
.note-body {
  max-width: calc(var(--col-width) + 2 * var(--margin));
  margin: 0 auto;
  padding: 4rem var(--margin) 6rem;
}

.note-body p {
  font-family: 'Barlow', sans-serif;
  font-weight: 400;
  font-size: 1rem;
  line-height: 1.75;
  color: var(--ink);
  max-width: 66ch;
  margin-bottom: 1.4rem;
}

/* ── ENTRY ANIMATIONS ────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.essay-header > * {
  animation: fadeUp 0.55s ease both;
}

.essay-kicker  { animation-delay: 0.05s; }
.essay-title   { animation-delay: 0.15s; }
.essay-lede    { animation-delay: 0.25s; }
.essay-meta    { animation-delay: 0.35s; }

/* ── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 640px) {
  .masthead-nav { display: none; }

  .theme-toggle { margin-left: auto; }

  .essay-body blockquote,
  .pull-quote {
    margin-left: 0;
  }

  .comparison {
    grid-template-columns: 1fr;
    margin-left: 0;
    width: 100%;
  }

  .comparison-item:first-child {
    border-right: none;
    border-bottom: 1px solid var(--rule);
  }

  .essay-body > p:first-child::first-letter {
    font-size: 3.2rem;
  }

  .pull-quote p::first-letter {
    font-size: 3.2rem;
  }

  .site-footer {
    flex-direction: column;
    gap: 1rem;
  }
}
