:root {
  --ink: #141412;
  --ink-soft: #4a4944;
  --paper: #fffdfa;
  --paper-sunk: #f0efe9;
  --line: #1c1b18;
  --line-soft: #d8d6cd;
  --masthead: #111110;
  --accent: #c31f1f;
  --accent-ink: #ffffff;
  --focus: #c31f1f;

  --cat-culture: #6d28d9;
  --cat-food: #a5540b;
  --cat-movement: #0f6a5f;
  --cat-people: #1d4ed8;
  --cat-places: #b91c1c;

  --font-display: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-body: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

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

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 12px 18px;
  z-index: 200;
  font-weight: 700;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
}

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

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

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

.masthead {
  background: var(--masthead);
  color: #fff;
  border-bottom: 5px solid var(--accent);
}

.masthead__top {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.masthead__kicker {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #d9a5a5;
}

.masthead__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  font-size: clamp(2.4rem, 5vw, 3.4rem);
  line-height: 0.98;
}

.masthead__tagline {
  margin: 8px 0 0;
  font-size: 15px;
  color: #cfcdc6;
  font-style: italic;
}

.masthead__date {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: #cfcdc6;
  white-space: nowrap;
}

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

.toolbar {
  background: var(--paper-sunk);
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  z-index: 20;
}

.toolbar__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: end;
  gap: 20px;
  flex-wrap: wrap;
}

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

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

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

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

#search-input,
#filter-select {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 10px 12px;
  font-size: 16px;
  min-height: 44px;
}

#search-input:focus-visible,
#filter-select:focus-visible {
  outline-offset: 1px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

.toggle-chip .icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
}

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

.toggle-chip[aria-pressed="true"] .icon {
  fill: var(--accent);
  stroke: var(--accent);
}

/* ---------- Layout ---------- */

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 48px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 40px;
  }
}

.story-index__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 2px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 6px;
}

.story-index__head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--font-mono);
}

.story-count {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
}

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

.story-item {
  border-bottom: 1px solid var(--line-soft);
  padding: 26px 0;
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 20px;
}

@media (max-width: 640px) {
  .story-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }
}

.story-item__index {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  padding-top: 4px;
}

.story-item__category {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
}

.story-item__category::before {
  content: "";
  width: 8px;
  height: 8px;
  background: currentColor;
  display: inline-block;
}

.story-item__title-btn {
  display: block;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 8px;
  text-align: left;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 21px;
  line-height: 1.25;
  color: var(--ink);
  cursor: pointer;
}

.story-item__title-btn:hover {
  color: var(--accent);
  text-decoration: underline;
}

.story-item__summary {
  margin: 0 0 10px;
  font-family: var(--font-body);
  font-size: 16px;
  color: #302f2b;
  max-width: 62ch;
}

.story-item__meta {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.story-item__saved-mark {
  color: var(--accent);
  font-weight: 700;
}

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

.empty-state {
  padding: 48px 0;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}

.empty-state p {
  font-family: var(--font-body);
  font-size: 18px;
  margin: 0 0 16px;
}

#reset-filters {
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 2px;
  padding: 10px 18px;
  min-height: 44px;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.sidebar__block h2 {
  font-family: var(--font-mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-bottom: 2px solid var(--line);
  padding-bottom: 8px;
  margin: 0 0 12px;
}

.sidebar__block p {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
  color: #302f2b;
}

.topic-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.topic-chips button {
  background: var(--paper-sunk);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}

.topic-chips button[aria-current="true"] {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.saved-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.saved-list li {
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}

.saved-list button {
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}

.saved-list button:hover {
  color: var(--accent);
  text-decoration: underline;
}

.sidebar__hint {
  color: var(--ink-soft) !important;
  font-style: italic;
}

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

.site-footer {
  border-top: 1px solid var(--line-soft);
  background: var(--paper-sunk);
}

.site-footer p {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}

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

.detail-dialog {
  position: fixed;
  inset: 0 0 0 auto;
  border: none;
  padding: 0;
  width: min(760px, 100vw);
  height: 100vh;
  max-height: 100vh;
  max-width: 100vw;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  overflow-y: auto;
}

.detail-dialog::backdrop {
  background: rgba(17, 17, 16, 0.6);
}

.detail-dialog:not([open]) {
  display: none;
}

.detail {
  padding: 24px 28px 64px;
  max-width: 680px;
}

.detail__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.detail__index {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  color: var(--ink);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.icon-button:hover {
  background: var(--paper-sunk);
}

.detail__category {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 8px;
}

.detail__title {
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: -0.01em;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  line-height: 1.08;
  margin: 0 0 12px;
}

.detail__meta {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 20px;
}

.save-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 2px;
  padding: 12px 20px;
  min-height: 44px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.save-button .icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: #fff;
  stroke-width: 1.6;
}

.save-button[aria-pressed="true"] {
  background: var(--accent);
}

.save-button[aria-pressed="true"] .icon {
  fill: #fff;
  stroke: #fff;
}

.detail__rule {
  border: none;
  border-top: 2px solid var(--line);
  margin: 28px 0;
}

.detail__body {
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.75;
  color: #201f1c;
}

.detail__body p {
  margin: 0 0 20px;
}

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

@media (prefers-reduced-motion: no-preference) {
  .toggle-chip,
  .story-item__title-btn,
  .save-button,
  .icon-button {
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  }
}

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

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
  .masthead__top {
    padding: 22px 16px 18px;
  }

  .toolbar__inner {
    padding: 14px 16px;
  }

  .layout {
    padding: 24px 16px 48px;
  }

  .detail {
    padding: 20px 18px 48px;
  }
}
