:root {
  color-scheme: dark;
  --bg: #07111d;
  --bg-soft: rgba(12, 20, 32, 0.82);
  --panel: rgba(14, 24, 40, 0.88);
  --panel-strong: rgba(10, 17, 28, 0.96);
  --line: rgba(184, 209, 255, 0.14);
  --text: #f5f8fc;
  --muted: #a8b3c8;
  --muted-2: #71819b;
  --accent: #ff8f6b;
  --accent-2: #68e3d1;
  --accent-3: #7ea8ff;
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.42);
  --radius: 8px;
  --control-radius: 10px;
  --content-max: 720px;
}

* {
  box-sizing: border-box;
}

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

html,
body,
#app-shell,
#ar-container,
#ar-container canvas {
  touch-action: none;
}

body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, #0b1524 0%, #09111d 36%, #06101a 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  background: none;
  color: inherit;
}

img {
  display: block;
}

.hidden {
  display: none !important;
}

#app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(1200px 500px at 50% 0%, rgba(126, 168, 255, 0.08), transparent 60%),
    radial-gradient(800px 500px at 15% 100%, rgba(104, 227, 209, 0.06), transparent 52%),
    linear-gradient(180deg, #09111d 0%, #07111d 100%);
}

#ar-container {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #000;
  width: 100vw;
  height: 100vh;
  width: 100dvw;
  height: 100dvh;
}

#ar-container canvas,
#ar-container video {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  z-index: 1;
  display: block;
  background: transparent;
}

.overlay,
#app-shell,
.ui-shell {
  width: 100vw;
  height: 100vh;
  width: 100dvw;
  height: 100dvh;
}

.ui-shell {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  pointer-events: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: var(--content-max);
  width: 100%;
  margin: 0 auto;
  pointer-events: auto;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
  background: #132033;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.brand-mark--large {
  width: 56px;
  height: 56px;
  border-radius: 12px;
}

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

.brand-kicker {
  margin: 0 0 3px;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--accent-2);
}

.brand-copy h1,
.loading-brand h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  font-weight: 700;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 18, 30, 0.36);
  backdrop-filter: blur(10px);
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 0 6px rgba(104, 227, 209, 0.18);
}

.scan-panel {
  pointer-events: auto;
  width: min(100%, 560px);
  margin: 0 auto;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.scan-frame {
  position: relative;
  min-height: 124px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(8, 14, 22, 0.14);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.scan-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 50%, rgba(126, 168, 255, 0.03) 50% 100%),
    linear-gradient(180deg, rgba(255, 143, 107, 0.03), transparent 72%);
  pointer-events: none;
}

.scan-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: rgba(104, 227, 209, 0.9);
  pointer-events: none;
}

.scan-corner.tl {
  top: 12px;
  left: 12px;
  border-top: 2px solid;
  border-left: 2px solid;
}

.scan-corner.tr {
  top: 12px;
  right: 12px;
  border-top: 2px solid;
  border-right: 2px solid;
}

.scan-corner.bl {
  bottom: 12px;
  left: 12px;
  border-bottom: 2px solid;
  border-left: 2px solid;
}

.scan-corner.br {
  right: 12px;
  bottom: 12px;
  border-right: 2px solid;
  border-bottom: 2px solid;
}

.scan-core {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-height: 96px;
  padding: 8px 10px;
  text-align: center;
}

.scan-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 0;
}

.scan-copy {
  margin: 0;
  max-width: 26em;
  color: var(--muted);
  line-height: 1.55;
  font-size: 13px;
}

.scan-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.scan-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 12px;
}

.instructions {
  pointer-events: auto;
  width: min(100%, var(--content-max));
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid rgba(104, 227, 209, 0.16);
  background: rgba(10, 18, 30, 0.44);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.16);
}

.instructions p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  pointer-events: auto;
  flex-wrap: wrap;
}

.tool-btn,
.video-tap,
.video-skip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--control-radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(13, 22, 35, 0.66);
  color: var(--text);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, opacity 0.18s ease;
}

.tool-btn:hover,
.video-tap:hover,
.video-skip:hover {
  transform: translateY(-1px);
  border-color: rgba(104, 227, 209, 0.28);
  background: rgba(16, 27, 43, 0.92);
}

.tool-btn svg,
.video-tap svg,
.video-skip svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex: 0 0 auto;
}

.tool-btn.is-active {
  border-color: rgba(104, 227, 209, 0.36);
  background: rgba(20, 36, 51, 0.96);
}

