:root {
  color-scheme: light;
  --ink: #121714;
  --ink-soft: #465149;
  --paper: #f4f1e8;
  --paper-bright: #fffdf7;
  --signal: #ff5a36;
  --acid: #c9ff46;
  --trail: #19b987;
  --sky: #61c9ff;
  --line: rgba(18, 23, 20, .16);
  --shadow: 0 20px 60px rgba(18, 23, 20, .2);
  --header-height: 72px;
  --footer-height: 0px;
  --panel-width: 390px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--ink);
  background: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button, select { font-size: 1rem; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, select:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 10000;
  top: 8px;
  left: 8px;
  min-height: 44px;
  padding: 10px 16px;
  color: var(--ink);
  background: var(--acid);
  border-radius: 8px;
  font-weight: 800;
  transform: translateY(-150%);
}

.skip-link:focus { transform: translateY(0); }

.map-app {
  display: grid;
  grid-template-rows: var(--header-height) minmax(0, 1fr);
  height: 100dvh;
  min-height: 480px;
}

.app-header {
  position: relative;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  min-height: var(--header-height);
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  color: var(--paper-bright);
  background: var(--ink);
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 9px;
  min-height: 44px;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--acid);
  border: 1px solid rgba(201, 255, 70, .5);
  border-radius: 50%;
}

.brand-mark svg {
  width: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: .92;
}

