@font-face {
  font-family: "DM Serif Display";
  src: url("assets/dm-serif.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("assets/dm-sans.ttf") format("truetype");
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("assets/ibm-plex-mono.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #faf6ee;
  --paper-2: #f3ecdd;
  --card: #fffdf7;
  --ink: #1c1611;
  --ink-soft: #57503f;
  --line: #e2d7c2;
  --brick: #b23c14;
  --brick-dark: #8c2e0e;
  --gold: #e8a33d;
  --teal: #0c6e64;
  --focus: #1a4fd6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 22, 17, 0.08), 0 10px 30px -18px rgba(28, 22, 17, 0.35);
  --serif: "DM Serif Display", Georgia, "Times New Roman", serif;
  --sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  background-image:
    radial-gradient(ellipse 60% 22% at 12% 0%, rgba(232, 163, 61, 0.14), transparent 70%),
    radial-gradient(ellipse 50% 20% at 95% 8%, rgba(178, 60, 20, 0.08), transparent 70%);
}

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

h1, h2, h3 { font-family: var(--serif); font-weight: 400; line-height: 1.08; margin: 0; }

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--ink);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  z-index: 100;
  transition: top 0.15s ease;
}
.skip:focus { top: 1rem; color: #fff; }

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

/* ---------- Masthead ---------- */
.masthead { border-bottom: 3px double var(--ink); }
.topbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.5rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
}
.topbar-right { display: flex; align-items: center; gap: 0.45rem; margin-left: auto; }
.dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--brick); display: inline-block; }

.wordmark-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2.5rem) 1.2rem;
  max-width: 1200px;
  margin: 0 auto;
}
.wordmark-text { flex: 1 1 auto; min-width: 0; }
.kicker {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brick);
  margin: 0 0 0.3rem;
}
.kicker-accent { color: var(--brick); }
.wordmark { font-size: clamp(2.4rem, 6vw, 4rem); letter-spacing: -0.01em; }
.mastnav { display: flex; gap: 1.1rem; font-size: 0.95rem; }
.mastnav a { color: var(--ink); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 600; }
.mastnav a:hover { border-bottom-color: var(--gold); }

/* ---------- Hero ---------- */
.hero {
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2.5rem);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
}
.hero-copy h2 { font-size: clamp(1.7rem, 3.6vw, 2.7rem); margin-bottom: 0.8rem; }
.lede { font-size: 1.08rem; color: var(--ink-soft); max-width: 34rem; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 1.2rem 0 1.4rem; }
.hero-stats { display: flex; gap: 2rem; margin: 0; padding: 1rem 0 0; border-top: 1px solid var(--line); }
.hero-stats div { display: grid; gap: 0.1rem; }
.hero-stats dt { font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--ink-soft); }
.hero-stats dd { margin: 0; font-family: var(--serif); font-size: 1.6rem; }

.hero-collage { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.ph { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem 0.5rem 0.4rem; margin: 0; box-shadow: var(--shadow); }
.ph img { border-radius: 6px; aspect-ratio: 4 / 3; object-fit: cover; width: 100%; }
.ph figcaption { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); padding: 0.45rem 0.3rem 0.2rem; }
.ph-a { grid-column: 1 / -1; }
.ph-a img { aspect-ratio: 16 / 8; }
.ph-b { transform: rotate(-1.2deg); }
.ph-c { transform: rotate(1.1deg); }

/* ---------- Buttons / fields ---------- */
.btn {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: 999px;
  border: 2px solid var(--ink);
  padding: 0.6rem 1.15rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.2;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--brick-dark); border-color: var(--brick-dark); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-toggle { background: var(--card); color: var(--ink); }
