:root {
  --bg: #0a0d12;
  --bg-2: #0e131a;
  --card: #121821;
  --card-2: #18202b;
  --line: #222c3a;
  --line-2: #2c394b;
  --text: #e7ecf3;
  --muted: #8794a8;
  --faint: #566174;
  --accent: #39b4ff;
  --accent-ink: #04121d;
  --vfo: #ffb547;
  --ok: #34d399;
  --warn: #f5b041;
  --bad: #f87171;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -200px, #12233a 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
  background: rgba(10, 13, 18, .82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: .2px; font-size: 15px; }
.brand-icon { width: 22px; height: 22px; color: var(--accent); }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-2); white-space: nowrap; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .15); }
.status.warn .dot { background: var(--warn); }
.status.bad .dot { background: var(--bad); }
.spacer { flex: 1; }
.listeners { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.vol { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.vol svg { width: 18px; height: 18px; }
.vol input { width: 110px; }
.play {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px 0 12px;
  border-radius: 999px; border: 0; cursor: pointer; font-weight: 600;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 4px 18px rgba(57, 180, 255, .25);
}
.play svg { width: 20px; height: 20px; }
.play .i-stop { display: none; }
.play.on { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.play.on .i-play { display: none; }
.play.on .i-stop { display: block; color: var(--accent); }

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px; font-size: 13px;
  background: rgba(245, 176, 65, .1); border: 1px solid rgba(245, 176, 65, .35); color: #ffd99a; }
.banner.bad { background: rgba(248, 113, 113, .1); border-color: rgba(248, 113, 113, .4); color: #ffc4c4; }

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  max-width: 1680px; margin: 0 auto;
  height: calc(100vh - 59px); height: calc(100dvh - 59px);
}
.radio { display: flex; flex-direction: column; gap: 16px; min-height: 0; }
.card { background: linear-gradient(180deg, var(--card) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------------------------------------------------------------- tuner */
.tuner { padding: 14px 18px; display: grid; grid-template-columns: auto 1fr minmax(220px, 300px);
  align-items: center; gap: 10px 24px; }
.freq-wrap { display: flex; align-items: baseline; gap: 8px; }
.freq { font-family: var(--mono); font-size: 42px; font-weight: 600; letter-spacing: -.5px;
  font-variant-numeric: tabular-nums; user-select: none; -webkit-user-select: none; line-height: 1; display: flex; }
.freq .d { position: relative; cursor: ns-resize; padding: 2px 0; border-radius: 4px; touch-action: none; }
.freq .d.lead { color: var(--faint); }
.freq .d:hover { background: linear-gradient(180deg, rgba(57,180,255,.18) 0 50%, rgba(57,180,255,.06) 50% 100%); }
.freq .d.low:hover { background: linear-gradient(180deg, rgba(57,180,255,.06) 0 50%, rgba(57,180,255,.18) 50% 100%); }
.freq .sep { color: var(--faint); padding: 0 1px; }
.unit { color: var(--muted); font-size: 13px; }
.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card-2); cursor: pointer; color: var(--muted); padding: 0; flex: none; }
.icon-btn:hover { color: var(--text); border-color: var(--line-2); }
.icon-btn svg { width: 17px; height: 17px; }
.tuner-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 7px; background: var(--card-2);
  border: 1px solid var(--line); color: var(--muted); font-variant-numeric: tabular-nums; }
.badge.mode { color: var(--vfo); border-color: rgba(255, 181, 71, .35); background: rgba(255, 181, 71, .08); }
.step { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.nudge { display: flex; gap: 6px; }
.smeter { display: flex; flex-direction: column; gap: 6px; }
.smeter-bar { position: relative; height: 10px; border-radius: 6px; background: #0a0f15; border: 1px solid var(--line); overflow: hidden; }
.smeter-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px;
  background: linear-gradient(90deg, #1d9bf0, #34d399 55%, #f5b041 80%, #f87171); transition: width .1s linear; }
.smeter-sq { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--vfo); left: 0; display: none; }
.smeter-val { display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sq-badge { font-family: var(--sans); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: var(--card-2); color: var(--faint); border: 1px solid var(--line); }
.sq-badge.open { color: #052014; background: var(--ok); border-color: var(--ok); }

/* ---------------------------------------------------------------- scope */
.scope { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; padding: 0; }
#spec { display: block; width: 100%; height: 38%; min-height: 150px; cursor: crosshair; touch-action: pan-y; }
.wf-wrap { position: relative; flex: 1; min-height: 140px; border-top: 1px solid var(--line); }
#wf { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: pan-y; image-rendering: auto; }
.wf-vfo { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed rgba(255, 181, 71, .65); pointer-events: none; }
.scope-tools { display: flex; align-items: center; gap: 18px; padding: 10px 14px; border-top: 1px solid var(--line);
  background: var(--bg-2); flex-wrap: wrap; }
.field-inline { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.range-pair input { width: 110px; }
.scope-tools .btn { margin-left: auto; }

/* ---------------------------------------------------------------- panel */
.panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); padding: 6px; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { position: relative; border: 0; background: transparent; padding: 9px 4px; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-size: 13px; font-weight: 550; }
.tabs button.active { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.tab-dot { position: absolute; top: 7px; right: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); display: none; }
.tab-dot.on { display: block; }
.tab-body { padding: 16px 16px 24px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.group { padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; margin-bottom: 0; }
.label { font-size: 12px; font-weight: 650; color: var(--text); letter-spacing: .3px; text-transform: uppercase; margin-bottom: 8px; }
.label.sub { text-transform: none; letter-spacing: 0; font-weight: 550; color: var(--muted); font-size: 12.5px; display: block; margin-bottom: 6px; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.label-row .label { margin-bottom: 6px; }
.value { font-family: var(--mono); font-size: 12.5px; color: var(--accent); }
.hint { margin: 8px 0 0; color: var(--faint); font-size: 12px; line-height: 1.45; }
.tag { font-size: 10.5px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--muted);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; margin-left: 6px; }
.mt { margin-top: 14px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; border-radius: 10px;
  background: #0a0f15; border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 7px 4px; cursor: pointer; color: var(--muted);
  font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
#modes { grid-template-columns: repeat(6, 1fr); grid-auto-flow: row; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; cursor: pointer; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--accent); box-shadow: 0 1px 6px rgba(0,0,0,.5); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--text); border: 3px solid var(--accent); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .icon-btn { font-size: 18px; line-height: 1; }

.sq-track { position: relative; }
.sq-level { position: absolute; left: 0; top: 11px; height: 4px; border-radius: 4px; width: 0;
  background: linear-gradient(90deg, rgba(57,180,255,.4), rgba(52,211,153,.9)); pointer-events: none; transition: width .1s linear; }
.sq-track input[type=range]::-webkit-slider-runnable-track { background: rgba(44, 57, 75, .55); }

select { background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 28px 6px 10px;
  -webkit-appearance: none; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5' fill='none' stroke='%238794a8' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center; background-size: 16px; font-size: 13px; }
.grid2 select { width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }

.switch-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.switch-row .hint { margin-top: 0; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-2); transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { border: 1px solid var(--line-2); background: var(--card-2); border-radius: 9px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 11px; font-size: 12.5px; }

.add-mem { display: flex; gap: 8px; margin-bottom: 14px; }
.add-mem input { flex: 1; min-width: 0; }
input[type=text], input[type=password] { background: #0a0f15; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; }
input[type=text]:focus, input[type=password]:focus { border-color: var(--accent); }
.mem-list, .tr-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.mem-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  background: var(--card-2); border: 1px solid var(--line); cursor: pointer; }
.mem-list li:hover { border-color: var(--line-2); }
.mem-list li.current { border-color: rgba(255, 181, 71, .5); }
.mem-main { flex: 1; min-width: 0; }
.mem-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mem-sub { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.mem-del { border: 0; background: transparent; color: var(--faint); cursor: pointer; font-size: 18px; padding: 2px 6px; border-radius: 6px; }
.mem-del:hover { color: var(--bad); }
.tr-actions { display: flex; gap: 6px; align-items: flex-end; justify-content: flex-end; }
.tr-list { margin-top: 4px; }
.tr-list li { padding: 10px 12px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--line); }
.tr-list li.empty { background: transparent; border-style: dashed; color: var(--faint); text-align: center; }
.tr-meta { display: flex; gap: 8px; font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.tr-meta b { color: var(--vfo); font-weight: 600; }
.tr-text { font-size: 14px; }
.tr-list li.new { animation: flash 1.2s ease-out; }
@keyframes flash { from { border-color: var(--ok); } to { border-color: var(--line); } }

/* ---------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(360px, 100%); background: var(--card); border: 1px solid var(--line-2); border-radius: 16px; padding: 18px; }
.freq-input { display: flex; align-items: center; gap: 8px; margin: 6px 0 16px; }
.freq-input input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 24px; }
.freq-input span { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------------------------------------------------------------- login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0; color: var(--muted); }
.login-card .err { color: var(--bad); min-height: 1em; }

.mobile-only { display: none; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .tuner { grid-template-columns: 1fr; }
  .layout { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 900px) {
  .layout { display: flex; flex-direction: column; height: auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); gap: 12px; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 16px 8px; gap: 10px; }
  .desktop-only { display: none; }
  .mobile-only { display: block; }
  .label-row.mobile-only { display: flex; margin-top: 12px; }
  .listeners { display: none; }
  .brand span { display: none; }
  .tuner { padding: 12px 14px; gap: 10px; }
  .freq { font-size: 34px; }
  .scope { height: 58vh; flex: none; }
  #spec { height: 40%; min-height: 120px; }
  .panel { overflow: visible; }
  .tabs { position: sticky; top: 56px; z-index: 5; background: var(--card); border-radius: var(--radius) var(--radius) 0 0; }
  .tab-body { overflow: visible; }
  .range-pair input { width: 72px; }
  .scope-tools { gap: 8px 12px; padding: 8px 10px; }
  .scope-tools .field-inline > label { display: none; }
  .banner { margin: 10px 16px 0; }
}
@media (max-width: 420px) {
  .freq { font-size: 29px; }
  #modes { grid-template-columns: repeat(3, 1fr); }
  .scope-tools { gap: 10px; }
  .status { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
}
