/* SPDX-License-Identifier: MIT */
/* Copyright (C) 2026 Justin McAllister K5EM */
/* Themes: dark is the default (and [data-theme="dark"]); [data-theme="light"] overrides the colours. js/theme.js
   sets data-theme before the first paint. The canvas code reads the --place-fill*, --line-* and --night-*
   values (lines.js themeVars), so a theme switch only has to repaint. */
:root {
  color-scheme: dark;
  --ocean: #070e18;
  --land: #1d2b3b;
  --coast: rgba(170, 200, 230, .30);
  --border: rgba(200, 220, 240, .30);
  --admin: rgba(200, 220, 240, .17);
  --lake-edge: rgba(170, 200, 230, .18);
  --sphere-edge: rgba(170, 200, 230, .35);
  --grid: rgba(200, 220, 240, .16);
  --grid-text: rgba(200, 220, 240, .6);
  --grid-halo: rgba(7, 14, 24, .8);
  --accent: #8cc8ff;
  --page: #060b12;
  --text: #e8edf3;
  --muted: #93a1b2;
  --panel: rgba(9, 15, 24, .82);
  --edge: rgba(255, 255, 255, .14);
  --shadow: rgba(0, 0, 0, .55);
  --btn-hover: rgba(30, 44, 62, .92);
  --focus: #7fb4ff;
  --pressed-bg: rgba(40, 70, 105, .9);
  --hud-shadow: 0 1px 3px rgba(0, 0, 0, .9);
  --hud-muted: var(--muted);
  --hb-rule: rgba(200, 215, 235, .3);
  --hb-on: #fff;
  --count-col: #c3cfdc;
  --count-track: rgba(200, 215, 235, .10);
  --bar-bg: rgba(7, 12, 19, .96);
  --play-bg: rgba(40, 70, 105, .9);
  --play-hover: rgba(55, 92, 135, .95);
  --play-edge: rgba(140, 200, 255, .45);
  --play-fg: #fff;
  --on-edge: rgba(140, 200, 255, .4);
  --sel-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2393a1b2' stroke-width='1.5'/%3E%3C/svg%3E");
  --option-bg: #101824;
  --scrub-track: rgba(255, 255, 255, .035);
  --scrub-hist: rgba(200, 215, 235, .22);
  --scrub-tick: rgba(200, 215, 235, .35);
  --head: #fff;
  --knob-edge: rgba(7, 12, 19, .9);
  --hint-bg: rgba(0, 0, 0, .78);
  --trend-bg: rgba(9, 15, 24, .72);
  --trend-bg-solid: #0a111b;
  --endcard-bg: rgba(9, 15, 24, .9);
  --endcard-edge: rgba(140, 200, 255, .35);
  --endcard-shadow: rgba(0, 0, 0, .6);
  --error-edge: rgba(255, 110, 110, .55);
  /* canvas (lines.js): place activity fill, line compositing, night overlay */
  --place-fill: #3a5f86;
  --place-fill-max: .3;
  --line-blend: lighter;
  --night-rgb: 0, 2, 10;
  --night-alpha: .045;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --bar-h: calc(72px + var(--safe-b));
  --gap: 12px;
}
@media (max-width: 699px), (orientation: portrait) {
  :root { --gap: 8px; }
}
@media (max-width: 699px) {
  :root { --bar-h: calc(150px + var(--safe-b)); }
}
/* Light: the map palette of cwskimviz's light theme (ocean, land, borders, coast), panels in warm white. */
:root[data-theme="light"] {
  color-scheme: light;
  /* a mid-light basemap after Google Maps' (PSKReporter's) tiles: sky-blue water, warm grey-beige land, glaciers
     a little whiter. The light band colours are at their 1.8:1 contrast floor on this ocean
     (tests/band-colors.test.mjs) */
  --ocean: #a1c6e6;
  --land: #d1ccbf;
  --glacier: #e4e2db;
  --coast: rgba(79, 76, 69, .75);
  --border: #6f6b62;
  --admin: rgba(111, 107, 98, .5);
  --lake-edge: rgba(79, 76, 69, .35);
  --sphere-edge: rgba(79, 76, 69, .5);
  --grid: rgba(60, 70, 85, .22);
  --grid-text: rgba(50, 55, 65, .75);
  --grid-halo: rgba(240, 240, 236, .8);
  --accent: #1d65b8;
  --page: #e8e7e1;
  --text: #1a1a18;
  --muted: #54524c;
  --panel: rgba(255, 255, 255, .88);
  --edge: rgba(20, 20, 19, .18);
  --shadow: rgba(40, 38, 30, .22);
  --btn-hover: rgba(236, 235, 229, .96);
  --focus: #2a78d6;
  --pressed-bg: rgba(42, 120, 214, .14);
  --hud-shadow: 0 0 2px rgba(252, 251, 247, 1), 0 0 4px rgba(252, 251, 247, .9), 0 0 9px rgba(252, 251, 247, .8);
  --hud-muted: #3f3d38;
  --hb-rule: rgba(20, 20, 19, .28);
  --hb-on: #1a1a18;
  --count-col: #5d5a52;
  --count-track: rgba(20, 20, 19, .08);
  --bar-bg: rgba(250, 249, 245, .97);
  --play-bg: #2a78d6;
  --play-hover: #1f68c0;
  --play-edge: #1f68c0;
  --play-fg: #fff;
  --on-edge: rgba(42, 120, 214, .5);
  --sel-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235f5d57' stroke-width='1.5'/%3E%3C/svg%3E");
  --option-bg: #fff;
  --scrub-track: rgba(20, 20, 19, .04);
  --scrub-hist: rgba(70, 68, 60, .26);
  --scrub-tick: rgba(70, 68, 60, .4);
  --head: #1a1a18;
  --knob-edge: rgba(26, 26, 24, .85);
  --hint-bg: rgba(26, 26, 24, .82);
  --trend-bg: rgba(255, 255, 255, .82);
  --trend-bg-solid: #ffffff;
  --endcard-bg: rgba(255, 255, 255, .94);
  --endcard-edge: rgba(42, 120, 214, .35);
  --endcard-shadow: rgba(40, 38, 30, .22);
  --error-edge: rgba(200, 50, 50, .6);
  --place-fill: #6d88a8;
  --place-fill-max: .15;
  --line-blend: source-over;
  /* about 29% at full night (13 rings): the terminator reads on the light map, the ocean and the HUD stay clear */
  --night-rgb: 36, 54, 110;
  --night-alpha: .026;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100vw; height: 100vh; overflow: hidden;
  background: var(--page); color: var(--text);
  font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; }

