/* The Curb
   Shape rule: panels and cards use --radius-panel (16px); all
   interactive controls and media use --radius-media (10px). */

@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: "Work Sans";
  src: url("assets/work-sans.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 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f2f0eb;
  --surface: #fcfbf7;
  --surface-2: #e8e5dd;
  --ink: #191a1e;
  --muted: #575a63;
  --line: #d7d3c9;
  --accent: #c63a22;
  --accent-ink: #fbf8f4;
  --radius-panel: 16px;
  --radius-media: 10px;
  --maxw: 1200px;
  --shadow: 0 1px 2px rgba(25, 26, 30, 0.05), 0 16px 34px -22px rgba(25, 26, 30, 0.45);
}

:root[data-theme="dark"] {
  --paper: #141518;
  --surface: #1c1e22;
  --surface-2: #26292e;
  --ink: #f1efea;
  --muted: #a7aab2;
  --line: #303339;
  --accent: #f26b4e;
  --accent-ink: #1a1410;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 20px 44px -22px rgba(0, 0, 0, 0.75);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open {
  overflow: hidden;
}

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

button,
input,
select {
  font: inherit;
  color: inherit;
}

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

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 60;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 8px;
  text-decoration: none;
  transition: top 0.18s ease;
}
.skip-link:focus {
  top: 12px;
}

/* ---------- Masthead ---------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.masthead-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 68px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.wordmark {
  display: inline-flex;
  align-items: baseline;
  text-decoration: none;
  color: var(--ink);
}

.wordmark-name {
  font-family: "DM Serif Display", Georgia, "Times New Roman", serif;
  font-size: 1.75rem;
  line-height: 1;
  letter-spacing: -0.01em;
}

.wordmark-dot {
  color: var(--accent);
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 1.75rem;
  line-height: 1;
}

.masthead-tag {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.01em;
}

.masthead .ghost-btn {
  margin-left: auto;
}

.ghost-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}
.ghost-btn:hover {
  background: var(--surface-2);
  border-color: var(--ink);
}
.ghost-btn:active {
  transform: translateY(1px);
}

/* ---------- Controls ---------- */

.controls-bar {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.controls-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 24px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 200px auto;
  gap: 16px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label,
.field .field-label {
  font-family: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.field input[type="search"],
.field select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  color: var(--ink);
  font-size: 0.95rem;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.field input[type="search"]::placeholder {
  color: var(--muted);
  opacity: 1;
}
.field input[type="search"]:hover,
.field select:hover {
  border-color: var(--muted);
}
.field input[type="search"]:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);
}

.field select {
  appearance: none;
  cursor: pointer;
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.saved-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}
.saved-toggle:hover {
  border-color: var(--ink);
}
.saved-toggle:active {
  transform: translateY(1px);
}
.saved-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.saved-toggle-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  font-weight: 600;
}
.saved-toggle[aria-pressed="true"] .saved-toggle-count {
  background: var(--accent-ink);
  color: var(--accent);
}

/* ---------- Index ---------- */

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 40px 24px 72px;
}

.index-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 32px;
}

.index-head h1 {
  margin: 0;
  font-family: "DM Serif Display", Georgia, serif;
  font-weight: 400;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.015em;
}

.index-count {
  margin: 0;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.story-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
}

.story-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.22s ease,
    border-color 0.22s ease;
}
.story-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--ink) 30%, var(--line));
}

.card-media {
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--surface-2);
}
.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.story-card:hover .card-media img {
  transform: scale(1.04);
}

