/* Longer Way — route-line editorial. Paper, ink, one signal red. */
:root {
  --paper: #f4eee2;
  --surface: #fbf8f0;
  --ink: #1d2230;
  --muted: #565b69;
  --rule: #1d2230;
  --hair: #cfc6b3;
  --accent: #b32d17;
  --on-accent: #fff8ee;
  --focus: #0b57d0;

  --c-culture: #e2a794;
  --c-food: #efbf4a;
  --c-movement: #d9442b;
  --c-people: #3f6e5e;
  --c-places: #2c4a72;

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

  --gutter: clamp(20px, 4vw, 48px);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px; --s9: 96px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 18px/1.55 var(--serif);
  -webkit-font-smoothing: antialiased;
}
body.locked { overflow: hidden; }
h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

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

.wrap { width: 100%; max-width: 1320px; margin-inline: auto; padding-inline: var(--gutter); }

.skip {
  position: absolute; left: var(--s4); top: -100px; z-index: 100;
  background: var(--ink); color: var(--paper); padding: var(--s2) var(--s4); font-family: var(--sans);
}
.skip:focus { top: var(--s2); }

/* ---------- Masthead ---------- */
.masthead { padding-top: var(--s5); }
.dateline {
  display: flex; justify-content: space-between; gap: var(--s4); flex-wrap: wrap;
  font: 600 12px/1.3 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  padding-bottom: var(--s3); border-bottom: 1px solid var(--hair);
}
.wordmark {
  display: flex; align-items: center; gap: clamp(10px, 2vw, 28px);
  font: 700 clamp(2.6rem, 11.4vw, 10rem)/.95 var(--serif);
  letter-spacing: -.035em;
  padding: var(--s5) 0 var(--s4);
}
.rail {
  position: relative; flex: 1 1 40px; min-width: 40px; height: 14px; align-self: center;
  margin-top: .12em;
}
.rail::before { /* the line */
  content: ""; position: absolute; left: 12px; right: 12px; top: 50%; height: 6px; margin-top: -3px;
  background: var(--accent);
}
.rail::after { /* terminus ring */
  content: ""; position: absolute; right: 0; top: 50%; width: 22px; height: 22px; margin-top: -11px;
  border-radius: 50%; border: 6px solid var(--accent); background: var(--paper);
}
.wordmark .rail::before { left: 0; }
.mast-foot {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5); align-items: end;
  padding: var(--s4) 0 var(--s5);
  border-top: 3px solid var(--rule);
}
.tagline { font: italic 400 clamp(1.4rem, 2.6vw, 2.1rem)/1.15 var(--serif); }
.intro { color: var(--muted); max-width: 46ch; justify-self: end; }

