:root {
  --bg: #0b1020;
  --surface: #131a2e;
  --surface-2: #1a2340;
  --line: #26304f;
  --text: #e6ebf7;
  --muted: #8f9bbd;
  --accent: #ffd166;      /* ISS / sunlit */
  --accent-2: #7aa2ff;    /* shadow / UI */
  --exc: #4ade80;
  --good: #2dd4bf;
  --fair: #fbbf24;
  --poor: #6b7591;
  --danger: #f87171;
  --radius: 14px;
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
}
a { color: var(--accent-2); }
h2 { font-size: 1.02rem; margin: 0 0 .6rem; font-weight: 650; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  position: relative; z-index: 1001;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.chip {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: .4rem .8rem; font: inherit; font-size: .88rem;
  max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
/* phones: the icon alone names the app, the location badge gets the room */
@media (max-width: 420px) {
  .brand span { display: none; }
  .chip { max-width: calc(100vw - 80px); }
}

main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }
#view-passes, #view-alerts, #view-about { padding: 14px 16px calc(var(--tabbar-h) + var(--safe-b) + 16px); }
#view-passes > *, #view-alerts > *, #view-about > * { max-width: 720px; margin-left: auto; margin-right: auto; }

/* ---------- live ---------- */
#view-live { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
.map-wrap { position: relative; flex: 0 0 46%; min-height: 240px; }
#map { position: absolute; inset: 0; background: #0a0f1c; }
.live-panel { flex: 1; overflow-y: auto; padding: 14px 16px calc(var(--tabbar-h) + var(--safe-b) + 16px); }
@media (min-width: 900px) {
  #view-live { flex-direction: row; }
  .map-wrap { flex: 1 1 auto; }
  .live-panel { flex: 0 0 400px; border-left: 1px solid var(--line); }
}
.leaflet-popup.map-tip .leaflet-popup-content-wrapper {
  background: rgba(19, 26, 46, .97); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, .5);
}
.leaflet-popup.map-tip .leaflet-popup-content { margin: .5rem .7rem; font-size: .8rem; line-height: 1.4; }
.leaflet-popup.map-tip .leaflet-popup-tip { background: rgba(19, 26, 46, .97); }
.leaflet-popup.map-tip i { color: var(--muted); }
/* mouse long-press feedback: fills while held, solid when releasing will set the location */
.press-ring { position: absolute; z-index: 650; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%;
  border: 3px solid #f472b6; pointer-events: none; opacity: 0; transform: scale(.25); }
.press-ring.on { opacity: .9; transform: scale(1); transition: transform .6s linear, opacity .15s; }
.press-ring.ready { background: rgba(244, 114, 182, .35); }

.iss-icon { filter: drop-shadow(0 0 6px rgba(255, 209, 102, .7)); transition: filter .5s; }
.iss-icon.eclipsed { filter: drop-shadow(0 0 4px rgba(122, 162, 255, .7)) grayscale(.6) brightness(.8); }
.leaflet-container { font: inherit; background: #05070d; }
/* overlap tiles by half a pixel: some browsers leave hairline gaps between them */
.imagery .leaflet-tile { width: 256.5px !important; height: 256.5px !important; }
.leaflet-control-attribution { background: rgba(11, 16, 32, .7) !important; color: var(--muted) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); }
path.track-past { stroke: #8f9bbd; stroke-opacity: .45; stroke-width: 2; fill: none; stroke-dasharray: 3 5; }
path.track-lit { stroke: var(--accent); stroke-width: 2.5; fill: none; }
path.track-dark { stroke: var(--accent-2); stroke-width: 2.5; fill: none; stroke-opacity: .85; }
path.foot-horizon { stroke: #5eead4; stroke-opacity: .35; stroke-width: 1; fill: #5eead4; fill-opacity: .04; stroke-dasharray: 4 4; }
path.foot-visible { stroke: #5eead4; stroke-opacity: .8; stroke-width: 1.5; fill: #5eead4; fill-opacity: .08; }
path.observer { stroke: #fff; stroke-width: 2; fill: #f472b6; fill-opacity: 1; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .4rem .65rem; min-width: 0; display: flex; justify-content: space-between; align-items: baseline; gap: .4rem; }
.stat .k { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .95rem; white-space: nowrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.card-head h2 { margin: 0; }
.look { display: flex; align-items: center; gap: 12px; }
.look .big { font-size: 1.05rem; font-weight: 650; }
.look .sub { color: var(--muted); font-size: .86rem; }
.look.up { border-color: var(--accent); background: linear-gradient(135deg, rgba(255, 209, 102, .12), transparent 60%); }
.compass { width: 54px; height: 54px; flex: 0 0 54px; }
.compass circle { fill: var(--surface-2); stroke: var(--line); }
.compass text { fill: var(--muted); font-size: 9px; font-weight: 700; }
.compass .needle { fill: var(--accent); }

.next-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .2rem; }
.countdown { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 650; }
.fine { color: var(--muted); font-size: .76rem; margin: .8rem 0; }
.hint { color: var(--muted); font-size: .86rem; margin: .3rem 0 .7rem; }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }

/* ---------- passes ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: 14px 0 6px; flex-wrap: wrap; }
.list-head { color: var(--muted); font-size: .84rem; margin: 4px 2px 0; }
.day-head { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; margin: 14px 2px 6px; }
.pass { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.pass.target { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255, 209, 102, .25); }
.pass-head { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; list-style: none; }
.pass-head::-webkit-details-marker { display: none; }
.when .time { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.when .dur { color: var(--muted); font-size: .76rem; }
.meta { font-size: .86rem; min-width: 0; }
.meta .dir { color: var(--muted); }
.score-wrap { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 60px; }
.score {
  width: 46px; height: 46px; border-radius: 50%; border: 3px solid currentColor; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  font-weight: 750; font-size: 1.1rem; line-height: 1; font-variant-numeric: tabular-nums;
}
.score-label { font-size: .62rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; line-height: 1; }
.exc { color: var(--exc); } .good { color: var(--good); } .fair { color: var(--fair); } .poor { color: var(--poor); }
.badge { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-right: .25rem; white-space: nowrap; }
.badge.ok { color: var(--exc); }
.pass-body { padding: 0 14px 14px; display: grid; grid-template-columns: minmax(0, 220px) 1fr; gap: 14px; align-items: start; }
@media (max-width: 520px) { .pass-body { grid-template-columns: 1fr; } .pass-body .skychart { max-width: 260px; margin: 0 auto; } }
.pass-body table { width: 100%; border-collapse: collapse; font-size: .84rem; font-variant-numeric: tabular-nums; }
.pass-body td, .pass-body th { padding: .25rem .3rem; text-align: left; border-bottom: 1px solid var(--line); }
.pass-body th { color: var(--muted); font-weight: 500; }
.wxrow { font-size: .84rem; margin: .5rem 0; }
.factors { display: grid; grid-template-columns: auto 1fr auto auto; gap: 4px 8px; align-items: center; font-size: .78rem; color: var(--muted); margin: .6rem 0 .3rem; }
.factors .pct { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.factors .why { font-variant-numeric: tabular-nums; }
.equation { font-size: .8rem; color: var(--muted); margin: .2rem 0 .4rem; font-variant-numeric: tabular-nums; }
.equation b { color: var(--text); }
.equation a { margin-left: .4rem; }

/* scoring explainer */
.explain h3 { font-size: .9rem; margin: 1rem 0 .3rem; color: var(--accent); }
.explain p, .explain li { font-size: .88rem; color: var(--muted); }
.explain li b, .explain p b { color: var(--text); }
.explain ul { padding-left: 1.2rem; margin: .4rem 0; }
.explain-table { border-collapse: collapse; font-size: .85rem; width: 100%; }
.explain-table th { text-align: left; vertical-align: top; padding: .4rem .7rem .4rem 0; white-space: nowrap; font-weight: 600; }
.explain-table td { color: var(--muted); padding: .4rem 0; border-bottom: 1px solid var(--line); }
.explain-table tr:last-child td { border-bottom: 0; }
.explain-table ul { margin: .3rem 0; }
.explain-table li { font-size: .85rem; }
.mag-table { border-collapse: collapse; margin-top: .4rem; }
.explain-table .mag-table td { padding: .15rem .8rem .15rem 0; border: 0; }
.mag-table td:first-child, .mag-table td:last-child { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }

/* about */
.about-head { display: flex; align-items: center; gap: 14px; }
.about-head h2 { margin: 0; font-size: 1.15rem; }
.about-head .hint { margin: .2rem 0 0; }
.about-list { padding-left: 1.1rem; margin: 0; font-size: .88rem; color: var(--muted); }
.about-list li { margin: .35rem 0; }
.about-list b { color: var(--text); }
.bar { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--good); border-radius: 3px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: .6rem; }

.skychart { width: 100%; height: auto; display: block; }
.sky-bg { fill: #0d1428; stroke: var(--line); stroke-width: 1.5; }
.sky-ring { fill: none; stroke: var(--line); stroke-width: 1; }
.sky-ring-label { fill: var(--muted); font-size: 8px; }
.sky-cardinal { fill: var(--muted); font-size: 11px; font-weight: 700; }
.skychart polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.sky-vis { stroke: var(--accent); stroke-width: 4; }
.sky-lit { stroke: var(--accent); stroke-opacity: .4; stroke-width: 2; stroke-dasharray: 2 4; }
.sky-dark { stroke: var(--accent-2); stroke-opacity: .5; stroke-width: 2; stroke-dasharray: 2 4; }
.sky-arrow { fill: var(--accent); }
.sky-start, .sky-end, .sky-max { fill: var(--bg); stroke: var(--accent); stroke-width: 2; }
.sky-label { fill: var(--text); font-size: 10px; font-weight: 600; paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.sky-live { fill: #fff; stroke: var(--accent); stroke-width: 3; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { stroke-width: 7; stroke-opacity: .4; } }

/* ---------- forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  background: var(--accent); color: #1b1300; border: 0; border-radius: 10px;
  padding: .55rem .9rem; font: inherit; font-weight: 600; font-size: .88rem; cursor: pointer; text-decoration: none;
}
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row input { flex: 1; min-width: 0; }
.field { margin: .75rem 0; }
.field label { display: flex; justify-content: space-between; font-size: .86rem; margin-bottom: .3rem; }
.field output { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
/* Sliders: grey track, yellow fill between --a and --b (fractions 0-1), yellow knobs.
   The fill stops are offset by half a knob, matching where the browser draws the knob. */
input[type=range] {
  --a: -1; --b: 0; --knob: 18px; /* --a below 0: single sliders fill from the very start of the track */
  -webkit-appearance: none; appearance: none; width: 100%; height: 24px; margin: 0; background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right,
    var(--line) calc(var(--knob) / 2 + (100% - var(--knob)) * var(--a)), var(--accent) 0,
    var(--accent) calc(var(--knob) / 2 + (100% - var(--knob)) * var(--b)), var(--line) 0);
}
input[type=range]::-moz-range-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right,
    var(--line) calc(var(--knob) / 2 + (100% - var(--knob)) * var(--a)), var(--accent) 0,
    var(--accent) calc(var(--knob) / 2 + (100% - var(--knob)) * var(--b)), var(--line) 0);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: var(--knob); height: var(--knob); margin-top: calc(2px - var(--knob) / 2);
  border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--accent);
}
input[type=range]::-moz-range-thumb {
  width: calc(var(--knob) - 4px); height: calc(var(--knob) - 4px);
  border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--accent);
}
input[type=range]:focus-visible { outline: none; }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent-2); }
input[type=range]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--accent-2); }