/* ---- map views ---- */
#main { position: fixed; left: 0; top: 0; right: 0; bottom: var(--bar-h); }
.mv { overflow: hidden; cursor: grab; user-select: none; -webkit-user-select: none; }
.mv:active { cursor: grabbing; }
.mv > svg, .mv > canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }
.mv > canvas { pointer-events: none; }
.mv path { vector-effect: non-scaling-stroke; fill: none; stroke: none; }
.mv .mv-sphere { fill: var(--ocean); }
.mv .mv-land { fill: var(--land); stroke: var(--coast); stroke-width: .7px; }
.mv .mv-glacier { display: none; } /* light theme only */
:root[data-theme="light"] .mv .mv-glacier { display: inline; fill: var(--glacier); stroke: none; }
.mv .mv-lake { fill: var(--ocean); stroke: var(--lake-edge); stroke-width: .5px; }
.mv .mv-admin { stroke: var(--admin); stroke-width: .6px; }
.mv .mv-border { stroke: var(--border); stroke-width: 1px; }
.mv .mv-grid { stroke: var(--grid); stroke-width: .7px; }
.mv-grid-labels text { font-size: 10px; fill: var(--grid-text); stroke: var(--grid-halo); stroke-width: 3px;
  stroke-linejoin: round; paint-order: stroke; }
