:root {
  --bg: #0E1320; --panel: #161D2E; --panel2: #1E2740; --line: #2A3450;
  --text: #E8ECF5; --muted: #8E99B5; --accent: #2E8BFF; --accent2: #1B6FE0;
  --ok: #34D399; --bad: #F87171; --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.2em; margin: 6px 0; font-size: 14px; }
h1 { font-size: 26px; margin: 8px 0 2px; } h2 { font-size: 17px; margin: 0 0 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: #3a4770; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.link { background: none; border: 0; color: var(--accent); font-weight: 500; height: 36px; }
.btn.ghost { background: none; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
input { width: 100%; height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; }
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input { margin-top: 6px; }

.screen { min-height: 100%; }
#auth { display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card form { text-align: left; margin-top: 22px; }
.auth-card .btn { width: 100%; }
.logo { width: 64px; height: 64px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 18px 0; font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand img { width: 28px; height: 28px; }
.who { display: flex; align-items: center; gap: 8px; }
.badge { white-space: nowrap; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.home-main { max-width: 880px; margin: 0 auto; padding: 20px 16px 40px; }
.connect-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 26px; }
.id-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; }
@media (max-width: 620px) { .id-form { grid-template-columns: 1fr; } }
.list-head { display: flex; justify-content: space-between; align-items: baseline; }
.device-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.device { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.device .row { display: flex; align-items: center; gap: 10px; }
.device .name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .meta { font-size: 13px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #4B5675; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 4px rgba(52,211,153,.15); }
.device .actions { display: flex; gap: 8px; }
.device .actions .btn { flex: 1; height: 40px; }
.device .actions .btn.icon { flex: none; width: 40px; padding: 0; }
.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; }

.overlay { position: fixed; inset: 0; background: rgba(8,11,20,.75); display: grid; place-items: center; z-index: 50; }
.wait-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; text-align: center; width: min(340px, 90vw); }
.spinner { width: 38px; height: 38px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Session */
#session { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; }
.stage { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; }
#video { position: absolute; transform-origin: 0 0; background: #000; cursor: none; user-select: none; -webkit-user-select: none; }
#session.trackpad #video, #session.touch #video { cursor: default; }
.vcursor { position: absolute; width: 18px; height: 18px; margin: -2px 0 0 -2px; pointer-events: none; z-index: 5;
  background: no-repeat center/contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18"><path d="M2 1l13 9-6 1-3 6z" fill="white" stroke="black" stroke-width="1.3"/></svg>'); }
.stage-msg { position: absolute; z-index: 6; background: rgba(14,19,32,.9); padding: 12px 18px; border-radius: 10px; border: 1px solid var(--line); }

.toolbar { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 4px; padding: 5px; max-width: calc(100vw - 16px); overflow-x: auto;
  background: rgba(22,29,46,.94); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(8px); scrollbar-width: none; }
.toolbar::-webkit-scrollbar { display: none; }
.tb { flex: none; height: 36px; min-width: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tb:hover, .tb.on { background: var(--panel2); }
.tb.danger { color: #fff; background: #B42318; }
.tb-name { font-weight: 700; padding: 0 6px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.tb-stat { font-size: 12px; color: var(--muted); white-space: nowrap; padding-right: 4px; }
.tb-sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; flex: none; }
.tb-show { position: absolute; top: max(4px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 20;
  width: 56px; height: 22px; border: 1px solid var(--line); border-radius: 0 0 10px 10px; background: rgba(22,29,46,.9); color: var(--muted); }
.menu { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 54px); left: 50%; transform: translateX(-50%); z-index: 21;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px; display: grid; grid-template-columns: repeat(2, minmax(140px, 1fr)); gap: 4px; max-width: calc(100vw - 16px); }
.menu button { text-align: left; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.menu button:hover, .menu button.on { background: var(--panel2); }
.menu small { display: block; color: var(--muted); font-size: 12px; }
#qualMenu, #monMenu { grid-template-columns: 1fr; min-width: 220px; }

.keybar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; gap: 4px; overflow-x: auto; padding: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: rgba(22,29,46,.96); border-top: 1px solid var(--line); scrollbar-width: none; }
.keybar::-webkit-scrollbar { display: none; }
.keybar button { flex: none; min-width: 46px; height: 40px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; }
.keybar button.on { background: var(--accent); border-color: var(--accent); }
.kb-input { position: absolute; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }
.toast { position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%); z-index: 30; background: var(--panel); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; max-width: 90vw; }
.drop-hint { position: absolute; inset: 16px; z-index: 25; border: 3px dashed var(--accent); border-radius: 18px; display: grid; place-items: center; font-size: 20px; font-weight: 700; background: rgba(46,139,255,.12); pointer-events: none; }
@media (hover: hover) and (pointer: fine) { .touch-only { display: none; } }
@media (hover: none), (pointer: coarse) { .desk-only { display: none; } }
@media (max-width: 440px) { .brand span { display: none; } #planBadge { max-width: 52vw; overflow: hidden; text-overflow: ellipsis; } }
