:root {
  --bg: #0d0f17;
  --panel: #151826;
  --panel-2: #1d2133;
  --text: #f1ece4;
  --muted: #a3a7b8;
  --accent: #ffb54d;
  --accent-2: #6fe3ff;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #1b1f33 0%, var(--bg) 70%);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

button { font: inherit; color: inherit; }

/* ---------- HUD ---------- */
.hud { position: fixed; z-index: 5; pointer-events: none; }
.hud > * { pointer-events: auto; }

.hud-top {
  top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
}
.brand { display: flex; flex-direction: column; gap: 2px; pointer-events: none; }
.brand-name { font-weight: 700; font-size: clamp(20px, 4.5vw, 28px); letter-spacing: -0.02em; }
.brand-sub { color: var(--muted); font-size: 14px; }

.hud-actions { display: flex; gap: 8px; }
.chip {
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(21,24,38,.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.chip:hover { background: rgba(40,45,70,.85); border-color: rgba(255,255,255,.3); }
.chip.icon { width: 44px; padding: 0; font-style: italic; font-family: Georgia, serif; font-size: 18px; }

.hud-bottom {
  bottom: calc(16px + var(--safe-b));
  left: 50%; transform: translateX(-50%);
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(13,15,23,.55);
  transition: opacity .6s;
}
.hud-bottom.hide { opacity: 0; }

/* ---------- Menu / credits ---------- */
.menu {
  position: fixed; z-index: 6;
  top: calc(70px + var(--safe-t)); right: calc(16px + var(--safe-r));
  width: min(320px, calc(100vw - 32px));
  background: rgba(21,24,38,.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.menu ul { list-style: none; margin: 0; padding: 0; }
.menu li button {
  width: 100%; text-align: left;
  background: none; border: 0; border-radius: 12px;
  padding: 12px 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.menu li button:hover, .menu li button:focus-visible { background: var(--panel-2); outline: none; }
.menu li strong { font-weight: 500; }
.menu li span { color: var(--muted); font-size: 13px; }
.credits { padding: 14px 16px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.credits p { margin: 0 0 8px; }
.credits p:last-child { margin: 0; }
.credits a { color: var(--accent-2); }

/* ---------- Floating labels ---------- */
#labels { position: fixed; inset: 0; z-index: 4; pointer-events: none; overflow: hidden; }
.hotspot {
  position: absolute; left: 0; top: 0;
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 13px 7px 9px;
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(13,15,23,.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 14px; font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  will-change: transform;
  transition: opacity .3s, background .2s, border-color .2s;
}
.hotspot::after { /* bigger touch target */
  content: ""; position: absolute; inset: -6px;
}
.hotspot:hover, .hotspot.active, .hotspot:focus-visible {
  background: rgba(40,45,70,.92); border-color: var(--accent); outline: none;
}
.hotspot .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(255,181,77,.7);
  animation: pulse 2s infinite;
}
.hotspot.hidden { opacity: 0; pointer-events: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,181,77,.7); }
  70% { box-shadow: 0 0 0 10px rgba(255,181,77,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,181,77,0); }
}

/* ---------- Viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 20; }
.viewer[hidden] { display: none; }
.viewer-backdrop {
  position: absolute; inset: 0;
  background: rgba(5,6,10,.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .3s ease;
}
.viewer-panel {
  position: absolute;
  inset: max(3vh, 20px) max(3vw, 20px);
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  opacity: 0; transform: translateY(24px) scale(.97);
  transition: opacity .3s ease, transform .35s cubic-bezier(.2,.8,.2,1);
}
.viewer.open .viewer-backdrop { opacity: 1; }
.viewer.open .viewer-panel { opacity: 1; transform: none; }

.viewer-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: var(--panel);
  flex-shrink: 0;
}
.back-btn, .ext-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 44px; min-width: 44px;
  padding: 0 14px 0 8px;
  border: 0; border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}
.ext-btn { padding: 0; }
.back-btn:hover, .ext-btn:hover { background: #2a2f47; }
.back-btn:focus-visible, .ext-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.viewer-titles { min-width: 0; flex: 1; }
.viewer-titles h2 { margin: 0; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-titles p { margin: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.viewer-body { position: relative; flex: 1; background: #fff; }
.viewer-body.video { background: #000; }
.viewer-body iframe {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0; display: block;
  opacity: 0; transition: opacity .3s;
}
.viewer-body.loaded iframe { opacity: 1; }
.spinner {
  position: absolute; top: 50%; left: 50%;
  width: 36px; height: 36px; margin: -18px 0 0 -18px;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,.12);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
.viewer-body.video .spinner { border-color: rgba(255,255,255,.15); border-top-color: var(--accent); }
.viewer-body.loaded .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Phones: full-screen sheet */
@media (max-width: 700px), (max-height: 500px) {
  .viewer-panel {
    inset: 0;
    border-radius: 0;
    border: 0;
    transform: translateY(40px);
  }
  .viewer-bar {
    padding-top: calc(8px + var(--safe-t));
    padding-left: calc(10px + var(--safe-l));
    padding-right: calc(10px + var(--safe-r));
  }
  .viewer-body { margin-bottom: 0; }
  .hud-bottom { font-size: 12px; }
}

/* ---------- Loader ---------- */
.loader {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity .6s ease, visibility .6s;
}
.loader.done { opacity: 0; visibility: hidden; }
.loader-inner { width: min(260px, 70vw); text-align: center; color: var(--muted); }
.loader-inner p { margin: 0 0 12px; }
.bar { height: 4px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.pct { margin-top: 10px !important; font-variant-numeric: tabular-nums; font-size: 13px; }

/* No WebGL: show the list as the main UI */
body.no-webgl #scene, body.no-webgl #labels, body.no-webgl #hint, body.no-webgl #menu-btn { display: none; }
body.no-webgl #menu { display: block; top: 50%; left: 50%; right: auto; transform: translate(-50%, -50%); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