.mv-azi .mv-sphere, .mv-globe .mv-sphere { stroke: var(--sphere-edge); stroke-width: 1px; }
.btn {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 6px;
  border: 1px solid var(--edge); background: var(--panel); color: var(--text);
  cursor: pointer; line-height: 1;
}
.btn:hover { background: var(--btn-hover); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
/* Lower right of the map: the zoom-to buttons (North America | All | USA | EU) and the Merc | Azi | Globe toggle. In
   one row where they fit, else the zoom-to row wraps above; phones stack them in a column (the zoom-to buttons
   vertical). */
#main-tools {
  position: fixed; right: var(--gap); bottom: calc(var(--bar-h) + var(--gap));
  display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 6px;
  max-width: calc(100vw - 2 * var(--gap));
}
#zoom-to .narrow { display: none; }
.seg { display: inline-flex; }
.seg .btn { min-width: 40px; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
.seg .btn:first-child { border-radius: 6px 0 0 6px; }
.seg .btn:not(:first-child):not(:last-child) { border-radius: 0; }
.seg .btn:last-child { border-radius: 0 6px 6px 0; }
.seg .btn + .btn { border-left: 0; }
.seg .btn[aria-pressed="true"] { color: var(--accent); background: var(--pressed-bg); }
/* Phones: the short zoom-to labels (NA), so both groups fit one row. */
@media (max-width: 699px) {
  #main-tools { gap: 4px; }
  #zoom-to .wide { display: none; }
  #zoom-to .narrow { display: inline; }
  .seg .btn { min-width: 36px; padding: 0 6px; }
}
/* Top right: the light/dark toggle (shows the icon of the theme it switches to). */
#theme-toggle {
  position: fixed; top: var(--gap); right: calc(var(--gap) + env(safe-area-inset-right, 0px));
  width: 32px; padding: 0; display: grid; place-items: center; color: var(--muted);
}
#theme-toggle:hover { color: var(--text); }
#theme-toggle svg { width: 18px; height: 18px; display: block; }
:root[data-theme="light"] #theme-toggle .sun, :root:not([data-theme="light"]) #theme-toggle .moon { display: none; }