/* ---------- Controls ---------- */
.controls {
  background: var(--paper);
  border-top: 3px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.control-row { display: grid; grid-template-columns: minmax(0, 1fr) 220px auto; gap: var(--s4); padding-top: var(--s4); align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font: 700 12px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.field input, .field select {
  width: 100%; height: 48px; padding: 0 var(--s4);
  background: var(--surface); border: 1.5px solid var(--ink); border-radius: 2px;
  font: 400 17px/1 var(--sans);
}
.field select { appearance: none; padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 22px) 52%, calc(100% - 16px) 52%; background-size: 6px 6px; background-repeat: no-repeat;
}
.field input::placeholder { color: #6d717d; }

.saved-toggle {
  height: 48px; display: inline-flex; align-items: center; gap: var(--s2); padding: 0 var(--s4);
  background: transparent; border: 1.5px solid var(--ink); border-radius: 2px;
  font: 700 15px/1 var(--sans); letter-spacing: .02em; white-space: nowrap;
}
.saved-toggle .bm { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.saved-toggle .count {
  display: inline-block; min-width: 1.6em; padding: 2px 6px; margin-left: 2px; text-align: center;
  background: var(--ink); color: var(--paper); border-radius: 99px; font-size: 12px;
}
.saved-toggle:hover { background: var(--surface); }
.saved-toggle[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.saved-toggle[aria-pressed="true"] .bm { fill: var(--paper); }
.saved-toggle[aria-pressed="true"] .count { background: var(--paper); color: var(--ink); }

/* route-line topic stops */
.route { padding: var(--s4) 0 var(--s3); }
.stops { display: flex; position: relative; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.stops::-webkit-scrollbar { display: none; }
.stops li { flex: 1 0 auto; position: relative; }
.stops li::before { /* line segment through the stop */
  content: ""; position: absolute; left: 0; right: 0; top: 9px; height: 4px; background: var(--ink); opacity: .85;
}
.stops li:first-child::before { left: 9px; }
.stops li:last-child::before { right: calc(100% - 9px); }
.stop-btn {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  background: none; border: 0; padding: 0 var(--s4) 4px 0; text-align: left;
  font: 700 13px/1.1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--ink);
  min-height: 44px;
}
.stop-btn .dot {
  width: 22px; height: 22px; border-radius: 50%; background: var(--paper); border: 4px solid var(--ink);
  transition: background .15s, border-color .15s, transform .15s;
}
.stop-btn:hover .dot { border-color: var(--accent); }
.stop-btn[aria-pressed="true"] { color: var(--accent); }
.stop-btn[aria-pressed="true"] .dot { background: var(--accent); border-color: var(--accent); transform: scale(1.15); }
.stop-btn .n { font-weight: 600; color: var(--muted); letter-spacing: .04em; margin-left: 2px; }

/* ---------- Listing ---------- */
.listing { padding-top: var(--s7); padding-bottom: var(--s8); }
.listing-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s4); margin-bottom: var(--s5); }
.listing-head h2 { font: 700 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; }
.result-count { font: 400 15px/1.3 var(--sans); color: var(--muted); }

.story-list { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: var(--s6); row-gap: var(--s7); }
.story { grid-column: span 4; min-width: 0; }
.story:nth-child(8n+1) { grid-column: 1 / -1; }
.story:nth-child(8n+2), .story:nth-child(8n+8) { grid-column: span 7; }
.story:nth-child(8n+3), .story:nth-child(8n+7) { grid-column: span 5; }

.story article { position: relative; height: 100%; display: flex; flex-direction: column; gap: var(--s4); }
.story:has(.open:focus-visible) article { outline: 3px solid var(--focus); outline-offset: 6px; }
.story .open:focus-visible { outline: 0; }

.art {
  position: relative; overflow: hidden; background: var(--bg, var(--c-places)); aspect-ratio: 4 / 3;
  border-bottom: 4px solid var(--ink);
}
.story:nth-child(8n+2) .art, .story:nth-child(8n+8) .art { aspect-ratio: 16 / 9; }
.art svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; transition: transform .5s cubic-bezier(.2,.7,.2,1); }
.story:hover .art svg { transform: scale(1.04); }
.art.flip svg { transform: scaleX(-1); }
.story:hover .art.flip svg { transform: scaleX(-1.04) scaleY(1.04); }
.art .i { fill: var(--ink); }
.art .p { fill: var(--paper); }
.art .ln { fill: none; stroke: var(--paper); stroke-linecap: round; stroke-linejoin: round; }
.art .lni { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }
.art .num {
  position: absolute; left: 0; top: 0; padding: 6px 12px; background: var(--paper); color: var(--ink);
  font: 700 12px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase;
}
[data-cat="Culture"] { --bg: var(--c-culture); }
[data-cat="Food"] { --bg: var(--c-food); }
[data-cat="Movement"] { --bg: var(--c-movement); }
[data-cat="People"] { --bg: var(--c-people); }
[data-cat="Places"] { --bg: var(--c-places); }

.kicker {
  display: flex; align-items: center; gap: var(--s2);
  font: 700 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent);
}
.kicker::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--accent); flex: none; }
.kicker::after { content: ""; flex: 0 0 28px; height: 3px; background: var(--accent); }
.saved-badge {
  margin-left: auto; padding: 3px 7px; background: var(--ink); color: var(--paper);
  letter-spacing: .1em; font-size: 11px; border-radius: 2px;
}
.story h3 { font: 700 clamp(1.45rem, 2.1vw, 1.9rem)/1.12 var(--serif); letter-spacing: -.015em; text-wrap: balance; }
.summary { color: var(--muted); font-size: 1.0625rem; line-height: 1.5; max-width: 52ch; }
.meta { font: 400 14px/1.3 var(--sans); color: var(--muted); }
.meta b { color: var(--ink); font-weight: 600; }
.open {
  margin-top: auto; align-self: flex-start; background: none; border: 0; padding: 4px 0;
  font: 700 14px/1.2 var(--sans); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink); border-bottom: 3px solid var(--accent);
}
.open::after { content: ""; position: absolute; inset: 0; } /* whole card is the hit area */
.story:hover .open { color: var(--accent); }

