@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: 100 900;
  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;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f6f1e6;
  --paper-raised: #fffdf8;
  --ink: #211d17;
  --ink-soft: #5b5348;
  --rule: #ddd3c1;
  --accent: #b5502f;
  --accent-ink: #ffffff;
  --focus: #1c5fb8;
  --shadow: 0 18px 40px -22px rgba(33, 29, 23, 0.45);
  --radius: 4px;
  --serif: "DM Serif Display", Georgia, "Times New Roman", serif;
  --sans: "Work Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
}

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.75rem 1.25rem;
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  left: 0;
}

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

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Header ---------- */

.site-header {
  border-bottom: 3px solid var(--ink);
  padding: 2rem 1.5rem 1.5rem;
  max-width: 1180px;
  margin: 0 auto;
}

.masthead {
  text-align: center;
  margin-bottom: 1.75rem;
}

.kicker {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  color: var(--accent);
  margin: 0 0 0.4rem;
}

.wordmark {
  font-family: var(--serif);
  font-size: clamp(2.6rem, 6vw, 4.2rem);
  margin: 0;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--ink-soft);
  font-size: 1rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: end;
  justify-content: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.field label {
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.field-search {
  flex: 1 1 260px;
}

.field-filter {
  flex: 0 1 200px;
}

input[type="search"],
select {
  font-family: var(--sans);
  font-size: 1rem;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  width: 100%;
}

input[type="search"]::-webkit-search-cancel-button {
  cursor: pointer;
}

.saved-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1rem;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.saved-toggle .bookmark-icon {
  width: 14px;
  height: 18px;
  color: currentColor;
}

.saved-toggle[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.saved-toggle[aria-pressed="true"] .bookmark-icon path {
  fill: currentColor;
}

/* ---------- Main list ---------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

.result-count {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 1.25rem;
}

.story-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 1.75rem;
}

.story-card {
  position: relative;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-open {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font: inherit;
}

.card-media {
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--rule);
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.card-open:hover .card-media img,
.card-open:focus-visible .card-media img {
  transform: scale(1.04);
}

.card-body {
  padding: 1.1rem 1.25rem 1.35rem;
}

.category-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  margin-bottom: 0.6rem;
}

.card-title {
  font-family: var(--serif);
  font-size: 1.4rem;
  line-height: 1.25;
  margin: 0 0 0.5rem;
}

.card-summary {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.card-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin: 0;
}

.saved-badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--ink);
  color: var(--paper);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.saved-badge svg {
  width: 12px;
  height: 15px;
}

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--ink-soft);
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
}

.empty-state button {
  margin-top: 1rem;
  padding: 0.55rem 1.1rem;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

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

.site-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
  border-top: 1px solid var(--rule);
}

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

.detail-dialog {
  border: none;
  border-radius: 0;
  padding: 0;
  width: min(720px, 100vw);
  height: 100vh;
  max-height: 100vh;
  max-width: 100vw;
  margin: 0 0 0 auto;
  background: var(--paper);
  color: var(--ink);
}

.detail-dialog::backdrop {
  background: rgba(33, 29, 23, 0.55);
}

.detail-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 2.5rem 2rem 4rem;
  position: relative;
}

.close-detail {
  position: sticky;
  top: 0;
  float: right;
  margin-left: 1rem;
  background: var(--paper-raised);
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  z-index: 2;
}

.close-detail svg {
  width: 16px;
  height: 16px;
}

.detail-article {
  clear: both;
  max-width: 60ch;
  margin: 0 auto;
}

.detail-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius);
  margin: 0 0 1.25rem;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.6rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.detail-title {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  line-height: 1.2;
  margin: 0 0 1.1rem;
}

.save-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1.75rem;
}

.save-toggle .bookmark-icon {
  width: 14px;
  height: 18px;
}

.save-toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.save-toggle[aria-pressed="true"] .bookmark-icon path {
  fill: currentColor;
}

.detail-body p {
  margin: 0 0 1.1rem;
  font-size: 1.05rem;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  .site-header {
    padding: 1.5rem 1rem 1.25rem;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .field-filter,
  .field-search {
    flex-basis: auto;
  }

  .saved-toggle {
    justify-content: center;
  }

  main {
    padding: 1.25rem 1rem 3rem;
  }

  .story-grid {
    grid-template-columns: 1fr;
  }

  .detail-dialog {
    width: 100vw;
  }

  .detail-scroll {
    padding: 1.5rem 1.1rem 3rem;
  }
}