.card-body {
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-meta {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.card-meta .card-category {
  color: var(--accent);
  font-weight: 600;
}

.card-title {
  margin: 0;
  font-family: "DM Serif Display", Georgia, serif;
  font-weight: 400;
  font-size: 1.4rem;
  line-height: 1.16;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.card-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.55;
}

.card-byline {
  margin: auto 0 0;
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.card-hit {
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: inherit;
}
.card-hit:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -4px;
}

.story-card:hover .card-title,
.story-card:focus-within .card-title {
  color: var(--accent);
}

/* Lead story: asymmetric split on wide screens */
@media (min-width: 900px) {
  .story-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 30px;
  }
  .story-card.lead {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    align-items: stretch;
  }
  .story-card.lead .card-media {
    aspect-ratio: auto;
    height: 100%;
    min-height: 360px;
  }
  .story-card.lead .card-body {
    padding: 40px 40px 36px;
    gap: 14px;
  }
  .story-card.lead .card-title {
    font-size: clamp(1.9rem, 3vw, 2.6rem);
    line-height: 1.08;
  }
  .story-card.lead .card-summary {
    font-size: 1.05rem;
    max-width: 42ch;
  }
}

@media (min-width: 1180px) {
  .story-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .story-card.lead {
    grid-template-columns: 1.5fr 1fr;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .story-card {
    animation: cardIn 0.55s cubic-bezier(0.16, 1, 0.3, 1) both;
    animation-delay: calc(var(--i, 0) * 45ms);
  }
  @keyframes cardIn {
    from {
      opacity: 0;
      transform: translateY(14px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

/* ---------- Skeletons & empty ---------- */

.skeleton {
  height: 340px;
  border-radius: var(--radius-panel);
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface) 50%, var(--surface-2) 70%);
  background-size: 220% 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .skeleton {
    animation: shimmer 1.4s ease-in-out infinite;
  }
  @keyframes shimmer {
    from {
      background-position: 180% 0;
    }
    to {
      background-position: -40% 0;
    }
  }
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius-panel);
  padding: 56px 28px;
  text-align: center;
  background: var(--surface);
}
.empty-state h2 {
  margin: 0 0 8px;
  font-family: "DM Serif Display", Georgia, serif;
  font-weight: 400;
  font-size: 1.8rem;
}
.empty-state p {
  margin: 0 auto 24px;
  color: var(--muted);
  max-width: 46ch;
}

.primary-btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.18s ease, transform 0.12s ease;
}
.primary-btn:hover {
  filter: brightness(1.08);
}
.primary-btn:active {
  transform: translateY(1px);
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.footer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 40px 24px 56px;
  display: grid;
  gap: 12px;
}
.footer-inner p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 70ch;
}
.footer-brand {
  margin-bottom: 4px !important;
}
.footer-note {
  font-size: 0.78rem !important;
}

/* ---------- Detail dialog ---------- */

#detail {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: none;
  max-height: none;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
#detail::backdrop {
  background: rgba(16, 17, 20, 0.62);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
@media (prefers-reduced-motion: no-preference) {
  #detail[open]::backdrop {
    animation: backdropIn 0.25s ease both;
  }
  #detail[open] .detail-shell {
    animation: shellIn 0.34s cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  @keyframes backdropIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
  @keyframes shellIn {
    from {
      opacity: 0;
      transform: translateY(16px) scale(0.985);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

.detail-shell {
  background: var(--paper);
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  border-radius: 0;
  overflow: hidden;
}

@media (min-width: 760px) {
  #detail[open] {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
  }
  .detail-shell {
    width: min(840px, 100%);
    height: min(92dvh, 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius-panel);
    box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.6);
  }
}

.detail-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  flex: none;
}

.save-btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.save-btn:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.save-btn:active {
  transform: translateY(1px);
}
.save-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.detail-scroll {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.detail-article {
  padding: 34px clamp(20px, 5vw, 56px) 64px;
  max-width: 720px;
  margin: 0 auto;
}

.detail-category {
  margin: 0 0 12px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  font-weight: 600;
}

.detail-title {
  margin: 0 0 16px;
  font-family: "DM Serif Display", Georgia, serif;
  font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 3rem);
  line-height: 1.06;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.detail-summary {
  margin: 0 0 16px;
  font-size: 1.12rem;
  line-height: 1.5;
  color: var(--ink);
}
.detail-summary::before {
  content: "";
}

.detail-byline {
  margin: 0 0 28px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.detail-figure {
  margin: 0 0 30px;
}
.detail-figure img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: var(--radius-media);
  background: var(--surface-2);
}
.detail-figure figcaption {
  margin-top: 10px;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.45;
}

.detail-body p {
  margin: 0 0 1.25em;
  font-size: 1.06rem;
  line-height: 1.75;
}
.detail-body p:first-of-type::first-letter {
  float: left;
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 3.4rem;
  line-height: 0.82;
  padding: 4px 10px 0 0;
  color: var(--accent);
}
.detail-body p:last-child {
  margin-bottom: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .masthead-inner {
    padding: 0 16px;
    min-height: 62px;
    gap: 12px;
  }
  .masthead-tag {
    display: none;
  }
  .wordmark-name,
  .wordmark-dot {
    font-size: 1.55rem;
  }
  .controls-inner {
    grid-template-columns: 1fr 1fr;
    padding: 16px;
    gap: 12px;
  }
  .field-search {
    grid-column: 1 / -1;
  }
  .field-saved {
    align-items: stretch;
  }
  main {
    padding: 28px 16px 56px;
  }
  .index-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 24px;
  }
  .footer-inner {
    padding: 32px 16px 48px;
  }
  .detail-article {
    padding: 26px 20px 56px;
  }
  .detail-body p:first-of-type::first-letter {
    font-size: 2.8rem;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .masthead {
    background: var(--paper);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  #detail::backdrop {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
