:root {
  --bg: #0c0d0f;
  --card: #141518;
  --raised: #1b1c20;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --text: #ededef;
  --muted: #8b8f98;
  --faint: #5b5f68;
  --talk: #ffb547;
  --radio: #5cc8ff;
  --phone: #a78bfa;
  --good: #4ade80;
  --bad: #f87171;
  --r-lg: 18px;
  --r: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px clamp(16px, 3vw, 32px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 28px; height: 28px; }
.brand circle { fill: var(--talk); }
.brand .r1, .brand .r2 { fill: none; stroke: var(--talk); stroke-width: 2; }
.brand .r1 { opacity: 0.55; }
.brand .r2 { opacity: 0.25; }
.brand span { font-size: 22px; font-weight: 700; letter-spacing: -0.04em; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px 0 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
body[data-state="live"] .status i { background: var(--good); box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.12); }
body[data-state="live"][data-q="1"] .status i { background: var(--talk); box-shadow: 0 0 0 4px rgba(255, 181, 71, 0.12); }
body[data-state="live"][data-q="2"] .status i,
body[data-state="live"][data-q="3"] .status i,
body[data-state="offline"] .status i { background: var(--bad); box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.12); }
body[data-state="pair"] .status i, body[data-state="wait"] .status i { background: var(--talk); }
body[data-state="live"] .status { color: var(--text); }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 32px) 32px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}

.stage {
  position: relative;
  min-height: min(760px, calc(100vh - 100px));
  padding: clamp(24px, 4vw, 44px);
  overflow: hidden;
}

.view { display: none; }
body[data-state="start"] .v-start,
body[data-state="pair"] .v-pair,
body[data-state="wait"] .v-wait,
body[data-state="offline"] .v-offline,
body[data-state="replaced"] .v-replaced { display: flex; }
body[data-state="live"] .v-live { display: grid; }

.v-start, .v-pair, .v-wait, .v-offline, .v-replaced {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: inherit;
  padding: 24px 0;
}

.stage h1 {
  margin: 0 0 12px;
  font-size: clamp(30px, 4.2vw, 48px);
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.035em;
}

.stage p { margin: 0 0 28px; max-width: 46ch; color: var(--muted); font-size: 16px; }

kbd {
  font-family: inherit;
  font-weight: 600;
  color: var(--text);
  padding: 2px 7px;
  background: var(--raised);
  border: 1px solid var(--line-2);
  border-radius: 6px;
}

.hero-rings {
  position: relative;
  width: 168px;
  height: 168px;
  margin-bottom: 36px;
}

.hero-rings span, .hero-rings b {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
}

.hero-rings span {
  border: 1.5px solid var(--talk);
  opacity: 0;
  animation: ripple 3.6s cubic-bezier(0.2, 0.6, 0.3, 1) infinite;
}

.hero-rings span:nth-child(2) { animation-delay: 1.2s; }
.hero-rings span:nth-child(3) { animation-delay: 2.4s; }

.hero-rings b {
  width: 22px;
  height: 22px;
  background: var(--talk);
  box-shadow: 0 0 40px 8px rgba(255, 181, 71, 0.35);
}

.hero-rings.idle span { animation-duration: 6s; }

@keyframes ripple {
  0% { transform: scale(0.12); opacity: 0.9; }
  100% { transform: scale(1); opacity: 0; }
}

.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--r);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn.primary {
  height: 48px;
  padding: 0 22px;
  border: 0;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
}

.btn.primary:hover { background: #fff; }
.btn.primary:disabled { opacity: 0.4; cursor: default; }

.btn.ghost {
  width: 100%;
  height: 40px;
  margin-top: 6px;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
}

.btn.ghost:hover { border-color: var(--line-2); }
.btn.ghost[aria-pressed="true"] { border-color: var(--talk); color: var(--talk); }

.btn.link {
  background: none;
  border: 0;
  padding: 14px 0 0;
  font-size: 13px;
  font-weight: 500;
}

.danger { color: var(--bad); }

:focus-visible { outline: 2px solid var(--talk); outline-offset: 2px; }

.note { margin-top: 18px !important; font-size: 14px !important; }

#pairForm { display: flex; flex-direction: column; align-items: center; gap: 20px; }

.digits { display: flex; gap: 10px; }

.digits input {
  width: 54px;
  height: 66px;
  background: var(--raised);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  color: var(--text);
  text-align: center;
  font: 600 28px/1 "Geist", sans-serif;
  font-variant-numeric: tabular-nums;
  caret-color: var(--talk);
}

.digits input:focus { outline: none; border-color: var(--talk); box-shadow: 0 0 0 4px rgba(255, 181, 71, 0.14); }
.digits input:nth-child(3) { margin-right: 10px; }

.err { min-height: 1.5em; margin: 16px 0 0 !important; color: var(--bad) !important; font-size: 14px !important; }

.v-live {
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  min-height: inherit;
}

.live-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.live-head h1 { margin-bottom: 4px; }
.live-head p { margin: 0; font-size: 14px; }

.talk {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 181, 71, 0.12);
  color: var(--talk);
  font-size: 13px;
  font-weight: 600;
}

