:root {
  --bg: #0b0d12;
  --panel: #14171f;
  --panel-2: #1b1f2a;
  --accent: #4b7bec;
  --accent-2: #6c93f0;
  --text: #f2f4f8;
  --text-dim: #9aa3b2;
  --danger: #e74c4c;
  --ok: #35c65a;
  --warn: #f0a83c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none; touch-action: none; user-select: none;
}
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; }

/* ── Connect screen ─────────────────────────────────────────── */
#screen-connect {
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(circle at 30% 20%, #182238 0%, var(--bg) 60%);
}
.connect-card {
  width: 100%; max-width: 400px; background: var(--panel);
  border: 1px solid #242938; border-radius: 20px; padding: 28px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand h1 { font-size: 19px; margin: 0; font-weight: 700; }
.hint { color: var(--text-dim); font-size: 13px; line-height: 1.5; margin: 0 0 20px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%; background: var(--panel-2); border: 1px solid #2a3040; border-radius: 10px;
  padding: 12px 14px; color: var(--text); font-size: 15px; outline: none;
}
.field input:focus { border-color: var(--accent); }

.link-banner {
  background: rgba(75,123,236,.12); border: 1px solid rgba(75,123,236,.35);
  color: var(--accent-2); font-size: 13px; border-radius: 10px; padding: 10px 12px;
  margin-bottom: 14px; line-height: 1.4;
}
.link-banner.expired { background: rgba(231,76,76,.12); border-color: rgba(231,76,76,.4); color: #ff8a8a; }

.btn-primary, .btn-secondary {
  width: 100%; border: none; border-radius: 12px; padding: 14px; font-size: 15px;
  font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:active { background: var(--accent-2); }
.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid #2a3040; margin-top: 8px; }

.remember { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 13px; color: var(--text-dim); }
.error { color: var(--danger); font-size: 13px; margin: 14px 0 0; text-align: center; }

/* ── Control screen ─────────────────────────────────────────── */
#screen-control { background: #000; overflow: hidden; }
#video-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}
#look-layer { position: absolute; inset: 0; z-index: 5; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 10px) 8px calc(var(--safe-left) + 10px);
  background: linear-gradient(to bottom, rgba(0,0,0,.55), transparent);
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none;
  background: rgba(20,23,31,.65); backdrop-filter: blur(6px);
  color: var(--text); font-size: 17px; display: flex; align-items: center; justify-content: center;
}
.status-pill {
  display: flex; align-items: center; gap: 6px; background: rgba(20,23,31,.65);
  backdrop-filter: blur(6px); border-radius: 999px; padding: 6px 12px; font-size: 12px;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.status-connecting .dot { background: var(--warn); animation: pulse 1s infinite; }
.status-live .dot { background: var(--ok); }
.status-error .dot { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

#stats {
  margin-left: auto; display: flex; gap: 8px; font-size: 11px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
#stats span { background: rgba(20,23,31,.65); backdrop-filter: blur(6px); padding: 5px 8px; border-radius: 8px; }

/* ── Joystick ────────────────────────────────────────────────── */
#joystick-zone {
  position: absolute; left: 14vw; top: 80vh; transform: translate(-50%, -50%);
  z-index: 15; width: 28vmin; height: 28vmin; max-width: 160px; max-height: 160px;
}
#joystick-base {
  position: relative; width: 100%; height: 100%; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25); background: rgba(20,23,31,.25);
}
#joystick-nub {
  position: absolute; left: 50%; top: 50%; width: 42%; height: 42%;
  border-radius: 50%; background: rgba(75,123,236,.55);
  transform: translate(-50%, -50%);
}

/* ── Action buttons ──────────────────────────────────────────── */
#action-buttons { position: absolute; inset: 0; z-index: 15; pointer-events: none; }
.action-btn {
  position: absolute; transform: translate(-50%, -50%);
  border-radius: 50%; border: 2px solid rgba(255,255,255,.28);
  background: rgba(0,0,0,.35); color: #fff; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; pointer-events: auto;
}
.action-btn.pressed { background: rgba(75,123,236,.6); border-color: rgba(75,123,236,.8); }
.action-btn.edit-mode { outline: 2px dashed #ff8a2b; outline-offset: 3px; }

/* ── Settings drawer ─────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55);
  display: flex; justify-content: flex-end;
}
#settings-panel {
  width: min(360px, 88vw); height: 100%; background: var(--panel);
  padding: calc(var(--safe-top) + 16px) 18px calc(var(--safe-bottom) + 18px);
  overflow-y: auto; border-left: 1px solid #242938;
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.settings-head h2 { font-size: 17px; margin: 0; }
.settings-section { margin-top: 22px; }
.settings-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin: 0 0 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--text-dim); word-break: break-all; }
#input-sensitivity { width: 100%; }

.btn-row {
  display: flex; gap: 8px; align-items: center; background: var(--panel-2);
  border: 1px solid #2a3040; border-radius: 10px; padding: 8px 10px; margin-bottom: 8px;
}
.btn-row input[type="text"] { width: 60px; background: transparent; border: none; color: var(--text); font-size: 13px; outline: none; }
.btn-row input[type="text"].label-in { width: 70px; }
.btn-row label { font-size: 11px; color: var(--text-dim); display: flex; align-items: center; gap: 4px; }
.btn-row .spacer { flex: 1; }
.btn-row .remove-btn { background: none; border: none; color: var(--danger); font-size: 16px; padding: 2px 6px; }
