:root {
  color-scheme: dark;
  --bg: #101116;
  --panel: #191a22;
  --panel-raised: #20212b;
  --ink: #f4f2fa;
  --muted: #9695a5;
  --line: #2b2c38;
  --accent: #9878ff;
  --accent-soft: #302747;
  --green: #62d9a4;
  --red: #ff6878;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
h1, h2, p, figure { margin: 0; }

.topbar { height: 64px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; background: #15161c; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; }
.logo { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: #fff; background: var(--accent); font-weight: 800; font-size: 18px; }
.brand h1 { font-size: 15px; letter-spacing: .01em; }
.tagline { margin-top: 1px; color: var(--muted); font-size: 11px; }
.pills { display: flex; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--panel); font-size: 11px; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: #777886; }
.pill.on { color: var(--green); border-color: #345b4e; }
.pill.on i, .pill.live i { background: var(--green); }
.pill.live { color: var(--green); border-color: #345b4e; }

.layout { width: min(1500px, 100%); min-height: calc(100dvh - 64px); margin: 0 auto; padding: 18px 24px; display: grid; grid-template-columns: minmax(360px, 1fr) minmax(420px, .95fr); grid-template-rows: minmax(170px, auto) minmax(370px, 1fr); grid-template-areas: "mic fx" "call fx"; gap: 14px; }
.area-mic { grid-area: mic; }
.area-fx { grid-area: fx; }
.area-call { grid-area: call; }
.card { min-width: 0; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.card h2 { font-size: 14px; font-weight: 700; letter-spacing: .01em; }
.hint { color: var(--muted); font-size: 11px; }
.count { margin-left: 5px; color: var(--muted); font-size: 11px; font-weight: 500; }

.row { display: flex; align-items: center; gap: 8px; }
.area-mic > .row { margin-top: 13px; }
.btn { height: 38px; padding: 0 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: var(--panel-raised); font-weight: 650; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn.danger { color: #fff; background: #b83f54; border-color: #b83f54; }
.btn.subtle { height: 32px; padding: 0 10px; color: var(--muted); background: transparent; font-size: 11px; }
.btn.icon-btn { width: 40px; padding: 0; }
.btn.grow { flex: 1; }
.input { min-width: 0; height: 40px; flex: 1; padding: 0 12px; outline: none; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #12131a; }
.input:focus { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, .fx:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mic-check { margin-top: 11px; display: grid; grid-template-columns: auto minmax(90px, 1fr); align-items: center; gap: 6px 10px; }
.small-label { color: var(--muted); font-size: 10px; }
select.input { height: 32px; font-size: 11px; }
.meter { height: 5px; grid-column: 1 / -1; overflow: hidden; border-radius: 9px; background: #2a2b35; }
.meter-fill { width: 0; height: 100%; background: var(--green); transition: width .06s linear; }
.mic-hint { grid-column: 1 / -1; color: var(--muted); font-size: 10px; }
.mic-hint.ok { color: var(--green); }
.mic-hint.warn { color: #e9b65a; }
.scopes { display: none; }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); font-size: 11px; cursor: pointer; }
.switch small { color: var(--muted); }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch .track { position: relative; width: 32px; height: 18px; flex: none; border-radius: 99px; background: #393a46; transition: background .15s; }
.switch .thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: white; transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(14px); }
.switch.attention { outline: 1px solid var(--accent); outline-offset: 4px; border-radius: 5px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 12px 0 0; }
.stats.five { grid-template-columns: repeat(auto-fit, minmax(86px, 1fr)); }
.stats div { min-width: 0; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-raised); }
.stats dt { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .04em; }
.stats dd { margin: 2px 0 0; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.good { color: var(--green); } .meh { color: #e9b65a; } .bad { color: var(--red); }

.area-fx { min-height: 0; overflow-y: auto; }
.fx-head h2 { font-size: 15px; }
.fx-head .hint { margin-top: 3px; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 14px 0 12px; padding-bottom: 3px; scrollbar-width: thin; }
.chip { flex: none; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: transparent; font-size: 10px; font-weight: 650; cursor: pointer; }
.chip[aria-selected="true"] { color: #d8ccff; background: var(--accent-soft); border-color: #59467f; }
.fx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.fx { min-width: 0; min-height: 76px; padding: 9px 10px; display: grid; align-content: center; gap: 3px; text-align: left; color: var(--ink); background: #20212a; border: 1px solid transparent; border-radius: 10px; cursor: pointer; }
.fx:hover { background: #282936; }
.fx[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.fx-icon { font-size: 18px; line-height: 1; }
.fx-name { font-size: 11px; font-weight: 700; }
.fx-desc { color: var(--muted); font-size: 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.area-call { min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; }
.call-header { width: 100%; display: flex; align-items: center; gap: 9px; text-align: left; }
.call-header h2 { font-size: 12px; color: var(--muted); font-weight: 600; }
.call-live-dot { width: 8px; height: 8px; border-radius: 50%; background: #656672; }
.status { margin-top: 2px; color: var(--muted); font-size: 10px; }
.status.live { color: var(--green); font-weight: 700; }
.status.error { color: var(--red); }
.call-visual { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.call-orb { width: 100px; height: 100px; display: grid; place-items: center; border: 1px solid #574879; border-radius: 50%; color: #d8ccff; background: radial-gradient(circle at 35% 30%, #3e315f, #211b31 72%); box-shadow: 0 0 55px rgba(152,120,255,.12), inset 0 0 22px rgba(152,120,255,.12); font-size: 33px; }
.call-peer { margin-top: 16px; font-size: 15px; font-weight: 700; }
.call-prompt { max-width: 310px; margin-top: 4px; color: var(--muted); font-size: 11px; }
.layout { grid-template-rows: minmax(170px, auto) minmax(370px, 1fr) auto; grid-template-areas: "mic fx" "call fx" "phone fx"; }
.area-phone { grid-area: phone; display: grid; gap: 10px; }
.area-phone .call-header { align-items: flex-start; }
.area-phone .call-header > div { flex: 1; min-width: 0; }
.area-phone.phone-live { border-color: #51426f; }
.area-phone.phone-live .call-live-dot { background: var(--green); box-shadow: 0 0 0 5px rgba(98,217,164,.1); }
.pstn-timer { color: var(--green); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pstn-row .input { flex: 1; min-width: 0; }
.pstn-settings { display: grid; gap: 4px; }
.pstn-settings[open] { padding-bottom: 2px; }
.pstn-settings .input { width: 100%; margin-bottom: 4px; }
body.in-call .area-phone { display: none; }
.server-row { width: min(400px, 100%); display: grid; gap: 4px; margin-bottom: 8px; }
.server-row .input { text-align: center; }
.call-controls { width: min(400px, 100%); }
.call-controls .input { text-align: center; }
#leaveBtn { margin-left: auto; }
.diagnostics, .recording { width: 100%; color: var(--muted); text-align: left; font-size: 10px; }
.diagnostics summary, .recording summary { cursor: pointer; }
.diagnostics .hint { margin-top: 6px; }
.recording-content { padding-top: 8px; }
.rec-result { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.rec-result audio { min-width: 0; max-width: 100%; flex: 1; }
#remoteAudio, .foot { display: none; }
.toast { position: fixed; z-index: 5; bottom: 18px; left: 50%; max-width: calc(100% - 28px); transform: translateX(-50%); padding: 10px 14px; color: white; background: #b83f54; border-radius: 9px; }

body.in-call { overflow: hidden; }
body.in-call .layout { height: calc(100dvh - 64px); grid-template-rows: 148px minmax(0, 1fr); grid-template-areas: "mic fx" "call fx"; overflow: hidden; }
body.in-call .area-mic { display: grid; grid-template-columns: auto minmax(130px, 1fr) auto; align-items: center; gap: 12px; }
body.in-call .area-mic h2 { white-space: nowrap; }
body.in-call .area-mic > .row { margin: 0; }
body.in-call .area-mic .mic-check { margin: 0; }
body.in-call .area-mic .mic-hint { display: none; }
body.in-call .area-mic .controls { margin: 0; }
body.in-call .area-call { border-color: #51426f; }
body.in-call .call-live-dot { background: var(--green); box-shadow: 0 0 0 5px rgba(98,217,164,.1); }
body.in-call .call-orb { animation: pulse 2s ease-in-out infinite; }
body.in-call .call-prompt { display: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(152,120,255,.06), 0 0 65px rgba(152,120,255,.2); } }

@media (max-width: 900px) {
  .topbar { height: 58px; padding: 0 14px; }
  .tagline { display: none; }
  .layout { min-height: calc(100dvh - 58px); display: flex; flex-direction: column; padding: 10px; gap: 10px; }
  .card { padding: 14px; }
  .area-fx { max-height: 65vh; }
  .area-call { min-height: 300px; }
  body.in-call { overflow: hidden; }
  body.in-call .layout { height: calc(100dvh - 58px); min-height: 0; display: grid; grid-template-columns: 1fr; grid-template-rows: 125px minmax(0, 1fr) 98px; grid-template-areas: "call" "fx" "mic"; padding: 8px; gap: 8px; }
  body.in-call .area-call { min-height: 0; }
  body.in-call .area-mic { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; }
  body.in-call .area-mic h2, body.in-call .area-mic .mic-check { display: none; }
  body.in-call .area-mic > .row { flex: 1; margin: 0; }
  body.in-call .area-mic #beepBtn { display: none; }
  body.in-call .area-mic .controls { margin: 0; }
  body.in-call .area-fx { max-height: none; height: 100%; }
  body.in-call .fx-grid { grid-template-columns: repeat(auto-fill, minmax(94px, 1fr)); gap: 6px; }
  body.in-call .fx { min-height: 66px; padding: 7px; }
  body.in-call .call-orb { width: 60px; height: 60px; font-size: 24px; }
  body.in-call .call-peer { margin-top: 9px; font-size: 13px; }
  body.in-call .call-controls { width: min(340px, 100%); }
  body.in-call .call-controls .input { max-width: 130px; }
  body.in-call .diagnostics, body.in-call .recording { display: none; }
}