/* ---- HUD (top-left) ---- */
#hud {
  position: fixed; left: var(--gap); top: var(--gap); max-width: min(440px, calc(100vw - 3 * var(--gap) - 32px)); /* clear of #theme-toggle */
  pointer-events: none; text-shadow: var(--hud-shadow);
}
#title { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .01em; }
#clock { margin-top: 6px; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
#count { font-size: 13px; color: var(--hud-muted); font-variant-numeric: tabular-nums; }
#count:empty, #clock:empty, #legend:empty, #counts[hidden] { display: none; }
/* The band chart and, to its right, the cumulative zone and DXCC bars (same column size and style). */
#charts { display: flex; flex-wrap: wrap; align-items: flex-end; column-gap: 9px; row-gap: 4px; margin-top: 6px; }
/* Band activity chart (cwskimviz style): count above, a column in the band colour, the band below. */
#legend { display: flex; gap: 3px; align-items: flex-end; height: 60px; pointer-events: auto; }
#counts {
  display: flex; gap: 3px; align-items: flex-end; height: 60px; padding-left: 9px;
  border-left: 1px solid var(--hb-rule);
}
.hb {
  width: 32px; height: 100%; padding: 0; border: 0; border-radius: 3px; background: none; color: var(--hud-muted);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; cursor: pointer;
  font: inherit; text-shadow: inherit;
}
.hb .n, .hb .lab { font-size: 10px; line-height: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hb .colbox { flex: 1 1 auto; width: 70%; display: flex; align-items: flex-end; min-height: 0; }
.hb .col { display: block; width: 100%; min-height: 1px; border-radius: 2px 2px 0 0; opacity: .85; transition: height .2s;
  background: var(--c); }
:root[data-theme="light"] .hb:not(.cb) .col { background: var(--c-light); opacity: 1; }
.hb .lab { width: 100%; text-align: center; border-top: 1px solid var(--hb-rule); color: var(--text); }
.hb:hover .col { opacity: 1; }
.hb:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
#legend.filtered .hb[aria-pressed="false"] { opacity: .35; }
/* Count columns: a neutral colour (they are not bands) over a faint track that marks the total. */
.cb { cursor: default; }
.cb .colbox { background: var(--count-track); border-radius: 2px 2px 0 0; }
.cb .col { background: var(--count-col); transition: none; }
.cb .lab { letter-spacing: -.03em; }
.hb[aria-pressed="true"] .col { opacity: 1; box-shadow: 0 0 0 1px var(--hb-on); }
.hb[aria-pressed="true"] .lab { font-weight: 700; }
@media (max-width: 699px) {
  #legend, #counts { height: 42px; gap: 2px; }
  #charts { column-gap: 6px; }
  #counts { padding-left: 6px; gap: 5px; } /* "36/40" labels are wider than the column */
  .hb { width: 28px; }
  .hb .n, .hb .lab { font-size: 9.5px; line-height: 11px; }
  #title { font-size: 15px; }
  #clock { font-size: 14px; margin-top: 4px; }
}

/* ---- trend charts: top right, left of the theme toggle; inside the HUD, under its charts, on phones ---- */
#trends {
  position: fixed; top: var(--gap); right: calc(var(--gap) + 32px + 8px + env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 6px; padding: 7px 9px; width: 190px;
  background: var(--trend-bg); border: 1px solid var(--edge); border-radius: 8px; text-shadow: none;
}
#trends:empty { display: none; }
.trend { pointer-events: auto; }
.trend-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 11px; line-height: 14px; }
.trend-label { color: var(--muted); }
.trend-value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend svg { display: block; width: 100%; height: 36px; overflow: visible; cursor: crosshair; }
.trend-base { stroke: var(--hb-rule); stroke-width: 1; }
.trend-rest { fill: none; stroke: var(--muted); stroke-opacity: .35; stroke-width: 1.5; stroke-linejoin: round; }
.trend-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend-dot { fill: var(--accent); stroke: var(--trend-bg-solid); stroke-width: 2; }
.trend-hair { stroke: var(--text); stroke-opacity: .5; stroke-width: 1; }
@media (max-width: 699px) {
  #trends { position: static; flex-direction: row; gap: 10px; width: auto; margin-top: 6px; padding: 5px 7px; }
  .trend { flex: 1 1 0; min-width: 0; }
  .trend-head { font-size: 10px; }
  .trend svg { height: 28px; }
}

/* ---- bottom bar: one row at >= 700px; below that, buttons on row 1 and the scrubber on row 2 ---- */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 calc(var(--gap) + env(safe-area-inset-right, 0px)) var(--safe-b) calc(var(--gap) + env(safe-area-inset-left, 0px));
  background: var(--bar-bg); border-top: 1px solid var(--edge);
}
.bar-btns, .bar-group { display: flex; align-items: center; gap: 6px; flex: none; }
.bar-btn { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; }
.bar-play { width: 44px; border-color: var(--play-edge); background: var(--play-bg); color: var(--play-fg); }
.bar-play:hover { background: var(--play-hover); }
.bar-toggle { height: 36px; min-width: 64px; font-size: 13px; white-space: nowrap; }
.bar-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--on-edge); }
.bar-speed { display: inline-flex; align-items: center; gap: 6px; }
.bar-label { font-size: 12px; color: var(--muted); }
@media (max-width: 1099px) { .bar-label { display: none; } } /* more room for the scrubber */
.sel {
  height: 36px; padding: 0 24px 0 9px; border-radius: 6px; font: inherit; font-size: 13px;
  border: 1px solid var(--edge); color: var(--text); cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background: var(--panel) var(--sel-arrow) no-repeat right 8px center;
}
.sel:focus-visible, .scrub:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.mv:focus-visible { outline: 2px solid var(--focus); outline-offset: -3px; }
.sel option { background: var(--option-bg); color: var(--text); }
.sel-ant { font-weight: 600; max-width: 18em; }

