/* shadcn/ui neutral tokens (v4), vanilla CSS */
:root {
  --radius: 0.625rem;
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --popover: oklch(1 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);
  --highlight: oklch(0.646 0.222 41.116);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
.dark {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --popover: oklch(0.205 0 0);
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --border: oklch(1 0 0 / 10%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);
  --highlight: oklch(0.769 0.188 70.08);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.43 var(--font);
  color: var(--foreground);
  background: var(--background);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent); }

#map { position: fixed; inset: 0; background: var(--muted); }

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-sm);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 16px; border-radius: calc(var(--radius) - 2px);
  font-weight: 500; white-space: nowrap; transition: background-color .15s, color .15s, opacity .15s;
}
.btn-icon { width: 36px; padding: 0; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: color-mix(in oklch, var(--primary) 90%, transparent); }
.btn-ghost:hover { background: var(--accent); }
.btn-outline { border: 1px solid var(--border); background: var(--background); box-shadow: var(--shadow-xs); }
.btn-outline:hover { background: var(--accent); }
.btn-sm { height: 32px; padding: 0 12px; gap: 6px; font-size: 13px; }

/* Inputs */
.input {
  height: 36px; width: 100%; min-width: 0; padding: 0 12px;
  border: 1px solid var(--input); border-radius: calc(var(--radius) - 2px);
  background: transparent; box-shadow: var(--shadow-xs);
  transition: border-color .15s, box-shadow .15s;
}
.dark .input { background: color-mix(in oklch, var(--input) 30%, transparent); }
.input::placeholder { color: var(--muted-foreground); }
.input:focus-visible { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring) 50%, transparent); }
.input[aria-invalid="true"] { border-color: oklch(0.577 0.245 27.325); }
input[type="search"]::-webkit-search-cancel-button { display: none; }

/* Segmented control (shadcn Tabs list) */
.segmented {
  display: inline-flex; height: 36px; padding: 3px; gap: 2px;
  background: var(--muted); border-radius: var(--radius); flex: none;
}
.segmented button {
  padding: 0 8px; border-radius: calc(var(--radius) - 2px); border: 1px solid transparent;
  font-size: 13px; font-weight: 500; color: var(--muted-foreground); transition: color .15s, background-color .15s;
}
.segmented button[aria-checked="true"] { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }
.dark .segmented button[aria-checked="true"] { background: color-mix(in oklch, var(--input) 30%, transparent); border-color: var(--input); }

/* Switch */
.switch { width: 32px; height: 18.4px; border-radius: 999px; background: var(--input); padding: 1px; display: inline-flex; transition: background-color .15s; flex: none; }
.switch span { width: 16px; height: 16px; border-radius: 999px; background: var(--background); transition: transform .15s; }
.dark .switch span { background: var(--foreground); }
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"] span { transform: translateX(14px); }
.dark .switch[aria-checked="true"] span { background: var(--primary-foreground); }

/* Badge */
.badge {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; gap: 4px;
  border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px);
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.badge-secondary { background: var(--secondary); border-color: transparent; }

.skeleton { background: var(--accent); border-radius: calc(var(--radius) - 2px); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* Panel */
.panel {
  position: fixed; top: 12px; left: 12px; width: 384px; max-height: calc(100dvh - 120px);
  display: flex; flex-direction: column; gap: 12px; padding: 16px; z-index: 2;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: -6px -6px -4px 0; }
.brand { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.row { display: flex; gap: 8px; }
.field { position: relative; }
.field-icon { position: absolute; left: 11px; top: 10px; color: var(--muted-foreground); pointer-events: none; }
.search .input { padding-left: 34px; }

.results { position: absolute; top: 42px; left: 0; right: 0; padding: 4px; z-index: 5; box-shadow: var(--shadow-md); border-radius: calc(var(--radius) - 2px); }
.results button, .menu-item {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: calc(var(--radius) - 4px);
}
.results button:hover, .results button[aria-selected="true"], .menu-item:hover { background: var(--accent); }
.results small, .muted { color: var(--muted-foreground); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--muted-foreground); transition: all .15s;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }

.summary {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-top: 12px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; text-align: left;
}
.summary svg { transition: transform .15s; }
.summary[aria-expanded="false"] svg { transform: rotate(-90deg); }

.list { list-style: none; margin: -4px -8px -8px; padding: 0 0 4px; overflow-y: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; }
.list li button {
  display: grid; grid-template-columns: 1fr auto; gap: 0 12px; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: calc(var(--radius) - 2px);
}
.list li button:hover, .list li button[aria-current="true"] { background: var(--accent); }
.list .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.list .d { color: var(--muted-foreground); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.list .k { grid-column: 1 / -1; color: var(--muted-foreground); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .more { padding: 8px; color: var(--muted-foreground); font-size: 12px; }

/* Menu */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 40px; width: 236px; padding: 4px; z-index: 6; box-shadow: var(--shadow-md); border-radius: calc(var(--radius) - 2px); }
.menu-label { padding: 6px 8px 4px; font-size: 12px; color: var(--muted-foreground); font-weight: 500; }
.menu .segmented { display: flex; margin: 0 4px 4px; }
.menu .segmented button { flex: 1; }
.menu-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; cursor: pointer; }
.menu-item { flex-direction: row; gap: 4px; }
.sep { height: 1px; background: var(--border); margin: 4px -4px; }
code { font-family: var(--mono); font-size: 12px; }

/* Time bar */
.timebar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  width: min(880px, calc(100vw - 24px)); padding: 10px 12px; z-index: 2;
  display: flex; align-items: center; gap: 8px;
}
.timebar .i-pause { display: none; }
.timebar.playing .i-play { display: none; }
.timebar.playing .i-pause { display: block; }
.slider-wrap { flex: 1; position: relative; padding: 6px 8px 14px; min-width: 0; }
.year {
  min-width: 92px; text-align: right; font-size: 22px; font-weight: 600; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; padding-right: 4px;
}
.ticks { position: absolute; left: 16px; right: 16px; bottom: -2px; height: 14px; }
.ticks span { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--muted-foreground); font-variant-numeric: tabular-nums; white-space: nowrap; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 16px; margin: 0; background: transparent; display: block;
  --pct: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--primary) var(--pct), var(--muted) var(--pct));
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--muted); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--primary); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5px; border-radius: 999px;
  background: var(--background); border: 1px solid var(--primary); box-shadow: var(--shadow-sm); transition: box-shadow .15s;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 999px; background: var(--background); border: 1px solid var(--primary); box-shadow: var(--shadow-sm);
}
input[type="range"]:hover::-webkit-slider-thumb, input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px color-mix(in oklch, var(--ring) 50%, transparent); }
input[type="range"]:focus-visible { box-shadow: none; }

