:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b1f27;
  --muted: #5b6472;
  --border: #d9dde4;
  --accent: #e8590c;
  --accent-text: #ffffff;
  --header-bg: #0f1a2e;
  --header-text: #f1f3f7;
  --focus: #1971c2;
  --shadow: 0 6px 24px rgba(15, 26, 46, 0.16);
  --open: #2b8a3e;
  --viewable: #a5681a;
  --restricted: #c92a2a;
  --banner-bg: #fff3bf;
  --banner-text: #5c3c00;
  --banner-border: #f0d264;
  --panel-width: 360px;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d121c;
    --surface: #161d2b;
    --surface-2: #1f2838;
    --text: #e8ebf1;
    --muted: #9aa4b5;
    --border: #2c3647;
    --accent: #ff7a2e;
    --accent-text: #10141c;
    --header-bg: #080d17;
    --focus: #74c0fc;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    --open: #69db7c;
    --viewable: #ffc078;
    --restricted: #ff8787;
    --banner-bg: #3d2f00;
    --banner-text: #ffe8a3;
    --banner-border: #6b5200;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
  background: var(--header-bg); color: var(--header-text);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { width: 30px; height: 30px; fill: var(--accent); flex: none; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: 0.2px; }
.tagline { margin: 0; font-size: 12px; opacity: 0.75; }

/* Concept banner */
.concept-banner {
  padding: 8px 16px; font-size: 13px; line-height: 1.4;
  background: var(--banner-bg); color: var(--banner-text);
  border-bottom: 1px solid var(--banner-border);
}

/* Buttons */
button { font: inherit; cursor: pointer; }
.btn-ghost {
  background: transparent; color: inherit; border: 1px solid rgba(255,255,255,0.35);
  border-radius: 999px; padding: 5px 14px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-primary {
  background: var(--accent); color: var(--accent-text); border: 0;
  border-radius: 8px; padding: 9px 16px; font-weight: 600;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn-secondary {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; text-decoration: none; display: inline-flex;
}
.btn-small {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px; font-size: 13px;
}
.btn-small[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-link {
  background: none; border: 0; color: var(--focus); padding: 4px 0; font-size: 13px;
  text-decoration: underline;
}

/* Layout */
.layout { flex: 1; display: flex; position: relative; min-height: 0; }

.panel {
  width: var(--panel-width); flex: none;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
  min-height: 0;
}
.panel-controls { padding: 12px 16px 8px; border-bottom: 1px solid var(--border); }

input[type="search"], select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: 0.4px; }

.route-info { margin-top: 8px; font-size: 13px; color: var(--muted); }
.route-info strong { color: var(--text); }
.route-info a { margin-top: 6px; }

.filters { margin-top: 10px; }
.filters summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.filter-count {
  display: inline-block; background: var(--accent); color: var(--accent-text);
  border-radius: 999px; font-size: 11px; padding: 0 7px; margin-left: 4px;
}
.filter-count[hidden] { display: none; }
.filter-group { margin: 8px 0; }
.filter-group h3 { margin: 0 0 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 13px;
}
.chip[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.list-head { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; font-size: 13px; color: var(--muted); }

.site-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.site-list li { margin: 0 0 6px; }
.site-card {
  width: 100%; text-align: left; display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px;
}
.site-card:hover, .site-card.active { border-color: var(--accent); }
.site-card .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex: none; }
.site-card .step {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.site-card .name { font-weight: 600; display: block; }
.site-card .summary { color: var(--muted); font-size: 13px; display: block; margin-top: 2px; }
.site-card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-size: 12px; }
.empty { padding: 20px 12px; color: var(--muted); text-align: center; }

.badge { border-radius: 4px; padding: 1px 6px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.badge.open { color: var(--open); }
.badge.viewable { color: var(--viewable); }
.badge.restricted { color: var(--restricted); }
.badge.plain { color: var(--muted); font-weight: 500; }
.distance { color: var(--muted); }

/* Map */
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 500;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow);
}
.legend div { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.legend .ring { width: 10px; height: 10px; border-radius: 50%; border: 2px dashed var(--muted); }

.step-marker {
  background: var(--accent); color: var(--accent-text); border: 2px solid #fff;
  border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.leaflet-container { font: inherit; }
.leaflet-tooltip { font-size: 13px; }

/* Detail */
.detail {
  position: absolute; top: 12px; right: 12px; bottom: 12px; z-index: 1000;
  width: 400px; max-width: calc(100% - 24px);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow-y: auto; padding: 18px 20px 24px;
}
.detail[hidden] { display: none; }
.detail-close {
  position: sticky; top: 0; float: right; margin: -6px -8px 0 8px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  font-size: 20px; line-height: 1;
}
.detail h2 { margin: 0 0 6px; font-size: 21px; line-height: 1.25; }
.detail .era-line { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.detail .badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.detail .lede { font-weight: 500; margin: 10px 0; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; margin: 14px 0; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail .actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.detail h3 { font-size: 14px; margin: 18px 0 6px; }
.detail .sources { padding-left: 18px; margin: 0; font-size: 14px; }
.detail .sources a { color: var(--focus); }
.detail .credits-list { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.detail .credits-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.detail .credits-list li:last-child { border-bottom: 0; }
.detail .credit-name { font-weight: 600; }
.detail .credit-name a, .detail .credit-empty a { color: var(--focus); }
.detail .credit-role { color: var(--muted); }
.detail .credit-empty { font-size: 14px; color: var(--muted); margin: 0; }
.notice {
  font-size: 13px; padding: 8px 10px; border-radius: 8px; margin: 10px 0;
  background: color-mix(in srgb, var(--viewable) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--viewable) 40%, var(--surface));
}
.notice.danger {
  background: color-mix(in srgb, var(--restricted) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--restricted) 40%, var(--surface));
}

/* About dialog */
dialog {
  max-width: 560px; width: calc(100% - 32px); border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 20px 24px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 10, 20, 0.55); }
dialog h2 { margin-top: 0; }
dialog h3 { font-size: 15px; margin: 16px 0 4px; }
dialog ul { padding-left: 18px; }
.credits { font-size: 12px; color: var(--muted); }
dialog a { color: var(--focus); }

/* Tab bar (mobile only) */
.tabbar { display: none; }

@media (max-width: 767px) {
  .panel { width: 100%; border-right: 0; }
  body[data-view="map"] .panel { display: none; }
  body[data-view="list"] .map-wrap { display: none; }
  .panel-controls { padding: 10px 16px 8px; }
  .site-list { padding: 8px 16px; }
  .filters:not([open]) { margin-bottom: 0; }

  .tabbar {
    display: flex; border-top: 1px solid var(--border); background: var(--surface);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar button {
    flex: 1; padding: 12px 0; background: none; border: 0; color: var(--muted); font-weight: 600;
  }
  .tabbar button[aria-pressed="true"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

  .detail { inset: 0; width: 100%; max-width: none; border-radius: 0; border: 0; padding: 16px; }
  .legend { bottom: 12px; left: 8px; }
  .brand h1 { font-size: 16px; }
}
