:root {
  --bg: #0b0d12; --card: #141821; --line: #252b38; --text: #e8ebf2; --muted: #8b93a7;
  --accent: #4f8cff; --accent-2: #7b5cff; --danger: #ff5b6b; --ok: #36d399; --warn: #f5b84b;
  color-scheme: dark;
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; }

#shell {
  min-height: 100%; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) 16px 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2340 0%, transparent 60%), var(--bg);
}
.card {
  width: min(420px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); text-align: center;
}
.card.wide { width: min(620px, 100%); text-align: left; }
.logo { width: 56px; height: 56px; margin: 0 auto 16px; background: url(icon.svg) center / contain no-repeat; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
button {
  font: inherit; color: var(--text); background: #1d2230; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; cursor: pointer; transition: transform .06s, background .15s, opacity .15s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; font-weight: 600; }
button.big { width: 100%; padding: 16px; font-size: 17px; margin: 18px 0 8px; border-radius: 14px; }
button.ghost { background: transparent; }
button.link { background: none; border: 0; color: var(--muted); text-decoration: underline; margin-top: 16px; }
input, select, textarea {
  font: inherit; color: var(--text); background: #0f1219; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.otp { text-align: center; font-size: 30px; letter-spacing: .45em; padding: 14px; margin: 18px 0 12px; font-variant-numeric: tabular-nums; }
#login-form button { width: 100%; padding: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); vertical-align: middle; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--danger); }
details.settings { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
details.settings summary { cursor: pointer; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 12px; }
.grid label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.grid label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.grid label.check input { width: auto; }
footer { margin-top: 16px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 6px auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- session ---------- */
#session { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#stage { position: absolute; inset: 0; display: grid; place-items: center; }
#screen { display: block; background: #000; outline: none; image-rendering: auto; touch-action: none; }
#viewport { position: relative; transform-origin: 0 0; will-change: transform; }
#cursor-overlay { position: absolute; pointer-events: none; left: 0; top: 0; width: 100%; height: 100%; }
#ime { position: absolute; left: -1000px; top: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; }

.toolbar {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 2px; padding: 5px; border-radius: 14px; z-index: 10;
  background: rgba(20,24,33,.82); backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(255,255,255,.08); box-shadow: 0 8px 30px rgba(0,0,0,.4);
  transition: opacity .25s;
}
.toolbar button, .toolbar-show { background: transparent; border: 0; padding: 8px; border-radius: 10px; display: grid; place-items: center; }
.toolbar button:hover { background: rgba(255,255,255,.08); }
.toolbar button.active { background: rgba(79,140,255,.25); }
.toolbar svg, .toolbar-show svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar button.danger { color: var(--danger); }
.toolbar.idle { opacity: .25; }
.toolbar.idle:hover { opacity: 1; }
.toolbar-show { position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 10; background: rgba(20,24,33,.7); border-radius: 0 0 10px 10px; padding: 2px 14px; }

.popover {
  position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 56px); left: 50%; transform: translateX(-50%);
  min-width: 260px; max-height: 70vh; overflow: auto; z-index: 11; padding: 6px; border-radius: 12px;
  background: rgba(20,24,33,.95); backdrop-filter: blur(14px); border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.popover button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 9px 12px; }
.popover button:hover { background: rgba(255,255,255,.07); }
.popover button.selected::after { content: " ✓"; color: var(--accent); }
.popover.panel { width: min(380px, 92vw); padding: 12px; display: grid; gap: 8px; }
.popover.panel .row { justify-content: flex-start; }
.popover.panel .row button { width: auto; display: inline-block; text-align: center; padding: 8px 14px; border: 1px solid var(--line); }
.popover.panel .row button.primary { border: 0; }

.stats {
  position: absolute; left: 10px; bottom: max(10px, env(safe-area-inset-bottom)); z-index: 9; pointer-events: none;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre;
  background: rgba(0,0,0,.6); padding: 8px 10px; border-radius: 8px; color: #cfe3ff;
}
.toast {
  position: absolute; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 12;
  background: rgba(20,24,33,.95); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; max-width: 90vw;
}
.overlay-msg { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; z-index: 8; background: rgba(0,0,0,.55); }
.overlay-msg p { margin: 8px 0 0; color: var(--muted); }

#pair-form { display: grid; gap: 10px; margin-top: 14px; }
.steps { text-align: left; padding-left: 20px; margin: 12px 0 0; }
.steps li { margin: 6px 0; }
