/* ---------------------------------------------------------------
   Sightline — real-time object recognition
   --------------------------------------------------------------- */

:root {
  --bg: #080a0f;
  --bg-soft: #0d1017;
  --panel: rgba(255, 255, 255, 0.035);
  --panel-solid: #10141d;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #eef2f9;
  --text-dim: #98a3b8;
  --text-faint: #6b7689;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --accent-glow: rgba(56, 189, 248, 0.35);
  --danger: #fb7185;
  --ok: #34d399;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 24px 70px -20px rgba(0, 0, 0, 0.85);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 12% -12%, rgba(56, 189, 248, 0.16), transparent 62%),
    radial-gradient(900px 560px at 92% 0%, rgba(167, 139, 250, 0.14), transparent 58%),
    radial-gradient(1200px 800px at 50% 120%, rgba(16, 185, 129, 0.07), transparent 60%),
    var(--bg);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 35%, transparent 100%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 26px 28px 40px;
}

/* ------------------------------- header ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--accent);
  background: linear-gradient(160deg, rgba(56, 189, 248, 0.18), rgba(167, 139, 250, 0.12));
  border: 1px solid rgba(56, 189, 248, 0.28);
  box-shadow: 0 0 28px -6px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  flex: none;
}

.brand-mark svg { width: 27px; height: 27px; }

.brand-text h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-text p {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  white-space: nowrap;
  transition: color 0.25s ease, border-color 0.25s ease;
}

.model-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 0 transparent;
  flex: none;
}

.model-chip[data-state="loading"] .model-dot {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

.model-chip[data-state="ready"] { color: #c9f7e5; border-color: rgba(52, 211, 153, 0.25); }
.model-chip[data-state="ready"] .model-dot { background: var(--ok); box-shadow: 0 0 10px rgba(52, 211, 153, 0.8); }

.model-chip[data-state="error"] { color: #ffd7dd; border-color: rgba(251, 113, 133, 0.3); }
.model-chip[data-state="error"] .model-dot { background: var(--danger); }

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 356px;
  gap: 22px;
  align-items: start;
}

/* -------------------------------- stage -------------------------------- */

.stage-wrap { min-width: 0; }

.stage {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 40%, #0e131c, #05070b 78%);
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  isolation: isolate;
}

.stage[data-state="live"] { border-color: rgba(56, 189, 248, 0.22); }

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.4s ease;
  background: transparent;
}

.stage[data-state="live"] #video { opacity: 1; }

#video.mirrored { transform: scaleX(-1); }

#overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 2;
}

/* HUD */
.stage-hud {
  position: absolute;
  inset: 12px 12px auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.stage[data-state="live"] .stage-hud { opacity: 1; transform: none; }

.hud-right { display: flex; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: 0.02em;
  color: #dfe7f5;
  background: rgba(8, 11, 17, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  font-variant-numeric: tabular-nums;
}

.live-pill { text-transform: uppercase; letter-spacing: 0.08em; font-size: 10.5px; }
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.stage[data-state="live"] .live-dot {
  background: #f87171;
  box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6);
  animation: livePulse 2s ease-out infinite;
}

/* placeholder */
.placeholder {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 45%, rgba(56, 189, 248, 0.07), transparent 55%),
    rgba(6, 8, 12, 0.55);
  backdrop-filter: blur(3px);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}

.stage[data-state="live"] .placeholder {
  opacity: 0;
  visibility: hidden;
}

.placeholder-inner { max-width: 400px; display: flex; flex-direction: column; align-items: center; }

.ph-icon {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  margin-bottom: 18px;
  color: var(--accent);
  background: radial-gradient(circle at 35% 30%, rgba(56, 189, 248, 0.22), rgba(56, 189, 248, 0.04));
  border: 1px solid rgba(56, 189, 248, 0.22);
  box-shadow: 0 0 44px -10px var(--accent-glow);
}

.ph-icon svg { width: 30px; height: 30px; }
.ph-icon.is-error { color: var(--danger); background: rgba(251, 113, 133, 0.1); border-color: rgba(251, 113, 133, 0.3); box-shadow: none; }

.placeholder h2 {
  margin: 0 0 8px;
  font-size: 21px;
  font-weight: 620;
  letter-spacing: -0.015em;
}

.placeholder p {
  margin: 0 0 20px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-dim);
}

.privacy-note {
  margin: 14px 0 0 !important;
  font-size: 11.5px !important;
  color: var(--text-faint) !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.privacy-note::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.7);
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid rgba(56, 189, 248, 0.18);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  margin-bottom: 16px;
}

.stage-caption {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 12px 4px 0;
  font-size: 12px;
  color: var(--text-faint);
}

.kbd {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

/* -------------------------------- panel -------------------------------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 24px;
}

.card {
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.018));
  border: 1px solid var(--line);
  padding: 16px;
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 44px -28px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.count-badge {
  min-width: 26px;
  height: 22px;
  padding: 0 8px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.22);
}

/* object list */
.obj-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}

.obj-list:empty { display: none; }

.obj-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid transparent;
}

