:root {
  --bg: #0a1226;
  --card: rgba(22, 24, 32, 0.72);
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef0f6;
  --muted: #8b90a0;
  --accent: #8fb0ea;
  --accent2: #5b8def;
  --danger: #ff6b7a;
  --ok: #4ade80;
  --r: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --kb: 0px;
  --inset-b: 0px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- connect ---------- */
.screen { position: fixed; inset: 0; }
#connect { display: flex; flex-direction: column; align-items: center; justify-content: safe center; padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r)) calc(24px + var(--safe-b)) calc(20px + var(--safe-l)); overflow-y: auto; }
.glow { position: absolute; inset: -20%; pointer-events: none;
  background: radial-gradient(40% 35% at 30% 20%, rgba(143,176,234,.18), transparent 70%), radial-gradient(35% 30% at 75% 75%, rgba(91,141,239,.14), transparent 70%);
  filter: blur(10px); animation: drift 18s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate3d(3%, -2%, 0) scale(1.05); } }
.card { position: relative; width: 100%; max-width: 400px; padding: 28px; border-radius: 26px; background: var(--card);
  border: 1px solid var(--line); backdrop-filter: blur(30px) saturate(140%); -webkit-backdrop-filter: blur(30px) saturate(140%);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.6); animation: rise .5s cubic-bezier(.2,.8,.2,1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.brand { margin-bottom: 26px; }
.brand .lockup { display: block; height: 34px; width: auto; max-width: 100%; }
.brand p { margin: 10px 0 0; font-size: 14px; }
h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; font-weight: 650; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 7px 2px; letter-spacing: .01em; }
.field input { width: 100%; height: 50px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); outline: none;
  background: rgba(255,255,255,.04); color: var(--text); font-size: 17px; transition: border-color .15s, background .15s, box-shadow .15s; }
.field input:focus { border-color: rgba(143,176,234,.6); background: rgba(255,255,255,.06); box-shadow: 0 0 0 4px rgba(143,176,234,.12); }
.field input.bad { border-color: rgba(255,107,122,.6); box-shadow: 0 0 0 4px rgba(255,107,122,.1); }
.field input.pin { font-variant-numeric: tabular-nums; letter-spacing: .35em; font-size: 20px; font-weight: 600; }
.field input.pin.pw { letter-spacing: .04em; }
.pinrow { position: relative; }
.pinrow input.pin { padding-right: 64px; }
.pinmode { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); height: 32px; min-width: 48px; padding: 0 10px; border: 0; border-radius: 8px; background: rgba(255,255,255,.08); color: inherit; opacity: .75; font: 600 13px/1 inherit; letter-spacing: .02em; cursor: pointer; }
.pinmode:hover, .pinmode:focus-visible { opacity: 1; background: rgba(255,255,255,.14); }
.err { min-height: 20px; margin: 2px 2px 10px; color: var(--danger); font-size: 13.5px; }
.btn { width: 100%; height: 52px; border: 0; border-radius: 15px; font-weight: 600; font-size: 16px; transition: transform .12s, filter .15s, opacity .15s; }
.btn:active { transform: scale(.98); }
.btn.primary { color: #0a1226; background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 10px 30px -10px rgba(91,141,239,.6); }
.btn.primary:hover { filter: brightness(1.07); }
.btn[disabled] { opacity: .6; pointer-events: none; }
.recent { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.recent-h { font-size: 12.5px; color: var(--muted); margin: 0 0 8px 2px; }
.ritem { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: 12px; border: 0; background: transparent; text-align: left; transition: background .15s; }
.ritem:hover { background: rgba(255,255,255,.05); }
.ritem .dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(143,176,234,.12); color: var(--accent); flex: none; }
.ritem .dot svg { width: 18px; height: 18px; }
.ritem b { display: block; font-weight: 550; font-size: 14.5px; }
.ritem small { color: var(--muted); font-size: 12.5px; }
.ritem .x { margin-left: auto; opacity: .4; padding: 4px 6px; border-radius: 6px; }
.ritem .x:hover { opacity: 1; background: rgba(255,255,255,.08); }
.foot { position: relative; margin-top: 18px; font-size: 13px; text-align: center; }

/* ---------- session ---------- */
#session { background: #000; }
#stage { position: absolute; inset: 0 0 var(--inset-b) 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#video { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #000; pointer-events: none; will-change: transform; }
#stage.desktop { cursor: default; }
#vcursor { position: absolute; left: 0; top: 0; width: 22px; height: 22px; margin: -3px 0 0 -3px; pointer-events: none; z-index: 2;
  background: no-repeat center/contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 2l15 11-7 1-4 7z' fill='white' stroke='black' stroke-width='1.4' stroke-linejoin='round'/%3E%3C/svg%3E");
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }

.bar { position: absolute; left: 50%; top: calc(10px + var(--safe-t)); transform: translateX(-50%); z-index: 10; display: flex; align-items: center; gap: 2px;
  padding: 5px; border-radius: 16px; max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none; background: rgba(18,19,25,.78); border: 1px solid var(--line);
  backdrop-filter: blur(24px) saturate(150%); -webkit-backdrop-filter: blur(24px) saturate(150%); box-shadow: 0 12px 40px rgba(0,0,0,.45);
  transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .2s; }
.bar.hide { transform: translate(-50%, calc(-100% - 20px - var(--safe-t))); opacity: 0; pointer-events: none; }
.bar::-webkit-scrollbar { display: none; }
.ib { flex: none; width: 42px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 11px; background: transparent; color: #d9dcea; transition: background .15s, color .15s; }
.ib:hover { background: rgba(255,255,255,.08); }
.ib.on { background: rgba(143,176,234,.18); color: var(--accent); }
.ib.danger:hover { background: rgba(255,107,122,.16); color: var(--danger); }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.bar-handle { position: absolute; left: 50%; top: var(--safe-t); transform: translateX(-50%); z-index: 9; width: 140px; height: 30px; border: 0; background: transparent; padding: 0; }
.bar-handle::after { content: ""; display: block; margin: 8px auto 0; width: 48px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.4); box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.stats { position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b) + var(--inset-b)); z-index: 5; font: 11.5px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; color: rgba(255,255,255,.78);
  background: rgba(0,0,0,.55); padding: 4px 8px; border-radius: 8px; pointer-events: none; opacity: 0; transition: opacity .3s; }
.stats.show { opacity: 1; }

.keys { position: absolute; left: 0; right: 0; bottom: var(--kb); z-index: 11; display: flex; gap: 6px; overflow-x: auto; padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  background: rgba(18,19,25,.9); border-top: 1px solid var(--line); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); scrollbar-width: none; }
.keys::-webkit-scrollbar { display: none; }
.keys { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
.keys button { flex: none; min-width: 46px; height: 38px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.06); font-size: 14px; font-weight: 550; }
.keys button.on { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #0a1226; border-color: transparent; }
.keys button:active { transform: scale(.95); }
.kb-up .keys { padding-bottom: 8px; }
#kbd { position: fixed; left: 0; top: 0; width: 1px; height: 1px; padding: 0; border: 0; opacity: 0; font-size: 16px; pointer-events: none; resize: none; }

.sheet { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-start; justify-content: center; padding-top: calc(62px + var(--safe-t)); background: rgba(0,0,0,.25); }
.sheet-card { min-width: 260px; max-width: calc(100vw - 24px); padding: 8px; border-radius: 18px; background: rgba(24,25,33,.94); border: 1px solid var(--line);
  backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px); box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: pop .18s cubic-bezier(.2,.8,.2,1) both; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
.sheet-card h3 { margin: 8px 12px 6px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border: 0; border-radius: 11px; background: transparent; text-align: left; }
.opt:hover { background: rgba(255,255,255,.06); }
.opt small { display: block; color: var(--muted); font-size: 12.5px; }
.opt .chk { margin-left: auto; color: var(--accent); opacity: 0; }
.opt.sel .chk { opacity: 1; }
.sheet textarea { width: 100%; min-height: 110px; margin: 4px 0 8px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--text); font: inherit; resize: vertical; outline: none; }
.row { display: flex; gap: 8px; }
.row .btn { height: 44px; font-size: 14.5px; }
.btn.ghost { background: rgba(255,255,255,.07); }
.btn.slim { width: auto; height: 40px; padding: 0 22px; font-size: 14.5px; margin-top: 4px; }

.overlay { position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: rgba(11,12,16,.92); transition: opacity .3s; }
.overlay.gone { opacity: 0; pointer-events: none; }
.overlay p { margin: 0; color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.12); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: absolute; left: 50%; bottom: calc(70px + var(--safe-b) + var(--inset-b)); max-width: calc(100vw - 24px); white-space: normal; text-align: center; transform: translate(-50%, 10px); z-index: 40; padding: 10px 16px; border-radius: 12px;
  background: rgba(30,31,40,.95); border: 1px solid var(--line); font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (hover: hover) and (pointer: fine) { #bMode, #bKeyboard, .bar-handle { display: none; } }
@media (max-width: 400px) { .ib { width: 38px; } .sheet-card { min-width: 0; width: calc(100vw - 24px); } }
.badge { position: absolute; left: calc(10px + var(--safe-l)); bottom: calc(10px + var(--safe-b) + var(--inset-b)); z-index: 5; display: flex; align-items: center; gap: 6px; padding: 5px 10px 5px 8px; border-radius: 9px;
  font-size: 12.5px; color: #fff; background: rgba(0,0,0,.6); border: 1px solid var(--line); pointer-events: none; }
.badge svg { width: 15px; height: 15px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field input:focus-visible { outline: none; }
.sheet-card { max-height: calc(100% - 80px - var(--safe-t)); overflow-y: auto; }
@media (max-height: 420px) { .sheet { padding-top: calc(56px + var(--safe-t)); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
