:root {
  --bg: #050c1a;
  --bg2: #0a1630;
  --panel: rgba(12, 24, 50, .72);
  --panel-solid: #0d1a36;
  --line: rgba(110, 190, 255, .16);
  --text: #e8f4ff;
  --muted: #8ea6cc;
  --c1: #5ef0ff;
  --c2: #b47cff;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --grad: linear-gradient(135deg, #5ef0ff 0%, #5cc6ff 45%, #b47cff 100%);
  --r: 16px;
  --shadow: 0 20px 60px -20px rgba(0, 0, 0, .75), 0 0 0 1px var(--line);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: rgba(140,160,255,.12); padding: 2px 6px; border-radius: 6px; }

.view { min-height: 100%; }
.card { background: var(--panel); backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-radius: var(--r); box-shadow: var(--shadow); }

h2.section, .settings h3 { font-family: var(--gw-font); font-weight: 700; }
.card { box-shadow: 0 20px 60px -20px rgba(0,0,0,.75), 0 0 0 1px var(--line), inset 0 1px 0 rgba(255,255,255,.04); }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); }
input, select { width: 100%; margin-top: 6px; padding: 12px 14px; font: inherit; color: var(--text);
  background: rgba(5, 8, 20, .6); border: 1px solid var(--line); border-radius: 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: var(--c1); box-shadow: 0 0 0 3px rgba(56,232,255,.18); }
