:root {
  --bg: #060a11;
  --bg-2: #080e18;
  --panel: #0d1522;
  --panel-2: #111c2c;
  --panel-3: #162335;
  --line: #1d2b40;
  --line-soft: #162234;
  --text: #e9f0fa;
  --muted: #8fa2bb;
  --muted-2: #6c7f99;
  --accent: #5b8cff;
  --accent-2: #39d3c4;
  --ok: #3ddc97;
  --warn: #f3b962;
  --danger: #ff6f7d;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --font: "Segoe UI", system-ui, -apple-system, "Inter", Roboto, sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(91, 140, 255, 0.16), transparent 60%),
    radial-gradient(900px 560px at 92% 0%, rgba(57, 211, 196, 0.10), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

.shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }

/* ---------- nav ---------- */
.nav {
  display: flex; align-items: center; gap: 22px;
  padding: 22px 0; border-bottom: 1px solid var(--line-soft);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 650; letter-spacing: -0.02em; font-size: 17px;
}
.brand img { width: 30px; height: 30px; }
.brand span b { color: var(--accent); font-weight: 700; }
.nav-links { display: flex; gap: 6px; margin-left: 14px; }
.nav-links a {
  color: var(--muted); font-size: 14px; padding: 8px 12px; border-radius: 9px;
}
.nav-links a:hover, .nav-links a.active { color: var(--text); background: var(--panel-2); }
.nav-spacer { flex: 1; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #8a5bff); color: #fff;
}
.user-chip .who { font-size: 13px; line-height: 1.2; }
.user-chip .who small { display: block; color: var(--muted-2); font-size: 11px; }

/* ---------- buttons / fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, #6c99ff, var(--accent));
  color: #06101f; box-shadow: 0 8px 24px rgba(91, 140, 255, 0.28);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-ghost { background: var(--panel); border-color: var(--line); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); }
.btn-danger { background: rgba(255, 111, 125, 0.12); border-color: rgba(255, 111, 125, 0.35); color: #ffb3ba; }
.btn-danger:hover:not(:disabled) { background: rgba(255, 111, 125, 0.2); }
.btn-quiet { background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--text); background: var(--panel-2); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 9px; border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); border-color: var(--line); }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 15px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.field input, .field select {
  width: 100%; padding: 12px 13px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder { color: var(--muted-2); }
.field input:focus, .field select:focus {
  border-color: rgba(91, 140, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.14);
}
.hint { font-size: 12px; color: var(--muted-2); line-height: 1.5; }
.error-text { color: #ffb3ba; font-size: 13px; min-height: 18px; margin: 4px 0 12px; }

/* ---------- cards ---------- */
.card {
  background: linear-gradient(180deg, rgba(17, 28, 44, 0.92), rgba(13, 21, 34, 0.92));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset;
}

/* ---------- auth ---------- */
.auth-body { display: grid; grid-template-columns: 1.05fr 0.95fr; min-height: 100vh; }
.auth-brand {
  padding: 54px clamp(34px, 6vw, 84px); display: flex; flex-direction: column; justify-content: center;
  border-right: 1px solid var(--line-soft);
  background:
    radial-gradient(700px 400px at 10% 20%, rgba(91, 140, 255, 0.14), transparent 65%),
    radial-gradient(600px 400px at 90% 80%, rgba(57, 211, 196, 0.08), transparent 60%);
}
.auth-brand .brand { margin-bottom: auto; }
.auth-brand h1 {
  font-size: clamp(34px, 4vw, 52px); line-height: 1.05; letter-spacing: -0.035em;
  margin: 64px 0 18px; font-weight: 680;
}
.auth-brand h1 em {
  font-style: normal;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.auth-brand > p { color: var(--muted); max-width: 460px; line-height: 1.65; font-size: 15.5px; }
.auth-points { list-style: none; padding: 0; margin: 34px 0 0; display: grid; gap: 13px; max-width: 460px; }
.auth-points li { display: flex; gap: 11px; align-items: flex-start; color: var(--muted); font-size: 14px; }
.auth-points .tick {
  flex: none; width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center;
  background: rgba(61, 220, 151, 0.12); color: var(--ok); font-size: 12px; margin-top: 1px;
}
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth-card { width: min(420px, 100%); padding: 34px; box-shadow: var(--shadow); }
.auth-card h2 { font-size: 24px; letter-spacing: -0.02em; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 26px; line-height: 1.55; }
.auth-card .btn { width: 100%; margin-top: 6px; }
.auth-foot { margin-top: 18px; text-align: center; color: var(--muted-2); font-size: 12.5px; }
.fineprint { color: var(--muted-2); font-size: 12px; text-align: center; margin-top: 22px; max-width: 420px; }

/* ---------- dashboard ---------- */
.page { padding: 44px 0 70px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 30px; }
.page-head h1 { font-size: 34px; letter-spacing: -0.03em; font-weight: 670; }
.page-head p { color: var(--muted); margin-top: 7px; font-size: 14.5px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 7px; margin-bottom: 12px;
  color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 18px; }
.device-card { padding: 22px; display: flex; flex-direction: column; gap: 20px; transition: border-color 0.15s, transform 0.15s; }
.device-card:hover { border-color: #2a3f5c; transform: translateY(-1px); }
.device-top { display: flex; gap: 13px; align-items: flex-start; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--muted-2); }
.status-dot.online { background: var(--ok); box-shadow: 0 0 0 4px rgba(61, 220, 151, 0.12); }
.status-dot.offline { background: #44546b; }
.device-top h3 { font-size: 17px; letter-spacing: -0.01em; }
.device-meta { color: var(--muted-2); font-size: 12.5px; margin-top: 4px; display: flex; gap: 7px; flex-wrap: wrap; }
.device-actions { display: flex; gap: 8px; margin-top: auto; }
.device-actions .btn { flex: 1; }
.device-actions .btn-quiet { flex: 0 0 auto; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 650; letter-spacing: 0.02em;
}
.badge.online { background: rgba(61, 220, 151, 0.1); color: var(--ok); }
.badge.offline { background: rgba(143, 162, 187, 0.09); color: var(--muted); }

.empty {
  padding: 68px 24px; text-align: center; border: 1px dashed #26374f; border-radius: var(--radius);
  background: rgba(13, 21, 34, 0.45);
}
.empty .orb {
  width: 62px; height: 62px; margin: 0 auto 18px; border-radius: 18px;
  display: grid; place-items: center; color: var(--accent);
  background: rgba(91, 140, 255, 0.1); border: 1px solid rgba(91, 140, 255, 0.25);
}
.empty h3 { font-size: 18px; margin-bottom: 7px; }
.empty p { color: var(--muted); font-size: 14px; max-width: 440px; margin: 0 auto 22px; line-height: 1.6; }

.member-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.member {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 11px 5px 5px;
  border: 1px solid var(--line); border-radius: 999px; font-size: 12.5px; color: var(--text);
}
.member small { color: var(--muted-2); margin-left: 2px; }
.member .member-remove { width: 20px; height: 20px; font-size: 14px; border-radius: 50%; }
.avatar.small { width: 24px; height: 24px; font-size: 10px; }

.security-card { margin-top: 26px; padding: 22px 24px; display: flex; gap: 16px; align-items: flex-start; }
.security-card .shield {
  width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: rgba(57, 211, 196, 0.1); color: var(--accent-2);
}
.security-card h3 { font-size: 15px; margin-bottom: 5px; }
.security-card p { color: var(--muted); font-size: 13.5px; line-height: 1.6; }

/* ---------- modal ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0;
  background: var(--panel); color: var(--text); width: min(480px, calc(100% - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(3, 7, 13, 0.72); backdrop-filter: blur(4px); }
.modal { padding: 28px; }
.modal h2 { font-size: 21px; letter-spacing: -0.02em; margin-bottom: 6px; }
.modal .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 22px; line-height: 1.55; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

.code-box {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 19px; letter-spacing: 0.16em; color: var(--accent-2);
}
.cmd-box {
  position: relative; margin-top: 12px; padding: 14px 16px; border-radius: 11px;
  background: #070c14; border: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 12.5px; color: #b8c8dd; line-height: 1.55;
  overflow-wrap: anywhere;
}
.copy-row { display: flex; justify-content: flex-end; margin-top: 12px; }
.steps { display: grid; gap: 16px; }
.step { display: flex; gap: 12px; }
.step .num {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-3); color: var(--muted); font-size: 12px; font-weight: 700;
}
.step b { display: block; font-size: 13.5px; margin-bottom: 3px; }
.step p { color: var(--muted); font-size: 12.5px; line-height: 1.5; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 100; }
.toast {
  padding: 13px 16px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 13.5px; box-shadow: var(--shadow);
  min-width: 240px; max-width: 360px; animation: toast-in 0.18s ease-out;
}
.toast.ok { border-color: rgba(61, 220, 151, 0.35); }
.toast.err { border-color: rgba(255, 111, 125, 0.35); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- viewer ---------- */
.viewer-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; background: #05080d; }
.viewer-bar {
  display: flex; align-items: center; gap: 14px; padding: 12px 18px;
  border-bottom: 1px solid var(--line-soft); background: rgba(9, 15, 24, 0.94);
  backdrop-filter: blur(10px); z-index: 5;
}
.viewer-bar .back {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px;
  color: var(--muted); border: 1px solid transparent;
}
.viewer-bar .back:hover { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.viewer-title { font-size: 14.5px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
.viewer-title small { color: var(--muted-2); font-weight: 400; font-size: 12px; }
.viewer-spacer { flex: 1; }
.viewer-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tool { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.tool select, .tool input[type="range"] { accent-color: var(--accent); }
.tool select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font-size: 12.5px; color: var(--text);
}
.tool input[type="range"] { width: 92px; }
.stat-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 11px;
  border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.stat-pill b { color: var(--text); font-weight: 600; }
.stage { position: relative; flex: 1; display: grid; place-items: center; padding: 22px; overflow: hidden; }
.stage::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(700px 420px at 50% 40%, rgba(91, 140, 255, 0.05), transparent 70%);
  pointer-events: none;
}
canvas#screen {
  max-width: 100%; max-height: 100%; border-radius: 10px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.65); background: #000;
  outline: 1px solid rgba(255, 255, 255, 0.07); cursor: default;
}
canvas#screen.grabbing { cursor: none; }
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center; text-align: center; padding: 30px;
  background: rgba(5, 8, 13, 0.72); backdrop-filter: blur(3px); z-index: 3;
  transition: opacity 0.2s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.overlay h2 { font-size: 20px; letter-spacing: -0.02em; }
.overlay p { color: var(--muted); font-size: 14px; max-width: 430px; line-height: 1.6; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(91, 140, 255, 0.2); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.viewer-foot { padding: 9px 18px; color: var(--muted-2); font-size: 11.5px; border-top: 1px solid var(--line-soft); display: flex; gap: 16px; }
.viewer-foot .live { color: var(--ok); }

@media (max-width: 900px) {
  .auth-body { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-panel { min-height: 100vh; }
  .nav-links { display: none; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .viewer-tools .tool.quality, .viewer-tools .tool.fps { display: none; }
  .viewer-foot { display: none; }
}
@media (max-width: 620px) {
  .shell { width: calc(100% - 24px); }
  .page { padding-top: 28px; }
  .page-head h1 { font-size: 27px; }
  .auth-card { padding: 26px 22px; }
  .device-grid { grid-template-columns: 1fr; }
}