/* Lead story: two-column feature */
.story:nth-child(8n+1) article { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--s4) var(--s6); align-items: stretch; }
.story:nth-child(8n+1) .art { grid-row: 1; aspect-ratio: auto; min-height: 420px; border-bottom: 0; border-right: 6px solid var(--ink); }
.story:nth-child(8n+1) .txt { grid-column: 2; display: flex; flex-direction: column; gap: var(--s4); align-self: center; padding-block: var(--s5); }
.story:nth-child(8n+1) h3 { font-size: clamp(2.2rem, 4.4vw, 4rem); line-height: 1.02; letter-spacing: -.025em; }
.story:nth-child(8n+1) .summary { font-size: 1.25rem; }
.story:nth-child(8n+1) .open { margin-top: var(--s2); }
.story:not(:nth-child(8n+1)) .txt { display: flex; flex-direction: column; gap: var(--s3); flex: 1; }

/* Empty */
.empty { border: 1.5px dashed var(--ink); padding: var(--s8) var(--s5); text-align: center; background: var(--surface); }
.empty-title { font: 700 clamp(1.8rem, 4vw, 2.8rem)/1.1 var(--serif); }
.empty-msg { margin: var(--s3) auto var(--s5); max-width: 44ch; color: var(--muted); }
.btn {
  background: var(--ink); color: var(--paper); border: 0; border-radius: 2px; padding: 14px 22px; min-height: 48px;
  font: 700 14px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
}
.btn:hover { background: var(--accent); }

/* ---------- Colophon ---------- */
.colophon { border-top: 3px solid var(--rule); padding: var(--s6) 0 var(--s8); font: 400 14px/1.5 var(--sans); color: var(--muted); }
.colophon .wrap { display: grid; gap: var(--s2); max-width: 760px; margin-left: max(0px, calc((100% - 1320px) / 2)); }
.colophon strong { color: var(--ink); }
.end-line { display: flex; margin-bottom: var(--s3); }
.end-line .rail { flex: 0 0 160px; }

/* ---------- Detail dialog ---------- */
dialog.detail {
  position: fixed; inset: 0 0 0 auto; margin: 0; padding: 0; border: 0;
  width: min(820px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh;
  background: var(--paper); color: var(--ink); overflow-y: auto; overscroll-behavior: contain;
  border-left: 4px solid var(--ink);
  animation: slide-in .3s cubic-bezier(.2,.7,.2,1);
}
dialog.detail::backdrop { background: rgba(29, 34, 48, .6); animation: fade-in .25s ease; }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.d-bar {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: var(--s4);
  padding: var(--s3) var(--gutter); background: var(--paper); border-bottom: 1px solid var(--ink);
  font: 700 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase;
}
.d-bar .brand { display: flex; align-items: center; gap: var(--s2); }
.d-bar .brand::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--accent); }
.close-btn {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s4);
  background: var(--ink); color: var(--paper); border: 0; border-radius: 2px;
  font: 700 13px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase;
}
.close-btn:hover { background: var(--accent); }
.close-btn:focus-visible { outline-color: var(--focus); }
.d-art { position: relative; aspect-ratio: 16 / 7; overflow: hidden; background: var(--bg); border-bottom: 4px solid var(--ink); }
.d-art svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.d-art .i { fill: var(--ink); } .d-art .p { fill: var(--paper); }
.d-art .ln { fill: none; stroke: var(--paper); stroke-linecap: round; stroke-linejoin: round; }
.d-art .lni { fill: none; stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }
.d-art.flip svg { transform: scaleX(-1); }

