:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #16202f;
  --muted: #5b6678;
  --border: #dde3ee;
  --accent: #1d5fd1;
  --accent-text: #ffffff;
  --good: #1a8a4a;
  --warn: #b36b00;
  --row-hl: #eaf1ff;
  --map-sea: #dce6f3;
  --map-land: #b7c4d6;
  --map-grid: rgba(22, 32, 47, 0.08);
  --map-night: rgba(16, 28, 56, 0.22);
  --keypad: #e7ebf3;
  --key-hl: #e3ecff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1320; --card: #151d2e; --text: #e6ebf5; --muted: #98a3b8; --border: #26324a;
    --accent: #5b95ff; --accent-text: #08101e; --good: #4cc488; --warn: #f0a640; --row-hl: #1c2a46; --keypad: #0f1626; --key-hl: #1a2a4a;
    --map-sea: #0b1220; --map-land: #2a3954; --map-grid: rgba(230, 235, 245, 0.07); --map-night: rgba(0, 0, 0, 0.42);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1320; --card: #151d2e; --text: #e6ebf5; --muted: #98a3b8; --border: #26324a;
  --accent: #5b95ff; --accent-text: #08101e; --good: #4cc488; --warn: #f0a640; --row-hl: #1c2a46; --keypad: #0f1626; --key-hl: #1a2a4a;
    --map-sea: #0b1220; --map-land: #2a3954; --map-grid: rgba(230, 235, 245, 0.07); --map-night: rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header, main, footer { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 28px; }
