:root {
  --bg: #f5f4f1;
  --panel: #ffffff;
  --line: #d8d4ce;
  --line-strong: #c3beb7;
  --text: #131313;
  --muted: #77716a;
  --badge: #e8e5df;
  --shadow: 0 1px 0 rgba(19, 19, 19, 0.04);
  --field-bg: #ffffff;
  --field-placeholder: #8f8a82;
  --font-sans: Arial, Helvetica, sans-serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg: #101110;
  --panel: #161817;
  --line: #2a2d2b;
  --line-strong: #3b403d;
  --text: #f2efe7;
  --muted: #b1aca2;
  --badge: #202321;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
  --field-bg: #191b1a;
  --field-placeholder: #9d988f;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

:root {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

a {
  color: inherit;
}

.page-shell {
  width: min(1240px, calc(100% - 2rem));
  margin: 0 auto;
  padding: max(0rem, env(safe-area-inset-top, 0px)) 0 4rem;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 1.75rem;
  margin-bottom: 0.5rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  color: var(--text);
}

.theme-toggle-icon {
  width: 1rem;
  height: 1rem;
}

.masthead {
  display: grid;
  justify-items: center;
  gap: 0.9rem;
  padding: 0.3rem 0 2.2rem;
}

.masthead-meta {
  width: min(56rem, 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-icon-image {
  width: 4.75rem;
  height: auto;
  object-fit: contain;
}

h1,
h2 {
  margin: 0;
  font-weight: 300;
}

h1 {
  font-size: clamp(2.6rem, 5vw, 4rem);
  letter-spacing: -0.045em;
}

.brand-home {
  color: inherit;
  text-decoration: none;
}

.brand-home:hover {
  opacity: 0.85;
}

.masthead-copy {
  width: min(34rem, 100%);
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.45;
  display: grid;
  gap: 0.1rem;
}

.toolbar {
  display: grid;
  gap: 0.55rem;
  width: min(64rem, 100%);
  margin: 0 auto 1.75rem;
}

/* Search + all filters on one line (wraps on small screens). */
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.55rem;
}

.toolbar-label,
.results-copy,
.tile-range,
.tile-category,
.tile-kicker,
.eyebrow {
  font-family: var(--font-mono);
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.filter-field {
  display: grid;
  gap: 0.25rem;
  flex: 1 1 7rem;
  min-width: 0;
}

.toolbar-meta {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 1rem;
}

.toolbar-label {
  font-size: 0.72rem;
  color: var(--muted);
}

.search-input,
.filter-select {
  width: 100%;
  min-height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--field-bg);
  box-shadow: var(--shadow);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
}

/* Search is the primary input but kept compact — it no longer spans the row. */
.search-input {
  flex: 2 1 12rem;
  max-width: 20rem;
  padding: 0 0.85rem;
}

.filter-select {
  appearance: none;
  padding: 0 2.5rem 0 0.95rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.search-input::placeholder {
  color: var(--field-placeholder);
}

.search-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--line-strong);
}

.results-copy,
.utility-link {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  text-decoration: none;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 3rem 2.2rem;
  align-items: start;
}

.tile-card {
  display: grid;
  grid-template-columns: 6.1rem minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.tile-marker {
  display: grid;
  justify-items: center;
  gap: 0.4rem;
  text-align: center;
}

.tile-icon-image {
  width: 5.2rem;
  height: auto;
  object-fit: contain;
}

.tile-range {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text);
}

.tile-main {
  min-width: 0;
}

.tile-kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  margin: 0 0 0.45rem;
}

.tile-chip {
  margin: 0;
  padding: 0.24rem 0.46rem;
  border: 0;
  border-radius: 0.35rem;
  background: var(--badge);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.tile-chip:hover,
.tile-chip:focus-visible {
  color: var(--text);
}

.tile-chip.is-active {
  color: var(--text);
  font-weight: 700;
}

.tile-title {
  font-size: 1.06rem;
  line-height: 1.2;
  font-weight: 400;
}

.tile-title-link {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-underline-offset: 0.16em;
}

.tile-title-link:hover,
.tile-title-link:focus-visible {
  color: #000;
}

:root[data-theme="dark"] .tile-title-link:hover,
:root[data-theme="dark"] .tile-title-link:focus-visible {
  color: #fff;
}

.tile-address {
  display: inline-block;
  margin: 0.25rem 0 0;
  font-size: 0.82rem;
  line-height: 1.35;
  color: inherit;
  opacity: 0.62;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-underline-offset: 0.16em;
}

.tile-address:hover,
.tile-address:focus-visible {
  opacity: 0.95;
}

.tile-description {
  margin: 0.45rem 0 0;
  font-size: 0.98rem;
  line-height: 1.58;
}

.empty-state {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
  text-align: center;
}

@media (max-width: 1040px) {
  .timeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100% - 1rem, 100%);
  }

  .topbar {
    margin-bottom: 0.25rem;
  }

  .masthead {
    gap: 0.7rem;
    padding-top: 0;
    padding-bottom: 1.1rem;
  }

  .masthead-meta {
    width: 100%;
    font-size: 0.78rem;
  }

  .brand-lockup {
    gap: 0.65rem;
  }

  .brand-icon-image {
    width: 3.25rem;
  }

  h1 {
    font-size: clamp(1.5rem, 8vw, 2.1rem);
  }

  .masthead-copy {
    font-size: 0.78rem;
    line-height: 1.3;
    max-width: 100%;
  }

  .toolbar,
  .masthead-copy {
    width: 100%;
  }

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

  .toolbar {
    gap: 0.5rem;
    margin-bottom: 1.1rem;
  }

  /* Search on its own line; Status/Type/Area + sort icon share the next row. */
  .search-input {
    flex: 1 1 100%;
    max-width: none;
    min-height: 2.2rem;
    font-size: 0.82rem;
    padding-inline: 0.75rem;
  }

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

  .filter-field .toolbar-label {
    font-size: 0.64rem;
  }

  .filter-select {
    min-height: 2.2rem;
    padding-left: 0.55rem;
    padding-right: 1.3rem;
    font-size: 0.8rem;
  }

  .sort-icon {
    width: 2.2rem;
    height: 2.2rem;
  }

  .toolbar-meta {
    justify-content: space-between;
    align-items: center;
  }

  .results-copy {
    font-size: 0.8rem;
  }

  .tile-card {
    grid-template-columns: 5rem minmax(0, 1fr);
    gap: 0.85rem;
  }

  .tile-icon-image {
    width: 4.25rem;
  }

  .tile-description {
    font-size: 0.94rem;
    line-height: 1.5;
  }

  .tile-chip {
    font-size: 0.68rem;
  }
}