.talk[hidden] { display: none; }
.talk::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.talk.radio { background: rgba(92, 200, 255, 0.12); color: var(--radio); }

.radar-wrap { display: grid; place-items: center; min-height: 0; }

#radar { width: min(100%, 620px); aspect-ratio: 1; display: block; }

.live-foot { display: grid; gap: 12px; }

.channels { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; min-height: 32px; }

.channels li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}

.channels li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.channels li.k2 { color: var(--radio); background: rgba(92, 200, 255, 0.1); }
.channels li.k3 { color: var(--phone); background: rgba(167, 139, 250, 0.1); }

.warn {
  margin: 0 !important;
  max-width: none !important;
  padding: 12px 14px;
  border-radius: var(--r);
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.22);
  color: #fecaca !important;
  font-size: 14px !important;
}

.side { display: grid; gap: 16px; align-content: start; }

.conn { padding: 20px; }

.conn-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 18px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.ping { display: flex; align-items: center; gap: 10px; }
.ping span { font-size: 34px; font-weight: 650; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; line-height: 1; }

.q { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.q.good { background: var(--good); }
.q.ok { background: var(--talk); }
.q.bad { background: var(--bad); }

.quality { display: grid; justify-items: end; gap: 8px; }
.quality span { font-size: 13px; font-weight: 600; color: var(--muted); }

.qbar { display: flex; gap: 4px; }
.qbar i { width: 16px; height: 6px; border-radius: 3px; background: var(--raised); }

body[data-q="0"] .qbar i { background: var(--good); }
body[data-q="1"] .qbar i:nth-child(-n+3) { background: var(--talk); }
body[data-q="2"] .qbar i:nth-child(-n+2) { background: var(--bad); }
body[data-q="3"] .qbar i:nth-child(1) { background: var(--bad); }
body[data-q="0"] .quality span { color: var(--good); }
body[data-q="1"] .quality span { color: var(--talk); }
body[data-q="2"] .quality span, body[data-q="3"] .quality span { color: var(--bad); }

.stats { margin: 0; display: grid; gap: 9px; }
.stats div { display: flex; justify-content: space-between; gap: 16px; font-size: 13.5px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.settings { padding: 6px 20px 18px; }

details { border-bottom: 1px solid var(--line); padding-bottom: 14px; }

summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  font-weight: 600;
  font-size: 14px;
}

summary::-webkit-details-marker { display: none; }
summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-3px);
  transition: transform 0.2s;
}
details[open] summary::after { transform: rotate(-135deg) translateX(-2px); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }

select {
  appearance: none;
  width: 100%;
  height: 40px;
  padding: 0 34px 0 12px;
  background: var(--raised) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238b8f98' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 13px center;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  text-overflow: ellipsis;
}

select:hover { border-color: var(--line-2); }

input[type="range"] {
  --v: 50%;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  margin: 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--text) var(--v), var(--raised) var(--v));
}

input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--raised); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--text); }

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 0; }

.meter { position: relative; height: 6px; margin: -4px 0 16px; border-radius: 3px; background: var(--raised); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--muted); border-radius: 3px; transition: width 0.06s linear; }
.meter i.hot { background: var(--good); }
.meter b { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--talk); }
.meter b[hidden] { display: none; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 14px; background: var(--raised); border-radius: 12px; }
.seg button { height: 34px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: 500 13.5px "Geist", sans-serif; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); }
.seg button:disabled { opacity: 0.4; cursor: default; }
.hint { margin: -6px 0 14px; font-size: 12.5px; color: var(--muted); }
#vadField[hidden] { display: none; }

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  cursor: pointer;
  font-size: 14px;
}

.switch span { order: -1; }

.switch input {
  appearance: none;
  flex: none;
  width: 36px;
  height: 20px;
  margin: 0;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line-2);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}

.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s, background 0.15s;
}

.switch input:checked { background: var(--text); border-color: var(--text); }
.switch input:checked::after { transform: translateX(16px); background: var(--bg); }

.unlock {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--talk);
  color: #1a1206;
  font: 600 14px "Geist", sans-serif;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.unlock[hidden] { display: none; }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .stage { min-height: 0; }
  .v-start, .v-pair, .v-wait, .v-offline, .v-replaced { min-height: 480px; }
}

@media (max-width: 480px) {
  .digits { gap: 6px; }
  .digits input { width: 42px; height: 56px; font-size: 24px; }
  .digits input:nth-child(3) { margin-right: 6px; }
  .live-head { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .hero-rings span { opacity: 0.25; transform: scale(0.6); }
}
