:root {
  --bg: #0b1220; --bg2: #111a2e; --card: #16223a; --line: #263556; --txt: #e8eefc; --mut: #8fa0c4;
  --pri: #3b82f6; --pri2: #2563eb; --ok: #22c55e; --bad: #ef4444;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--txt); overflow: hidden; overscroll-behavior: none;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; overflow-y: auto; }
.screen.active { display: block; }
#screen-session.active { overflow: hidden; background: #000; bottom: auto; height: var(--vh, 100%); }
#handle { position: absolute; z-index: 6; left: 50%; top: calc(var(--safe-t) + 2px); transform: translateX(-50%); width: 56px; height: 18px; border-radius: 0 0 12px 12px; background: rgba(15,23,42,.6); border: 0; }
#handle::after { content: ''; position: absolute; left: 20px; top: 7px; width: 16px; height: 3px; border-radius: 2px; background: #cbd5e1; }
#topbar:not(.hide) ~ #handle { opacity: 0; pointer-events: none; }

/* ---- conexão ---- */
#screen-connect { padding: calc(var(--safe-t) + 28px) 20px calc(var(--safe-b) + 20px); background: radial-gradient(900px 500px at 50% -10%, #1a2b52 0%, var(--bg) 60%); }
.brand { text-align: center; margin: 12px 0 24px; }
.logo { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 18px; background: linear-gradient(135deg, var(--pri), #7c3aed); display: grid; place-items: center; box-shadow: 0 10px 30px rgba(59,130,246,.35); }
.logo svg { width: 34px; height: 34px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: .2px; }
.brand p { margin: 4px 0 0; color: var(--mut); }
.card { max-width: 440px; margin: 0 auto; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
.card label { display: block; font-size: 13px; color: var(--mut); margin: 12px 0 6px; }
.card label:first-child { margin-top: 0; }
input { width: 100%; background: var(--bg2); border: 1px solid var(--line); color: var(--txt); border-radius: 12px; padding: 14px; font: inherit; font-size: 17px; outline: none; }
input:focus { border-color: var(--pri); box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
#in-id { font-size: 24px; letter-spacing: 2px; font-variant-numeric: tabular-nums; text-align: center; }
.pw { position: relative; }
.pw input { padding-right: 52px; }
.pw .icon-btn { position: absolute; right: 4px; top: 4px; }
.primary { width: 100%; margin-top: 18px; padding: 15px; border-radius: 14px; font-weight: 600; font-size: 17px; background: linear-gradient(180deg, var(--pri), var(--pri2)); color: #fff; }
.primary:active { filter: brightness(.9); }
.primary:disabled { opacity: .55; }
.secondary { padding: 12px 22px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.msg { min-height: 20px; margin: 12px 0 0; text-align: center; font-size: 14px; color: var(--bad); }
.msg.info { color: var(--mut); }
.recent { max-width: 440px; margin: 22px auto 0; }
.recent h2 { font-size: 13px; color: var(--mut); text-transform: uppercase; letter-spacing: .08em; margin: 0 0 8px; font-weight: 600; }
.recent button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: left; }
.recent .dot { width: 36px; height: 36px; border-radius: 10px; background: var(--bg2); display: grid; place-items: center; }
.recent b { display: block; font-variant-numeric: tabular-nums; }
.recent small { color: var(--mut); }
.foot { max-width: 440px; margin: 22px auto 0; text-align: center; color: var(--mut); font-size: 13px; }
.link { background: none; color: var(--pri); text-decoration: underline; padding: 8px; font-size: 14px; }

.center { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 10px; }
.center p { color: var(--mut); max-width: 320px; margin: 0; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--pri); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- sessão ---- */
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; background: #000; }
#cv { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; image-rendering: auto; }
#cursor { position: absolute; width: 22px; height: 22px; margin: -2px 0 0 -2px; pointer-events: none; z-index: 3;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M3 2l7 19 3-8 8-3z' fill='white' stroke='black' stroke-width='1.5' stroke-linejoin='round'/></svg>") no-repeat; background-size: contain; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.55); z-index: 4; }
#toast { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translateX(-50%) translateY(20px); background: rgba(15,23,42,.95); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: .25s; pointer-events: none; max-width: 86vw; text-align: center; z-index: 6; }
#toast.on { opacity: 1; transform: translateX(-50%); }

#topbar { position: absolute; left: 0; right: 0; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-t) + 6px) calc(var(--safe-r) + 8px) 8px calc(var(--safe-l) + 8px);
  background: linear-gradient(180deg, rgba(8,13,26,.92), rgba(8,13,26,.75)); backdrop-filter: blur(10px); transition: transform .25s; }
#topbar.hide { transform: translateY(-110%); }
#topbar .title { flex: 1; min-width: 0; padding: 0 6px; }
#topbar b, #topbar small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar small { color: var(--mut); font-size: 12px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; background: transparent; font-size: 20px; display: grid; place-items: center; }
.icon-btn:active { background: rgba(255,255,255,.1); }
.chip { padding: 8px 12px; border-radius: 999px; background: rgba(59,130,246,.18); border: 1px solid rgba(59,130,246,.5); font-size: 13px; font-weight: 600; }

#keys { position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; gap: 6px; overflow-x: auto; padding: 8px calc(var(--safe-r) + 8px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 8px);
  background: rgba(8,13,26,.95); border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; scrollbar-width: none; }
#keys::-webkit-scrollbar { display: none; }
#keys button { flex: none; min-width: 46px; height: 42px; padding: 0 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-size: 14px; }
#keys button.on { background: var(--pri); border-color: var(--pri); }
#kbd { position: fixed; left: -100px; top: 0; width: 40px; height: 40px; opacity: 0; font-size: 16px; padding: 0; border: 0; }

/* ---- bottom sheets ---- */
#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 78vh; overflow-y: auto; background: var(--bg2); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0;
  padding: 8px 14px calc(var(--safe-b) + 16px); animation: up .22s ease-out; max-width: 560px; margin: 0 auto; }
.sheet.tall { height: 70vh; display: flex; flex-direction: column; }
@keyframes up { from { transform: translateY(100%); } }
.grip { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 4px 12px; font-size: 18px; }
.sheet > button, .opts button { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px; margin-bottom: 6px; border-radius: 14px; background: var(--card); border: 1px solid transparent; text-align: left; font-size: 16px; position: relative; }
.sheet > button span { width: 28px; text-align: center; }
.sheet small { margin-left: auto; color: var(--mut); font-size: 13px; }
.opts button { flex-direction: column; align-items: flex-start; gap: 2px; }
.opts button small { margin: 0; }
.opts button.sel { border-color: var(--pri); background: rgba(59,130,246,.15); }
.opts.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opts.grid button { margin: 0; justify-content: center; text-align: center; align-items: center; min-height: 56px; font-size: 14px; }
.danger { color: #fca5a5; }
#chat-badge { position: absolute; right: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
#chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px; }
#chat-log div { max-width: 80%; padding: 8px 12px; border-radius: 14px; background: var(--card); align-self: flex-start; word-break: break-word; }
#chat-log div.me { align-self: flex-end; background: var(--pri2); }
#chat-form { display: flex; gap: 8px; margin-top: 8px; }
#chat-form .primary { width: auto; margin: 0; padding: 0 18px; }

dialog { background: var(--card); color: var(--txt); border: 1px solid var(--line); border-radius: 18px; padding: 20px; max-width: 86vw; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog div { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
dialog .primary { width: auto; margin: 0; padding: 12px 20px; }
.logo-img { display: block; height: 118px; width: auto; margin: 0 auto 10px; filter: drop-shadow(0 8px 24px rgba(59, 130, 246, .35)); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
