:root {
  --bg: #07080b;
  --panel: #12151c;
  --panel-2: #1a1e27;
  --panel-3: #232836;
  --border: #2a3040;
  --text: #eef0f5;
  --muted: #8d95a6;
  --accent: #5b8cff;
  --accent-2: #7aa2ff;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --panic: #e5383b;
  --bar-h: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

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

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

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }

/* ---------- buttons & inputs ---------- */
.btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
}
.btn:hover { border-color: #3a4256; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.big { padding: 12px; font-size: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); outline: none; }

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

.check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* ---------- PANIC (fixed top-left, above everything) ---------- */
.panic {
  position: fixed;
  top: calc(var(--safe-top) + 7px);
  left: 7px;
  z-index: 1000;
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px 0 10px;
  border: 0;
  border-radius: 9px;
  background: var(--panic);
  color: #fff;
  font: 700 13px/1 system-ui, sans-serif;
  letter-spacing: .06em;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(229, 56, 59, .45);
  touch-action: manipulation;
}
.panic:hover { background: #f04a4d; }
.panic:active { transform: scale(.96); }
.panic svg { width: 17px; height: 17px; stroke-width: 2.2; }

/* ---------- login ---------- */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 70px 18px 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(91, 140, 255, .16), transparent 60%),
    radial-gradient(700px 400px at 110% 110%, rgba(52, 211, 153, .08), transparent 60%);
}
.login-card { width: min(390px, 100%); padding: 28px; display: grid; gap: 16px; }
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 4px; }
.brand-icon {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff;
}
.brand-icon svg { width: 24px; height: 24px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; font-size: 14px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-msg { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--muted); }
.login-msg.error { color: var(--bad); }

/* ---------- app ---------- */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }

.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: calc(var(--bar-h) + var(--safe-top));
  padding: var(--safe-top) 8px 0 112px;   /* left padding leaves room for PANIC */
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.app.toolbar-hidden .toolbar { display: none; }

.status-pill {
  flex: none;
  max-width: 45vw;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 13px;
}
#statusText { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.stats { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .18); }
.dot.connecting { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.offline { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }

.tools {
  margin-left: auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tools::-webkit-scrollbar { display: none; }

.tool {
  position: relative;
  flex: none;
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: 500 13px/1 system-ui, sans-serif;
  cursor: pointer;
  white-space: nowrap;
}
.tool:hover { background: var(--panel-3); }
.tool:active { background: var(--border); }
.tool.active { background: var(--panel-3); border-color: var(--border); }
/* invisible native <select> stretched over the button: native pickers work great on phones */
.select-tool select {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px;
}

.show-toolbar {
  position: fixed;
  top: calc(var(--safe-top) + 7px);
  right: 7px;
  z-index: 900;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(18, 21, 28, .85);
  color: var(--text);
  cursor: pointer;
}

/* ---------- remote screen ---------- */
.stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
#screen {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  outline: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.remote-cursor {
  position: absolute;
  left: 0; top: 0;
  width: 16px; height: 22px;
  pointer-events: none;
  will-change: transform;
}
.remote-cursor path { fill: #fff; stroke: #000; stroke-width: 1.3; stroke-linejoin: round; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 8, 11, .72);
  text-align: center;
}
.overlay-card { max-width: 400px; padding: 24px; display: grid; gap: 14px; justify-items: center; }
.overlay-card p { margin: 0; color: var(--text); }
.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); } }

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 14px;
  border-radius: 10px;
  background: rgba(18, 21, 28, .92);
  border: 1px solid var(--border);
  font-size: 13px;
  pointer-events: none;
}

.mobile-input {
  position: fixed;
  left: 0; bottom: 0;
  width: 1px; height: 1px;
  opacity: 0;
  border: 0; padding: 0;
  font-size: 16px; /* stops iOS zooming in */
}

.banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(18, 21, 28, .95);
  border: 1px solid var(--warn);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.banner p { margin: 0; flex: 1; }
.banner strong { color: var(--warn); }
.banner .btn { flex: none; padding: 7px 12px; font-size: 13px; }

/* ---------- dialog ---------- */
.dialog { color: var(--text); width: min(480px, calc(100% - 28px)); padding: 22px; }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog form { display: grid; gap: 12px; }
.dialog h2 { margin: 0; font-size: 19px; }
.dialog p { margin: 0; font-size: 14px; }
.dialog textarea { resize: vertical; }
.row { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- responsive ---------- */
@media (hover: hover) and (pointer: fine) {
  .touch-only { display: none !important; }
}
@media (max-width: 900px) {
  .tool .label { display: none; }
  .tool { padding: 0 9px; }
}
@media (max-width: 560px) {
  .stats { display: none; }
  #statusText { max-width: 90px; }
  .toolbar { gap: 6px; padding-left: 104px; }
  .panic { padding: 0 10px 0 8px; }
}
