:root {
  --paper: #f3eee3;
  --card: #fbf8f1;
  --ink: #1d1b18;
  --muted: #5d574d;
  --rule: #cfc6b4;
  --accent: #b23a0e;
  --accent-ink: #fff8f0;
  --focus: #0b57d0;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --pad: clamp(1rem, 4vw, 3rem);
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: rgba(178, 58, 14, 0.15);
}
html.modal-open { overflow: hidden; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  overflow-x: hidden;
}

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; touch-action: manipulation; }
a { color: inherit; touch-action: manipulation; }
[id] { scroll-margin-top: 1rem; }

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

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  border-radius: 4px;
}
.skip:focus { top: 1rem; }

/* ---------- Masthead ---------- */
.masthead {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem var(--pad) 0;
  text-align: center;
}
.dateline {
  font-size: 0.8125rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--ink);
}
.wordmark {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(3.5rem, 13vw, 9rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  padding-top: 1rem;
}
.tagline {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.05rem, 2.4vw, 1.35rem);
  color: var(--accent);
  padding: 0.35rem 0 1rem;
}
.nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.25rem clamp(0.5rem, 3vw, 2rem);
  border-top: 1px solid var(--ink);
  border-bottom: 4px double var(--ink);
  padding: 0.25rem 0;
}
.nav a {
  display: inline-block;
  padding: 0.55rem 0.6rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
}
.nav a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 6px; }

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--pad);
}

/* ---------- Intro ---------- */
.intro {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  max-width: 54rem;
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3.5rem) 0 clamp(1.5rem, 3vw, 2.25rem);
  text-align: center;
}
.intro h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 3.1rem);
  line-height: 1.12;
  text-wrap: balance;
}
.intro em { color: var(--accent); }
.intro p {
  font-family: var(--serif);
  font-size: clamp(1.05rem, 2vw, 1.2rem);
  color: var(--muted);
  text-wrap: pretty;
}

