:root {
  --onyx: #080b0d;
  --charcoal: #1e1e22;
  --limestone: #f2f1ec;
  --gold: #d4af37;
  --gold-deep: #9b722e;
  --sandstone: #c8b08a;
  --muted: #b8b7b2;
  --line: rgba(212, 175, 55, 0.24);
  --panel: rgba(8, 11, 13, 0.86);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-right: max(18px, env(safe-area-inset-right));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  --safe-left: max(18px, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

.spatial-hud,
.spatial-hud *,
.capture-modal,
.capture-modal * {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--limestone);
  background: var(--onyx);
  font-family: "Montserrat", sans-serif;
  overscroll-behavior: none;
}

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

button,
a,
select,
input[type="range"] {
  touch-action: manipulation;
}

.spatial-hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.spatial-topbar {
  position: absolute;
  top: var(--safe-top);
  right: var(--safe-right);
  left: var(--safe-left);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 68px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(110deg, rgba(212, 175, 55, 0.08), transparent 28%),
    rgba(8, 11, 13, 0.88);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(18px);
  pointer-events: auto;
}

.spatial-brand,
.spatial-close {
  display: inline-flex;
  align-items: center;
  color: var(--limestone);
  text-decoration: none;
}

.spatial-brand {
  gap: 12px;
}

.spatial-brand img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.spatial-brand span {
  display: grid;
  gap: 2px;
}

.spatial-brand strong {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 0.9;
  text-transform: uppercase;
}

.spatial-brand small {
  color: var(--gold);
  font-size: 0.56rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.license-lockup {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.license-lockup span,
.engine-badge,
.tracking-pill,
.gesture-hint span {
  border: 1px solid rgba(212, 175, 55, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--sandstone);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.license-lockup span {
  padding: 8px 12px;
}

.spatial-close {
  gap: 8px;
  padding: 11px 14px;
  border: 1px solid rgba(212, 175, 55, 0.26);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.spatial-close span:first-child {
  color: var(--gold);
  font-size: 1.1rem;
}

.spatial-project-card {
  position: absolute;
  top: calc(var(--safe-top) + 88px);
  left: var(--safe-left);
  width: min(470px, calc(100vw - 36px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    radial-gradient(circle at top left, rgba(212, 175, 55, 0.13), transparent 42%),
    var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.spatial-eyebrow {
  color: var(--gold);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.spatial-project-card h1 {
  margin: 8px 0 10px;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(1.65rem, 3vw, 2.45rem);
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 0.95;
  text-transform: uppercase;
}

.project-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.project-meta span + span {
  color: var(--sandstone);
}

.feature-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.feature-chips span {
  padding: 6px 9px;
  border: 1px solid rgba(212, 175, 55, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.spatial-context-orbit {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.spatial-context-orbit span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid rgba(212, 175, 55, 0.14);
  border-radius: 999px;
  color: #9f978a;
  background: rgba(0, 0, 0, 0.14);
  font-size: 0.52rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.spatial-context-orbit span::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #766e62;
}

.spatial-context-orbit span[data-connected="true"] {
  color: var(--sandstone);
}

.spatial-context-orbit span[data-connected="true"]::before {
  background: #8ac49a;
  box-shadow: 0 0 9px rgba(138, 196, 154, 0.62);
}

.tracking-pill {
  position: absolute;
  top: calc(var(--safe-top) + 88px);
  left: 50%;
  display: flex;
  gap: 9px;
  align-items: center;
  max-width: min(430px, calc(100vw - 36px));
  padding: 10px 14px;
  color: var(--limestone);
  background: rgba(8, 11, 13, 0.82);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.tracking-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.55);
  animation: tracking-pulse 1.8s infinite;
}

.tracking-pill[data-state="ready"] .tracking-dot {
  background: #9bc994;
  animation: none;
}

.tracking-pill[data-state="error"] .tracking-dot {
  background: #d88975;
  animation: none;
}

.spatial-controls {
  position: absolute;
  right: var(--safe-right);
  bottom: calc(var(--safe-bottom) + 34px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(470px, calc(100vw - 36px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(212, 175, 55, 0.06), transparent 34%),
    var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
  pointer-events: auto;
}

.control-tab {
  padding: 11px 8px;
  border: 0;
  border-bottom: 1px solid rgba(212, 175, 55, 0.13);
  color: var(--muted);
  background: transparent;
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.control-tab.is-active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.control-panel {
  display: none;
  grid-column: 1 / -1;
  gap: 13px;
  padding: 16px 4px 4px;
}

.control-panel.is-active {
  display: grid;
}

.control-panel p,
.spatial-disclaimer {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.65;
}

.control-field {
  display: grid;
  gap: 7px;
}

.control-field label,
.control-label-row output {
  color: var(--sandstone);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.control-label-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.control-field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-radius: 10px;
  color: var(--limestone);
  background: #171a1d;
  font-size: 0.76rem;
}

.control-field input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.material-board-mini {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  min-height: 54px;
  padding: 10px 11px;
  border: 1px solid rgba(212, 175, 55, 0.14);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.022);
}

.material-board-mini > div:first-child {
  min-width: 0;
}

.material-board-mini span,
.material-board-mini strong {
  display: block;
}

.material-board-mini span {
  margin-bottom: 4px;
  color: #8f877a;
  font-size: 0.52rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.material-board-mini strong {
  overflow: hidden;
  color: var(--limestone);
  font-size: 0.68rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.material-board-swatches {
  display: flex;
  flex: 0 0 auto;
}

.material-board-swatches i {
  width: 24px;
  height: 24px;
  margin-left: -5px;
  border: 2px solid #171a1d;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.spatial-preflight {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.spatial-preflight article {
  min-width: 0;
  padding: 9px;
  border: 1px solid rgba(212, 175, 55, 0.13);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.02);
}

.spatial-preflight article span,
.spatial-preflight article strong {
  display: block;
}

.spatial-preflight article span {
  margin-bottom: 4px;
  color: #898174;
  font-size: 0.49rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.spatial-preflight article strong {
  overflow: hidden;
  font-size: 0.61rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spatial-preflight article[data-state="ready"] strong {
  color: #9bc994;
}

.spatial-preflight article[data-state="attention"] strong {
  color: #e0b878;
}

.spatial-verification-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 3px;
}

.spatial-verification-head span,
.spatial-verification-head strong {
  color: var(--sandstone);
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.spatial-verification-head strong {
  color: var(--gold);
}

.spatial-checklist {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.spatial-checklist label {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid rgba(212, 175, 55, 0.12);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.018);
  font-size: 0.56rem;
  line-height: 1.35;
}

.spatial-checklist input {
  flex: 0 0 auto;
  accent-color: var(--gold);
}

.spatial-verify-note {
  padding-top: 9px;
  border-top: 1px solid rgba(212, 175, 55, 0.1);
  font-size: 0.57rem !important;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.control-grid button,
.control-grid a,
.capture-actions button,
.capture-actions a {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 9px 10px;
  border: 1px solid rgba(212, 175, 55, 0.23);
  border-radius: 10px;
  color: var(--limestone);
  background: rgba(255, 255, 255, 0.035);
  font-size: 0.61rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
}

.control-grid button:hover,
.control-grid a:hover,
.capture-actions button:hover,
.capture-actions a:hover {
  color: var(--onyx);
  border-color: var(--gold);
  background: linear-gradient(135deg, #b98a3f, #e1c477);
}

.spatial-disclaimer {
  grid-column: 1 / -1;
  margin: 12px 4px 2px;
  padding-top: 12px;
  border-top: 1px solid rgba(212, 175, 55, 0.12);
  font-size: 0.58rem;
}

.gesture-hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 8px);
  left: var(--safe-left);
  display: flex;
  gap: 7px;
}

.gesture-hint span {
  padding: 7px 10px;
  color: var(--limestone);
  background: rgba(8, 11, 13, 0.72);
  backdrop-filter: blur(10px);
}

.engine-badge {
  position: absolute;
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  padding: 7px 10px;
  color: rgba(242, 241, 236, 0.66);
  background: rgba(8, 11, 13, 0.62);
}

.engine-badge a {
  margin-left: 7px;
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.capture-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 5, 6, 0.86);
  backdrop-filter: blur(18px);
}

.capture-modal[hidden] {
  display: none;
}

.capture-card {
  width: min(720px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--onyx);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.55);
}

.capture-card img {
  display: block;
  width: 100%;
  max-height: 70vh;
  margin: 14px 0;
  border-radius: 14px;
  object-fit: contain;
  background: #111;
}

.capture-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

a-scene {
  position: fixed !important;
  inset: 0;
  z-index: 1;
  width: 100% !important;
  height: 100% !important;
}

@keyframes tracking-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.55);
  }
  70% {
    box-shadow: 0 0 0 9px rgba(212, 175, 55, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(212, 175, 55, 0);
  }
}

@media (max-width: 900px) {
  .spatial-topbar {
    grid-template-columns: 1fr auto;
  }

  .license-lockup {
    display: none;
  }

  .spatial-project-card {
    top: calc(var(--safe-top) + 82px);
    width: min(330px, calc(100vw - 36px));
    padding: 16px;
  }

  .tracking-pill {
    top: auto;
    right: auto;
    bottom: calc(var(--safe-bottom) + 302px);
    left: 50%;
    width: auto;
    min-width: min(320px, calc(100vw - 36px));
    justify-content: center;
    text-align: center;
  }

  .spatial-controls {
    right: var(--safe-right);
    bottom: calc(var(--safe-bottom) + 28px);
    left: var(--safe-left);
    width: auto;
  }

  .gesture-hint,
  .engine-badge {
    display: none;
  }
}

@media (max-width: 560px) {
  .spatial-topbar {
    min-height: 60px;
    padding: 8px 10px;
  }

  .spatial-brand img {
    width: 38px;
    height: 38px;
  }

  .spatial-brand strong {
    font-size: 1.18rem;
  }

  .spatial-close {
    padding: 9px 11px;
  }

  .spatial-close span:last-child {
    display: none;
  }

  .spatial-project-card {
    top: calc(var(--safe-top) + 74px);
    width: calc(100vw - 36px);
    pointer-events: none;
  }

  .spatial-project-card h1 {
    max-width: 15ch;
    font-size: 1.42rem;
    letter-spacing: 0.015em;
    line-height: 1;
    text-wrap: balance;
  }

  .feature-chips {
    display: none;
  }

  .tracking-pill {
    bottom: calc(var(--safe-bottom) + 249px);
    min-width: calc(100vw - 36px);
    font-size: 0.57rem;
    letter-spacing: 0.08em;
    white-space: normal;
  }

  .control-panel {
    max-height: 218px;
    overflow-y: auto;
  }

  .spatial-disclaimer {
    display: none;
  }

  .spatial-context-orbit {
    display: none;
  }

  .spatial-preflight,
  .spatial-checklist {
    grid-template-columns: 1fr;
  }

  .tracking-pill {
    bottom: calc(var(--safe-bottom) + 299px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tracking-dot {
    animation: none;
  }
}
