:root {
  --bg: #0b0d11;
  --bg-2: #11141a;
  --surface: #161a21;
  --surface-2: #1c2230;
  --border: #283041;
  --border-hi: #3a455a;
  --text: #e6e9ef;
  --text-dim: #98a0ad;
  --text-faint: #6b7480;
  --accent: #3dff7a;
  --accent-dim: #2bd968;
  --amber: #ffb84d;
  --blue: #6db8ff;
  --danger: #ff6b6b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(61, 255, 122, 0.07), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(109, 184, 255, 0.06), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: calc(14px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-left)) 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(22, 26, 33, 0.9), rgba(11, 13, 17, 0.6));
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 0 8px rgba(61, 255, 122, 0.35));
}

.brand-text { min-width: 0; }

h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.tagline {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}
.pill:empty { display: none; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11.5px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.status::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}
.cam-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: rgba(61, 255, 122, 0.14);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.cam-btn:hover { background: rgba(61, 255, 122, 0.22); }
.cam-btn:active { transform: scale(0.97); }
.cam-btn:disabled { opacity: 0.55; cursor: default; }
.cam-btn.live {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text-dim);
}

.status.locked { color: var(--accent); border-color: rgba(61, 255, 122, 0.4); background: rgba(61, 255, 122, 0.1); }
.status.coast  { color: var(--amber);  border-color: rgba(255, 184, 77, 0.4);  background: rgba(255, 184, 77, 0.1); }
.status.search { color: var(--text-dim); }
.status.manual { color: var(--blue);   border-color: rgba(109, 184, 255, 0.4); background: rgba(109, 184, 255, 0.1); }

/* ---------- warning banner ---------- */

.warning {
  margin: 12px max(16px, env(safe-area-inset-left)) 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 184, 77, 0.12);
  border: 1px solid rgba(255, 184, 77, 0.45);
  color: #ffd591;
  font-size: 13px;
  font-weight: 500;
}

/* ---------- layout ---------- */

main {
  max-width: 1280px;
  margin: 0 auto;
  /* extra bottom padding clears the fixed controls dock */
  padding: 16px max(16px, env(safe-area-inset-right))
           calc(80px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.stage-wrap { margin-bottom: 14px; }

.stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  aspect-ratio: 16 / 9;
}

#video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: manipulation;
}

#debug {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 26%;
  max-width: 220px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: none;
  image-rendering: pixelated;
  pointer-events: none;
  box-shadow: var(--shadow);
}

/* ---------- docked controls bar ---------- */

/* Pinned to the bottom of the viewport so it never scrolls away. The toggle is
   the always-visible handle; collapsing hides the controls but keeps the bar. */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: linear-gradient(180deg, rgba(22, 26, 33, 0.97), rgba(17, 20, 26, 0.99));
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  padding-bottom: env(safe-area-inset-bottom);
}

.controls-toggle {
  display: flex;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px max(16px, env(safe-area-inset-left));
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.controls-toggle .chev { transition: transform 0.2s ease; color: var(--text-dim); }
.controls-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-left)) 14px;
  max-height: 46vh;
  overflow-y: auto;
}
.dock.collapsed .controls { display: none; }

.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  white-space: nowrap;
  font-size: 13px;
}

.controls select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  max-width: 46vw;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.controls button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.controls button:hover { border-color: var(--border-hi); }
.controls button:active { transform: scale(0.97); }
.controls button.active {
  background: rgba(61, 255, 122, 0.14);
  border-color: var(--accent);
  color: var(--accent);
}

.controls input[type="range"] {
  width: 120px;
  accent-color: var(--accent);
}

/* ---------- hint + gallery + disclaimer ---------- */

.hint {
  color: var(--text-faint);
  line-height: 1.55;
  margin: 0 0 18px;
}
.hint b { color: var(--text-dim); font-weight: 600; }

.gallery { margin-top: 6px; }

.gallery h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
}

.gallery h2 button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

#gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.shot {
  text-decoration: none;
  color: var(--text-dim);
  font-size: 11px;
}

.shot img {
  display: block;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.shot span {
  display: block;
  padding-top: 4px;
}

.disclaimer {
  margin-top: 28px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.6;
}
.disclaimer strong { color: var(--text-dim); }

/* ---------- responsive: phones & small tablets ---------- */

@media (max-width: 760px) {
  body { font-size: 15px; }

  .topbar { padding-bottom: 12px; }
  .hud { width: 100%; }
  .tagline { display: none; }

  .controls { flex-direction: column; align-items: stretch; }
  .controls label { justify-content: space-between; }
  .controls select { max-width: none; flex: 1; margin-left: 12px; }
  .controls input[type="range"] { width: 100%; flex: 1; margin-left: 12px; }
  .btn-row { display: grid; grid-template-columns: 1fr 1fr; }
  .controls button { padding: 11px 12px; }

  .cam-btn { width: 100%; justify-content: center; }
}

/* portrait phones: a taller stage so the simulated room / camera fills more height */
@media (max-width: 760px) and (orientation: portrait) {
  .stage { aspect-ratio: 3 / 4; }
}

@media (hover: none) {
  #overlay { cursor: default; }
}

@media (prefers-reduced-motion: reduce) {
  .controls-toggle .chev { transition: none; }
}
