/* Kerbside. Editorial journal: Literata for reading, Space Grotesk for interface.
   One accent (vermilion), square corners throughout, light and dark via system setting. */

@font-face {
  font-family: "Literata";
  src: url("assets/literata.ttf") format("truetype");
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("assets/space-grotesk.ttf") format("truetype");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --paper: #eef1ee;
  --surface: #f9fbf9;
  --ink: #0f1917;
  --muted: #475753;
  --line: #bcc7c2;
  --accent: #b8340f;
  --on-accent: #fff8f4;
  --focus: #b8340f;

  --serif: "Literata", Georgia, "Times New Roman", serif;
  --sans: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --gutter: clamp(1.25rem, 4vw, 3.5rem);
  --max: 1360px;
  --bar-h: 60px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1311;
    --surface: #151d1a;
    --ink: #e9efeb;
    --muted: #a5b3ad;
    --line: #2c3833;
    --accent: #ff8a62;
    --on-accent: #1d0e08;
    --focus: #ff8a62;
  }
  .thumb img, .detail-figure img { filter: brightness(0.88) saturate(0.95); }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--bar-h) + 1rem);
  -webkit-text-size-adjust: 100%;
}
html.lock { overflow: hidden; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }

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

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  z-index: 40;
}
.skip:focus { top: 0.75rem; }

/* ---------- Top bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--bar-h);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.bar-inner {
  max-width: var(--max);
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.wordmark, .foot-mark {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 1.6rem;
  letter-spacing: -0.04em;
  text-decoration: none;
  line-height: 1;
}
.wordmark span, .foot-mark span { color: var(--accent); }
.tagline {
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--muted);
}
.bar-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.bar-link {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  padding: 0.5rem 0;
  background: linear-gradient(var(--accent), var(--accent)) 0 100% / 0 2px no-repeat;
  transition: background-size 0.3s var(--ease);
}
.bar-link:hover { background-size: 100% 2px; }

.saved-toggle {
  font: 500 0.95rem/1 var(--sans);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 0.7rem 1rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, transform 0.15s;
}
.saved-toggle:hover { background: var(--surface); }
.saved-toggle[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}
.saved-toggle:active { transform: translateY(1px); }
.saved-count {
  font-variant-numeric: tabular-nums;
  min-width: 1.4em;
  padding: 0.1rem 0.4rem;
  text-align: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.8rem;
  font-weight: 700;
}

/* ---------- Hero ---------- */
.hero {
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 4.25rem) var(--gutter) clamp(2rem, 4vw, 3rem);
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 4fr);
  column-gap: clamp(2rem, 8vw, 8rem);
  align-items: end;
}
.hero h1 {
  font-size: clamp(2.1rem, 4.4vw, 3.9rem);
  font-weight: 650;
  line-height: 1.08;
  letter-spacing: -0.025em;
  max-width: 18ch;
  text-wrap: balance;
}
.hero-sub {
  margin-top: 1.25rem;
  max-width: 34ch;
  font-size: 1.15rem;
  color: var(--muted);
}

.controls {
  display: grid;
  gap: 1rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--ink);
}
.field { display: grid; gap: 0.4rem; }
.field label {
  font: 600 0.85rem/1.2 var(--sans);
}
.field input, .field select {
  width: 100%;
  min-height: 48px;
  padding: 0.65rem 0.85rem;
  font: 400 1rem/1.3 var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--muted);
  border-radius: 0;
}
.field input::placeholder { color: var(--muted); opacity: 1; }
.field input:focus-visible, .field select:focus-visible {
  outline-offset: 1px;
  border-color: var(--ink);
}

.reset {
  justify-self: start;
  font: 500 0.9rem/1.2 var(--sans);
  color: var(--ink);
  background: none;
  border: 0;
  padding: 0.4rem 0;
  min-height: 44px;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
  cursor: pointer;
}

