:root {
  --bg: #0a0e13;
  --panel: #121922;
  --panel-2: #18212c;
  --line: #233041;
  --text: #e8eef5;
  --muted: #8796a8;
  --accent: #3aa8ff;
  --rx: #2fd07a;
  --tx: #ff4747;
  --warn: #ffb020;
  --lcd-bg: #0c1612;
  --lcd-text: #a6f5c4;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, select { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- login ---------- */
.login { align-items: center; justify-content: center; padding: 24px; padding-top: calc(24px + var(--safe-t));
  background: radial-gradient(120% 80% at 50% 0%, #142233 0%, var(--bg) 60%); }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.logo { width: 76px; height: 76px; }
.login h1 { margin: 10px 0 2px; font-size: 28px; letter-spacing: .5px; }
.login .site { margin: 0 0 26px; color: var(--muted); }
.login form { display: grid; gap: 14px; text-align: left; }
.login label span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; text-transform: uppercase; letter-spacing: .6px; }
.login input { width: 100%; font-size: 18px; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--text); outline: none; }
.login input:focus { border-color: var(--accent); }
.primary { margin-top: 6px; padding: 15px; border: 0; border-radius: 14px; background: var(--accent); color: #04121f; font-weight: 700; font-size: 17px; }
.primary:disabled { opacity: .6; }
.error { min-height: 1.3em; margin: 0; color: #ff7b7b; text-align: center; font-size: 14px; }
.warn { margin-top: 18px; padding: 12px; border-radius: 12px; background: #2b1d05; color: var(--warn); font-size: 14px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.login .lang-seg { margin-top: 22px; }

/* ---------- unlock ---------- */
.unlock { align-items: center; justify-content: center; background: radial-gradient(120% 80% at 50% 30%, #13263a 0%, var(--bg) 65%); }
.unlock-btn { display: flex; flex-direction: column; align-items: center; gap: 14px; border: 0; background: none; font-size: 20px; font-weight: 600; }
.unlock-btn img { width: 120px; height: 120px; animation: breathe 2.4s ease-in-out infinite; }
.unlock-btn small { color: var(--muted); font-weight: 400; font-size: 15px; }
@keyframes breathe { 50% { transform: scale(1.06); filter: drop-shadow(0 0 18px #3aa8ff66); } }

/* ---------- radio ---------- */
.radio { padding: calc(8px + var(--safe-t)) 14px calc(10px + var(--safe-b)); gap: 10px; }
.top { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.site-name { flex: 1; text-align: center; font-weight: 600; font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); min-width: 92px; }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--rx); box-shadow: 0 0 8px var(--rx); }
.conn.connecting i, .conn.offline i { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: blink 1s steps(2) infinite; }
.conn.offline { color: var(--warn); }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; margin-left: 52px; }
@keyframes blink { 50% { opacity: .25; } }

.lcd { background: linear-gradient(180deg, #0f1c16, var(--lcd-bg)); border: 1px solid #1b3326; border-radius: var(--radius); padding: 10px 12px 12px;
  box-shadow: inset 0 0 30px #00000080, 0 0 0 1px #00000060; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--lcd-text); }
.lcd-row { display: flex; align-items: center; gap: 8px; }
.ch-step { width: 44px; height: 44px; border-radius: 12px; border: 1px solid #1f3a2c; background: #0a130f; color: var(--lcd-text); font-size: 26px; line-height: 1; }
.ch-step:disabled { opacity: .35; }
.ch-name { flex: 1; text-align: center; display: flex; flex-direction: column; }
.ch-name small { font-size: 11px; opacity: .7; letter-spacing: 1px; }
.ch-name strong { font-size: 22px; letter-spacing: 1.5px; text-transform: uppercase; text-shadow: 0 0 10px #6ff0a055; }
.lcd-status { display: flex; flex-direction: column; align-items: center; margin: 10px 0 8px; min-height: 46px; justify-content: center; }
.lcd-main { font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.lcd-sub { font-size: 13px; opacity: .75; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
body[data-state="rx"] .lcd-main, body[data-state="replay"] .lcd-main { color: #5cffa0; }
body[data-state="tx"] .lcd-main { color: #ff8a8a; }
body[data-state="requesting"] .lcd-main, body[data-state="offline"] .lcd-main { color: var(--warn); }
.meter { display: grid; grid-template-columns: repeat(16, 1fr); gap: 3px; height: 10px; margin: 0 6px 10px; }
.meter i { border-radius: 2px; background: #1a2e23; }
.meter i.on { background: var(--lcd-text); box-shadow: 0 0 6px #6ff0a088; }
body[data-state="tx"] .meter i.on { background: #ff7070; box-shadow: 0 0 6px #ff505088; }
.meter i.on.hot { background: var(--warn); }
.zone { display: flex; align-items: center; gap: 6px; background: #0a130f; border: 1px solid #1f3a2c; border-radius: 12px; padding: 0 10px; }
.zone svg { width: 18px; height: 18px; flex: none; }
.zone select { flex: 1; min-width: 0; appearance: none; -webkit-appearance: none; background: transparent; border: 0; color: var(--lcd-text); font: inherit; font-size: 15px; padding: 11px 0; outline: none; }
.zone select.unset { color: var(--warn); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; position: relative; display: flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 14px; font-weight: 600; }
.chip.on { background: #10273c; border-color: var(--accent); color: var(--text); }
.chip em { font-style: normal; font-size: 12px; background: var(--panel-2); border-radius: 999px; padding: 1px 7px; color: var(--muted); }
.chip.live::after { content: ""; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--rx); box-shadow: 0 0 6px var(--rx); }
.chip.emergency { color: #ff9a9a; }

.ptt-wrap { flex: 1; display: grid; place-items: center; min-height: 0; }
.ptt { --c: var(--accent); position: relative; width: min(68vw, 40vh, 280px); aspect-ratio: 1; border-radius: 50%;
  border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; touch-action: none;
  background: radial-gradient(circle at 50% 35%, #1d2a38 0%, #121a23 70%);
  box-shadow: 0 0 0 6px #0d141c, 0 0 0 9px color-mix(in srgb, var(--c) 55%, transparent), 0 18px 40px #000a, inset 0 2px 0 #ffffff12;
  transition: transform .08s, box-shadow .2s; }
.ptt:active { transform: scale(.975); }
.ptt .mic { width: 46px; height: 46px; color: var(--c); stroke-width: 1.6; }
.ptt-label { font-weight: 800; font-size: 17px; letter-spacing: 1.2px; color: var(--text); }
.ptt-sub { font-size: 13px; color: var(--muted); max-width: 80%; text-align: center; }
.ptt-timer { position: absolute; bottom: 16%; font: 700 15px ui-monospace, Menlo, monospace; color: #ffd0d0; }
body[data-state="rx"] .ptt, body[data-state="replay"] .ptt { --c: var(--rx); }
body[data-state="requesting"] .ptt { --c: var(--warn); }
body[data-state="tx"] .ptt { --c: var(--tx); background: radial-gradient(circle at 50% 35%, #5a1414 0%, #2a0b0b 75%); animation: txpulse 1.1s ease-in-out infinite; }
body[data-state="tx"] .ptt .mic { color: #fff; }
body[data-state="offline"] .ptt { --c: #4a5563; opacity: .6; }
@keyframes txpulse { 50% { box-shadow: 0 0 0 6px #0d141c, 0 0 0 9px var(--tx), 0 0 46px 10px #ff3b3b66, inset 0 2px 0 #ffffff12; } }
.ptt.deny { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.bottom { display: grid; grid-template-columns: 1fr 1fr 1fr 1.35fr; gap: 8px; flex: none; }
.nav-btn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 64px; border-radius: 16px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 600; }
.nav-btn:disabled { opacity: .4; }
.nav-btn em { position: absolute; top: 6px; right: 8px; font-style: normal; font-size: 11px; background: var(--accent); color: #031220; border-radius: 999px; padding: 0 6px; font-weight: 700; }
.sos-btn { position: relative; overflow: hidden; height: 64px; border-radius: 16px; border: 1px solid #6b1d1d; background: #2a0d0d; color: #ff6b6b; display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; }
.sos-btn b { font-size: 20px; letter-spacing: 2px; position: relative; }
.sos-btn small { font-size: 11px; opacity: .8; position: relative; }
.sos-fill { position: absolute; inset: 0; background: #d92626; transform-origin: left; transform: scaleX(var(--p, 0)); }
.sos-btn.arming { color: #fff; }
.sos-btn.active { background: #d92626; color: #fff; animation: blink 1s steps(2) infinite; }

.sos-banner { border: 0; border-radius: 14px; padding: 11px 14px; background: #a31515; color: #fff; font-weight: 700; font-size: 14px; text-align: left; display: flex; align-items: center; gap: 10px; animation: bannerglow 1.4s ease-in-out infinite; }
.sos-banner.mine { background: #7a1010; }
.sos-banner .grow { flex: 1; }
.sos-banner small { display: block; font-weight: 500; opacity: .9; }
.sos-banner .cancel { background: #fff2; border: 1px solid #fff5; border-radius: 10px; padding: 6px 10px; font-size: 13px; color: #fff; }
@keyframes bannerglow { 50% { background-color: #d01d1d; } }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; background: #000a; z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 82vh; z-index: 21; background: var(--panel); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; padding-bottom: var(--safe-b); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet header { display: flex; align-items: center; padding: 16px 18px 8px; }
.sheet h2 { flex: 1; margin: 0; font-size: 19px; }
.close { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--panel-2); font-size: 22px; line-height: 1; color: var(--muted); }
.sheet-body { overflow-y: auto; padding: 4px 18px 18px; -webkit-overflow-scrolling: touch; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 14px 0 6px; }
.person { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.person .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rx); flex: none; }
.person.off .dot { background: #3a4654; }
.person.talking .dot { background: var(--tx); box-shadow: 0 0 8px var(--tx); }
.person .who { flex: 1; min-width: 0; }
.person .who b { display: block; font-weight: 600; }
.person .who small { color: var(--muted); }
.badge { font-size: 10px; font-weight: 800; letter-spacing: .6px; padding: 2px 6px; border-radius: 6px; background: #2d2510; color: var(--warn); margin-left: 6px; vertical-align: 2px; }
.person.off { opacity: .55; }
.empty { color: var(--muted); text-align: center; padding: 26px 0; }
.logrow { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.logrow time { font: 600 14px ui-monospace, Menlo, monospace; color: var(--muted); width: 50px; }
.logrow .who { flex: 1; }
.logrow .dur { color: var(--muted); font-size: 14px; }
.play { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); color: var(--accent); display: grid; place-items: center; }
.play svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }

.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.settings .row.col { flex-direction: column; align-items: stretch; }
.settings .row.muted { color: var(--muted); font-size: 14px; }
.settings input[type=range] { width: 100%; accent-color: var(--accent); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { flex: none; width: 48px; height: 28px; border-radius: 999px; background: #2b3746; position: relative; transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }
.me-card { padding: 12px 14px; border-radius: 14px; background: var(--panel-2); margin-bottom: 4px; }
.me-card b { display: block; font-size: 17px; }
.me-card small { color: var(--muted); }
.btn-secondary, .btn-danger { display: block; width: 100%; text-align: center; text-decoration: none; margin-top: 14px; padding: 14px; border-radius: 14px; font-weight: 700; }
.btn-secondary { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.btn-danger { background: transparent; border: 1px solid #5a2222; color: #ff8080; }
.version { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 0; }

/* ---------- emergency overlay ---------- */
.sos-overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: calc(20px + var(--safe-t)) 20px calc(20px + var(--safe-b));
  background: #b30f0f; animation: sosflash 0.9s steps(2) infinite; }
.sos-overlay.silenced { animation: none; background: #8f0c0c; }
@keyframes sosflash { 50% { background: #4d0606; } }
.sos-inner { width: 100%; max-width: 420px; text-align: center; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.sos-icon { width: 84px; height: 84px; border-radius: 50%; border: 5px solid #fff; display: grid; place-items: center; font-size: 50px; font-weight: 900; margin-bottom: 8px; }
.sos-title { font-size: 34px; font-weight: 900; letter-spacing: 3px; }
.sos-who { font-size: 28px; font-weight: 800; margin-top: 6px; }
.sos-where { font-size: 22px; font-weight: 600; background: #0003; border-radius: 12px; padding: 6px 14px; margin-top: 4px; }
.sos-when { opacity: .85; font-size: 15px; }
.sos-acks { min-height: 1.4em; font-size: 15px; opacity: .95; margin: 8px 0 10px; }
.sos-ack { width: 100%; padding: 20px; border-radius: 18px; border: 0; background: #fff; color: #a10e0e; font-size: 21px; font-weight: 900; letter-spacing: .5px; }
.sos-actions { display: flex; flex-wrap: wrap; gap: 10px; width: 100%; margin-top: 10px; }
.sos-secondary { flex: 1 1 calc(50% - 5px); padding: 14px 10px; border-radius: 14px; border: 2px solid #ffffff88; background: #0002; color: #fff; font-weight: 700; font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 50; max-width: calc(100% - 32px);
  background: #1e2a38; border: 1px solid var(--line); color: var(--text); padding: 12px 16px; border-radius: 14px; font-size: 15px; box-shadow: 0 10px 30px #000a; text-align: center; animation: up .18s ease-out; }

@media (min-width: 700px) {
  .radio { max-width: 460px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .sheet { max-width: 460px; margin: 0 auto; }
}
@media (max-height: 640px) {
  .lcd-status { min-height: 36px; margin: 6px 0; }
  .nav-btn, .sos-btn { height: 56px; }
}
