:root {
  --bg: #05070a;
  --ink: #f4f6f8;
  --muted: #a3adb8;
  --faint: #6c7681;
  --accent: #ff6a3d;
  --accent-ink: #1b0a04;
  --glass: rgba(14, 17, 22, 0.82);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.16);
  --radius: 24px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(80% 60% at 18% 0%, rgba(255, 106, 61, 0.14), transparent 62%),
    radial-gradient(70% 55% at 100% 100%, rgba(86, 138, 255, 0.12), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button, input { font: inherit; color: inherit; }

#video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.55s ease;
}

body.is-live #video { opacity: 1; }

/* The demo is a landscape clip played on any screen; letterbox it instead of
   cropping the marker away. Camera streams fill the viewport natively. */
body.is-demo #video {
  object-fit: contain;
  background: #05070a;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
  background:
    radial-gradient(120% 90% at 50% 46%, transparent 42%, rgba(0, 0, 0, 0.42) 100%),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.38), transparent 16%, transparent 76%, rgba(0, 0, 0, 0.5));
}

body.is-live .vignette { opacity: 1; }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}

.hud > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: rgba(255, 255, 255, 0.86);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.5);
}

.brand-mark {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 14px rgba(255, 106, 61, 0.55);
}

.brand-accent { color: var(--accent); }

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

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 11, 15, 0.6);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.82);
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--faint);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
  transition: background 0.3s, box-shadow 0.3s;
}

.status[data-state="starting"] .status-dot,
.status[data-state="searching"] .status-dot {
  background: #ffb15c;
  box-shadow: 0 0 0 3px rgba(255, 177, 92, 0.16);
  animation: pulse 1.8s ease-in-out infinite;
}

.status[data-state="tracking"] .status-dot {
  background: #48e08d;
  box-shadow: 0 0 0 3px rgba(72, 224, 141, 0.18), 0 0 12px rgba(72, 224, 141, 0.8);
}

.status[data-state="error"] .status-dot {
  background: #ff6a5c;
  box-shadow: 0 0 0 3px rgba(255, 106, 92, 0.18);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 11, 15, 0.6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- tracking furniture ---------- */
.reticle {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(60vw, 250px);
  height: min(60vw, 250px);
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
  opacity: 0.6;
  transition: opacity 0.3s ease, visibility 0.3s;
  animation: breathe 3.2s ease-in-out infinite;
}

.corner {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 0 solid rgba(255, 255, 255, 0.72);
  filter: drop-shadow(0 1px 6px rgba(0, 0, 0, 0.45));
}

.corner.tl { top: 0; left: 0; border-top-width: 1.5px; border-left-width: 1.5px; border-top-left-radius: 6px; }
.corner.tr { top: 0; right: 0; border-top-width: 1.5px; border-right-width: 1.5px; border-top-right-radius: 6px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 1.5px; border-right-width: 1.5px; border-bottom-right-radius: 6px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 1.5px; border-left-width: 1.5px; border-bottom-left-radius: 6px; }

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 11, 15, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 11.5px;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.72);
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s;
}

.payload {
  position: fixed;
  left: calc(18px + env(safe-area-inset-left));
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 5;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.38);
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s;
}

.is-hidden { opacity: 0; visibility: hidden; }

/* ---------- landing ---------- */
.landing {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  transition: opacity 0.4s ease, visibility 0.4s;
}

.landing.is-gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.card {
  width: min(430px, 100%);
  padding: 26px 26px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--glass);
  backdrop-filter: blur(26px) saturate(1.25);
  -webkit-backdrop-filter: blur(26px) saturate(1.25);
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: rise 0.65s cubic-bezier(0.2, 0.75, 0.25, 1) both;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 0;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #929ca7;
  white-space: nowrap;
}

.live-dot {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 106, 61, 0.8);
  animation: pulse 2.4s ease-in-out infinite;
}

.marker-thumb {
  width: 76px;
  height: 76px;
  padding: 5px;
  border-radius: 11px;
  background: #fff;
  transform: rotate(2.5deg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  flex: none;
}

h1 {
  margin: 0 0 14px;
  font-size: clamp(30px, 7.4vw, 38px);
  font-weight: 620;
  line-height: 1.04;
  letter-spacing: -0.035em;
  color: #fbfcfd;
}

h1 em {
  font-style: normal;
  color: var(--accent);
}

.lede {
  margin: 0 0 22px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--muted);
  max-width: 34ch;
}

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 680;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(255, 106, 61, 0.28);
  transition: transform 0.16s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.primary:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 14px 32px rgba(255, 106, 61, 0.34); }
.primary:active { transform: translateY(0); }
.primary:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.primary:disabled { opacity: 0.6; cursor: default; }

.primary svg { transition: transform 0.2s ease; }
.primary:hover svg { transform: translateX(3px); }

.actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--faint);
}

.actions a,
.actions .link {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.28);
  text-underline-offset: 3px;
  transition: color 0.2s, text-decoration-color 0.2s;
}

.actions a:hover,
.actions .link:hover { color: #fff; text-decoration-color: var(--accent); }

.link {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.dot {
  width: 3px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.26);
}

.fineprint {
  margin: 18px 0 0;
  font-size: 11px;
  letter-spacing: 0.01em;
  color: var(--faint);
  text-align: center;
}

.fineprint a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.22);
  text-underline-offset: 2px;
  transition: color 0.2s, text-decoration-color 0.2s;
}

.fineprint a:hover {
  color: rgba(255, 255, 255, 0.85);
  text-decoration-color: var(--accent);
}

.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 106, 92, 0.3);
  background: rgba(255, 106, 92, 0.08);
  color: #ffb3a8;
  font-size: 12.5px;
  line-height: 1.45;
}

.error:empty { display: none; }

/* ---------- settings ---------- */
.panel {
  position: fixed;
  top: calc(62px + env(safe-area-inset-top));
  right: 16px;
  z-index: 12;
  width: min(320px, calc(100vw - 32px));
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--line-strong);
  background: rgba(12, 15, 20, 0.94);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: rise 0.28s ease both;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c9d0d8;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  font-size: 12.5px;
  color: #cfd5dc;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field input[type="number"] {
  width: 96px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-family: var(--mono);
  font-size: 13px;
}

.field input[type="number"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field input[type="range"] { flex: 1; accent-color: var(--accent); }

.field output {
  width: 46px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.7);
  text-align: right;
}

.unit { font-size: 11.5px; color: var(--faint); }

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

.panel-link {
  display: inline-block;
  margin-top: 18px;
  font-size: 12px;
  color: #fff;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  padding-bottom: 2px;
}

.panel-link:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- debug ---------- */
#debug { display: none; }

body.has-debug #debug {
  display: block;
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 9;
  max-width: 320px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.55);
  font-family: var(--mono);
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
}

.debug summary { cursor: pointer; letter-spacing: 0.08em; text-transform: uppercase; font-size: 9.5px; }
.debug pre { margin: 8px 0 0; white-space: pre-wrap; line-height: 1.5; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes breathe {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.8; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
  .landing {
    align-items: flex-end;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  }
  .card { padding: 22px 20px 18px; border-radius: 22px; }
  .card-top { margin-bottom: 18px; }
  .marker-thumb { width: 64px; height: 64px; }
  .lede { font-size: 13.5px; }
  .primary { height: 50px; }
  .hint { font-size: 11px; max-width: calc(100vw - 32px); white-space: normal; text-align: center; }
}

@media (max-width: 380px) {
  h1 { font-size: 27px; }
  .marker-thumb { width: 56px; height: 56px; }
  .actions { flex-wrap: wrap; }
}

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