:root {
  --bg: #0d1322;
  --panel: rgba(17, 22, 35, 0.9);
  --panel-solid: #121724;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef1f6;
  --text-2: #b4bccb;
  --text-3: #8791a4;
  --accent: #ffb454;
  --accent-ink: #2a1a00;
  --radius: 14px;
  --gap: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
body { font-size: 14px; line-height: 1.4; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

#map { position: absolute; inset: 0; }
.maplibregl-canvas { cursor: crosshair; }
.maplibregl-ctrl-bottom-right { bottom: 96px; right: 4px; }
.maplibregl-ctrl-group { background: var(--panel-solid); border: 1px solid var(--line); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-attrib { background: rgba(13, 19, 34, 0.75) !important; color: var(--text-3); }
.maplibregl-ctrl-attrib a { color: var(--text-2); }
.maplibregl-ctrl-attrib-button { filter: invert(1); }

.panel {
  position: absolute; z-index: 5;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

/* ── top bar ── */
#topbar {
  position: absolute; z-index: 6; top: var(--gap); left: var(--gap); right: var(--gap);
  display: flex; align-items: center; gap: 10px; pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 42px; white-space: nowrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 21px; font-weight: 650; letter-spacing: 0.01em;
}
.brand-mark { width: 14px; height: 14px; border-radius: 50%; background: linear-gradient(135deg, #f8cf8a, #e0562f 60%, #3b74c4); }
#search { position: relative; flex: 0 1 300px; min-width: 150px; }
#search-input {
  width: 100%; height: 42px; padding: 0 16px; border-radius: 21px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit;
}
#search-input::placeholder { color: var(--text-3); }
#search-results {
  position: absolute; top: 48px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
#search-results button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 8px; color: var(--text-2); }
#search-results button:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }
#search-results .muted { padding: 8px 10px; color: var(--text-3); }

#layers, .seg {
  display: flex; padding: 4px; gap: 2px; height: 42px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 21px;
}
#layers button, .seg button {
  border: 0; background: none; padding: 0 14px; border-radius: 17px; color: var(--text-2); white-space: nowrap; font-weight: 550;
}
#layers button:hover:not(:disabled), .seg button:hover { color: var(--text); }
#layers button.on, .seg button.on { background: var(--accent); color: var(--accent-ink); }
#layers button:disabled { opacity: 0.4; cursor: default; }
.top-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.chip-btn {
  height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--text-2); white-space: nowrap;
}
.chip-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.1); }
.chip-btn.on { color: var(--accent); border-color: rgba(255, 180, 84, 0.5); }
#spots-btn { height: 42px; border-radius: 21px; background: var(--panel); padding: 0 14px; }
.icon-btn { width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.06); color: var(--text-2); flex: none; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.14); color: var(--text); }
.icon-btn.small { width: 24px; height: 24px; font-size: 11px; }