input.otp { letter-spacing: .5em; font-size: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.error { color: var(--bad); min-height: 1.2em; margin: 0; font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: rgba(140,160,255,.08); color: var(--text); font: 600 14px/1 inherit; cursor: pointer;
  transition: transform .08s, background .15s, opacity .15s; }
.btn:hover { background: rgba(140,160,255,.16); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { border: 0; background: var(--grad); color: #050816; box-shadow: 0 8px 30px -8px rgba(56,232,255,.55); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; padding: 14px; font-size: 15px; }
.btn.busy span::after { content: "…"; }

/* login */
#login, #setup { display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(400px, 100%); padding: 32px 28px; display: grid; gap: 16px; animation: rise .4s ease-out; }
.login-card .brand { margin-bottom: 8px; }
.fine { display: flex; gap: 6px; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; margin: 0; }
.i { width: 14px; height: 14px; fill: none; stroke: var(--ok); stroke-width: 2; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* dashboard */
#dash { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; gap: 12px; }
.who { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.settings { padding: 20px; }
.settings h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.settings .row { display: flex; gap: 24px; justify-content: space-between; flex-wrap: wrap; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; background: rgba(5,8,20,.5); padding: 5px; border-radius: 14px; border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 9px 14px; border-radius: 10px; cursor: pointer; font: 600 13px/1.2 inherit; text-align: left; }
.seg button small { display: block; font-weight: 400; font-size: 11px; opacity: .8; }
.seg button[aria-checked="true"] { background: var(--grad); color: #050816; }
.seg button:not([aria-checked="true"]):hover { color: var(--text); background: rgba(140,160,255,.08); }
.toggles { display: grid; gap: 10px; min-width: 240px; }
.tog { display: flex; gap: 12px; align-items: center; cursor: pointer; color: var(--text); font-size: 14px; }
.tog small { display: block; color: var(--muted); font-size: 12px; }
.tog input { display: none; }
.tog i { flex: none; width: 40px; height: 22px; border-radius: 22px; background: rgba(140,160,255,.2); position: relative; transition: background .2s; }
.tog i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.tog input:checked + i { background: var(--grad); }
.tog input:checked + i::after { transform: translateX(18px); }
.custom { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.custom input[type=range] { padding: 0; accent-color: var(--c1); background: none; border: 0; box-shadow: none; }
.section { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 32px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.host { padding: 20px; display: grid; gap: 14px; position: relative; overflow: hidden; animation: rise .35s ease-out both; }
.host::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--grad); opacity: .0; transition: opacity .2s; }
.host.online::before { opacity: 1; }
.host .h { display: flex; gap: 14px; align-items: center; }
.host .os { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: rgba(140,160,255,.1); flex: none; }
.host .os svg { width: 24px; height: 24px; stroke: var(--text); fill: none; stroke-width: 1.6; }
.host .meta { min-width: 0; }
.host h4 { margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host .st { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4b5378; }
.online .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.inuse .dot { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 24px; }
.chip { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: rgba(140,160,255,.1); color: var(--muted); border: 1px solid var(--line); }
.chip.key { color: var(--ok); border-color: rgba(52,211,153,.35); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.chip.warn { color: var(--warn); border-color: rgba(251,191,36,.35); }
.chip.bad { color: var(--bad); border-color: rgba(248,113,113,.4); }
.host .acts { display: flex; gap: 8px; }
.host .acts .btn.primary { flex: 1; }
.empty { color: var(--muted); }

/* stream */
#stream { position: fixed; inset: 0; background: #000; overflow: hidden; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; outline: none; touch-action: none; }
#stream.locked #video { cursor: none; }
#stream:not(.locked) #video { cursor: default; }
.mobile-kbd { position: absolute; left: -1000px; top: 0; width: 1px; height: 1px; opacity: 0; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: radial-gradient(circle, rgba(5,12,26,.55), rgba(5,12,26,.96)), url(bg-net.svg); z-index: 5; }
.conn { padding: 28px 32px; width: min(380px, calc(100% - 32px)); text-align: center; }
.conn h3 { margin: 14px 0; }
.steps { list-style: none; padding: 0; margin: 0 0 18px; text-align: left; display: grid; gap: 8px; }
.steps li { color: var(--muted); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.steps li::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #3a4266; flex: none; }
.steps li.active { color: var(--text); }
.steps li.active::before { border-color: var(--c1); border-top-color: transparent; animation: spin .8s linear infinite; }
.steps li.done { color: var(--text); }
.steps li.done::before { border: 0; background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' stroke='%23050816' stroke-width='2' fill='none'/%3E%3C/svg%3E") center/12px no-repeat; }
.steps li.fail::before { border-color: var(--bad); background: var(--bad); }
.conn-ghost { width: 96px; filter: drop-shadow(0 0 16px rgba(94,200,255,.45)); }
.conn .flow { margin: 4px -8px 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 4; display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; border-radius: 14px; background: rgba(12, 18, 36, .82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow); transition: opacity .25s, transform .25s; max-width: calc(100% - 24px); overflow-x: auto; }
.toolbar.hide { opacity: 0; transform: translate(-50%, -140%); pointer-events: none; }
.tb-handle { position: absolute; top: 0; left: 25%; right: 25%; height: 10px; z-index: 3; }
.tb-host { font-weight: 600; font-size: 13px; padding: 0 8px; white-space: nowrap; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.tb { width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--text); cursor: pointer; display: grid; place-items: center; font-size: 12px; flex: none; }
.tb svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tb:hover { background: rgba(140,160,255,.14); }
.tb.on { background: rgba(56,232,255,.18); color: var(--c1); }
.tb.danger:hover { background: rgba(248,113,113,.2); color: var(--bad); }
.tb-select { width: auto; margin: 0; padding: 7px 10px; font-size: 13px; border-radius: 10px; }
.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: rgba(140,160,255,.12); color: var(--muted); white-space: nowrap; }
.badge.p2p { color: var(--ok); background: rgba(52,211,153,.12); }
.badge.relay { color: var(--warn); background: rgba(251,191,36,.12); }
.cpanel { position: absolute; left: 12px; bottom: 12px; z-index: 4; width: min(380px, calc(100% - 24px)); max-height: calc(100% - 90px);
  overflow-y: auto; padding: 14px 16px; background: rgba(6, 14, 32, .86); }
.cp-head { display: flex; align-items: center; gap: 10px; }
.cp-head .ghost { width: 40px; }
.cp-head b { display: block; font: 700 13px var(--gw-font); letter-spacing: .08em; text-transform: uppercase; }
.cp-head small { display: block; color: var(--muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace; }
.cp-head .q-meter { margin-left: auto; }
.cpanel .flow { margin: 6px -4px 2px; }
.cpanel h4 { margin: 12px 0 6px; font: 700 10px var(--gw-font); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.cp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cp-grid div { background: rgba(94,200,255,.06); border: 1px solid var(--line); border-radius: 10px; padding: 6px 9px; }
.cp-grid small { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.cp-grid b { font: 600 13px ui-monospace, Consolas, monospace; color: #dff7ff; }
.cp-sec { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 12px; }
.cp-sec li { display: flex; gap: 8px; align-items: flex-start; line-height: 1.35; }
.cp-sec li::before { content: ""; flex: none; width: 14px; height: 14px; margin-top: 1px; border-radius: 50%; background: var(--ok) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' stroke='%23050816' stroke-width='2' fill='none'/%3E%3C/svg%3E") center/10px no-repeat; box-shadow: 0 0 8px rgba(52,211,153,.5); }
.cp-sec li.warn::before { background-color: var(--warn); box-shadow: 0 0 8px rgba(251,191,36,.5); }
.cp-sec li span { color: var(--muted); font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

dialog { border: 0; color: var(--text); padding: 24px; width: min(480px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(3, 5, 12, .7); backdrop-filter: blur(4px); }
dialog h3 { margin: 0 0 8px; }
dialog p { color: var(--muted); font-size: 14px; }
dialog input, dialog textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
textarea { width: 100%; margin-top: 10px; padding: 12px 14px; font-size: 13px; color: var(--text); background: rgba(5,8,20,.6);
  border: 1px solid var(--line); border-radius: 12px; outline: none; resize: vertical; word-break: break-all; }
textarea:focus { border-color: var(--c1); box-shadow: 0 0 0 3px rgba(56,232,255,.18); }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.fine-left { font-size: 12px !important; margin: 6px 0 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.toasts { position: fixed; bottom: 16px; right: 16px; z-index: 50; display: grid; gap: 8px; max-width: calc(100% - 32px); }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--panel-solid); box-shadow: var(--shadow); font-size: 14px; animation: rise .25s ease-out; border-left: 3px solid var(--c1); }
.toast.err { border-left-color: var(--bad); }

@media (max-width: 640px) {
  .settings .row { flex-direction: column; }
  .seg button { flex: 1 1 45%; }
  .who span { display: none; }
  .tb-host { display: none; }
}

.lead-s { margin: 0; color: var(--muted); font-size: 14px; }
.fine a { color: var(--c1); }
.update-banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; margin-bottom: 16px;
  box-shadow: 0 0 0 1px rgba(56,232,255,.35), 0 20px 60px -20px rgba(0,0,0,.7); }
.lang-sel { position: fixed; top: 12px; right: 12px; z-index: 6; width: auto; margin: 0; padding: 6px 10px; font-size: 12px; border-radius: 10px; }
.lang-sel.inline { position: static; }
body:has(#stream:not([hidden])) .lang-sel { display: none; }
.badge.dbg { color: #fca5a5; background: rgba(248,113,113,.15); font-weight: 700; letter-spacing: .06em; }
.debug-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.debug-row .btn { margin-left: auto; }
