/* City Journal — editorial magazine styles */
@font-face {
  font-family: "Literata";
  src: url("assets/literata.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("assets/space-grotesk.ttf") format("truetype");
  font-weight: 300 700;
  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 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #18181b;
  --ink-soft: #3f3f46;
  --paper: #fafaf7;
  --card: #ffffff;
  --border: #e4e1d9;
  --border-strong: #cdc8bd;
  --muted-fg: #5c5851;
  --accent: #b23a1f;
  --accent-ink: #7d2713;
  --accent-soft: #f6e7e0;
  --accent-veil: rgba(178, 58, 31, 0.08);
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.04), 0 8px 24px rgba(24, 24, 27, 0.06);
  --shadow-lift: 0 2px 4px rgba(24, 24, 27, 0.06), 0 18px 40px rgba(24, 24, 27, 0.10);

  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --max: 1240px;
  --gutter: clamp(16px, 4vw, 48px);
  --radius: 4px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  font-family: var(--sans);
  font-size: 14px;
  z-index: 200;
  text-decoration: none;
  transition: top .15s ease;
}
.skip-link:focus { top: 12px; }

/* ---------- Masthead ---------- */
.masthead {
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}
.masthead-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(20px, 4vw, 34px) var(--gutter) clamp(14px, 3vw, 22px);
  text-align: center;
}
.masthead-wordmark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 28px);
}
.masthead-wordmark .rule {
  flex: 1;
  height: 0;
  border-top: 1px solid var(--ink);
  max-width: 220px;
}
.wordmark {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.22em;
  font-size: clamp(22px, 5vw, 38px);
  color: var(--ink);
  white-space: nowrap;
}
.masthead-tag {
  margin: 10px 0 0;
  font-family: var(--sans);
  font-size: clamp(11px, 2vw, 13px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-fg);
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.toolbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 12px var(--gutter);
  display: grid;
  grid-template-columns: 1fr minmax(160px, 220px) auto;
  gap: clamp(10px, 2vw, 18px);
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-fg);
}
.control { position: relative; display: flex; align-items: center; }
.field-icon {
  position: absolute;
  left: 12px;
  width: 18px; height: 18px;
  color: var(--muted-fg);
  pointer-events: none;
}
.control input,
.control select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.control input { padding-left: 38px; }
.control select { padding-right: 34px; cursor: pointer; }
.control input:focus,
.control select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-veil);
}
.chevron {
  position: absolute;
  right: 10px;
  width: 18px; height: 18px;
  color: var(--muted-fg);
  pointer-events: none;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.toggle:hover { border-color: var(--ink); }
.toggle .bookmark-icon { width: 17px; height: 17px; }
.toggle .saved-count {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 20px;
  text-align: center;
}
.toggle[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.toggle[aria-pressed="true"] .saved-count {
  background: var(--accent);
  color: #fff;
}

/* ---------- Page ---------- */
.page {
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(20px, 3vw, 32px) var(--gutter) var(--space-8);
}
.results-meta {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-fg);
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: clamp(18px, 3vw, 30px);
}

/* ---------- Stories grid ---------- */
.stories {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: clamp(20px, 2.5vw, 36px);
}
.story {
  grid-column: span 4;
  display: flex;
  flex-direction: column;
  background: transparent;
  border: 0;
  text-align: left;
  padding: 0;
  color: inherit;
  position: relative;
}
.story.feature {
  grid-column: span 12;
  flex-direction: row;
  align-items: stretch;
  gap: clamp(20px, 3vw, 48px);
  padding-bottom: clamp(24px, 3vw, 40px);
  margin-bottom: clamp(8px, 1.5vw, 14px);
  border-bottom: 1px solid var(--ink);
}
.story-card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--border);
  border-radius: var(--radius);
}
.story.feature .story-card-media {
  flex: 0 0 44%;
  aspect-ratio: auto;
  min-height: 280px;
}
.story-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .5s ease;
}
.story:hover .story-card-media img { transform: scale(1.035); }
.story-card-media::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 55%, rgba(24,24,27,0.12));
  pointer-events: none;
}
.story-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  flex: 1;
}
.story.feature .story-body {
  padding-top: 6px;
  justify-content: center;
  gap: 14px;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-ink);
  margin: 0;
}
.story-title {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
  font-size: clamp(20px, 2.1vw, 26px);
  text-wrap: balance;
}
.story.feature .story-title {
  font-size: clamp(30px, 4.4vw, 48px);
  letter-spacing: -0.015em;
}
.story-summary {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0;
  text-wrap: pretty;
}
.story.feature .story-summary { font-size: clamp(16px, 1.8vw, 19px); }
.story-meta {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted-fg);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: center;
  margin-top: 4px;
}
.story-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; }
.story-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 12px;
}
.open-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: transparent;
  border: 0;
  padding: 6px 0;
  position: relative;
}
.open-item .arrow {
  width: 16px; height: 16px;
  transition: transform .2s ease;
}
.story:hover .open-item .arrow { transform: translateX(3px); }
.open-item::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  height: 1.5px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .25s ease;
}
.story:hover .open-item::after,
.open-item:focus-visible::after { transform: scaleX(1); }

