/* ---------- tokens ---------- */
:root {
  --bg: #0d1117; --surface: #151b23; --surface-2: #1c232d; --surface-3: #232c38; --border: #2a3340;
  --text: #e6edf3; --text-2: #9aa7b4; --text-3: #6b7785;
  --accent: #f59e0b;
  --accent-soft: color-mix(in oklab, var(--accent) 55%, var(--surface));
  --accent-quiet: color-mix(in oklab, var(--accent) 24%, var(--surface));
  --accent-ghost: color-mix(in oklab, var(--accent) 9%, var(--surface));
  --on-accent: color-mix(in oklab, var(--accent) 18%, #000);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 32px rgba(0,0,0,.4);
  /* One hue per region. Amber/orange is avoided: it is the downlink colour. */
  --r-us: #60a5fa; --r-ca: #f87171; --r-mx: #2dd4bf; --r-eu: #a78bfa;
  --r-br: #4ade80; --r-jp: #f472b6; --r-cn: #e2e8f0; --r-au: #a3e635;
  --font-display: 'Bricolage Grotesque', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 13px/1.5 var(--font-body);
  background-image: radial-gradient(1200px 500px at 85% -10%, var(--accent-ghost), transparent 70%);
  background-attachment: fixed;
}
.sp { flex: 1; }
.lbl-sm { color: var(--text-3); font-size: 12px; }
.btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font: 12px var(--font-body); padding: 5px 9px; cursor: pointer; }
.btn.on { background: var(--accent-quiet); border-color: var(--accent-soft); }

/* ---------- page layout: rail + full-viewport main ---------- */
.app { display: flex; height: 100vh; }
.wrap { flex: 1 1 auto; min-width: 0; padding: 12px 14px; height: 100vh; display: flex; flex-direction: column; }
.pgrid { flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: stretch; }
/* The chart area height is set by sizeChart() in app.js, not by content: the map below must not move */
.cmain { min-width: 0; display: flex; flex-direction: column; }
.mapcard { flex: 1 1 0; min-height: 260px; display: flex; flex-direction: column; margin-top: 12px; }
/* Small screens: see the responsive block at the end of this file (it must come last to win). */

/* ---------- rail ---------- */
.rail { flex: 0 0 46px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 0; border-right: 1px solid var(--border); background: color-mix(in oklab, var(--surface) 70%, var(--bg)); }
.brand { writing-mode: vertical-rl; transform: rotate(180deg); font: 700 20px var(--font-display); letter-spacing: .01em; white-space: nowrap; }
.brand span { color: var(--accent); }
.railbtn { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 34px; padding: 8px 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text-2); cursor: pointer; font: 600 11px var(--font-body); }
.railbtn .ic { font-size: 13px; line-height: 1; }
.railbtn .vt { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
.railbtn:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.railbtn:disabled { opacity: .35; cursor: default; }
.railbtn.info .ic { font: italic 700 13px Georgia, serif; }
.railbtn .pop { display: none; position: absolute; left: 44px; bottom: 0; width: 360px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); color: var(--text-2); font: 400 12px/1.5 var(--font-body); z-index: 30; text-align: left; }
.railbtn .pop b { color: var(--text); }
.railbtn.info:hover .pop, .railbtn.info:focus .pop { display: block; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.2); padding: 14px 16px; }
.card-h { display: flex; align-items: center; gap: 12px; margin: -14px -16px 12px; padding: 10px 16px 9px; border-bottom: 1px solid var(--border); border-radius: 12px 12px 0 0; background: linear-gradient(180deg, var(--accent-ghost), transparent); }
.card-h .btn { padding: 4px 8px; }
.ch-n { font: 700 22px/1 var(--font-display); color: var(--accent); }
.ch-t { font-weight: 600; font-size: 13px; line-height: 1.2; }
.ch-s { color: var(--text-3); font-size: 11px; }
.ch-row2 { flex-basis: 100%; display: flex; flex-wrap: nowrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding-top: 7px; border-top: 1px dashed color-mix(in oklab, var(--border) 70%, transparent); }
.spec-h { flex-wrap: wrap; row-gap: 8px; }
.hctl { display: flex; gap: 4px; align-items: center; margin-right: auto; }
.hctl .lbl-sm { margin-right: 4px; }
.vmode { margin-right: 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { position: relative; width: 32px; height: 18px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); transition: background .15s, border-color .15s; }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-2); transition: transform .15s, background .15s; }
.switch input:checked + .track { background: var(--accent-quiet); border-color: var(--accent); }
.switch input:checked + .track .knob { transform: translateX(14px); background: var(--accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent-soft); outline-offset: 2px; }
.switch .sw-lbl { font-size: 12px; color: var(--text-2); }
.switch input:checked ~ .sw-lbl { color: var(--text); }
.cmain .adv-only { display: none; }
.cmain.adv .adv-only { display: flex; }
.cmain.adv .std-only { display: none; }
/* one line in both views, so the header (and the map below) keeps its height when switching view */
.legend { display: flex; gap: 14px; color: var(--text-2); font-size: 12px; margin-left: auto; min-width: 0; overflow: hidden; white-space: nowrap; }
.legend svg { vertical-align: middle; margin-right: 5px; }

