:root {
  --glass: rgba(40, 40, 46, 0.42);
  --glass-strong: rgba(50, 50, 58, 0.72);
  --stroke: rgba(255, 255, 255, 0.16);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.58);
  --feather: 3.5%;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #050506;
  color: var(--text);
  font: 14px/1.4 -apple-system, "SF Pro Text", "PingFang SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  overscroll-behavior: none;
}

#ambient {
  position: fixed;
  inset: -10%;
  background-size: cover;
  background-position: center;
  filter: blur(70px) saturate(1.3) brightness(0.45);
  transform: scale(1.1);
  transition: background-image 0.6s;
}

#title {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  right: max(20px, env(safe-area-inset-right));
  z-index: 5;
  pointer-events: none;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.65);
}
#title .brand { font-size: 17px; font-weight: 600; letter-spacing: 0.2px; }
#title .sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#stageWrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}
#stage {
  position: relative;
  border-radius: 34px;
  overflow: hidden;
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--stroke);
  transition: border-radius 0.5s, box-shadow 0.5s, background-color 1.6s;
  touch-action: none;
  cursor: grab;
}
#stage.dragging { cursor: grabbing; }

#stage canvas,
#stage #preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  -webkit-mask-image:
    linear-gradient(to right, transparent, #000 var(--feather), #000 calc(100% - var(--feather)), transparent),
    linear-gradient(to bottom, transparent, #000 var(--feather), #000 calc(100% - var(--feather)), transparent);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent, #000 var(--feather), #000 calc(100% - var(--feather)), transparent),
    linear-gradient(to bottom, transparent, #000 var(--feather), #000 calc(100% - var(--feather)), transparent);
  mask-composite: intersect;
}

#stageFill {
  position: absolute;
  inset: -8%;
  background-size: cover;
  background-position: center;
  filter: blur(28px) saturate(1.2) brightness(0.75);
  transition: opacity 1.6s ease;
}

/* Loading reveal: glowing dots read best on near-black, and the photo gives way fast. */
#stage.revealing { background-color: #040406; }
#stage.revealing #stageFill { opacity: 0; transition: opacity 0.4s ease; }
#stage.revealing #preview { transition: opacity 0.45s ease, filter 0.45s ease; }

#preview {
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.4s ease, filter 1.4s ease;
}
#preview.show { opacity: 1; transition: none; }
#preview.dim { filter: brightness(0.55) blur(2px); }

body.immersive #stage { border-radius: 0; box-shadow: none; }
body.immersive { --feather: 6%; }
/* Full-bleed orbit scenes fill the screen cleanly without dark edge vignetting. */
body.orbit-mode.immersive #stage canvas,
body.orbit-mode.immersive #stage #preview {
  -webkit-mask-image: none;
  mask-image: none;
}

#status {
  position: absolute;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 84px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass-strong);
  backdrop-filter: blur(30px) saturate(1.6);
  -webkit-backdrop-filter: blur(30px) saturate(1.6);
  border: 1px solid var(--stroke);
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  z-index: 3;
}
body:not(.immersive) #status { bottom: 28px; }

.spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#ornament {
  position: fixed;
  left: 50%;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 8px));
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 7px;
  border-radius: 26px;
  width: max-content;
  background: var(--glass);
  backdrop-filter: blur(40px) saturate(1.8);
  -webkit-backdrop-filter: blur(40px) saturate(1.8);
  border: 1px solid var(--stroke);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  max-width: calc(100vw - 20px);
}

