/* AR Lab — TV/desktop is incidental; this is designed for a phone or iPad held
   in the hand, over a live camera feed. Everything floats over video, so panels
   lean on blur + dark translucency rather than solid fills. */

:root {
  --bg: #05070d;
  --ink: #f2f5fa;
  --muted: #93a0b8;
  --accent: #6fd3ff;
  --accent-dim: #21506b;
  --danger: #ff6b6b;
  --panel: rgba(10, 14, 22, 0.72);
  --stroke: rgba(255, 255, 255, 0.14);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  background: var(--bg);
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  /* NOT opaque: LocAR's camera <video> sits at a negative z-index, and an
     in-flow block background paints *after* negative-z descendants — an opaque
     body here hides the camera feed entirely. */
  background: transparent;
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
}

/* LocAR creates its own <video>, appends it to <body>, and sets z-index:-100
   inline. Negative z-index is fragile (see the body background note above), so
   pull it up into the normal positioned layer and stack our canvases over it.
   The inline style means these need !important. */
body > video {
  position: fixed !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  z-index: 0 !important;
  background: #000 !important;
}

#gl, #overlay, #swap, #touch {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
#gl { z-index: 1; }
#swap { z-index: 2; pointer-events: none; }
#overlay { z-index: 3; pointer-events: none; }
#touch { z-index: 4; }

/* --------------------------------------------------------------- start --- */

#start {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 10%, #12203a 0%, #05070d 70%);
  transition: opacity 0.45s ease;
}
#start.gone { opacity: 0; pointer-events: none; }

.start-card { max-width: 380px; text-align: center; }
.start-card h1 {
  margin: 0 0 12px;
  font-size: 34px;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, #9be5ff, #cbb6ff 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.start-card p { color: var(--muted); margin: 0 0 22px; }

#start-btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 15px 40px;
  font: 600 17px/1 inherit;
  color: #04121c;
  background: linear-gradient(100deg, #7fe0ff, #a99cff);
  box-shadow: 0 10px 34px rgba(90, 170, 255, 0.32);
}
#start-btn:disabled { opacity: 0.55; }
#start-msg { margin-top: 18px; font-size: 13px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ----------------------------------------------------------------- hud --- */

#hud {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  left: 12px;
  z-index: 20;
  padding: 7px 12px;
  border-radius: 10px;
  font: 500 11.5px/1 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--stroke);
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
}
#hud b { color: var(--ink); font-weight: 600; }
body[data-mode="view"] #hud { display: none; }

/* --------------------------------------------------------------- modes --- */

#modes {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  right: 12px;
  z-index: 30;
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--stroke);
}
#modes button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: 600 13px/1 inherit;
  padding: 9px 13px;
  border-radius: 9px;
}
#modes button.active { background: var(--accent-dim); color: #cdefff; }

/* -------------------------------------------------------------- panels --- */

.panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--safe-b) + 12px);
  z-index: 20;
  padding: 10px;
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--stroke);
}
body:not([data-mode="explore"]) #explore-panel { display: none; }

.layer-row { display: flex; gap: 7px; }
.layer-row + .layer-row { margin-top: 7px; }

.layer {
  flex: 1;
  appearance: none;
  border: 1px solid var(--stroke);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  font: 600 13px/1.25 inherit;
  padding: 9px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.layer small { font-weight: 500; font-size: 10px; opacity: 0.72; }
.layer i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #3a4557;
  display: block;
  margin-bottom: 1px;
}
.layer.on { color: var(--ink); border-color: rgba(111, 211, 255, 0.5); background: rgba(33, 80, 107, 0.5); }
.layer.on i { background: var(--accent); box-shadow: 0 0 9px var(--accent); }