/* two knobs on one track: only the knobs take the pointer; the second track is see-through */
.dual { position: relative; height: 24px; }
.dual input { position: absolute; inset: 0; pointer-events: none; --a: inherit; --b: inherit; }
.dual input::-webkit-slider-thumb { pointer-events: auto; }
.dual input::-moz-range-thumb { pointer-events: auto; }
.dual input + input::-webkit-slider-runnable-track { background: none; }
.dual input + input::-moz-range-track { background: none; }
.scale { display: flex; justify-content: space-between; font-size: .7rem; color: var(--muted); padding: 0 2px; font-variant-numeric: tabular-nums; }
input:not([type]), input[type=url], input[type=search], select {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: .55rem .7rem; font: inherit;
}
.switch { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .88rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { width: 42px; height: 24px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; position: relative; transition: background .2s; flex: 0 0 42px; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .2s, background .2s; }
.switch input:checked + span { background: rgba(255, 209, 102, .25); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.switch:has(input:disabled) { cursor: not-allowed; }
.switch input:disabled + span { opacity: .4; }
.status { list-style: none; padding: 0; margin: .4rem 0 .8rem; font-size: .84rem; }
.status li { padding: .2rem 0; display: flex; gap: .5rem; }
.status li > span:first-child { flex: 0 0 1.1em; text-align: center; font-weight: 700; } /* icons of different widths, text in one column */
.btn.small { padding: .3rem .7rem; font-size: .8rem; border-radius: 8px; margin: .3rem 0 .1rem; }
.status .ok { color: var(--exc); } .status .warn { color: var(--fair); } .status .bad { color: var(--danger); } .status .info { color: var(--muted); }
.log summary { cursor: pointer; color: var(--muted); font-size: .84rem; margin-top: .6rem; }
.log ul { font-size: .76rem; color: var(--muted); list-style: none; padding-left: 0; font-variant-numeric: tabular-nums; }
.log li { padding: .15rem 0; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
  display: flex; height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(11, 16, 32, .96); border-top: 1px solid var(--line); backdrop-filter: blur(8px);
}
.tabbar a { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .72rem; white-space: nowrap; }
.tabbar a span { font-size: 1.25rem; filter: grayscale(1) opacity(.7); }
.tabbar a.active { color: var(--accent); }
.tabbar a.active span { filter: none; }

/* ---------- dialog / toast ---------- */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 0; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlg { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.or { text-align: center; color: var(--muted); font-size: .8rem; }
.results { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
.results li button { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); padding: .6rem .3rem; font: inherit; cursor: pointer; }
.results li small { color: var(--muted); }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .9rem; font-size: .88rem;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 2000; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