.btn {
  appearance: none;
  border: 0;
  color: var(--text);
  background: transparent;
  font: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
  transition: background 0.2s, transform 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn:active { transform: scale(0.96); }
.btn.active { background: rgba(255, 255, 255, 0.92); color: #111; }
.btn:disabled { opacity: 0.4; cursor: default; }

.divider { width: 1px; height: 22px; background: var(--stroke); margin: 0 4px; }

.scenes {
  display: flex;
  flex: none;
  gap: 6px;
  padding: 3px;
  overflow-x: auto;
  max-width: min(40vw, 360px);
  scrollbar-width: none;
}
.scenes::-webkit-scrollbar { display: none; }
.scenes .thumb {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.2s, transform 0.2s;
}
.scenes .thumb:hover { transform: scale(1.08); }
.scenes .thumb.active { outline-color: #fff; }

#headDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 8px 0 2px;
  background: #ff5f57;
  box-shadow: 0 0 10px currentColor;
}
#headDot.ok { background: #32d74b; }

#hint {
  position: fixed;
  right: 24px;
  top: 22px;
  z-index: 5;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
  transition: opacity 1s;
}

#dropOverlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  font-size: 22px;
  font-weight: 500;
}
#dropOverlay > div {
  padding: 40px 60px;
  border: 2px dashed rgba(255, 255, 255, 0.5);
  border-radius: 28px;
}

.hidden { display: none !important; }
body.orbit-mode .single-only { display: none !important; }
body:not(.stereo) .stereo-only { display: none !important; }
body.hub .local-only { display: none !important; }
body.static .local-only,
body.static .upload-only { display: none !important; }
body.mobile .desktop-only,
body.mobile #hint { display: none !important; }
body.share-view .upload-only,
body.share-view .local-only,
body.share-view .desktop-only { display: none !important; }
body.share-view:not(.scenes-open) .scenes,
body.share-view:not(.scenes-open) .divider { display: none !important; }

/* Free-view stereo: both panels must look identical apart from parallax, so no edge
   feathering or blurred backdrop that would differ between the eyes. */
body.stereo #stage { border-radius: 14px; background: #000; }
body.stereo #stage canvas { -webkit-mask-image: none; mask-image: none; }
body.stereo #stageFill,
body.stereo #preview { display: none; }

#stereoDots { display: none; }
body.stereo #stereoDots { display: block; }
#stereoDots i {
  position: absolute;
  top: 12px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.6);
  z-index: 2;
  pointer-events: none;
}

/* Mobile landscape stereo maximizes screen real estate for natural parallel fusion. */
body.mobile.stereo #title { display: none; }
body.mobile.stereo #ornament {
  bottom: max(8px, env(safe-area-inset-bottom));
  padding: 5px 8px;
  gap: 4px;
}
body.mobile.stereo #ornament .scenes,
body.mobile.stereo #ornament .divider { display: none; }

/* Share poster modal */
#shareModal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.poster-card {
  width: min(380px, 100%);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-radius: 26px;
  background: rgba(28, 30, 36, 0.92);
  border: 1px solid var(--stroke);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
}
.poster-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 15px;
  padding: 0 4px;
}
.icon-close {
  appearance: none;
  border: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.poster-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  overflow: auto;
}
#posterImg {
  width: 100%;
  max-height: min(62dvh, 480px);
  object-fit: contain;
  border-radius: 16px;
  display: block;
  user-select: auto;
  -webkit-touch-callout: default;
}
.poster-tip {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.poster-actions {
  display: flex;
  gap: 8px;
}
.poster-actions .btn {
  flex: 1;
  text-align: center;
  background: rgba(255, 255, 255, 0.12);
}
.poster-actions .btn.active {
  background: rgba(255, 255, 255, 0.94);
  color: #111;
}

/* Narrow windows: scenes get their own scrollable row above the controls. */
@media (max-width: 980px) {
  .scenes { flex-basis: 100%; max-width: 100%; justify-content: safe center; }
  .divider { display: none; }
}
@media (max-width: 720px) {
  #hint { display: none; }
  #title .brand { font-size: 15px; }
  #ornament {
    border-radius: 22px;
    padding: 6px;
    gap: 4px;
  }
  .btn { padding: 7px 11px; font-size: 12.5px; }
  .scenes .thumb { width: 32px; height: 32px; }
}