/* ── finder ── */
#finder { top: 66px; left: var(--gap); width: 272px; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 12px 14px; border: 0; background: none; font-weight: 650; font-size: 15px;
}
.chev { color: var(--text-3); transition: transform 0.2s; }
#finder.collapsed .chev { transform: rotate(-90deg); }
#finder.collapsed .panel-body { display: none; }
.panel-body { padding: 0 14px 14px; }
.hint { margin: 0 0 10px; color: var(--text-3); font-size: 13px; }
.crit { padding: 8px 0 4px; border-top: 1px solid var(--line); }
.crit-top { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.crit-top input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.crit-text { color: var(--text-2); }
.crit.on .crit-text { color: var(--text); }
.crit output { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 650; color: var(--text-3); }
.crit.on output { color: var(--accent); }
.crit input[type=range] { width: 100%; margin: 6px 0 2px; accent-color: var(--accent); opacity: 0.55; }
.crit.on input[type=range] { opacity: 1; }
.crit.disabled { opacity: 0.45; }
.view-switch { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.view-switch .label { display: block; color: var(--text-3); font-size: 12px; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.seg.wide { height: 36px; background: rgba(255, 255, 255, 0.05); }
.seg.wide button { flex: 1; padding: 0 8px; font-size: 13px; }

/* ── legend ── */
#legend { left: var(--gap); bottom: 96px; width: 272px; padding: 12px 14px 10px; }
.lg-title { font-weight: 650; }
.lg-sub { color: var(--text-3); font-size: 12px; margin-bottom: 8px; }
.lg-bar { position: relative; height: 12px; border-radius: 6px; }
.lg-mark { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); }
.lg-ticks { position: relative; height: 18px; margin-top: 4px; font-size: 11.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.lg-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.lg-ticks.even { display: flex; justify-content: space-between; }
.lg-ticks.even span { position: static; transform: none; }
.lg-steps { display: grid; grid-template-columns: repeat(13, 1fr); gap: 2px; }
.lg-steps i { height: 12px; border-radius: 2px; }
body.busy #legend .lg-title::after { content: " · loading…"; color: var(--text-3); font-weight: 400; }

/* ── month bar ── */
#monthbar {
  left: 50%; transform: translateX(-50%); bottom: 34px; display: flex; align-items: center; gap: 6px; padding: 6px;
  border-radius: 26px; max-width: calc(100vw - 2 * var(--gap));
}
#play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.08); flex: none; font-size: 13px; }
#play:hover { background: rgba(255, 255, 255, 0.16); }
#months { display: flex; gap: 2px; }
#months button { border: 0; background: none; height: 40px; min-width: 46px; padding: 0 6px; border-radius: 20px; color: var(--text-2); font-weight: 550; }
#months button:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
#months button.on { background: var(--accent); color: var(--accent-ink); }
#months .tiny { display: none; }
body.view-count #months button.on { background: rgba(255, 255, 255, 0.14); color: var(--text); }

/* ── card ── */
#card, #spots {
  top: 66px; right: var(--gap); width: 360px; max-height: calc(100vh - 66px - 96px); overflow-y: auto; padding: 14px 16px 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 18px; line-height: 1.25; }
.card-head .sub { margin: 2px 0 0; color: var(--text-3); font-size: 12.5px; }
.card-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.match { padding: 10px 12px; border-radius: 10px; background: rgba(255, 180, 84, 0.08); border: 1px solid rgba(255, 180, 84, 0.22); margin-bottom: 6px; }
.match.plain { background: rgba(255, 255, 255, 0.04); border-color: var(--line); }
.match-head { color: var(--text-2); }
.match-head b { color: var(--text); }
.match-cells { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; margin: 8px 0 6px; }
.match-cells i { font-style: normal; text-align: center; font-size: 11px; padding: 3px 0; border-radius: 4px; background: rgba(255, 255, 255, 0.06); color: var(--text-3); }
.match-cells i.yes { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.match-sub { color: var(--text-3); font-size: 12.5px; }
.chart-block { padding-top: 12px; }
.ch-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ch-title { color: var(--text-2); font-size: 13px; }
.ch-read { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ch-read i { font-style: normal; color: var(--text-3); font-size: 12.5px; margin-right: 4px; }
.ch-read b { font-size: 17px; }
.ch-read span { color: var(--text-2); font-size: 12.5px; margin-left: 4px; }
.ch-vals { display: flex; flex-wrap: wrap; gap: 4px 12px; font-variant-numeric: tabular-nums; color: var(--text); font-size: 13px; }
.ch-vals i, .spot-list i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.note { margin: 12px 0 0; color: var(--text-3); font-size: 12.5px; }
.spot-list { list-style: none; margin: 0 0 4px; padding: 0; }
.spot-list li { display: flex; align-items: center; gap: 4px; padding: 3px 0; }
.spot-name { flex: 1; text-align: left; border: 0; background: none; padding: 4px 2px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spot-name:hover { color: var(--accent); }

/* ── charts ── */
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.c-band { fill: rgba(255, 255, 255, 0.07); }
.c-cross { stroke: rgba(255, 255, 255, 0.45); stroke-width: 1; }
.c-base { stroke: rgba(255, 255, 255, 0.14); stroke-width: 1; }
.c-thresh { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0.8; }
.c-line { fill: none; stroke: #9aa5b8; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { stroke: var(--panel-solid); stroke-width: 2; }
.c-val { fill: var(--text-2); font-size: 10.5px; text-anchor: middle; font-variant-numeric: tabular-nums; }
.c-tick { fill: var(--text-3); font-size: 10px; text-anchor: middle; }
.c-tick.on { fill: var(--text); font-weight: 700; }
.c-hit { fill: transparent; cursor: pointer; }

/* ── misc ── */
.pin { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 4px solid #10131c; box-shadow: 0 0 0 2px #fff, 0 3px 10px rgba(0, 0, 0, 0.6); }
#hover {
  position: absolute; z-index: 4; top: 0; left: 0; pointer-events: none; padding: 5px 9px; border-radius: 8px;
  background: rgba(10, 14, 24, 0.92); border: 1px solid var(--line); font-size: 13px; color: var(--text-2); white-space: nowrap;
}
#hover b { color: var(--text); }
#toast {
  position: absolute; z-index: 20; left: 50%; bottom: 110px; transform: translateX(-50%); padding: 10px 16px; border-radius: 20px;
  background: #f4f6fa; color: #141824; font-weight: 550; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); max-width: 90vw; text-align: center;
}
#credits {
  position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; padding: 6px 12px; font-size: 11.5px; color: var(--text-3);
  background: rgba(13, 19, 34, 0.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
}
#credits button { border: 0; background: none; padding: 0; color: var(--text-2); text-decoration: underline; font-size: inherit; }
dialog#about { max-width: 560px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-solid); color: var(--text); padding: 20px 22px; }
dialog#about::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog#about h2 { margin: 0 0 8px; }
dialog#about li { margin-bottom: 8px; color: var(--text-2); }
dialog#about p { color: var(--text-2); }
dialog#about b { color: var(--text); }
dialog#about button { margin-top: 6px; padding: 8px 18px; border-radius: 18px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 650; }

/* ── tablets ── */
@media (max-width: 1100px) {
  .brand-name { display: none; }
  .brand { padding: 0 13px; }
  #months button { min-width: 38px; }
}

/* ── phones ── */
@media (max-width: 760px) {
  :root { --gap: 8px; }
  #topbar { flex-wrap: wrap; gap: 6px; }
  .brand { display: none; }
  #search { flex: 1 1 auto; order: 1; }
  .top-right { order: 2; gap: 6px; }
  #layers { order: 3; flex: 1 1 100%; }
  #layers button { flex: 1; padding: 0 6px; font-size: 13px; }
  #finder { top: 106px; width: min(272px, calc(100vw - 16px)); }
  #finder.collapsed { width: auto; }
  #finder.collapsed .panel-head { padding: 9px 12px; font-size: 13.5px; gap: 8px; }
  #legend { bottom: 86px; width: 210px; padding: 9px 11px 7px; }
  body.has-card #legend { display: none; }
  #monthbar { bottom: 26px; width: calc(100vw - 16px); padding: 4px; }
  #months { flex: 1; }
  #months button { flex: 1; min-width: 0; padding: 0; height: 38px; }
  #months .full { display: none; }
  #months .tiny { display: inline; }
  #play { width: 38px; height: 38px; }
  #card, #spots { top: auto; bottom: 76px; left: 8px; right: 8px; width: auto; max-height: 52vh; }
  .maplibregl-ctrl-bottom-right { display: none; }
  #credits { font-size: 10px; padding: 4px 8px; }
  #hover { display: none; }
}