.brand-copy strong {
  font-size: 1.16rem;
  font-weight: 900;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.brand-copy small {
  margin-top: 5px;
  color: rgba(255, 255, 255, .58);
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.header-copy {
  min-width: 0;
  text-align: right;
}

.header-copy p { display: none; }
.header-copy span {
  display: block;
  overflow: hidden;
  color: rgba(255, 255, 255, .68);
  font-size: .7rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-shell { position: relative; min-height: 0; overflow: hidden; }
.map-stage, #map { position: absolute; inset: 0; }
#map { z-index: 0; background: #dce5de; }

.map-toolbar {
  position: absolute;
  z-index: 900;
  top: 10px;
  right: 10px;
  left: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  pointer-events: none;
}

.color-control,
.view-controls,
.legend,
.loading-card,
.map-error { pointer-events: auto; }

.color-control {
  display: grid;
  gap: 2px;
  width: 204px;
  padding: 6px 10px 7px;
  color: var(--ink);
  background: rgba(255, 253, 247, .96);
  border: 1px solid rgba(18, 23, 20, .12);
  border-radius: 10px;
  box-shadow: 0 5px 20px rgba(18, 23, 20, .16);
  backdrop-filter: blur(12px);
}

.color-control > span {
  color: var(--ink-soft);
  font-size: .61rem;
  font-weight: 900;
  letter-spacing: .1em;
  line-height: 1;
  text-transform: uppercase;
}

.color-control select {
  width: 100%;
  min-height: 44px;
  padding: 0 24px 0 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-size: 1rem;
  font-weight: 800;
}

.view-controls { display: flex; gap: 8px; }
.view-controls .map-button { flex: 1 1 0; padding-inline: 9px; }
.map-button {
  min-height: 44px;
  padding: 0 13px;
  color: var(--ink);
  background: rgba(255, 253, 247, .96);
  border: 1px solid rgba(18, 23, 20, .16);
  border-radius: 10px;
  box-shadow: 0 5px 20px rgba(18, 23, 20, .14);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .03em;
  text-transform: uppercase;
  backdrop-filter: blur(12px);
}

.map-button:hover { background: var(--acid); }
.map-button:active { transform: translateY(1px) scale(.98); }
.map-button[aria-pressed="true"] { color: var(--paper-bright); background: var(--ink); }

.legend {
  position: absolute;
  z-index: 850;
  right: 10px;
  bottom: 18px;
  width: min(210px, calc(100vw - 20px));
  max-height: min(42dvh, 300px);
  padding: 12px;
  overflow: auto;
  color: var(--ink);
  background: rgba(255, 253, 247, .94);
  border: 1px solid rgba(18, 23, 20, .12);
  border-radius: 13px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.legend-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
}

.legend-heading strong {
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.legend-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 5px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  font-size: .72rem;
  font-weight: 800;
}

.legend-toggle:active { color: var(--signal); }
.legend-items { display: grid; gap: 8px; padding-top: 5px; }
.legend.is-collapsed .legend-items,
.legend.is-collapsed .legend-key { display: none; }

.legend-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  font-size: .72rem;
}

.legend-color {
  width: 12px;
  height: 12px;
  background: var(--legend-color);
  border: 2px solid var(--paper-bright);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(18, 23, 20, .25);
}

.legend-label { overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.legend-key {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin: 10px 0 0;
  padding-top: 9px;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  font-size: .61rem;
}

.route-swatch { width: 20px; height: 4px; background: var(--trail); border-radius: 99px; }
.dot-swatch { width: 10px; height: 10px; margin-left: 5px; background: var(--signal); border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px rgba(18, 23, 20, .25); }

.loading-card,
.map-error {
  position: absolute;
  z-index: 1000;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: min(280px, calc(100vw - 32px));
  padding: 16px;
  color: var(--ink);
  background: var(--paper-bright);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
}

.loading-card[hidden], .map-error[hidden] { display: none; }
.loading-card div, .map-error { flex-direction: column; align-items: flex-start; }
.loading-card strong, .loading-card span, .map-error strong, .map-error span { display: block; }
.loading-card span, .map-error span { color: var(--ink-soft); font-size: .78rem; }
.loading-mark {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 3px solid rgba(18, 23, 20, .14);
  border-top-color: var(--signal);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

.map-error .map-button { margin-top: 5px; box-shadow: none; background: var(--acid); }

.details-panel {
  position: absolute;
  z-index: 1100;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  max-height: min(58dvh, 520px);
  padding: 7px 18px max(18px, env(safe-area-inset-bottom));
  overflow: hidden;
  color: var(--ink);
  background: var(--paper-bright);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -18px 55px rgba(18, 23, 20, .25);
  transform: translateY(calc(100% + 24px));
  visibility: hidden;
  transition: transform .24s ease, visibility .24s step-end;
}

.details-panel.is-open {
  transform: translateY(0);
  visibility: visible;
  transition: transform .24s ease, visibility 0s;
}

.sheet-handle { align-self: center; width: 48px; height: 4px; background: rgba(18, 23, 20, .22); border-radius: 99px; }
.details-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}

.details-eyebrow {
  color: var(--signal);
  font-size: .66rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.icon-button svg, .focus-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-button:active { color: var(--paper-bright); background: var(--ink); }
.details-scroll { padding-bottom: 2px; overflow-y: auto; overscroll-behavior: contain; }
.details-heading { padding: 7px 0 18px; }
.details-date { color: var(--ink-soft); font-size: .76rem; font-weight: 700; }
.details-heading h1 { margin: 4px 0 7px; font-size: clamp(1.7rem, 8vw, 2.4rem); line-height: 1.02; letter-spacing: -.035em; }
.details-heading p { margin: 0; color: var(--trail); font-size: .84rem; font-weight: 850; }

.detail-chips { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 18px; }
.detail-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 10px;
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 800;
}

.detail-chip.is-hare { color: #fff; background: var(--signal); border-color: var(--signal); }
.detail-list { margin: 0; border-top: 1px solid var(--line); }
.detail-list > div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.detail-list dt { color: var(--ink-soft); font-size: .68rem; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.detail-list dd { margin: 0; font-size: .8rem; font-weight: 650; overflow-wrap: anywhere; }
.focus-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 50px;
  margin-top: 18px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--acid);
  border: 0;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.focus-button:active { transform: translateY(1px) scale(.99); background: #b7ef34; }
.focus-button:disabled { cursor: not-allowed; opacity: .38; filter: grayscale(1); }
.focus-button:disabled:active { transform: none; background: var(--acid); }

.app-footer { display: none; }

.leaflet-container { font-family: inherit; }
.leaflet-control-zoom { margin-top: 10px !important; margin-left: 10px !important; border: 0 !important; box-shadow: 0 5px 20px rgba(18, 23, 20, .18) !important; }
.leaflet-control-zoom a {
  display: grid !important;
  place-items: center;
  width: 44px !important;
  height: 44px !important;
  color: var(--ink) !important;
  background: rgba(255, 253, 247, .96) !important;
  border-bottom-color: var(--line) !important;
  font-size: 1.35rem !important;
  line-height: 1 !important;
}

.leaflet-control-zoom a:active { background: var(--acid) !important; }
.leaflet-control-attribution { max-width: 70%; padding: 2px 5px !important; background: rgba(255, 255, 255, .78) !important; font-size: 9px !important; }
.leaflet-control-attribution a { min-height: 0; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (width >= 620px) {
  :root { --header-height: 78px; }
  .app-header { padding-inline: 22px; }
  .brand-mark { width: 44px; height: 44px; }
  .brand-copy strong { font-size: 1.35rem; }
  .header-copy p { display: block; margin: 0; font-size: .76rem; font-weight: 750; }
  .header-copy span { margin-top: 2px; }
  .map-toolbar { top: 14px; right: 14px; left: 62px; flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .color-control { min-width: 154px; }
  .map-button { padding-inline: 16px; }
  .legend { right: 14px; bottom: 22px; }
}

@media (width >= 860px) {
  :root { --footer-height: 34px; }
  .map-app { grid-template-rows: var(--header-height) minmax(0, 1fr) var(--footer-height); }
  .map-shell { padding-right: var(--panel-width); background: var(--paper-bright); }
  .map-stage { right: var(--panel-width); }
  .map-toolbar { right: 14px; }
  .legend { right: 14px; bottom: 18px; }
  .details-panel {
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: var(--panel-width);
    max-height: none;
    padding: 12px 24px 22px;
    border-top: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    box-shadow: -16px 0 48px rgba(18, 23, 20, .12);
    transform: none;
    visibility: visible;
    transition: none;
  }
  .sheet-handle, .icon-button { display: none; }
  .details-toolbar { justify-content: flex-start; }
  .details-panel[aria-hidden="true"] .details-eyebrow { color: var(--ink-soft); }
  .details-heading { padding-top: 16px; }
  .details-heading h1 { font-size: 2.5rem; }
  .details-scroll { display: flex; flex: 1; flex-direction: column; }
  .focus-button { margin-top: auto; }
  .app-footer {
    position: relative;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 0 18px max(0px, env(safe-area-inset-bottom));
    color: rgba(255, 255, 255, .55);
    background: var(--ink);
    font-size: .62rem;
    letter-spacing: .04em;
    text-transform: uppercase;
  }
  .app-footer a { display: inline-grid; place-items: center; min-height: 30px; color: var(--acid); font-weight: 850; text-decoration: none; }
}

@media (width >= 1180px) {
  :root { --panel-width: 430px; }
  .app-header { padding-inline: 30px; }
  .details-panel { padding-inline: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
