:root {
  --bg: #0b1020;
  --surface: #131a2e;
  --raised: #1a2340;
  --border: #25304f;
  --text: #e6e9f2;
  --muted: #8b93ab;
  --accent: #6d8cff;
  --accent-ink: #0b1020;
  --warn: #f5b84a;
  --bad: #ff6b6b;
  --ok: #4ade80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1.4em; margin: 0; }

svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}

.primary {
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }

/* ---- sign in ---- */
.login { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; justify-items: center; }
.login h1 { margin: 4px 0 0; font-size: 20px; }
.login p { margin: 0; }
.login input, .login button { width: 100%; }
.login input, dialog select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none;
}
.login input:focus, dialog select:focus { border-color: var(--accent); }

/* ---- app shell ---- */
.app {
  height: 100dvh;
  display: grid;
  grid-template: "top top" auto "banner banner" auto "stage dock" 1fr / 1fr auto;
}

.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.who { display: flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.who strong { overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.error { background: var(--bad); }
.dot.connecting { background: var(--warn); }
.stats { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }
.top-actions { display: flex; gap: 2px; }

.icon {
  background: none; border: 0; border-radius: 8px; padding: 7px; display: grid; place-items: center; color: var(--muted);
}
.icon:hover { background: var(--raised); color: var(--text); }

.banner {
  grid-area: banner;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: #2a2210; border-bottom: 1px solid #5a4514; color: #f4dfae; font-size: 13px;
}
.banner div { flex: 1; }
.banner strong { display: block; color: var(--warn); }
.banner em { font-style: normal; font-weight: 600; color: #fff; }
.banner button { background: none; border: 1px solid #7a5f1c; border-radius: 8px; padding: 6px 10px; white-space: nowrap; }

.stage {
  grid-area: stage;
  min-width: 0; min-height: 0;
  display: grid; place-items: center;
  padding: 14px;
  position: relative;
}
.stage.drop::after {
  content: "Drop to send to the phone";
  position: absolute; inset: 10px; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 16px; background: rgba(11, 16, 32, .8); font-size: 16px;
}

.frame {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 0 1px var(--border), 0 24px 70px rgba(0, 0, 0, .55);
  line-height: 0;
}
#screen { display: block; touch-action: none; outline: none; cursor: default; user-select: none; -webkit-user-select: none; }

.overlay {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  padding: 24px; text-align: center; line-height: 1.45;
  background: rgba(8, 11, 22, .88);
}
.overlay p { margin: 0; max-width: 30ch; }
.overlay.still .spinner { display: none; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- controls ---- */
.dock {
  grid-area: dock;
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 8px; overflow: auto;
  border-left: 1px solid var(--border); background: var(--surface);
  scrollbar-width: none;
}
.dock::-webkit-scrollbar { display: none; }
.dock button {
  background: none; border: 0; border-radius: 10px;
  padding: 7px 8px; min-width: 56px;
  display: grid; justify-items: center; gap: 2px;
  color: var(--muted); font-size: 10.5px; line-height: 1.2;
  user-select: none; -webkit-user-select: none;
}
.dock button:hover { background: var(--raised); color: var(--text); }
.dock button:active { background: var(--border); }
.dock button.on { color: var(--accent); background: var(--raised); }
.dock i { height: 1px; background: var(--border); margin: 4px 6px; flex: none; }

@media (max-width: 720px), (orientation: portrait) {
  .app { grid-template: "top" auto "banner" auto "stage" 1fr "dock" auto / 1fr; }
  .dock {
    flex-direction: row; border-left: 0; border-top: 1px solid var(--border);
    padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .dock button { min-width: 52px; flex: none; }
  .dock i { width: 1px; height: auto; margin: 6px 3px; }
  .stage { padding: 8px; }
  .stats { display: none; }
}

/* Receives the on-screen keyboard's typing; has to exist and be focusable, but not be seen. */
.kbd {
  position: fixed; left: 0; bottom: 0; width: 1px; height: 1px;
  opacity: 0; border: 0; padding: 0; font-size: 16px; pointer-events: none;
}

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  max-width: min(90vw, 460px);
  background: var(--raised); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; z-index: 10;
}
.toast.bad { border-color: var(--bad); }

dialog.card { color: var(--text); width: min(340px, 92vw); }
dialog::backdrop { background: rgba(4, 6, 14, .65); }
dialog h2 { margin: 0 0 14px; font-size: 17px; }
dialog label { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
dialog select { color: var(--text); font-size: 14px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
dialog .row button:not(.primary) { background: none; border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; }