.tool-btn:active {
  transform: translateY(0);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

.overlay-loading {
  background: rgba(6, 10, 16, 0.62);
}

.overlay-video {
  background: rgba(5, 10, 17, 0.08);
}

.overlay-video.is-loading-model {
  background: rgba(5, 10, 17, 0.10);
  pointer-events: auto;
}

.overlay-video.is-buffering .video-copy,
.overlay-video.is-loading-model .video-copy {
  opacity: 0.9;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-video.is-loading-model .video-shade,
.overlay-video.is-loading-model .video-copy,
.overlay-video.is-loading-model .video-actions,
.overlay-video.is-loading-model .video-shade {
  opacity: 0.28;
}

.overlay-video.is-loading-model video {
  opacity: 0.35;
}

.overlay-video.is-loading-model .video-ui {
  opacity: 1;
  pointer-events: auto;
}

.loading-card {
  width: min(100%, 360px);
  padding: 18px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(12, 20, 32, 0.94);
  box-shadow: var(--shadow);
}

.loading-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.loading-copy {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.progress-shell {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.2s ease;
}

.progress-shell.is-indeterminate .progress-fill {
  width: 42%;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 18%, var(--accent-2) 50%, var(--accent) 82%, transparent 100%);
  background-size: 220% 100%;
  animation: loading-bar-slide 1.1s linear infinite;
}

.progress-shell--video {
  width: min(100%, 240px);
}

.overlay-video video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top) + 10px);
  right: max(14px, env(safe-area-inset-right) + 10px);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 14, 22, 0.72);
  color: var(--text);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.video-close svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.video-shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(6, 10, 16, 0.18) 0%, rgba(6, 10, 16, 0.48) 58%, rgba(6, 10, 16, 0.82) 100%),
    radial-gradient(900px 460px at 50% 32%, rgba(104, 227, 209, 0.12), transparent 58%);
  pointer-events: none;
}

.video-copy {
  position: absolute;
  left: 50%;
  top: max(88px, env(safe-area-inset-top) + 72px);
  z-index: 2;
  max-width: min(88vw, 320px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(8, 14, 22, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff6f1;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
}

.video-ui {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(100%, 360px);
  padding: 0 16px;
  transform: translateX(-50%);
}

.overlay-video.is-buffering .video-ui,
.overlay-video.is-loading-model .video-ui {
  z-index: 4;
}

.overlay-video.is-loading-model .video-close,
.overlay-video.is-buffering .video-close {
  z-index: 5;
}

.overlay-video.is-loading-model .video-actions,
.overlay-video.is-buffering .video-actions,
.overlay-video.is-loading-model .video-close,
.overlay-video.is-buffering .video-close,
.overlay-video.is-loading-model .video-pill,
.overlay-video.is-buffering .video-pill {
  pointer-events: auto;
}

.video-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.video-pill {
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 14, 22, 0.62);
  color: var(--text);
  backdrop-filter: blur(14px);
}

.overlay-video.is-loading-model .video-pill::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-top-color: var(--accent-2);
  vertical-align: middle;
  animation: spinner-rotate 0.8s linear infinite;
}

.overlay-video.is-loading-model .video-pill {
  display: inline-flex;
  align-items: center;
}

.video-tap {
  min-width: 0;
  background: rgba(104, 227, 209, 0.14);
  border-color: rgba(104, 227, 209, 0.26);
}

.video-skip {
  min-width: 0;
  background: rgba(255, 143, 107, 0.14);
  border-color: rgba(255, 143, 107, 0.28);
}

@keyframes loading-bar-slide {
  from {
    background-position: 0% 0;
  }
  to {
    background-position: 220% 0;
  }
}

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

body[data-phase="boot"] .scan-panel,
body[data-phase="video"] .scan-panel {
  opacity: 0;
  transform: translateY(14px);
  visibility: hidden;
  pointer-events: none;
}

body[data-phase="done"] .scan-panel,
body[data-phase="done"] .instructions {
  opacity: 0;
  transform: translateY(10px);
  visibility: hidden;
  pointer-events: none;
}

body[data-phase="boot"] .instructions,
body[data-phase="video"] .instructions,
body[data-phase="model"] .instructions {
  opacity: 0;
  transform: translateY(10px);
  visibility: hidden;
  pointer-events: none;
}

body[data-phase="boot"] .toolbar,
body[data-phase="video"] .toolbar {
  opacity: 0.18;
}

body[data-phase="model"] .scan-panel {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body[data-phase="model"] .toolbar {
  background: rgba(9, 16, 27, 0.42);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius);
  padding: 10px;
}

@media (max-width: 640px) {
  .ui-shell {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-pill {
    width: 100%;
    justify-content: center;
  }

  .scan-frame {
    min-height: 112px;
    padding: 12px;
  }

  .scan-core {
    min-height: 86px;
  }

  .scan-title {
    font-size: 17px;
  }

  .video-copy {
    top: max(78px, env(safe-area-inset-top) + 60px);
    max-width: calc(100vw - 48px);
    font-size: 18px;
  }

  .toolbar {
    justify-content: stretch;
  }

  .tool-btn {
    flex: 1 1 0;
  }

  body[data-phase="model"] .toolbar {
    padding: 8px;
  }
}

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