/* ==========================================================================
   RemoteDesk — phone client
   ========================================================================== */

:root {
  --bg:            #0b0d10;
  --bg-elev:       #14181d;
  --bg-elev-2:     #1c2128;
  --line:          #262c34;
  --text:          #e7ecf2;
  --text-dim:      #8b95a3;
  --accent:        #4c9aff;
  --accent-press:  #3d7fd6;
  --ok:            #35c07a;
  --warn:          #e0a33a;
  --danger:        #f0554d;

  --radius:   14px;
  --radius-l: 20px;

  --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);

  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-dim); }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ══════════════════════════ Login ═════════════════════════════════ */
#screen-login {
  align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px);
  background: radial-gradient(120% 80% at 50% 0%, #16202c 0%, transparent 60%), var(--bg);
}
.login-card { width: 100%; max-width: 340px; }
.brand { text-align: center; margin-bottom: 30px; }
.brand-mark { width: 52px; height: 52px; color: var(--accent); margin-bottom: 12px; }
.brand h1 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -.4px; }

#login-form input {
  width: 100%; padding: 15px 16px; margin-bottom: 12px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); outline: none;
  font-size: 17px;  /* ≥16px stops iOS auto-zoom */
  transition: border-color .18s var(--ease);
}
#login-form input:focus { border-color: var(--accent); background: var(--bg-elev-2); }