/* Sheet */
.sheet {
  position: fixed; top: 12px; right: 12px; bottom: 96px; width: 384px; z-index: 3;
  overflow-y: auto; padding: 20px; box-shadow: var(--shadow-md);
  animation: sheet-in .2s ease-out;
}
@keyframes sheet-in { from { transform: translateX(16px); opacity: 0; } }
.sheet-close { position: absolute; top: 10px; right: 10px; opacity: .7; }
.sheet-close:hover { opacity: 1; }
.sheet h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; margin: 0 32px 4px 0; }
.sheet .meta { color: var(--muted-foreground); font-size: 13px; font-variant-numeric: tabular-nums; }
.sheet .badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.sheet img { width: 100%; aspect-ratio: 16 / 10; max-height: 240px; object-fit: cover; border-radius: calc(var(--radius) - 2px); background: var(--muted); display: block; margin: 12px 0; }
.sheet p { margin: 12px 0; line-height: 1.6; }
.sheet .src { color: var(--muted-foreground); font-size: 12px; }
.sheet .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.sheet a { text-decoration: none; }
.sheet a:not(.btn-primary) { color: inherit; }
.sheet .timeline { list-style: none; padding: 0; margin: 12px -8px 0; }
.sheet .timeline li button { display: grid; grid-template-columns: 76px 1fr; gap: 12px; width: 100%; text-align: left; padding: 6px 8px; border-radius: calc(var(--radius) - 2px); }
.sheet .timeline li button:hover { background: var(--accent); }
.sheet .timeline .d { color: var(--muted-foreground); font-size: 12px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.sheet .credits p { margin: 8px 0; font-size: 13px; }
.sheet .credits a { text-decoration: underline; text-underline-offset: 3px; }

/* Tooltip and toast */
.tip {
  position: fixed; z-index: 4; pointer-events: none; padding: 6px 10px; max-width: 280px;
  background: var(--primary); color: var(--primary-foreground); border-radius: calc(var(--radius) - 2px);
  font-size: 12px; line-height: 1.35; transform: translate(-50%, calc(-100% - 12px));
}
.tip small { opacity: .7; display: block; }
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 7;
  padding: 10px 14px; background: var(--popover); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); font-size: 13px;
}

/* MapLibre controls in shadcn clothes */
.maplibregl-ctrl-group { background: var(--card) !important; border: 1px solid var(--border); border-radius: calc(var(--radius) - 2px) !important; box-shadow: var(--shadow-sm) !important; overflow: hidden; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--border) !important; }
.dark .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-attrib { background: color-mix(in oklch, var(--card) 80%, transparent) !important; color: var(--muted-foreground); font-size: 11px; }
.maplibregl-ctrl-attrib a { color: inherit !important; }
.maplibregl-ctrl-attrib-button { filter: none; }
.dark .maplibregl-ctrl-attrib-button { filter: invert(1); }
.maplibregl-ctrl-bottom-right { bottom: 96px; }
.maplibregl-ctrl-top-right { top: 4px; }

/* Phone */
@media (max-width: 720px) {
  .panel { top: 8px; left: 8px; right: 8px; width: auto; padding: 12px; gap: 10px; max-height: calc(100dvh - 170px); }
  .row .input { flex: 1; }
  .row .segmented button { padding: 0 7px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 0 12px; scrollbar-width: none; }
  .chip { flex: none; }
  .timebar { bottom: max(8px, env(safe-area-inset-bottom)); flex-wrap: wrap; padding: 8px; gap: 4px 6px; }
  .timebar .slider-wrap { order: 5; flex-basis: 100%; }
  .timebar .year { margin-left: auto; font-size: 18px; }
  .sheet { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62dvh; animation-name: sheet-up; }
  @keyframes sheet-up { from { transform: translateY(16px); opacity: 0; } }
  .maplibregl-ctrl-bottom-right { bottom: 132px; }
  .toast { bottom: 140px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
