/* The Local — everyday city life
   Editorial, text-forward design system. System font stacks only. */

:root {
  --paper: #f5efe2;
  --paper-raised: #fffdf7;
  --ink: #211c15;
  --ink-soft: #55503f;
  --ink-faint: #625c49;
  --rule: #ddd2b8;
  --rule-strong: #c9bb98;
  --accent: #a1341f;
  --accent-ink: #ffffff;
  --focus-ring: #1a4f8c;

  --cat-culture: #6b2f7d;
  --cat-food: #96470f;
  --cat-movement: #17497f;
  --cat-people: #276b47;
  --cat-places: #96301c;

  --serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --radius: 6px;
  --max-width: 1160px;

  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(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--serif);
  margin: 0;
}

p {
  margin: 0;
}

ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

button {
  font: inherit;
  color: inherit;
}

input, select, button {
  accent-color: var(--focus-ring);
}

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

/* Focus visibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  z-index: 100;
  border-radius: 0 0 6px 0;
}

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

/* Header */
.site-header {
  border-bottom: 3px solid var(--ink);
  background: var(--paper);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-5);
}

.masthead {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.mark {
  width: 40px;
  height: 40px;
  color: var(--accent);
  flex-shrink: 0;
}

.kicker {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
}

.wordmark {
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}

.tagline {
  margin-top: var(--space-4);
  max-width: 46ch;
  color: var(--ink-soft);
  font-size: 1.05rem;
  font-family: var(--serif);
  font-style: italic;
}

/* Controls */
.controls-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  border-bottom: 1px solid var(--rule-strong);
}

.controls-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

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

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

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

#search-input,
#category-filter {
  border: 1.5px solid var(--rule-strong);
  background: var(--paper-raised);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 1rem;
  min-height: 44px;
}

#search-input::-webkit-search-cancel-button {
  cursor: pointer;
}

.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 1.5px solid var(--rule-strong);
  background: var(--paper-raised);
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 44px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.pill-toggle:hover {
  border-color: var(--accent);
}

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

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

.pill-toggle[aria-pressed="true"] .icon-bookmark path {
  fill: var(--accent-ink);
}

/* Main / results */
#main-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-5) var(--space-5) var(--space-8);
}

.result-count {
  color: var(--ink-faint);
  font-size: 0.9rem;
  margin-bottom: var(--space-4);
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-5);
}

.story-card {
  border-top: 3px solid var(--cat-color, var(--accent));
  background: var(--paper-raised);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(33, 28, 21, 0.08);
  display: flex;
  flex-direction: column;
  position: relative;
}

.story-card:first-child {
  grid-column: span 2;
}

@media (max-width: 640px) {
  .story-card:first-child {
    grid-column: auto;
  }
}

.card-open {
  all: unset;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  cursor: pointer;
  width: 100%;
  height: 100%;
  border-radius: 2px;
}

.card-open:hover .card-title {
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.card-topic {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cat-color, var(--accent));
}

.card-title {
  font-size: 1.3rem;
  line-height: 1.25;
  font-weight: 700;
}

.story-card:first-child .card-title {
  font-size: 1.75rem;
}

.card-summary {
  color: var(--ink-soft);
  font-size: 0.97rem;
  line-height: 1.5;
}

.card-meta {
  margin-top: auto;
  padding-top: var(--space-2);
  color: var(--ink-faint);
  font-size: 0.85rem;
}

.saved-badge {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 20px;
  height: 20px;
  color: var(--accent);
  pointer-events: none;
}

/* Category color mapping */
.story-card[data-category="Culture"] { --cat-color: var(--cat-culture); }
.story-card[data-category="Food"] { --cat-color: var(--cat-food); }
.story-card[data-category="Movement"] { --cat-color: var(--cat-movement); }
.story-card[data-category="People"] { --cat-color: var(--cat-people); }
.story-card[data-category="Places"] { --cat-color: var(--cat-places); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  border: 1.5px dashed var(--rule-strong);
  border-radius: var(--radius);
  max-width: 520px;
  margin: var(--space-6) auto 0;
}

.empty-title {
  font-family: var(--serif);
  font-size: 1.3rem;
  margin-bottom: var(--space-2);
}

.empty-hint {
  color: var(--ink-soft);
  margin-bottom: var(--space-4);
}

.reset-button {
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}

.reset-button:hover {
  background: var(--accent);
  border-color: var(--accent);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--rule-strong);
  padding: var(--space-5);
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.85rem;
}

/* Detail overlay */
.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 25, 18, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  z-index: 50;
}

.detail-overlay[hidden] {
  display: none;
}

.detail-dialog {
  background: var(--paper-raised);
  width: 100%;
  max-width: 720px;
  max-height: min(88vh, 900px);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(20, 16, 10, 0.35);
  animation: dialog-in 0.22s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .detail-dialog {
    animation: none;
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

.detail-topic {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.close-detail {
  border: none;
  background: transparent;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink);
}

.close-detail:hover {
  background: var(--paper);
}

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

.detail-scroll {
  overflow-y: auto;
  padding: var(--space-5) var(--space-6) var(--space-7);
}

.detail-title {
  font-size: clamp(1.5rem, 3.5vw, 2.1rem);
  line-height: 1.2;
  margin-bottom: var(--space-3);
}

.detail-meta {
  color: var(--ink-faint);
  font-size: 0.92rem;
  margin-bottom: var(--space-4);
}

.save-button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  margin-bottom: var(--space-5);
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

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

.save-button[aria-pressed="true"] .icon-bookmark path {
  fill: var(--accent-ink);
}

.detail-body {
  font-family: var(--serif);
  font-size: 1.08rem;
  line-height: 1.7;
  color: var(--ink);
  max-width: 65ch;
}

.detail-body p {
  margin-bottom: var(--space-4);
}

.detail-body p:last-child {
  margin-bottom: 0;
}

/* Mobile */
@media (max-width: 640px) {
  .header-inner {
    padding: var(--space-5) var(--space-4) var(--space-4);
  }

  .controls-inner {
    padding: var(--space-3) var(--space-4);
    flex-direction: column;
    align-items: stretch;
  }

  .search-field,
  .filter-field {
    flex: 1 1 auto;
    width: 100%;
  }

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

  #main-content {
    padding: var(--space-4) var(--space-4) var(--space-7);
  }

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

  .detail-overlay {
    padding: 0;
  }

  .detail-dialog {
    max-width: none;
    max-height: none;
    height: 100%;
    border-radius: 0;
    animation: none;
  }

  .detail-scroll {
    padding: var(--space-4) var(--space-4) var(--space-6);
  }
}