.scrub {
  flex: 1 1 auto; min-width: 0; height: 62px; position: relative;
  cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 4px;
}
.scrub.dragging { cursor: grabbing; }
.scrub-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.scrub-track { fill: var(--scrub-track); }
.scrub-hist { fill: var(--scrub-hist); }
.scrub-hist.played { fill: var(--accent); opacity: .8; }
.scrub-tick { stroke: var(--scrub-tick); stroke-width: 1; }
.scrub-label { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.scrub-legend { font-size: 9px; letter-spacing: .04em; opacity: .75; }
.scrub-head-line { stroke: var(--head); stroke-width: 1.5; }
.scrub-head-knob { fill: #fff; stroke: var(--knob-edge); stroke-width: 1.5; }
.scrub:hover .scrub-head-knob, .scrub.dragging .scrub-head-knob { fill: var(--accent); }

@media (max-width: 699px) {
  #bar { flex-direction: column; align-items: stretch; justify-content: center; gap: 4px; padding-top: 6px; }
  .bar-btns { flex-direction: column; align-items: stretch; gap: 4px; }
  .bar-group { justify-content: space-between; gap: 4px; }
  .sel-ant { flex: 1 1 auto; min-width: 0; max-width: none; }
  .scrub { flex: none; height: 58px; }
  .bar-label { display: none; }
  .bar-btn { width: 34px; height: 34px; }
  .bar-play { width: 42px; }
  .sel, .bar-toggle { height: 34px; }
  .bar-toggle { min-width: 0; padding: 0 8px; }
}
@media (max-width: 359px) {
  .sel { padding: 0 18px 0 6px; background-position: right 5px center; }
  .bar-toggle { font-size: 12px; padding: 0 6px; }
}

/* ---- hint, status, end card ---- */
#hint {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 10px 16px; border-radius: 8px; background: var(--hint-bg); color: #fff;
  font-size: 14px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .25s;
}
#hint.show { opacity: 1; }
/* The projection tip: a bubble over the Azi button, its arrow at the button's middle (--arrow-x, set in app.js). */
#proj-tip {
  position: fixed; z-index: 20; max-width: 230px; padding: 8px 12px; border-radius: 8px; cursor: pointer;
  background: var(--panel); color: var(--text); border: 1px solid var(--accent); box-shadow: 0 4px 14px var(--shadow);
  font-size: 13px; line-height: 1.35; transition: opacity .4s;
}
#proj-tip[hidden] { display: none; }
#proj-tip.fading { opacity: 0; }
#proj-tip::after {
  content: ''; position: absolute; top: 100%; left: calc(var(--arrow-x, 50%) - 7px);
  border: 7px solid transparent; border-top-color: var(--accent);
}
.btn.tip-target { box-shadow: 0 0 0 2px var(--accent); }
#status {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--edge); max-width: calc(100vw - 32px);
}
#status[hidden], #status-retry[hidden], #endcard[hidden] { display: none; }
#status.error { border-color: var(--error-edge); }
#endcard {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center;
  padding: 20px 28px; border-radius: 12px; background: var(--endcard-bg); border: 1px solid var(--endcard-edge);
  box-shadow: 0 8px 40px var(--endcard-shadow); pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
#endcard-main { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
#endcard-sub { margin-top: 6px; color: var(--accent); font-size: 15px; font-weight: 600; letter-spacing: .02em; }
@media (max-width: 499px) { #endcard-main { font-size: 16px; } #endcard { padding: 14px 14px; } }
@media (max-height: 420px) {
  #title { font-size: 14px; }
  #clock { font-size: 13px; margin-top: 2px; }
}