.saved-flag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-ink);
}
.saved-flag svg { width: 13px; height: 13px; }

/* full-card click affordance via stretched link pattern */
.story { cursor: pointer; }
.story .open-item { z-index: 1; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: clamp(40px, 7vw, 80px) 20px;
  color: var(--muted-fg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  margin-top: 8px;
}
.empty-state svg { width: 48px; height: 48px; color: var(--border-strong); }
.empty-state h2 {
  font-family: var(--serif);
  font-weight: 600;
  color: var(--ink);
  margin: 14px 0 6px;
  font-size: 24px;
}
.empty-state p { margin: 0 0 20px; font-size: 15px; }
.recover {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 11px 20px;
  transition: background .15s ease;
}
.recover:hover { background: var(--accent-ink); }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--ink); background: var(--paper); }
.footer-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(28px, 4vw, 44px) var(--gutter);
  text-align: center;
}
.footer-word {
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.22em;
  font-size: 13px;
  margin: 0 0 8px;
  color: var(--ink);
}
.footer-note {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted-fg);
  margin: 0;
  max-width: 60ch;
  margin: 0 auto;
}

/* ---------- Detail dialog ---------- */
#detail {
  margin: 0 auto;
  border: 0;
  background: transparent;
  padding: 0;
  width: min(720px, 100vw);
  max-width: 100vw;
  max-height: 100vh;
  height: 100vh;
  color: var(--ink);
  overflow: visible;
}
#detail::backdrop {
  background: rgba(24, 24, 27, 0.55);
  backdrop-filter: blur(4px);
}
#detail[open] { animation: dialog-in .25s ease; }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.detail-article {
  position: relative;
  height: 100%;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}
.detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 9px 14px 9px 11px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: background .15s ease, border-color .15s ease;
}
.detail-close:hover { border-color: var(--ink); background: #fff; }
.detail-close svg { width: 16px; height: 16px; }

.detail-scroll {
  overflow-y: auto;
  padding: clamp(20px, 4vw, 36px) clamp(20px, 5vw, 56px) var(--space-7);
  scrollbar-gutter: stable;
}
.detail-head { padding-top: 28px; max-width: 62ch; }
.detail-head .eyebrow { font-size: 12px; }
.detail-title {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.015em;
  font-size: clamp(28px, 4.2vw, 42px);
  margin: 12px 0 14px;
  text-wrap: balance;
}
.byline {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted-fg);
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
}
.byline .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; }

.detail-figure { margin: clamp(20px, 3vw, 30px) 0 8px; }
.detail-figure img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--border);
}
.detail-figure figcaption {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted-fg);
  margin-top: 8px;
  font-style: italic;
}

.detail-actions { margin: 18px 0 26px; }
.save-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  padding: 11px 20px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  transition: background .15s ease, color .15s ease;
}
.save-toggle .save-mark {
  width: 17px; height: 17px;
  fill: transparent;
  stroke: var(--ink);
  stroke-width: 1.8;
  transition: fill .15s ease, stroke .15s ease;
}
.save-toggle:hover { background: var(--accent-soft); }
.save-toggle[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.save-toggle[aria-pressed="true"] .save-mark {
  fill: var(--accent);
  stroke: var(--accent);
}

.prose { font-family: var(--serif); font-size: clamp(17px, 1.6vw, 19px); line-height: 1.7; color: #2a2a2c; max-width: 64ch; }
.prose p { margin: 0 0 1.15em; }
.prose p:first-child:first-letter {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 3.6em;
  line-height: 0.82;
  float: left;
  margin: 6px 10px 0 -2px;
  color: var(--accent-ink);
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .story { grid-column: span 6; }
  .story.feature { grid-column: span 12; flex-direction: column; gap: 18px; }
  .story.feature .story-card-media { flex: none; aspect-ratio: 16 / 9; min-height: 0; }
}
@media (max-width: 720px) {
  .toolbar-inner {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .saved-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .saved-field .field-label { padding-bottom: 2px; }
  .saved-field .toggle { flex: 1; justify-content: center; }
  .story { grid-column: span 12; }
  .masthead-wordmark .rule { display: none; }
  .wordmark { letter-spacing: 0.18em; }
}
@media (max-width: 420px) {
  .detail-close span { display: none; }
  .detail-close { padding: 9px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .story:hover .story-card-media img { transform: none; }
}
