@font-face {
  font-family: "Literata";
  src: url("assets/literata.ttf") format("truetype");
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "DM Serif Display";
  src: url("assets/dm-serif.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Work Sans";
  src: url("assets/work-sans.ttf") format("truetype");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --paper: oklch(96.5% 0.02 88);
  --paper-deep: oklch(92.5% 0.03 85);
  --ink: oklch(24% 0.035 255);
  --muted: oklch(43% 0.03 255);
  --rule: oklch(78% 0.035 80);
  --accent: oklch(50% 0.17 33);
  --accent-deep: oklch(42% 0.15 33);
  --on-accent: oklch(97% 0.02 88);

  --display: "DM Serif Display", "Iowan Old Style", Georgia, serif;
  --text: "Literata", "Iowan Old Style", Georgia, serif;
  --ui: "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --gutter: clamp(1rem, 4vw, 2.5rem);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--rule) var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
main:focus { outline: none; }

::selection { background: var(--accent); color: var(--on-accent); }
input, select, textarea { caret-color: var(--accent); }

h1, h2, h3, p { margin: 0; }
img { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

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

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: var(--gutter);
  top: -4rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  z-index: 10;
  transition: top 0.2s var(--ease);
}
.skip:focus { top: 0.5rem; }

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

.icon {
  width: 1.15em; height: 1.15em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.masthead { padding-top: clamp(1rem, 2.5vw, 1.75rem); }

.masthead-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 2rem;
  flex-wrap: wrap;
  padding-bottom: 0.9rem;
}

.wordmark {
  font-family: var(--display);
  font-size: clamp(2.7rem, 8vw, 5.5rem);
  line-height: 0.95;
  letter-spacing: -0.025em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.wordmark .dot { color: var(--accent); }

.masthead-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
}
.tagline {
  font-family: var(--text);
  font-style: italic;
  font-size: 1rem;
  color: var(--muted);
}

.nav {
  display: flex;
  gap: 0.25rem;
  list-style: none;
  margin: 0; padding: 0;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  padding: 0.4rem 0.8rem;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.nav-link:hover { border-bottom-color: var(--accent); }
.nav-link[aria-current="true"] { border-bottom-color: var(--ink); font-weight: 650; }
.nav-link .count {
  font-variant-numeric: tabular-nums;
  min-width: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--paper-deep);
  text-align: center;
  font-size: 0.82rem;
  line-height: 1.5rem;
}
.nav-link .count.has { background: var(--accent); color: var(--on-accent); }

.double-rule {
  height: 6px;
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

/* ---------- Toolbar ---------- */

.browse { padding-top: 1.25rem; padding-bottom: 4rem; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.75rem;
  align-items: stretch;
}

.field {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 3rem;
  padding: 0 0.9rem;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
}
.field:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.field input, .field select {
  border: 0; background: transparent;
  outline: none;
  min-width: 0;
  height: 100%;
}
.field-search { color: var(--muted); }
.field-search input { flex: 1; color: var(--ink); font-size: 1rem; }
.field-search input::placeholder { color: var(--muted); opacity: 1; }
.field-search input::-webkit-search-cancel-button { filter: grayscale(1); cursor: pointer; }
.field-filter label {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.field-filter select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.5rem;
  font-weight: 500;
  cursor: pointer;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%231c2330' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 0.1rem center / 0.7rem no-repeat;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 3rem;
  padding: 0 1.1rem;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  font-weight: 600;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}
.toggle:hover { background: var(--paper-deep); }
.toggle[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.toggle[aria-pressed="true"] .icon { fill: currentColor; }

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2.75rem;
  margin-top: 0.5rem;
}
.result-count { font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.text-btn {
  background: none; border: 0; padding: 0.5rem 0;
  font-size: 0.9rem; font-weight: 600;
  color: var(--accent-deep);
  text-decoration: underline;
  text-underline-offset: 0.25em;
  text-decoration-thickness: 1.5px;
}
.text-btn:hover { color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: 3rem; padding: 0 1.4rem;
  background: var(--ink); color: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 2px;
  font-weight: 600;
  transition: background-color 0.2s var(--ease);
}
.btn:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

/* ---------- Story list ---------- */

.items { list-style: none; margin: 0; padding: 0; }

.item {
  position: relative;
  transition: background-color 0.25s var(--ease);
}
.item:hover { background: color-mix(in oklch, var(--paper-deep) 55%, transparent); }

.item .open {
  background: none; border: 0; padding: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
}
.item .open::after { content: ""; position: absolute; inset: 0; }
.item .open:focus-visible { outline: none; }
.item .open:focus-visible::after { outline: 3px solid var(--accent); outline-offset: -3px; }
.item:hover .open { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 0.18em; }

.title { text-wrap: balance; }
.summary { color: var(--muted); font-family: var(--text); text-wrap: pretty; }
.meta { font-size: 0.85rem; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.75rem; }
.meta .cat { font-weight: 650; color: var(--accent-deep); letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.78rem; }
.meta .sep { opacity: 0.5; }
.saved-mark {
  display: none;
  align-items: center; gap: 0.3rem;
  color: var(--accent-deep); font-weight: 600;
}
.item.is-saved .saved-mark { display: inline-flex; }
.saved-mark .icon { fill: currentColor; width: 1em; height: 1em; }

.thumb { overflow: hidden; background: var(--paper-deep); }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.7s var(--ease); }
.item:hover .thumb img { transform: scale(1.04); }

/* lead */
.item.lead {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
  padding: 1.75rem 0 2.25rem;
  border-bottom: 1px solid var(--rule);
}
.lead .thumb { aspect-ratio: 3 / 2; }
.lead .text { display: grid; gap: 1rem; align-content: center; }
.lead .title { font-family: var(--display); font-weight: 400; font-size: clamp(2.1rem, 4.4vw, 3.6rem); line-height: 1.04; letter-spacing: -0.015em; }
.lead .summary { font-size: 1.15rem; line-height: 1.5; }

/* index rows */
.item.row {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr) 12rem;
  gap: 0 clamp(1.25rem, 3vw, 2.5rem);
  align-items: start;
  padding: 1.6rem 0;
  border-bottom: 1px solid var(--rule);
}
.row .when { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 0.45rem; }
.row .when strong { display: block; font-family: var(--display); font-weight: 400; font-size: 1.9rem; line-height: 1; color: var(--ink); margin-bottom: 0.2rem; }
.row .text { display: grid; gap: 0.55rem; }
.row .title { font-family: var(--display); font-weight: 400; font-size: clamp(1.45rem, 2.3vw, 1.9rem); line-height: 1.12; letter-spacing: -0.01em; }
.row .thumb { aspect-ratio: 4 / 3; }

.lead .when { display: none; }

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

.empty {
  max-width: 32rem;
  margin: clamp(2.5rem, 8vw, 5rem) auto;
  text-align: center;
  display: grid;
  gap: 0.9rem;
  justify-items: center;
}
.empty[hidden] { display: none; }
.empty h2 { font-family: var(--display); font-weight: 400; font-size: clamp(1.9rem, 4vw, 2.6rem); line-height: 1.1; text-wrap: balance; }
.empty p { color: var(--muted); font-family: var(--text); margin-bottom: 0.6rem; text-wrap: pretty; }

/* ---------- Reader ---------- */

.reader[hidden], .browse[hidden] { display: none; }

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.reader-bar .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.6rem;
}

.back, .save {
  display: inline-flex; align-items: center; gap: 0.55rem;
  min-height: 2.9rem; padding: 0 1rem;
  border: 1.5px solid var(--ink); border-radius: 2px;
  background: var(--paper);
  font-weight: 600;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}
.back { border-color: transparent; padding-left: 0.4rem; }
.back:hover { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 0.2em; }
.save:hover { background: var(--paper-deep); }
.save[aria-pressed="true"] { background: var(--accent-deep); border-color: var(--accent-deep); color: var(--on-accent); }
.save[aria-pressed="true"]:hover { background: var(--ink); border-color: var(--ink); }
.save[aria-pressed="true"] .icon { fill: currentColor; }

.article { padding-top: clamp(1.5rem, 5vw, 3.5rem); padding-bottom: 3rem; }

.article-head {
  max-width: 52rem;
  margin-inline: auto;
  display: grid;
  gap: 1.1rem;
}
.article-head .meta { font-size: 0.9rem; }
.article-head h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.3rem, 6.2vw, 4.6rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.article-head h1:focus { outline: none; }
.dek {
  font-family: var(--text);
  font-style: italic;
  font-size: clamp(1.15rem, 2vw, 1.4rem);
  line-height: 1.45;
  color: var(--muted);
  text-wrap: pretty;
}
.byline { font-size: 0.95rem; }
.byline strong { font-weight: 650; }

.figure { max-width: 62rem; margin: clamp(1.5rem, 4vw, 2.5rem) auto; }
.figure .frame { aspect-ratio: 16 / 9; background: var(--paper-deep); overflow: hidden; }
.figure img { width: 100%; height: 100%; object-fit: cover; }
.figure figcaption { font-size: 0.82rem; color: var(--muted); padding-top: 0.6rem; max-width: 52rem; margin-inline: auto; }

.prose { max-width: 38rem; margin-inline: auto; font-family: var(--text); font-size: clamp(1.08rem, 1.5vw, 1.2rem); line-height: 1.72; }
.prose p + p { margin-top: 1.25em; }
.prose p:first-child::first-letter {
  font-family: var(--display);
  float: left;
  font-size: 4.3em;
  line-height: 0.82;
  padding: 0.07em 0.1em 0 0;
  color: var(--accent);
}
.prose p { text-wrap: pretty; }

.end-mark { display: block; width: 0.55rem; height: 0.55rem; background: var(--accent); margin: 2rem auto 0; transform: rotate(45deg); }

.more {
  max-width: 38rem; margin: 3rem auto 0; padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; justify-content: space-between; align-items: center;
}
.more a { color: inherit; font-family: var(--display); font-size: 1.35rem; line-height: 1.2; text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 0.2em; }
.more a:hover { color: var(--accent-deep); }
.more span { font-size: 0.85rem; color: var(--muted); display: block; }

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

.footer { padding-bottom: 2.5rem; margin-top: 1rem; }
.footer p { padding-top: 1rem; max-width: 46rem; font-size: 0.85rem; color: var(--muted); }

/* ---------- Motion ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
.items.enter .item { animation: rise 0.7s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 70ms); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Narrow ---------- */

@media (max-width: 62rem) {
  .item.row { grid-template-columns: 6.5rem minmax(0, 1fr) 9rem; }
}

@media (max-width: 46rem) {
  .masthead-row { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .masthead-side { align-items: flex-start; width: 100%; gap: 0.2rem; }
  .nav { margin-left: -0.8rem; }

  .toolbar { grid-template-columns: minmax(0, 1fr) auto; }
  .field-search { grid-column: 1 / -1; }
  .field-filter { min-width: 0; }
  .field-filter select { width: 100%; }

  .item.lead { grid-template-columns: 1fr; gap: 1.1rem; padding: 1.25rem 0 1.75rem; }
  .lead .title { font-size: 2.15rem; }
  .lead .summary { font-size: 1.05rem; }

  .item.row {
    grid-template-columns: minmax(0, 1fr) 5.75rem;
    grid-template-areas: "when when" "text thumb";
    gap: 0.4rem 1rem;
    padding: 1.25rem 0;
  }
  .row .when { grid-area: when; padding: 0; font-size: 0.82rem; }
  .row .when strong { display: inline; font-family: var(--ui); font-size: inherit; margin: 0; color: inherit; }
  .row .text { grid-area: text; }
  .row .thumb { grid-area: thumb; aspect-ratio: 1; }
  .row .title { font-size: 1.35rem; }
  .row .summary { font-size: 0.95rem; }

  .reader-bar .wrap { padding-block: 0.45rem; }
  .back span { display: inline; }
  .prose p:first-child::first-letter { font-size: 3.8em; }
}

@media (max-width: 26rem) {
  .toggle { padding: 0 0.8rem; }
}
