:root {
  --bg: #ffffff; --fg: #111111; --mid: #6b6b6b; --soft: #f3f3f3; --line: #dcdcdc; --strong: #000000; --inv: #ffffff;
  --lcd: #f5f5f5; --warn: #b3261e;
  --r: 12px; --navh: 62px;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d0d0d; --fg: #ececec; --mid: #8f8f8f; --soft: #1a1a1a; --line: #2e2e2e; --strong: #ffffff; --inv: #000000; --lcd: #151515; --warn: #ff8a80; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { min-height: 100vh; padding-bottom: calc(var(--navh) + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }
.muted { color: var(--mid); font-size: 14px; }
.grow { flex: 1; min-width: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.small { font-size: 12px; }
.note { margin: 0; font-size: 14px; color: var(--mid); }
.center-text { text-align: center; }
code { background: var(--soft); padding: 0 4px; border-radius: 4px; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- controls ---------- */
button, select, input { font: inherit; color: inherit; }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--soft); cursor: pointer; user-select: none; touch-action: manipulation;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .4; cursor: default; transform: none; }
button.primary { background: var(--strong); color: var(--inv); border-color: var(--strong); font-weight: 600; }
button.danger { background: var(--warn); color: #fff; border-color: var(--warn); font-weight: 600; }
button.ghost { background: transparent; }
button.sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
button.big { min-height: 56px; font-size: 20px; }
button.wide, .seg.wide { width: 100%; }
button.icon { min-height: 40px; width: 40px; padding: 0; border: 0; background: transparent; }
button.on { background: var(--strong); color: var(--inv); border-color: var(--strong); }
a.ghost { display: inline-flex; align-items: center; min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: inherit; font-size: 14px; }
input, select { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
input:focus, select:focus { outline: 2px solid var(--strong); outline-offset: -1px; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--strong); flex: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--mid); }
.field > input, .field > select, .field > .seg { color: var(--fg); font-size: 16px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 15px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.two, .three { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.three { grid-template-columns: 1fr 1fr 1fr; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 0 8px; min-height: 42px; font-size: 15px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--strong); color: var(--inv); }
.badge { display: inline-block; min-width: 8px; height: 8px; border-radius: 4px; background: var(--warn); }

/* ---------- connect ---------- */
.connect { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; overflow: auto; }
.cbox { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; }
.cbox h1 { margin: 0; text-align: center; font-size: 28px; letter-spacing: -.5px; }
.lead { margin: 0; text-align: center; color: var(--mid); }
.logo { width: 84px; height: 84px; margin: 0 auto; border-radius: 20px; }
.warn { padding: 12px 14px; border: 1px solid var(--warn); border-radius: 10px; color: var(--warn); font-size: 14px; }
.help { font-size: 14px; color: var(--mid); border-top: 1px solid var(--line); padding-top: 12px; }
.help summary { cursor: pointer; color: var(--fg); font-weight: 600; }
.help ol { padding-left: 20px; }

/* ---------- header ---------- */
#top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.hid { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.hid b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--mid); flex: none; }
.dot.on { background: var(--strong); border-color: var(--strong); }
.dot.wait { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.state { font-weight: 700; font-size: 13px; letter-spacing: .8px; padding: 3px 9px; border-radius: 6px; border: 1px solid var(--line); }
.state.tx { background: var(--warn); color: #fff; border-color: var(--warn); }
.state.rx { background: var(--strong); color: var(--inv); border-color: var(--strong); }
.hbat { display: flex; align-items: center; gap: 6px; font-size: 14px; font-variant-numeric: tabular-nums; }
.batt { position: relative; width: 28px; height: 13px; border: 1.5px solid var(--fg); border-radius: 3px; }
.batt::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2px; height: 4px; background: var(--fg); }
.batt i { position: absolute; left: 1px; top: 1px; bottom: 1px; width: 0; background: var(--strong); border-radius: 1px; }
.batt i.low { background: var(--warn); }
.banner { padding: 10px 14px; background: var(--soft); border-bottom: 1px solid var(--line); font-size: 14px; text-align: center; }
.apbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--soft); border-bottom: 1px solid var(--line);
}
.apbar p { margin: 2px 0 0; }

/* ---------- layout ---------- */
main { max-width: 720px; margin: 0 auto; padding: 14px; }
.view { display: flex; flex-direction: column; gap: 14px; }
.card { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card h3 { margin: 0; font-size: 17px; }
.ctitle { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- radio ---------- */
.lcd { background: var(--lcd); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.lrow { display: flex; align-items: center; gap: 10px; }
.chip { font-weight: 700; font-size: 13px; letter-spacing: .8px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); }
.chip.rx { background: var(--strong); color: var(--inv); border-color: var(--strong); }
.chip.tx { background: var(--warn); color: #fff; border-color: var(--warn); }
.freq { background: none; border: 0; padding: 0; min-height: 0; font-size: clamp(44px, 14vw, 64px); font-weight: 600; letter-spacing: -2px; font-variant-numeric: tabular-nums; justify-content: flex-start; }
.meter { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--strong); transition: width .3s; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.chips span { padding: 2px 8px; border: 1px solid var(--line); border-radius: 6px; font-variant-numeric: tabular-nums; }
.chips span.fill { background: var(--strong); color: var(--inv); border-color: var(--strong); }
.tune { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 10px; }
.tune select { min-height: 56px; text-align: center; }
.steppers { display: grid; gap: 10px 24px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stepper { display: grid; grid-template-columns: 1fr 52px 36px 52px; align-items: center; gap: 6px; font-size: 15px; color: var(--mid); }
.stepper b { text-align: center; color: var(--fg); font-size: 18px; font-variant-numeric: tabular-nums; }
.stepper button { padding: 0; font-size: 20px; }
.list { display: flex; flex-direction: column; }
.list .empty { color: var(--mid); font-size: 14px; padding: 8px 0; }
.mrow { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 4px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; text-align: left; width: 100%; justify-content: flex-start; }
.mrow:last-child { border-bottom: 0; }
.mrow.cur { font-weight: 700; }
.mrow.cur .nm::before { content: "▸ "; }
.mrow .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .sub { color: var(--mid); font-size: 13px; }
.mrow .fq { font-variant-numeric: tabular-nums; }
.mrow .x { color: var(--warn); font-size: 14px; }

/* ---------- APRS ---------- */
.stats, .tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.tiles { grid-template-columns: 1fr 1fr; }
.stats div, .tiles div { display: flex; flex-direction: column; min-width: 0; }
.stats span, .tiles span { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--mid); }
.stats b, .tiles b { font-size: 18px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.srow b { font-size: 16px; }
.srow .r { text-align: right; color: var(--mid); font-size: 13px; font-variant-numeric: tabular-nums; }
.srow .t { grid-column: 1 / -1; color: var(--mid); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pkt { padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 12px; word-break: break-all; }
.pkt .d { font-weight: 700; margin-right: 6px; }
.pkt .when { color: var(--mid); margin-right: 6px; }
.msgs { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 12px; }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 14px; background: var(--soft); align-self: flex-start; }
.bubble.out { align-self: flex-end; background: var(--strong); color: var(--inv); }
.bubble small { display: block; font-size: 11px; opacity: .7; margin-bottom: 2px; }
.compose { position: sticky; bottom: calc(var(--navh) + env(safe-area-inset-bottom)); display: flex; gap: 8px; padding: 10px 0; background: var(--bg); }
.compose .to { width: 110px; flex: none; }
.compose button { width: 48px; padding: 0; flex: none; }

/* ---------- GNSS ---------- */
.sky { display: flex; align-items: flex-end; gap: 3px; height: 120px; overflow-x: auto; }
.sky div { flex: 1 0 18px; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; font-size: 10px; color: var(--mid); }
.sky i { display: block; width: 100%; background: var(--strong); border-radius: 3px 3px 0 0; min-height: 2px; }
.sky i.weak { background: var(--mid); }

/* ---------- tools ---------- */
.decode { min-height: 90px; padding: 12px; background: var(--soft); border-radius: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tonebig { margin: 0; font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pad button { min-height: 50px; font-size: 20px; }
[data-tpane] { display: flex; flex-direction: column; gap: 12px; }
.scan { width: 100%; height: 160px; border: 1px solid var(--line); border-radius: 10px; touch-action: manipulation; }

/* ---------- settings ---------- */
.savebar { position: sticky; bottom: calc(var(--navh) + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 12px; padding: 12px 0; background: var(--bg); }
#iLog { max-height: 260px; overflow: auto; }
#iLog div { padding: 4px 0; border-bottom: 1px solid var(--line); }
#cfgForm { display: flex; flex-direction: column; gap: 14px; }

/* ---------- nav, dialog, toast ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--bg); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs button { flex: 1; min-width: 0; flex-direction: column; gap: 2px; min-height: var(--navh); padding: 0 2px; border: 0; border-radius: 0; background: transparent; font-size: 12px; color: var(--mid); }
#tabs button.on { color: var(--fg); font-weight: 700; }
#tabs button.on .ic { stroke-width: 2.4; }
dialog { border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); color: var(--fg); padding: 20px; width: min(92vw, 360px); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h3 { margin: 0; }
dialog input { font-size: 28px; min-height: 56px; font-variant-numeric: tabular-nums; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--navh) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  width: max-content; max-width: calc(100vw - 32px); padding: 10px 16px; text-align: center; border-radius: 10px; background: var(--strong); color: var(--inv); font-size: 15px; box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}
.toast.err { background: var(--warn); color: #fff; }

@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
}