/* ---------- Results ---------- */
.results {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter) clamp(3rem, 7vw, 6rem);
  outline: none;
}
.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: clamp(1.75rem, 3vw, 2.5rem);
}
.results-head h2 {
  font: 600 1.05rem/1.2 var(--sans);
}
.count {
  font: 400 0.9rem/1.2 var(--sans);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stories {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: clamp(1.25rem, 2.5vw, 2.5rem);
  row-gap: clamp(2.5rem, 4vw, 3.75rem);
}

.story {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding-top: 1rem;
  border-top: 2px solid var(--ink);
  grid-column: span 6;
}
.story[data-span="7"] { grid-column: span 7; }
.story[data-span="5"] { grid-column: span 5; }
.story[data-span="12"], .story.feature { grid-column: 1 / -1; }

.thumb {
  position: relative;
  flex: 1 1 auto;
  min-height: 240px;
  overflow: hidden;
  background: var(--line);
}
.story[data-span="5"] .thumb { min-height: 220px; }
.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.7s var(--ease);
}
.story:hover .thumb img { transform: scale(1.035); }

.txt { display: grid; gap: 0.6rem; align-content: start; }
.kicker {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font: 600 0.8rem/1.2 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}
.badge {
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 0.15rem 0.4rem;
}
.title {
  font-size: clamp(1.4rem, 2vw, 1.75rem);
  font-weight: 650;
  line-height: 1.18;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.open {
  all: unset;
  cursor: pointer;
  display: inline;
}
.open::after {
  content: "";
  position: absolute;
  inset: 0;
}
.open:focus-visible { outline: none; }
.open:focus-visible::after {
  outline: 3px solid var(--focus);
  outline-offset: 6px;
}
.story:hover .open { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; text-decoration-color: var(--accent); }

.sum { color: var(--muted); max-width: 52ch; }
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 1.25rem;
  margin-top: 0.25rem;
  font: 400 0.875rem/1.4 var(--sans);
  color: var(--muted);
}
.meta .by { color: var(--ink); font-weight: 600; }

/* Lead story */
.story.feature {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  column-gap: clamp(1.5rem, 4vw, 4rem);
  align-items: stretch;
}
.story.feature .thumb { min-height: clamp(320px, 38vw, 520px); }
.story.feature .txt {
  align-content: end;
  padding-bottom: 0.25rem;
  gap: 0.9rem;
}
.story.feature .title {
  font-size: clamp(1.9rem, 3.2vw, 3rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
}
.story.feature .sum { font-size: 1.15rem; }

/* Wide story */
.story[data-span="12"]:not(.feature) {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  column-gap: clamp(1.5rem, 4vw, 4rem);
  align-items: stretch;
}
.story[data-span="12"]:not(.feature) .thumb { min-height: 300px; }
.story[data-span="12"]:not(.feature) .txt { align-content: center; }
.story[data-span="12"]:not(.feature) .title { font-size: clamp(1.7rem, 2.6vw, 2.4rem); }

/* ---------- Empty state ---------- */
.empty {
  display: grid;
  justify-items: start;
  gap: 0.9rem;
  max-width: 34rem;
  padding: 2.5rem 0 1rem;
}
.empty h3 { font-size: clamp(1.6rem, 3vw, 2.25rem); font-weight: 650; line-height: 1.15; }
.empty p { color: var(--muted); }

.btn, .detail-btn {
  font: 600 0.95rem/1 var(--sans);
  min-height: 44px;
  padding: 0.8rem 1.1rem;
  border-radius: 0;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: transform 0.15s, background-color 0.2s, color 0.2s;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn:active, .detail-btn:active { transform: translateY(1px); }

/* ---------- Footer ---------- */
.foot {
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.foot-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 2.5rem var(--gutter);
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 4fr);
  column-gap: clamp(2rem, 8vw, 8rem);
  align-items: start;
}
.foot-note { font: 400 0.9rem/1.6 var(--sans); color: var(--muted); max-width: 52ch; }

/* ---------- Detail view (modal dialog) ---------- */
dialog.detail {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  color: var(--ink);
}
dialog.detail::backdrop { background: var(--paper); }

.detail-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.detail-bar-inner {
  max-width: var(--max);
  margin: 0 auto;
  min-height: var(--bar-h);
  padding: 0.5rem var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.detail-btn { background: transparent; color: var(--ink); }
.detail-btn:hover { background: var(--surface); }
.detail-btn.save[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.detail-article {
  max-width: var(--max);
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 4rem) var(--gutter) clamp(3rem, 7vw, 6rem);
}
.detail-head { max-width: 62rem; }
.detail-head .kicker { margin-bottom: 1rem; }
.detail-head h2 {
  font-size: clamp(2rem, 4.6vw, 4rem);
  font-weight: 650;
  line-height: 1.08;
  letter-spacing: -0.028em;
  text-wrap: balance;
  outline: none;
}
.deck {
  margin-top: 1.25rem;
  font-size: clamp(1.15rem, 1.8vw, 1.4rem);
  line-height: 1.5;
  color: var(--muted);
  max-width: 40ch;
}
.detail-figure { margin: clamp(2rem, 4vw, 3rem) 0 0; }
.detail-figure .frame {
  height: clamp(220px, 36vw, 500px);
  overflow: hidden;
  background: var(--line);
}
.detail-figure img { width: 100%; height: 100%; object-fit: cover; }
.detail-figure figcaption {
  margin-top: 0.6rem;
  font: 400 0.8rem/1.4 var(--sans);
  color: var(--muted);
}

.detail-grid {
  margin-top: clamp(2rem, 4vw, 3.5rem);
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr) minmax(0, 2fr);
  column-gap: clamp(1.5rem, 4vw, 4rem);
}
.byline {
  align-self: start;
  position: sticky;
  top: calc(var(--bar-h) + 1.5rem);
  display: grid;
  gap: 0.25rem;
  padding-top: 0.9rem;
  border-top: 2px solid var(--ink);
  font: 400 0.9rem/1.5 var(--sans);
  color: var(--muted);
}
.byline .by { color: var(--ink); font-weight: 600; font-size: 1rem; }

.prose {
  grid-column: 2;
  font-size: clamp(1.1rem, 1.5vw, 1.25rem);
  line-height: 1.75;
  max-width: 38em;
}
.prose p + p { margin-top: 1.4em; }

.detail-next {
  grid-column: 2;
  margin-top: 3.5rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--ink);
  display: grid;
  gap: 0.5rem;
  justify-items: start;
}
.detail-next .lead { font: 400 0.85rem/1.2 var(--sans); color: var(--muted); }
.next-link {
  all: unset;
  cursor: pointer;
  font-size: clamp(1.3rem, 2.2vw, 1.75rem);
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.015em;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}
.next-link:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }

/* ---------- Motion (only when the reader has not asked for less) ---------- */
@media (prefers-reduced-motion: no-preference) {
  /* Staggered entry on first load shows the reading order of the page. */
  .stories.intro .story {
    animation: rise 0.7s var(--ease) both;
    animation-delay: calc(var(--i, 0) * 70ms);
  }
  dialog.detail[open] { animation: panel 0.4s var(--ease) both; }
  @keyframes rise {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes panel {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: none; }
  }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* ---------- Tablet ---------- */
@media (max-width: 1100px) {
  .tagline { display: none; }
  .detail-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 8fr); }
  .detail-grid .prose, .detail-grid .detail-next { grid-column: 2; }
}

@media (max-width: 899px) {
  .hero { grid-template-columns: 1fr; row-gap: 2rem; }
  .hero h1 { max-width: 20ch; }
  .stories { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .story, .story[data-span="7"], .story[data-span="5"] { grid-column: auto; }
  .story[data-span="12"], .story.feature { grid-column: 1 / -1; }
  .story.feature, .story[data-span="12"]:not(.feature) {
    display: flex;
    flex-direction: column;
  }
  .story.feature .thumb, .story[data-span="12"]:not(.feature) .thumb { min-height: 260px; flex: none; }
  .foot-inner { grid-template-columns: 1fr; row-gap: 1rem; }
  .detail-grid { grid-template-columns: 1fr; row-gap: 1.5rem; }
  .byline { position: static; grid-column: 1; grid-auto-flow: row; }
  .detail-grid .prose, .detail-grid .detail-next { grid-column: 1; }
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  :root { --bar-h: 56px; }
  .stories { grid-template-columns: 1fr; }
  .story, .story[data-span] { grid-column: 1 / -1; }
  .thumb, .story[data-span="5"] .thumb { flex: none; min-height: 0; height: 200px; }
  .story.feature .thumb, .story[data-span="12"]:not(.feature) .thumb { height: 240px; min-height: 0; }
  .hero h1 { font-size: clamp(2rem, 9vw, 2.6rem); }
  .hero-sub { font-size: 1.05rem; }
  .bar-link { display: none; }
  .wordmark { font-size: 1.45rem; }
  .detail-bar-inner { gap: 0.5rem; }
  .detail-btn { padding: 0.8rem 0.85rem; font-size: 0.9rem; }
  .results-head { flex-direction: column; gap: 0.35rem; }
}
