:root {
  color-scheme: dark;
  --bg: #000;
  --card: rgba(24, 24, 28, 0.96);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f2f2f5;
  --muted: #9a9aa5;
  --accent: #4f8cff;
  --danger: #ff5f57;
  --ok: #30d158;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body.viewer { position: fixed; inset: 0; overflow: hidden; overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

button, select, input, textarea { font: inherit; color: inherit; }
button { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
button:hover { background: rgba(255, 255, 255, 0.14); }
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
button.danger { color: var(--danger); }
button.link { background: none; border: none; color: var(--muted); padding: 8px 0; text-decoration: underline; }
button.icon { padding: 6px 10px; }
select, input[type=password], input[type=text], input:not([type]), textarea.field-input {
  width: 100%; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); margin: 4px 0 0; }

/* ---------- viewer ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; background: #000; touch-action: none; }
#stage.drop { outline: 3px dashed var(--accent); outline-offset: -12px; }
#screen { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #000; image-rendering: auto; cursor: default; }
#tcursor { position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; background: rgba(79, 140, 255, 0.55); box-shadow: 0 0 0 1px #000, 0 2px 6px rgba(0,0,0,.5); pointer-events: none; z-index: 2; }
#tcursor.shape { left: 0; top: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent center / 100% 100% no-repeat; }

#kbd { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; font-size: 16px; caret-color: transparent; color: transparent; background: transparent; z-index: -1; }

#overlay { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(0, 0, 0, 0.72); z-index: 20; text-align: center; padding: 24px; }
#overlay.hidden { display: none; }
#overlay-extra a, #banner a { color: var(--accent); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.2); border-top-color: #fff; animation: spin 0.9s linear infinite; }
#overlay.static .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

#banner { position: fixed; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); max-width: min(560px, 92vw); background: #3a2a00; border: 1px solid #a07800; color: #ffe08a; border-radius: 12px; padding: 10px 14px; font-size: 14px; z-index: 15; }
#banner button { margin-left: 8px; padding: 4px 10px; }

#stats { position: fixed; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); background: rgba(0,0,0,.6); border-radius: 8px; padding: 4px 8px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; z-index: 12; pointer-events: none; }

#toast { position: fixed; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 56px); left: 50%; transform: translateX(-50%); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; z-index: 30; font-size: 14px; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
#toast button { margin-left: 10px; padding: 4px 10px; }

#fabbar { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); z-index: 25; display: flex; gap: 8px; align-items: center; touch-action: none; }
#fab, .space-btn { width: 44px; height: 44px; border-radius: 50%; padding: 0; background: rgba(30, 30, 36, 0.72); border: 1px solid rgba(255,255,255,.18); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); touch-action: none; display: grid; place-items: center; opacity: 0.75; }
#fab:hover, .space-btn:hover { opacity: 1; }
.space-btn svg { width: 20px; height: 20px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.space-btn:active { background: var(--accent); opacity: 1; }
#typehint { position: fixed; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 58px); transform: translateX(-50%); z-index: 26; padding: 10px 18px; border-radius: 22px; background: var(--accent); border: 0; color: #fff; font-weight: 600; font-size: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.45); }

#fab .dot { width: 12px; height: 12px; border-radius: 50%; background: #888; box-shadow: 0 0 0 3px rgba(255,255,255,.12); }
#fab.live .dot { background: var(--ok); }
#fab.bad .dot { background: var(--danger); }

#panel { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: calc(max(14px, env(safe-area-inset-bottom)) + 54px); width: min(360px, calc(100vw - 24px)); max-height: calc(100dvh - 90px); overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; z-index: 26; box-shadow: 0 20px 60px rgba(0,0,0,.6); -webkit-user-select: none; user-select: none; touch-action: pan-y; overscroll-behavior: contain; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.section-title { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid.small button { padding: 8px; font-size: 13px; }
.field { display: block; font-size: 13px; color: var(--muted); margin: 8px 0; }
.field select, .field input { margin-top: 4px; color: var(--text); }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.check input { width: 18px; height: 18px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
body:not(.touch) .touch-only { display: none; }

#keyrow { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 4px; padding: 6px max(6px, env(safe-area-inset-left)); padding-bottom: max(6px, env(safe-area-inset-bottom)); background: rgba(20, 20, 24, 0.95); border-top: 1px solid var(--line); z-index: 24; overflow-x: auto; touch-action: pan-x; }
#keyrow button { flex: 0 0 auto; min-width: 42px; padding: 8px 6px; font-size: 15px; }
#keyrow button.on { background: var(--accent); border-color: transparent; }

#dialog { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 40; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.6); }
#dialog .card { max-height: calc(100dvh - 32px); overflow-y: auto; -webkit-user-select: text; user-select: text; touch-action: pan-y; }
#dialog h2 { margin: 0 0 10px; font-size: 18px; }
#dialog textarea { width: 100%; min-height: 90px; background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical; font-size: 15px; }
#dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
#dialog img.qr { display: block; margin: 8px auto; width: 200px; height: 200px; image-rendering: pixelated; background: #fff; padding: 10px; border-radius: 10px; }
#dialog code { display: block; word-break: break-all; background: rgba(255,255,255,.06); padding: 8px; border-radius: 8px; font-size: 14px; }

/* ---------- login ---------- */
body.login { display: grid; place-items: center; min-height: 100dvh; padding: 20px; background: radial-gradient(ellipse at top, #1b2340, #000 70%); }
.login-card { text-align: center; }
.login-card h1 { margin: 10px 0 2px; font-size: 24px; }
.login-card .field { text-align: left; }
.login-card button.primary { width: 100%; margin-top: 12px; padding: 12px; }

/* ---------- typing on phones (must come after the base #keyrow rules) ---------- */
#keys-pill { position: fixed; top: 6px; right: max(8px, env(safe-area-inset-right)); z-index: 27; padding: 5px 11px; border-radius: 15px; font-size: 13px; font-weight: 600; background: rgba(30, 30, 36, 0.82); border: 1px solid rgba(255,255,255,.22); color: #fff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#keys-pill.on { background: var(--accent); border-color: transparent; }
body.typing #keyrow { padding-bottom: 4px; }  /* the keyboard covers the home bar, so no safe-area padding */
@media (orientation: landscape) and (max-height: 500px) {
  #keyrow { padding: 3px max(6px, env(safe-area-inset-left)); gap: 3px; }
  #keyrow button { min-width: 36px; padding: 3px 5px; font-size: 14px; }
}
#tcursor.drag { filter: drop-shadow(0 0 3px #4f8cff) drop-shadow(0 0 6px #4f8cff); }