/* ---------- EARFCN lookup ---------- */
.ef { display: flex; align-items: center; gap: 10px; }
.ef-box { position: relative; display: inline-flex; }
.ef input { width: 150px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; font: 13px var(--font-body); font-variant-numeric: tabular-nums; padding: 5px 28px 5px 9px; }
.ef input:focus { outline: none; border-color: var(--accent); }
#efClear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font: 600 14px/1 var(--font-body); cursor: pointer; display: none; padding: 0; }
#efClear:hover { background: var(--accent-quiet); color: var(--text); }
.ef-box.has #efClear { display: block; }
#efOut { font: 12px var(--font-body); color: var(--text-2); white-space: nowrap; }
#efOut b { color: var(--text); }
#efOut .bad { color: var(--text-3); }

/* ---------- spectrum chart ---------- */
.chartscroll { flex: none; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
svg.chart { width: 100%; display: block; user-select: none; touch-action: none; cursor: grab; }
.ax text { font: 10.5px var(--font-mono); fill: var(--text-3); }
.ax line { stroke: var(--border); }
.blab { font: 700 11px var(--font-mono); fill: var(--text-2); }
.blab.sel { fill: var(--accent); }
/* advanced view, label drawn over a narrow box's UL/DL blocks */
.blab.on-box { fill: var(--text); paint-order: stroke; stroke: var(--surface); stroke-width: 3px; pointer-events: none; }
.env { fill: var(--surface-2); stroke: var(--border); }
.env.sel { fill: var(--accent-ghost); stroke: var(--accent); stroke-width: 1.5; }
.env.tdd-env { stroke: var(--text-3); stroke-dasharray: 4 3; }
/* standard view: the whole band is one box */
.env.std { fill: var(--accent-quiet); stroke: var(--accent-soft); }
.env.std.tdd-env { fill: color-mix(in oklab, var(--accent) 12%, var(--surface)); stroke: var(--text-3); }
.env.std.sel { fill: color-mix(in oklab, var(--accent) 45%, var(--surface)); stroke: var(--accent); }
.stdlab { font: 700 11px var(--font-mono); fill: var(--text); pointer-events: none; }
.stdlab.out { fill: var(--text-2); }
.stdlab.sel { fill: var(--text); }
.item:hover .env.std { stroke: var(--accent); }
.item:hover .env { stroke: var(--accent-soft); }
.item.hov .env { stroke: var(--accent); }
.item.dim { opacity: .14; }
.dl { fill: var(--accent); }
.ul { fill: var(--accent-quiet); stroke: var(--accent-soft); stroke-width: 1; }
.tdd { fill: var(--accent-soft); }
.part:hover { filter: brightness(1.15); }
.in-dl { font: 700 10px var(--font-mono); fill: var(--on-accent); pointer-events: none; }
.in-ul { font: 700 10px var(--font-mono); fill: var(--text); pointer-events: none; }
.proj-ul { fill: var(--accent); opacity: .07; }
.proj-dl { fill: var(--accent); opacity: .13; }
.proj-edge { stroke: var(--accent-soft); stroke-dasharray: 2 3; opacity: .6; }
.mk { stroke: var(--text); stroke-width: 1.5; }
.mk-pair { stroke: var(--text-2); stroke-width: 1.2; stroke-dasharray: 4 3; }
.mk-tag { fill: var(--text); }
.mk-txt { font: 700 10.5px var(--font-mono); fill: var(--bg); }

/* ---------- band panel ---------- */
.panel { position: relative; min-height: 0; }
.panel > .tt { position: absolute; inset: 0; overflow-y: auto; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); font-size: 12px; }
.panel > .tt .tt-b { flex: 1; }
.tt-h { display: flex; align-items: center; gap: 10px; padding: 10px 12px 8px; border-bottom: 1px solid var(--border); background: linear-gradient(180deg, var(--accent-ghost), transparent); }
.tt-n { font: 700 24px/1 var(--font-display); color: var(--accent); }
.tt-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.tt-kind { color: var(--text-3); font-size: 11px; }
.tt-b { padding: 8px 12px 10px; }
.tt-sec { padding-top: 8px; margin-top: 8px; border-top: 1px solid var(--border); }
.tt-st { font: 600 10px var(--font-body); text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 4px; }
.tt-note { color: var(--text-2); font-size: 11.5px; }
.tt svg text { font-family: var(--font-mono); }
table.tt-t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.tt-t th { font: 600 10px var(--font-body); text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); text-align: left; padding: 2px 0; }
.tt-t th.r, .tt-t td.r { text-align: right; }
.tt-t td { font: 12px var(--font-mono); padding: 3px 0; }
.tt-t tr.hl td { color: var(--accent); }
.tt-t td .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 6px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.rel { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--text-2); font-size: 11.5px; }
.pill { display: inline-block; font: 600 10px var(--font-mono); padding: 1px 7px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
.pill.acc { background: var(--accent-quiet); border-color: var(--accent-soft); color: var(--text); }
.pill.off { opacity: .35; }
.tt-cur { display: flex; justify-content: space-between; gap: 8px; padding: 7px 12px; background: var(--surface-2); border-top: 1px solid var(--border); font-family: var(--font-mono); font-size: 12px; }
.tt-cur b { color: var(--text); font-weight: 700; }
.tt-foot { padding: 5px 12px; color: var(--text-3); font-size: 10.5px; border-top: 1px solid var(--border); }

/* ---------- map ---------- */
.map-h { flex-wrap: wrap; row-gap: 6px; margin-bottom: 10px; }
.mvt { display: flex; gap: 3px; margin-left: 6px; }
.regions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rchip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); border-radius: 999px; padding: 2px 9px 2px 7px; font: 500 11.5px var(--font-body); cursor: pointer; }
.rchip .dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--rc); }
.rchip:hover { border-color: var(--rc); color: var(--text); }
.rchip.on { background: color-mix(in oklab, var(--rc) 20%, var(--surface-2)); border-color: var(--rc); color: var(--text); }
.rchip.on .dot { background: var(--rc); }
.mapwrap { flex: 1 1 0; min-height: 0; position: relative; display: flex; background: color-mix(in oklab, var(--bg) 70%, var(--surface)); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
#map { flex: 1 1 auto; width: 100%; height: 100%; display: block; cursor: grab; }
.mapinfo { position: absolute; left: 10px; top: 8px; right: 60px; pointer-events: none; text-shadow: 0 1px 2px var(--bg); font-size: 12.5px; color: var(--text-2); }
.mapinfo b { color: var(--text); }
.mapinfo .bn { font: 700 12px var(--font-mono); color: var(--accent); margin-right: 4px; }
.mapinfo .pl { display: inline-block; font: 600 11px var(--font-mono); padding: 0 6px; margin: 0 2px; border-radius: 999px; background: var(--accent-quiet); color: var(--text); }
.mapinfo .pl.one { background: none; border: 1px dashed var(--accent-soft); color: var(--text-2); }
.mapinfo .muted { color: var(--text-3); }
.maplegend { position: absolute; left: 10px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 8px; font-size: 11px; color: var(--text-2); background: color-mix(in oklab, var(--surface) 85%, transparent); border: 1px solid var(--border); border-radius: 6px; }
.maplegend i { display: inline-block; width: 16px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.lg-both { background: var(--accent); }
.lg-one { background: color-mix(in oklab, var(--accent) 22%, var(--surface-3)); }
.lg-no { background: var(--surface-3); }
.lg-nt { background: color-mix(in oklab, var(--surface-2) 55%, var(--bg)); }
.lg-sel { border: 2px solid var(--text); }
.zbtns { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 4px; }
.zbtns button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: 600 15px var(--font-body); cursor: pointer; }
.zbtns button:hover { border-color: var(--accent-soft); }

#map .ctry, #map .sel-ol { vector-effect: non-scaling-stroke; }
#map .ctry { stroke: var(--surface); stroke-width: .5; cursor: pointer; transition: fill .12s; }
#map .ctry.nt { fill: color-mix(in oklab, var(--surface-2) 55%, var(--bg)); cursor: default; }
#map .ctry.no { fill: var(--surface-3); }
#map .ctry.one { fill: color-mix(in oklab, var(--accent) 22%, var(--surface-3)); }
#map .ctry.both { fill: var(--accent); }
#map .ctry.picked { fill: var(--accent-soft); }
#map .ctry.hov { stroke: var(--text); stroke-width: 1.5; }
#map .sel-ol { fill: none; stroke: var(--text); stroke-width: 2; pointer-events: none; }
/* world view: region labels */
#map .rbox { fill: color-mix(in oklab, var(--surface) 92%, transparent); stroke: var(--border); }
#map .rlab:hover .rbox { fill: var(--surface-2); }
#map .rlab.hot .rbox { stroke: var(--rc); stroke-width: 2; }
#map .rname { font: 700 11px var(--font-body); fill: var(--rc); }
#map .rbands { font: 500 11px var(--font-mono); fill: var(--text-2); }
#map .rbands .hit { fill: var(--accent); font-weight: 700; }
#map .lead { stroke: var(--rc); stroke-width: 1; opacity: .7; }
#map .lead-dot { fill: var(--rc); }
/* europe view: country labels */
#map .cbox { fill: color-mix(in oklab, var(--surface) 90%, transparent); stroke: var(--border); }
#map .clab:hover .cbox { fill: var(--surface-2); }
#map .clab.hot .cbox { stroke: var(--text); stroke-width: 1.6; }
#map .cname { font: 600 10.5px var(--font-body); fill: var(--text); }
#map .clead { stroke: var(--text-3); stroke-width: .8; }
#map .cdot { fill: var(--text-2); }

/* europe view: map on the left, country × band matrix on the right */
.eumatrix { display: none; }
.mapwrap.eu #map { flex: 0 0 auto; }
.mapwrap.eu .eumatrix { display: block; flex: 1 1 0; min-width: 0; overflow: auto; border-left: 1px solid var(--border); scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.mapwrap.eu .zbtns { right: auto; left: calc(var(--mapw) - 42px); }
.mapwrap.eu .maplegend { display: none; }
.mapwrap.eu .mapinfo { right: auto; max-width: calc(var(--mapw) - 70px); }
table.emx { border-collapse: collapse; width: 100%; font-size: 12px; }
.emx th, .emx td { padding: 0 6px; height: 21px; text-align: center; border-bottom: 1px solid color-mix(in oklab, var(--border) 60%, transparent); white-space: nowrap; }
.emx thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; font: 700 11px var(--font-mono); color: var(--text-2); height: 30px; cursor: pointer; }
.emx thead th small { display: block; font: 500 9px var(--font-body); color: var(--text-3); }
.emx thead th.bc:hover { color: var(--accent); }
.emx thead th.focus { color: var(--accent); }
.emx thead th.cn { font: 600 10px var(--font-body); text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); cursor: default; }
.emx .cn { text-align: left; font-weight: 500; }
.emx .cnt { color: var(--text-3); font: 11px var(--font-mono); }
.emx tbody tr { cursor: pointer; }
.emx tbody tr:hover td, .emx tbody tr.hov td { background: var(--surface-2); }
.emx tbody tr.sel td { background: color-mix(in oklab, var(--accent) 12%, var(--surface)); }
.emx tbody tr.sel .cn { font-weight: 700; }
.emx .focus { background: color-mix(in oklab, var(--accent) 7%, transparent); }
.emx tfoot td { position: sticky; bottom: 0; background: var(--surface); color: var(--text-2); font: 11px var(--font-mono); height: 24px; }
.emx tfoot td.cn { font: 600 10px var(--font-body); color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.emx i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; }
.emx i.m-both { background: var(--accent); }
.emx i.m-one { border: 1.5px dashed var(--accent-soft); }

/* ---------- responsive (kept last so it overrides the rules above) ---------- */
@media (max-height: 720px), (max-width: 980px) {
  .app, .wrap { height: auto; }
  .mapcard { flex: none; }
  .mapwrap { flex: none; height: 440px; }
}
@media (max-width: 980px) {
  .pgrid { grid-template-columns: minmax(0, 1fr); }
  .panel > .tt { position: static; }
  /* the one-line header rule is a desktop rule (it keeps the map still); on a phone, wrap */
  .ch-row2, .legend { flex-wrap: wrap; white-space: normal; }
  .legend { margin-left: 0; }
  .card-h { flex-wrap: wrap; }
  .mapwrap.eu { flex-direction: column; height: auto; }
  .mapwrap.eu #map { width: 100% !important; height: 360px; }
  .mapwrap.eu .eumatrix { border-left: 0; border-top: 1px solid var(--border); max-height: 420px; }
  .mapwrap.eu .zbtns { left: auto; right: 10px; }
}
@media (max-width: 600px) {
  .wrap { padding: 8px; }
  .rail { flex-basis: 38px; }
  .ef input { width: 130px; }
  .railbtn .pop { width: min(360px, calc(100vw - 60px)); }
}