.d-main { padding: var(--s7) var(--gutter) var(--s8); }
.d-main > * { max-width: 62ch; margin-inline: auto; }
.d-main h2 { font: 700 clamp(2.2rem, 5.2vw, 3.6rem)/1.04 var(--serif); letter-spacing: -.025em; text-wrap: balance; margin-top: var(--s4); }
.dek { font: italic 400 clamp(1.25rem, 2.4vw, 1.5rem)/1.4 var(--serif); color: var(--muted); margin-top: var(--s4); }
.byline {
  display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); margin-top: var(--s5); padding: var(--s3) 0;
  border-top: 3px solid var(--ink); border-bottom: 1px solid var(--hair);
  font: 400 14px/1.4 var(--sans); color: var(--muted);
}
.byline b { color: var(--ink); font-weight: 700; }
.d-actions { margin-top: var(--s5); }
.save-btn {
  display: inline-flex; align-items: center; gap: var(--s3); min-height: 48px; padding: 0 var(--s5);
  background: transparent; color: var(--ink); border: 2px solid var(--ink); border-radius: 2px;
  font: 700 14px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase;
}
.save-btn svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.save-btn:hover { background: var(--surface); }
.save-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.save-btn[aria-pressed="true"] svg { fill: currentColor; }
.body { margin-top: var(--s6); font-size: 1.2rem; line-height: 1.7; }
.body p + p { margin-top: 1.1em; }
.body p:first-child::first-letter {
  float: left; font: 700 4.6em/.8 var(--serif); padding: .06em .1em 0 0; color: var(--accent);
}
.d-end { margin-top: var(--s7); display: flex; align-items: center; gap: var(--s4); }
.d-end .rail { flex: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .story-list { column-gap: var(--s5); row-gap: var(--s6); }
  .story, .story:nth-child(n) { grid-column: span 6; }
  .story:nth-child(8n+1) { grid-column: 1 / -1; }
  .story:nth-child(8n+2) .art, .story:nth-child(8n+8) .art { aspect-ratio: 4 / 3; }
  .story:nth-child(8n+1) article { grid-template-columns: 1fr; }
  .story:nth-child(8n+1) .art { grid-row: auto; min-height: 0; aspect-ratio: 16 / 10; border-right: 0; border-bottom: 4px solid var(--ink); }
  .story:nth-child(8n+1) .txt { grid-column: 1; padding-block: 0; }
}
@media (max-width: 720px) {
  body { font-size: 17px; }
  .mast-foot { grid-template-columns: 1fr; gap: var(--s3); }
  .intro { justify-self: start; }
  .control-row { grid-template-columns: 1fr 1fr; }
  .field-search { grid-column: 1 / -1; }
  .field-topic { grid-column: 1; }
  .saved-toggle { grid-column: 2; justify-content: center; }
  .listing { padding-top: var(--s6); }
  .story-list { grid-template-columns: 1fr; row-gap: var(--s7); }
  .story, .story:nth-child(n) { grid-column: 1 / -1; }
  .story:nth-child(n) .art { aspect-ratio: 16 / 11; }
  dialog.detail { width: 100vw; border-left: 0; }
  .d-art { aspect-ratio: 16 / 9; }
  .d-main { padding-top: var(--s6); }
  .body { font-size: 1.125rem; }
  .close-btn span.long { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .story:hover .art svg { transform: none; }
  .story:hover .art.flip svg { transform: scaleX(-1); }
}