.obj-item.new { animation: rowIn 0.28s ease both; }

.obj-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c, var(--accent));
  box-shadow: 0 0 10px -1px var(--c, var(--accent));
}

.obj-meta { min-width: 0; display: flex; flex-direction: column; gap: 5px; }

.obj-name {
  font-size: 13.5px;
  font-weight: 550;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.obj-track {
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.obj-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--c, var(--accent)), color-mix(in srgb, var(--c, var(--accent)) 55%, #fff));
  transition: width 0.25s ease;
}

.obj-count {
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
}

/* empty state */
.empty-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 22px 10px 18px;
  transition: opacity 0.3s ease;
}

.empty-list[hidden] { display: none; }

.empty-orb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  margin-bottom: 12px;
  background: radial-gradient(circle at 35% 30%, rgba(56, 189, 248, 0.35), rgba(56, 189, 248, 0.05) 65%, transparent 70%);
  border: 1px dashed rgba(56, 189, 248, 0.35);
  animation: breathe 3.4s ease-in-out infinite;
}

.empty-list p { margin: 0 0 4px; font-size: 13px; font-weight: 550; color: var(--text-dim); }
.empty-list small { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; max-width: 230px; }

/* controls */
.control { margin-bottom: 16px; }

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.control-label output {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

.control-hint {
  margin: 7px 0 0;
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.45;
}

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  opacity: 0.85;
}

.range::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0.85;
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #0b1018;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5), 0 2px 10px rgba(0, 0, 0, 0.6);
  transition: transform 0.15s ease;
}

.range::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid #0b1018;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
}

.range:active::-webkit-slider-thumb { transform: scale(1.15); }

.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.35); }

.select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 10px 34px 10px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
  background:
    linear-gradient(45deg, transparent 50%, var(--text-dim) 50%) calc(100% - 17px) 50% / 5px 5px no-repeat,
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%) calc(100% - 12px) 50% / 5px 5px no-repeat,
    rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.select:hover:not(:disabled) { border-color: var(--line-strong); }
.select:focus-visible { outline: 2px solid rgba(56, 189, 248, 0.45); outline-offset: 2px; }
.select:disabled { opacity: 0.5; cursor: not-allowed; }
.select option { background: var(--panel-solid); color: var(--text); }

/* switches */
.switches {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 4px;
  cursor: pointer;
  border-radius: 8px;
}

.switch-copy { display: flex; flex-direction: column; gap: 2px; }
.switch-title { font-size: 13px; font-weight: 500; }
.switch-sub { font-size: 11px; color: var(--text-faint); }

.switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 38px;
  height: 22px;
  flex: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  transition: background 0.22s ease, border-color 0.22s ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #cfd8e8;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.22s ease;
}

.switch-input:checked + .switch-track {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-color: transparent;
}

.switch-input:checked + .switch-track .switch-thumb { transform: translateX(16px); background: #fff; }

.switch-input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.35); }

/* buttons */
.actions { display: grid; grid-template-columns: 1fr auto; gap: 9px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 11px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.005em;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-strong);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  user-select: none;
}

.btn svg { width: 16px; height: 16px; }

.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.22); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 2px solid rgba(56, 189, 248, 0.5); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  color: #04121c;
  background: linear-gradient(135deg, #67d7fb, #38bdf8 45%, #7dd3fc);
  border-color: transparent;
  box-shadow: 0 10px 30px -10px rgba(56, 189, 248, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  padding: 12px 22px;
  font-size: 13.5px;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #86e2ff, #4cc6fd 45%, #96dcff);
  box-shadow: 0 14px 34px -10px rgba(56, 189, 248, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.btn-danger { color: #ffdbe1; background: rgba(251, 113, 133, 0.1); border-color: rgba(251, 113, 133, 0.3); }
.btn-danger:hover:not(:disabled) { background: rgba(251, 113, 133, 0.18); border-color: rgba(251, 113, 133, 0.5); }

.footnote {
  margin: 2px 4px 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-faint);
  text-align: center;
}

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  padding: 11px 18px;
  border-radius: 11px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  background: rgba(18, 23, 33, 0.95);
  border: 1px solid var(--line-strong);
  box-shadow: 0 20px 50px -16px rgba(0, 0, 0, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
  z-index: 50;
  pointer-events: none;
  max-width: min(90vw, 420px);
  text-align: center;
}

.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* ------------------------------- animations ------------------------------- */

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  50% { transform: scale(1.08); opacity: 1; }
}

@keyframes rowIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------- responsive ------------------------------- */

@media (max-width: 1040px) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; }
  .app { padding: 22px 20px 34px; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .panel { position: static; }
  .stage { aspect-ratio: 4 / 3; }
  .obj-list { max-height: 220px; }
  .app { padding: 18px 16px 30px; }
  .brand-text p { display: none; }
}

@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .model-chip { font-size: 11.5px; padding: 7px 11px; }
  .stage { border-radius: 16px; aspect-ratio: 4 / 3; }
  .stage-caption { display: none; }
  .placeholder h2 { font-size: 18px; }
  .placeholder p { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