h1 { margin: 0; font-size: 1.8rem; }
h2 { margin: 0 0 12px; font-size: 1.15rem; }
.sub { color: var(--muted); margin: 4px 0 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); flex: 1 1 160px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; flex: 0 0 auto; }
label.inline input { width: 64px; }
input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; margin-top: 3px; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button, .button {
  font: inherit; cursor: pointer; text-decoration: none; display: inline-block;
  color: var(--text); background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 7px 14px;
}
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.hint { color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
code { font-size: .85em; }
a { color: var(--accent); }
.keymap summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.results-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: center; }
.results-head h2 { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip { font-size: .8rem; padding: 3px 10px; border-radius: 999px; }
.chip.off { opacity: .45; text-decoration: line-through; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
td.notes { white-space: normal; color: var(--muted); font-size: .82rem; min-width: 220px; }
tr.now td { background: var(--row-hl); }
.el-high { color: var(--good); font-weight: 600; }
.el-low { color: var(--muted); }
.small { color: var(--muted); font-size: .8rem; }
.next-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.big { font-size: 1.4rem; font-weight: 700; }
.mode { margin-top: 4px; font-weight: 600; }
.countdown { font-size: 2rem; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.tips ul { margin: 0; padding-left: 20px; }
footer { color: var(--muted); font-size: .8rem; padding-bottom: 30px; }
footer a { color: inherit; }

/* Collapsible UV-K1 / UV-K5 key map */
.keymap summary { cursor: pointer; list-style: none; padding-left: 1.4em; position: relative; }
.keymap summary::-webkit-details-marker { display: none; }
.keymap summary::before { content: "▸"; position: absolute; left: 0; top: 0; color: var(--accent); display: inline-block; transition: transform .15s; }
.keymap[open] summary::before { transform: rotate(90deg); }
.summary-title { font-weight: 700; font-size: 1.05rem; margin-right: 8px; }
.keymap-body { margin-top: 12px; }
.keymap-body p { margin: 0 0 10px; }
.steps { margin: 0 0 16px; padding-left: 20px; }
kbd {
  font: 600 .8rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: nowrap;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 2px 6px; background: var(--bg);
}
.keypads { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; }
.keypad { margin: 0; flex: 1 1 260px; max-width: 360px; background: var(--keypad); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.keypad figcaption { font-weight: 700; margin-bottom: 8px; }
.kp-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.kp-key {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 52px; padding: 4px 2px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--muted);
}
.kp-label { font-weight: 700; font-size: .95rem; color: var(--text); opacity: .55; }
.kp-sub { font-size: .62rem; line-height: 1.1; opacity: .7; }
.kp-key.used { border: 2px solid var(--accent); background: var(--key-hl); color: var(--text); }
.kp-key.used .kp-label { opacity: 1; }
.kp-tag { margin-top: 2px; font-size: .62rem; line-height: 1.1; font-weight: 700; color: var(--accent); }
.keytable td:first-child { width: 1%; }
.keytable td { white-space: normal; }
.keytable kbd { white-space: normal; display: inline-block; max-width: 7em; line-height: 1.3; }

/* Satellite map */
.map-wrap { margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
#map { display: block; width: 100%; touch-action: manipulation; }
.map-status { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font-size: .9rem; }
.map-status b { font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; color: var(--muted); font-size: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend .line { width: 18px; height: 2px; display: inline-block; }
.legend .line.thick { height: 4px; border-radius: 2px; }
.legend .ring { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--text); display: inline-block; }
.legend .ring.dashed { border-style: dashed; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; padding: 7px 10px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; max-width: 220px; }
#map-card .results-head .buttons { min-width: 0; max-width: 100%; }
#map-card label.inline { flex: 1 1 auto; min-width: 0; }
#map-card label.inline select { min-width: 0; flex: 1 1 auto; }
#passes tr[data-sat] { cursor: pointer; }
#passes tr[data-sat]:hover td { background: var(--row-hl); }

.check { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; margin-top: 12px; cursor: pointer; }
.check input { margin: 0; width: 16px; height: 16px; accent-color: var(--accent); }

/* Add-a-satellite form */
.add-sat { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.add-sat summary { cursor: pointer; list-style: none; padding-left: 1.4em; position: relative; }
.add-sat summary::-webkit-details-marker { display: none; }
.add-sat summary::before { content: "▸"; position: absolute; left: 0; top: 0; color: var(--accent); display: inline-block; transition: transform .15s; }
.add-sat[open] summary::before { transform: rotate(90deg); }
.add-form { margin-top: 12px; }
.add-form > label { margin-bottom: 12px; }
.add-form select { max-width: none; margin-top: 3px; padding: 7px 9px; }
textarea { font: .8rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; margin-top: 3px; resize: vertical; width: 100%; }
button.link { border: 0; padding: 0; background: none; color: var(--accent); text-decoration: underline; font-size: inherit; }
tr.custom td { background: var(--row-hl); }

.sub { max-width: 70ch; }
footer .repo { font-size: .9rem; margin: 0 0 6px; }
footer .repo a { color: var(--accent); font-weight: 600; }

/* 3D globe */
[hidden] { display: none !important; }
#globe { position: relative; background: radial-gradient(circle at 50% 45%, var(--card), var(--bg)); touch-action: none; }
#globe canvas { display: block; cursor: grab; }
#globe canvas:active { cursor: grabbing; }
.globe-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.globe-label {
  position: absolute; left: 0; top: 0; white-space: nowrap; font: 600 11px system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--muted); background: var(--card); opacity: .9; padding: 1px 5px; border-radius: 4px;
}
.globe-label.strong { color: var(--text); font-weight: 700; }
.map-3d-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.map-3d-row .check { margin-top: 8px; }
.map-3d-row .small { margin-top: 8px; }

/* Full-screen map (Fullscreen API, or a window-filling fallback) */
body.no-scroll { overflow: hidden; }
#map-card.is-full {
  position: fixed; inset: 0; z-index: 1000; margin: 0; border: 0; border-radius: 0;
  display: flex; flex-direction: column; background: var(--card); overflow: hidden;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
#map-card.is-full .map-wrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; margin-top: 8px; }
#map-card.is-full #globe { width: 100%; height: 100%; }
#map-card.is-full .map-status { margin-top: 6px; }
#map-full[aria-pressed="true"] { border-color: var(--accent); }
/* Phones in landscape: keep the map as big as possible */
@media (max-height: 520px) {
  #map-card.is-full h2, #map-card.is-full .legend, #map-card.is-full #globe-hint { display: none; }
  #map-card.is-full .results-head { gap: 6px; }
  #map-card.is-full .map-status { font-size: .8rem; gap: 2px 12px; }
  #map-card.is-full .map-3d-row .check { margin-top: 4px; }
}

/* CSV download buttons */
.button.download { display: inline-flex; align-items: center; gap: 8px; }
.file-icon { width: 24px; height: 24px; flex: none; color: var(--accent); }

/* Radio settings and channel column */
.settings { margin-top: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.settings summary { cursor: pointer; list-style: none; padding-left: 1.4em; position: relative; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary::before { content: "▸"; position: absolute; left: 0; top: 0; color: var(--accent); display: inline-block; transition: transform .15s; }
.settings[open] summary::before { transform: rotate(90deg); }
.settings-row { margin: 12px 0 0; }
.settings-row select { max-width: none; margin-top: 3px; padding: 7px 9px; }
.ch { font-variant-numeric: tabular-nums; font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }

/* Header with the app icon at the top right */
.site-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.header-text { min-width: 0; }
.site-icon { width: 96px; height: 96px; flex: none; border-radius: 22px; box-shadow: 0 4px 16px rgba(0, 0, 0, .25); }
@media (max-width: 600px) {
  .site-icon { width: 56px; height: 56px; border-radius: 13px; }
  .site-header { gap: 12px; }
}
.legend .night-swatch { width: 18px; height: 12px; border-radius: 3px; display: inline-block; background: linear-gradient(90deg, var(--map-land) 0 45%, #ffe2a3 45% 52%, #0a1020 52%); border: 1px solid var(--border); }