/* ---------- Controls ---------- */
.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 14rem auto;
  gap: 1rem;
  align-items: end;
  padding: 1.1rem 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--rule);
}
.field { display: grid; gap: 0.3rem; min-width: 0; }
.field label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
input[type="search"], select {
  width: 100%;
  min-height: 3rem;
  padding: 0.55rem 0.85rem;
  background-color: var(--card);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  font-size: 1rem;
}
select { cursor: pointer; }
input::placeholder { color: #6f685c; }
input[type="search"]:hover, select:hover { background-color: #fff; }

.saved-toggle, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0.5rem 1.1rem;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: transparent;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.saved-toggle:hover, .btn:hover { background: var(--ink); color: var(--paper); }
.saved-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.saved-toggle[aria-pressed="true"]:hover { background: #8f2d0a; border-color: #8f2d0a; }
.saved-toggle .count {
  min-width: 1.6rem;
  padding: 0 0.4rem;
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.8125rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.saved-toggle[aria-pressed="true"] .count { background: var(--accent-ink); color: var(--accent); }
.saved-toggle:hover .count { background: var(--paper); color: var(--ink); }

/* ---------- Stories grid ---------- */
.stories { padding: 1.5rem 0 4rem; }
.stories-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stories-head h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
}
.status { color: var(--muted); font-size: 0.9375rem; font-variant-numeric: tabular-nums; }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(1.25rem, 2.5vw, 2rem);
}
.grid[hidden], .empty[hidden] { display: none; }

.item {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}
.item:hover { transform: translateY(-3px); box-shadow: 0 10px 24px -12px rgba(29, 27, 24, 0.45); }
.item:has(.open-item:focus-visible) { outline: 3px solid var(--focus); outline-offset: 3px; }

.item--lead { grid-column: span 2; flex-direction: row; }
.item--lead .art { flex: 0 0 48%; aspect-ratio: auto; min-height: 100%; }
.item--lead .item-body { padding: clamp(1.25rem, 2.5vw, 2rem); justify-content: center; }
.item--lead .item-title { font-size: clamp(1.7rem, 2.6vw, 2.4rem); }
.item--lead .item-summary { font-size: 1.15rem; }

.art { display: block; aspect-ratio: 5 / 3; background: var(--bg); width: 100%; }
.art svg { display: block; width: 100%; height: 100%; }
.art .a { fill: var(--fg); }
.art .b { fill: var(--hi); }
.art .s { stroke: var(--fg); fill: none; stroke-linecap: round; stroke-linejoin: round; }
.art .sh { stroke: var(--hi); fill: none; stroke-linecap: round; stroke-linejoin: round; }

[data-cat="Culture"]  { --bg: #4a2340; --fg: #e9c4dd; --hi: #f2a94b; }
[data-cat="Food"]     { --bg: #e0a329; --fg: #3b2508; --hi: #fff0c9; }
[data-cat="Movement"] { --bg: #17504c; --fg: #bfe7dd; --hi: #ffd166; }
[data-cat="People"]   { --bg: #c4503a; --fg: #ffe4d6; --hi: #3a1a12; }
[data-cat="Places"]   { --bg: #36502f; --fg: #d3e6b8; --hi: #f6e27f; }

.item-body {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1.1rem 1.25rem 1.3rem;
  flex: 1;
  min-width: 0;
}
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.meta .cat { color: var(--accent); }
.meta .dot::before { content: "·"; margin-right: 0.6rem; }
.badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
  letter-spacing: 0.06em;
}
.badge[hidden] { display: none; }

.item-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.4rem;
  line-height: 1.2;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.open-item {
  all: unset;
  cursor: pointer;
}
.open-item::after { content: ""; position: absolute; inset: 0; }
.item:hover .open-item { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.item-summary { font-family: var(--serif); color: var(--muted); font-size: 1.0625rem; line-height: 1.5; text-wrap: pretty; }
.byline { margin-top: auto; padding-top: 0.4rem; font-size: 0.875rem; color: var(--ink); }

/* ---------- Empty ---------- */
.empty {
  display: grid;
  justify-items: center;
  gap: 0.75rem;
  max-width: 30rem;
  margin: 2rem auto;
  padding: 2.5rem 1.5rem;
  text-align: center;
  border: 1.5px dashed var(--ink);
  border-radius: 6px;
}
.empty h3 { font-family: var(--serif); font-size: 1.6rem; }
.empty p { color: var(--muted); }

/* ---------- Footer ---------- */
.footer {
  border-top: 4px double var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: 2.5rem var(--pad) calc(2.5rem + env(safe-area-inset-bottom));
  text-align: center;
  display: grid;
  gap: 0.6rem;
  justify-items: center;
}
.footer p { max-width: 38rem; text-wrap: pretty; }
.footer-mark { font-family: var(--serif); font-size: 2rem; font-weight: 700; }
.footer-note { color: #c9c1b0; font-size: 0.875rem; }

/* ---------- Detail dialog ---------- */
.detail {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(48rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6);
  animation: rise 0.22s ease-out;
}
.detail::backdrop { background: rgba(29, 27, 24, 0.68); }

.detail-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem clamp(1rem, 4vw, 2rem);
  background: var(--card);
  border-bottom: 1px solid var(--rule);
}
.detail-bar .btn { min-height: 2.75rem; padding: 0.4rem 1rem; background: var(--card); }
.detail-bar .btn:hover { background: var(--ink); }
.detail-bar .save[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.detail-bar .save[aria-pressed="true"]:hover { background: #8f2d0a; border-color: #8f2d0a; }
.detail .art { aspect-ratio: 16 / 6; }

.detail-inner { padding: clamp(1.25rem, 4vw, 2.5rem) clamp(1.25rem, 6vw, 4rem) clamp(2rem, 5vw, 3.5rem); }
.detail-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(2rem, 5.5vw, 3.1rem);
  line-height: 1.1;
  margin: 0.6rem 0 0.9rem;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.detail-dek {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.25rem;
  color: var(--muted);
  text-wrap: pretty;
}
.detail-by {
  margin: 1.1rem 0 1.75rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  font-size: 0.9375rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
}
.detail-body { max-width: 38rem; margin: 0 auto; }
.detail-body p {
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.75;
  margin-bottom: 1.2em;
  text-wrap: pretty;
}
.detail-body p:first-child::first-letter {
  float: left;
  font-size: 4.2em;
  line-height: 0.82;
  padding: 0.07em 0.1em 0 0;
  font-weight: 700;
  color: var(--accent);
}
.detail-end { text-align: center; padding-top: 1rem; }

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item--lead { grid-column: span 2; }
}
@media (max-width: 720px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .field--search { grid-column: 1 / -1; }
  .saved-toggle { align-self: end; }
  .grid { grid-template-columns: 1fr; }
  .item--lead { grid-column: auto; flex-direction: column; }
  .item--lead .art { flex: none; aspect-ratio: 5 / 3; min-height: 0; }
  .item--lead .item-title { font-size: 1.6rem; }
  .stories-head { flex-direction: column; gap: 0.15rem; }

  .detail {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  .detail-bar { padding-top: calc(0.75rem + env(safe-area-inset-top)); }
  .detail-body p { font-size: 1.125rem; }
}
@media (max-width: 380px) {
  .controls { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .detail { animation: none; }
  .item, .saved-toggle, .btn { transition: none; }
  .item:hover { transform: none; }
}