.btn-toggle[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-toggle[aria-pressed="true"] .pill { background: var(--gold); color: var(--ink); }
.pill {
  background: var(--paper-2);
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.78rem;
  padding: 0.05rem 0.55rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Browse ---------- */
.browse { max-width: 1200px; margin: 0 auto; padding: 0.5rem clamp(1rem, 4vw, 2.5rem) 1rem; }
.section-head h2 { font-size: clamp(1.8rem, 4vw, 2.6rem); margin-bottom: 0.3rem; }
.section-sub { color: var(--ink-soft); max-width: 44rem; margin: 0.2rem 0 0; }

.toolbar {
  display: grid;
  grid-template-columns: 1.4fr 1fr auto;
  gap: 0.9rem;
  align-items: end;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1.2rem;
  box-shadow: var(--shadow);
}
.field { display: grid; gap: 0.35rem; }
.field label, .field-label { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); font-weight: 700; }
.field input[type="search"], .field select {
  font: inherit;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  width: 100%;
}
.field input[type="search"]::placeholder { color: #8a8172; }

.resultline { font-family: var(--mono); font-size: 0.8rem; color: var(--ink-soft); margin: 1rem 0 0.8rem; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card:hover { transform: translateY(-3px); }
.card-media { position: relative; margin: 0; }
.card-media img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.badge {
  position: absolute;
  left: 0.7rem;
  top: 0.7rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
}
.badge .swatch { display: inline-block; width: 0.55em; height: 0.55em; border-radius: 50%; margin-right: 0.4em; vertical-align: baseline; }
.saved-ribbon {
  position: absolute;
  right: 0.7rem;
  top: 0.7rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
}
.card-body { padding: 1rem 1.05rem 1.1rem; display: flex; flex-direction: column; gap: 0.5rem; flex: 1; }
.card-meta { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em; }
.card-body h3 { font-size: 1.35rem; }
.card-summary { margin: 0; color: var(--ink-soft); font-size: 0.98rem; }
.card-byline { font-size: 0.85rem; color: var(--ink-soft); margin: 0; }
.card-foot { margin-top: auto; padding-top: 0.6rem; display: flex; gap: 0.6rem; align-items: center; }
.btn-read { background: var(--brick); border-color: var(--brick-dark); color: #fff; font-size: 0.9rem; padding: 0.5rem 1rem; }
.btn-read:hover { background: var(--brick-dark); }

.empty {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--card);
  padding: 2.2rem 1.5rem;
  text-align: center;
  margin-top: 1rem;
}
.empty-title { font-family: var(--serif); font-size: 1.5rem; margin: 0 0 0.4rem; }
.empty-sub { color: var(--ink-soft); margin: 0 0 1.2rem; }

/* ---------- Topics ---------- */
.topics { max-width: 1200px; margin: 0 auto; padding: 2.2rem clamp(1rem, 4vw, 2.5rem) 0.5rem; }
.topic-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.8rem; margin-top: 1rem; }
.topic {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 6px solid var(--brick);
  border-radius: 10px;
  padding: 0.85rem 0.9rem;
  cursor: pointer;
  font: inherit;
  box-shadow: var(--shadow);
}
.topic:hover { background: var(--paper-2); }
.topic strong { display: block; font-family: var(--serif); font-size: 1.1rem; font-weight: 400; }
.topic span { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }

/* ---------- About / footer ---------- */
.about { max-width: 1200px; margin: 0 auto; padding: 2.2rem clamp(1rem, 4vw, 2.5rem) 2.5rem; }
.about-card {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1.5rem;
  background: var(--ink);
  color: var(--paper);
  border-radius: 18px;
  padding: clamp(1.4rem, 3.5vw, 2.4rem);
  align-items: center;
}
.about-card h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
.about-card .kicker { color: var(--gold); }
.about-card p { color: #e9e1d2; }
.about-card .fineprint, .footer .fineprint { font-size: 0.82rem; color: #b7ad99; }
.about-card .fineprint { color: #c9bfa9; }
.about-ph { transform: rotate(1deg); }
.footer { border-top: 3px double var(--ink); }
.footer-inner { max-width: 1200px; margin: 0 auto; padding: 1.2rem clamp(1rem, 4vw, 2.5rem) 2rem; display: flex; flex-wrap: wrap; gap: 0.3rem 2rem; justify-content: space-between; }
.footer p { margin: 0.2rem 0; }

/* ---------- Reader dialog ---------- */
.reader {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0;
  max-width: min(46rem, calc(100vw - 2rem));
  width: 46rem;
  max-height: min(88vh, 900px);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(28, 22, 17, 0.5);
}
.reader::backdrop { background: rgba(28, 22, 17, 0.55); }
.reader-scroll { padding: clamp(1.2rem, 3vw, 2.2rem); overflow: auto; max-height: min(88vh, 900px); }
.reader-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.btn-close { background: transparent; border: 2px solid var(--ink); color: var(--ink); font-size: 0.9rem; padding: 0.45rem 0.95rem; }
.btn-close:hover { background: var(--paper-2); }
.reader h2 { font-size: clamp(1.7rem, 4vw, 2.5rem); margin: 0.4rem 0 0.6rem; }
.byline { font-family: var(--mono); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); margin: 0 0 1rem; }
.reader figure { margin: 0 0 1.2rem; }
.reader figure img { border-radius: 10px; width: 100%; aspect-ratio: 16 / 8; object-fit: cover; }
.reader figure figcaption { font-family: var(--mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); padding-top: 0.4rem; }
.prose p { font-size: 1.06rem; line-height: 1.75; margin: 0 0 1.1rem; }
.prose p:first-of-type::first-letter {
  font-family: var(--serif);
  font-size: 2.6em;
  float: left;
  line-height: 0.9;
  padding-right: 0.12em;
}
.reader-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; align-items: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0.9rem 0; margin: 1.2rem 0; }
.btn-save { background: var(--paper); }
.btn-save[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.pager { display: flex; justify-content: space-between; gap: 0.7rem; margin-top: 0.4rem; }
.pager button { background: transparent; border: 2px solid var(--ink); border-radius: 999px; padding: 0.5rem 1rem; font: inherit; font-weight: 700; font-size: 0.88rem; cursor: pointer; }
.pager button:hover { background: var(--paper-2); }
.pager button:disabled { opacity: 0.35; cursor: default; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .topic-grid { grid-template-columns: repeat(3, 1fr); }
  .hero { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar-hide { display: none; }
  .mastnav { display: none; }
  .toolbar { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .topic-grid { grid-template-columns: repeat(2, 1fr); }
  .about-card { grid-template-columns: 1fr; }
  .hero-stats { gap: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .card:hover { transform: none; }
  .ph-b, .ph-c, .about-ph { transform: none; }
}