.site-footer {
  margin: 2rem 0 1rem;
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.55;
}

.site-footer a {
  color: inherit;
}

/* --- Topbar icon buttons (sort + theme) --- */
.topbar {
  gap: 0.4rem;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--text);
}

.sort-glyph {
  display: inline-flex;
  align-items: center;
  gap: 0.08rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}

.sort-glyph svg {
  display: block;
}

.sort-dir {
  font-size: 0.8rem;
}

/* Sort: an icon that sits in the filter row, sized to match the select boxes. */
.sort-icon {
  flex: 0 0 auto;
  align-self: flex-end;
  width: 2.4rem;
  height: 2.4rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: var(--field-bg);
  box-shadow: var(--shadow);
  color: var(--muted);
}

.sort-icon:hover,
.sort-icon:focus-visible {
  color: var(--text);
  border-color: var(--line-strong);
}

/* --- Map view (toggle hidden for now; styles kept) --- */
.map {
  width: 100%;
  height: min(70vh, 640px);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  overflow: hidden;
  margin-bottom: 2rem;
}

.leaflet-popup-content {
  font-family: var(--font-sans, inherit);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* --- Year scrubber --- */
.timeline-wrap {
  position: relative;
}

/* Fixed right-edge scrubber — works on every screen size (like a fast-scroll bar). */
.year-rail {
  position: fixed;
  right: max(0.15rem, env(safe-area-inset-right, 0px));
  top: 50%;
  transform: translateY(-50%);
  width: 2.3rem;
  height: min(62vh, 460px);
  z-index: 20;
  cursor: pointer;
  touch-action: none;
}

.rail-track {
  position: relative;
  height: 100%;
  width: 100%;
}

/* The vertical guide line. */
.rail-track::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0.55rem;
  width: 2px;
  border-radius: 2px;
  background: var(--line);
}

.rail-ticks {
  position: absolute;
  inset: 0;
}

.rail-tick {
  position: absolute;
  right: 1.1rem;
  transform: translateY(-50%);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  opacity: 0.55;
  white-space: nowrap;
  pointer-events: none;
}

.rail-thumb {
  position: absolute;
  top: 0;
  right: 0;
  transform: translateY(-50%);
  min-width: 1.55rem;
  padding: 0.1rem 0.3rem;
  border-radius: 0.45rem;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  box-shadow: var(--shadow);
  transition: top 0.12s ease-out;
}

.year-rail:hover .rail-thumb,
.year-rail:active .rail-thumb {
  outline: 2px solid var(--line-strong);
}

/* Give the scrubber a faint backing on small screens so it reads over content. */
@media (max-width: 720px) {
  /* On mobile the rail is hidden until you scroll/touch, then fades out when
     idle — so it behaves like the native scrollbar instead of fighting it. */
  .year-rail {
    width: 1.9rem;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
  }

  .year-rail.rail-active {
    opacity: 1;
    pointer-events: auto;
  }

  .rail-tick {
    font-size: 0.55rem;
    right: 0.9rem;
  }

  .timeline-wrap {
    padding-right: 0;
  }
}