.hint { margin-top: 16px; text-align: center; color: var(--text-dim); font-size: 13px; }
.error {
  margin: 12px 0 0; padding: 10px 13px;
  background: rgba(240,85,77,.12); border: 1px solid rgba(240,85,77,.3);
  border-radius: 10px; color: #ff9a94; font-size: 14px;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px; border: 1px solid transparent; border-radius: var(--radius);
  background: var(--bg-elev-2); font-size: 16px; font-weight: 600;
  text-decoration: none;
  transition: transform .12s var(--ease), background .18s var(--ease), opacity .18s;
}
.btn:active { transform: scale(.975); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); color: #fff; width: 100%; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text-dim); }
.btn.danger { background: rgba(240,85,77,.14); color: #ff8b85; border-color: rgba(240,85,77,.3); }
.btn.wide { width: 100%; margin-top: 4px; }

.icon-btn {
  width: 40px; height: 40px; padding: 9px;
  background: transparent; border: none; border-radius: 11px; color: var(--text-dim);
}
.icon-btn:active { background: var(--bg-elev-2); }

/* ══════════════════════════ Home ══════════════════════════════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 14px) 18px 14px;
  border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h2 { margin: 0; font-size: 17px; font-weight: 620;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }

.dot { flex: none; width: 9px; height: 9px; border-radius: 50%;
       background: var(--text-dim); transition: background .25s, box-shadow .25s; }
.dot.online  { background: var(--ok);     box-shadow: 0 0 0 4px rgba(53,192,122,.16); }
.dot.offline { background: var(--danger); box-shadow: 0 0 0 4px rgba(240,85,77,.16); }
.dot.pending { background: var(--warn);   box-shadow: 0 0 0 4px rgba(224,163,58,.16); }

.home-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px 18px calc(var(--safe-b) + 28px);
}

.connect-card {
  display: flex; align-items: center; gap: 16px; width: 100%;
  padding: 20px; margin-bottom: 24px;
  background: linear-gradient(135deg, #1b2836, var(--bg-elev));
  border: 1px solid var(--line); border-radius: var(--radius-l);
  color: inherit; text-align: left;
  transition: transform .12s var(--ease), opacity .2s, border-color .2s;
}
.connect-card:active { transform: scale(.985); }
.connect-card[disabled] { opacity: .5; pointer-events: none; }
.connect-card.ready { border-color: rgba(76,154,255,.45); }
.connect-icon { flex: none; width: 46px; height: 46px; padding: 12px;
                background: var(--accent); border-radius: 50%; color: #fff; }
.connect-text { display: flex; flex-direction: column; min-width: 0; }
.connect-text strong { font-size: 18px; font-weight: 640; }
.connect-text span { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

.settings-group { border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 16px; min-height: 54px;
  background: var(--bg-elev); border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row > span { font-size: 15px; flex: none; }
.row input[type=range] { flex: 1; max-width: 60%; accent-color: var(--accent); }

.row select {
  padding: 7px 10px; max-width: 60%;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 9px; font-size: 15px; outline: none;
  appearance: none; -webkit-appearance: none;
  text-align: right; text-align-last: right;
}

/* ── Segmented control ────────────────────────────────────────────── */
.segmented {
  display: flex; gap: 2px; padding: 2px;
  background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 10px;
}
.segmented button {
  padding: 7px 12px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-dim);
  font-size: 13.5px; font-weight: 550;
  transition: background .18s var(--ease), color .18s;
}
.segmented button.on { background: var(--accent); color: #fff; }

.version { text-align: center; color: #4a525d; font-size: 12px; margin-top: 28px; }

/* ══════════════════════════ Session ═══════════════════════════════ */
.screen.session { background: #000; }

.stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; background: #000; }

#video {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  object-fit: contain; transform-origin: 0 0; background: #000; display: block;
}

.pointer {
  position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border-radius: 50%; border: 2px solid rgba(255,255,255,.9);
  background: rgba(76,154,255,.35); box-shadow: 0 0 0 1px rgba(0,0,0,.55);
  pointer-events: none; z-index: 6;
}

.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgba(11,13,16,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.overlay[hidden] { display: none; }
.overlay p { margin: 0; color: var(--text-dim); font-size: 15px; text-align: center; padding: 0 32px; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Always-on latency chip; expands into full stats on demand. */
.hud {
  position: absolute; z-index: 8;
  top: calc(var(--safe-t) + 8px); left: calc(var(--safe-l) + 10px);
  padding: 5px 9px; border-radius: 8px;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #9fb0c4; white-space: pre; pointer-events: none;
  opacity: .75;
}
.hud[hidden] { display: none; }

.sound-btn {
  position: absolute; z-index: 9; left: 50%;
  top: calc(var(--safe-t) + 12px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 11px;
  background: rgba(76,154,255,.92); border: none; border-radius: 999px;
  color: #fff; font-size: 13px; font-weight: 600;
  animation: toast-in .3s var(--ease);
}
.sound-btn[hidden] { display: none; }
.sound-btn svg { width: 16px; height: 16px; flex: none; }

.toast {
  position: absolute; z-index: 30; left: 50%; bottom: calc(var(--safe-b) + 92px);
  transform: translateX(-50%);
  padding: 11px 18px; max-width: 84vw;
  background: rgba(28,33,40,.96); border: 1px solid var(--line); border-radius: 999px;
  font-size: 14px; text-align: center;
  animation: toast-in .28s var(--ease); pointer-events: none;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.fab {
  position: absolute; z-index: 10;
  right: calc(var(--safe-r) + 14px); bottom: calc(var(--safe-b) + 14px);
  width: 50px; height: 50px; padding: 13px;
  background: rgba(28,33,40,.82); border: 1px solid var(--line);
  border-radius: 50%; color: var(--text);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .14s var(--ease), opacity .3s;
}
.fab svg { fill: currentColor; stroke: none; }
.fab:active { transform: scale(.9); }
.fab.dimmed { opacity: .3; }

.keybar {
  position: absolute; z-index: 12; left: 0; right: 0; bottom: var(--safe-b);
  display: flex; gap: 6px;
  padding: 9px calc(var(--safe-r) + 10px) 9px calc(var(--safe-l) + 10px);
  background: rgba(20,24,29,.93); border-top: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.keybar::-webkit-scrollbar { display: none; }
.keybar[hidden] { display: none; }
.keybar button {
  flex: none; min-width: 46px; padding: 10px 13px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; font-weight: 550;
}
.keybar button:active,
.keybar button.latched { background: var(--accent); border-color: var(--accent); color: #fff; }
.keybar-sep { flex: none; width: 1px; background: var(--line); margin: 4px 3px; }

.kbd-proxy {
  position: absolute; z-index: -1; bottom: 0; left: 0;
  width: 1px; height: 1px; padding: 0; border: none;
  background: transparent; color: transparent; opacity: 0;
}

/* ── Bottom sheet ─────────────────────────────────────────────────── */
.sheet-backdrop {
  position: absolute; inset: 0; z-index: 40;
  background: rgba(0,0,0,.5); animation: fade .22s var(--ease);
  /* Safari on iOS will not fire click on a plain div unless it looks
     clickable. Without this the backdrop swallows the tap and the menu
     cannot be dismissed. */
  cursor: pointer;
}
.sheet-backdrop[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: absolute; z-index: 41; left: 0; right: 0; bottom: 0;
  /* anchors .sheet-close */
  padding: 8px 16px calc(var(--safe-b) + 16px);
  background: var(--bg-elev); border-top: 1px solid var(--line);
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  animation: sheet-up .3s var(--ease);
  max-height: 88vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.sheet[hidden] { display: none; }
@keyframes sheet-up { from { transform: translateY(100%); } }

/* The grip is a real button: bigger tap target than it looks, and it closes. */
.sheet-handle {
  display: block; width: 56px; height: 20px; padding: 8px 9px;
  margin: 0 auto 10px; border: none; background: none;
}
.sheet-handle::before {
  content: ''; display: block; width: 38px; height: 4px;
  background: var(--line); border-radius: 2px;
}
.sheet-handle:active::before { background: var(--text-dim); }

.sheet-close {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  width: 34px; height: 34px; padding: 8px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 50%; color: var(--text-dim);
  transition: transform .12s var(--ease), color .18s;
}
.sheet-close:active { transform: scale(.9); color: var(--text); }

.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 14px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 15px 4px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 11.5px; color: var(--text-dim);
  transition: transform .12s var(--ease);
}
.tile:active { transform: scale(.94); }
.tile svg { width: 22px; height: 22px; color: var(--text); }
.tile.on { border-color: var(--accent); color: var(--accent); }
.tile.on svg { color: var(--accent); }

.sheet-section { border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }

/* ── Power row: four flat glyphs, no modal ────────────────────────── */
.power-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.power-row button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 13px 4px;
  background: transparent; border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text-dim); font-size: 11px;
  transition: transform .12s var(--ease), background .18s, color .18s, border-color .18s;
}
.power-row button svg { width: 20px; height: 20px; }
.power-row button:active { transform: scale(.94); background: var(--bg-elev-2); color: var(--text); }
.power-row button.warn:active   { color: var(--warn);   border-color: rgba(224,163,58,.45); }
.power-row button.danger:active { color: var(--danger); border-color: rgba(240,85,77,.45); }
.power-row button.armed {
  background: rgba(240,85,77,.14); border-color: rgba(240,85,77,.5); color: #ff8b85;
}

/* ── Modals ───────────────────────────────────────────────────────── */
.modal {
  position: absolute; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(0,0,0,.62);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 420px; padding: 20px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-l);
  animation: pop .24s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: scale(.94); } }
.modal-card h3 { margin: 0 0 14px; font-size: 17px; font-weight: 620; }
.modal-card textarea {
  width: 100%; padding: 13px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: var(--radius); resize: vertical; font-size: 16px; outline: none;
}
.modal-card textarea:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }
.file-meta { margin: 0 0 14px; font-size: 14px; word-break: break-all; }

.progress { height: 6px; background: var(--bg-elev-2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