#probe-panel { display: none; margin-top: 9px; }
#probe-panel.show { display: block; }
#probe-input {
  width: 100%;
  appearance: none;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font: 500 14px/1 inherit;
  padding: 11px 12px;
}
.probe-actions { display: flex; gap: 7px; margin-top: 7px; }
.probe-actions button {
  flex: 1;
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  font: 600 13px/1 inherit;
  background: var(--accent);
  color: #04121c;
}
.probe-actions button.ghost { background: rgba(255, 255, 255, 0.09); color: var(--ink); }
.probe-actions button:disabled { opacity: 0.6; }
#probe-panel .muted { margin: 8px 2px 0; }

/* -------------------------------------------------------------- drawer --- */

#drawer {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 25;
  padding: 0 12px calc(var(--safe-b) + 12px);
  background: linear-gradient(180deg, rgba(5, 7, 13, 0.5), rgba(5, 7, 13, 0.94) 22%);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--stroke);
  transform: translateY(calc(100% - 92px));
  transition: transform 0.32s cubic-bezier(0.3, 0.9, 0.3, 1), opacity 0.2s;
}
#drawer.open { transform: translateY(0); }
#drawer.dodge { opacity: 0.12; }
body:not([data-mode="build"]) #drawer { display: none; }

#drawer-toggle {
  display: block;
  width: 100%;
  appearance: none;
  border: 0;
  background: none;
  padding: 10px 0 6px;
}
#drawer-toggle span {
  display: block;
  width: 42px; height: 4px;
  margin: 0 auto;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.3);
}

#tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 9px;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none;
  flex: 0 0 auto;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font: 600 12.5px/1 inherit;
  padding: 8px 14px;
}
.tab.active { background: var(--accent-dim); color: #cdefff; border-color: rgba(111, 211, 255, 0.45); }

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
  padding-bottom: 6px;
}
.asset { text-align: center; }
.asset span {
  display: block;
  margin-top: 4px;
  font-size: 10.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.asset-thumb {
  aspect-ratio: 1;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: #161a24 center/cover no-repeat;
}
.asset-thumb.pending {
  background-image: linear-gradient(120deg, #1b2130, #2a3346);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.55; } }

.drag-ghost {
  position: fixed;
  z-index: 90;
  transform: translate(-50%, -50%);
  padding: 8px 13px;
  border-radius: 10px;
  font: 600 12px/1 inherit;
  background: var(--accent);
  color: #04121c;
  pointer-events: none;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
}

/* -------------------------------------------------------------- gizmo --- */

#gizmo {
  position: fixed;
  z-index: 22;
  transform: translate(-50%, -50%);
  display: none;
  pointer-events: none;
}
#gizmo.show { display: block; }
body:not([data-mode="build"]) #gizmo { display: none; }

.gizmo-ring {
  width: 66px; height: 66px;
  margin: -33px 0 0 -33px;
  position: absolute;
  border-radius: 50%;
  border: 2px dashed rgba(111, 211, 255, 0.85);
  animation: spin 9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gizmo-bar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--safe-b) + 108px);
  pointer-events: auto;
  padding: 11px 13px;
  border-radius: 15px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--stroke);
}
.gizmo-bar label {
  display: flex;
  justify-content: space-between;
  font: 600 12px/1 inherit;
  color: var(--muted);
  margin-bottom: 8px;
}
.gizmo-bar label span { color: var(--accent); }
#alt-slider { width: 100%; accent-color: var(--accent); }
.gizmo-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.gizmo-actions .muted { flex: 1; }
.gizmo-actions button {
  appearance: none;
  border: 0;
  border-radius: 9px;
  padding: 9px 14px;
  font: 600 12.5px/1 inherit;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
}
.gizmo-actions button.danger { background: rgba(255, 107, 107, 0.2); color: var(--danger); }

/* -------------------------------------------------------------- toast --- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 190px);
  z-index: 60;
  transform: translate(-50%, 12px);
  padding: 10px 17px;
  border-radius: 999px;
  font: 500 13px/1 inherit;
  background: rgba(12, 18, 28, 0.93);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  max-width: 84vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* View mode: nothing but the world and the switcher. */
body[data-mode="view"] .panel,
body[data-mode="view"] #drawer,
body[data-mode="view"] #gizmo,
body[data-mode="view"] #toast { display: none !important; }
