:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: #050104;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(ellipse at 50% 37%, rgba(208, 62, 34, 0.58) 0%, rgba(89, 13, 18, 0.38) 24%, transparent 51%),
    linear-gradient(180deg, #020106 0%, #120307 31%, #49100c 54%, #160403 100%);
}

#app {
  position: relative;
  isolation: isolate;
  background: #050104;
}

#atmosphere {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 95% 20% at 50% 28%, rgba(255, 113, 72, 0.42), rgba(143, 29, 23, 0.12) 45%, transparent 73%),
    linear-gradient(180deg, transparent 0%, rgba(155, 35, 24, 0.05) 27%, transparent 49%);
  mix-blend-mode: screen;
}

#scene {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

#overlay-scene {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  pointer-events: none;
}

#vignette {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.34), transparent 18%, transparent 78%, rgba(0, 0, 0, 0.18)),
    radial-gradient(ellipse at center, transparent 43%, rgba(0, 0, 0, 0.38) 112%);
}

#app.fog-debug-only #atmosphere,
#app.fog-debug-only #vignette {
  display: none;
}

#loading {
  position: absolute;
  left: 50%;
  bottom: 3rem;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(255, 208, 184, 0.18);
  border-radius: 999px;
  color: rgba(255, 235, 224, 0.8);
  background: rgba(12, 2, 4, 0.46);
  backdrop-filter: blur(10px);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transform: translateX(-50%);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

#loading.is-hidden {
  opacity: 0;
  transform: translate(-50%, 0.5rem);
  pointer-events: none;
}

#youtube-player {
  position: absolute;
  left: 1.25rem;
  bottom: 1.25rem;
  z-index: 1000;
  width: 280px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(255, 213, 193, 0.2);
  border-radius: 0.65rem;
  background: #050104;
  box-shadow: 0 0.8rem 2rem rgba(0, 0, 0, 0.38);
}

#youtube-player iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

#site-footer {
  position: absolute;
  right: 1rem;
  bottom: 0.45rem;
  z-index: 1001;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

#wireframe-control,
#youtube-visibility-control {
  position: fixed;
  left: 50%;
  bottom: 0.7rem;
  z-index: 2147483647;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 0.35rem;
  color: #fff;
  background: rgba(5, 1, 4, 0.7);
  font: 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  transform: translateX(-50%);
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}

#youtube-visibility-control {
  margin-left: 2.8rem;
}

#wireframe-control input,
#youtube-visibility-control input {
  margin: 0;
  accent-color: #fff;
  cursor: pointer;
  pointer-events: auto;
}

#youtube-player.is-hidden {
  display: none;
}

#terrain-video-projection {
  --projection-width: 62vw;
  --projection-opacity: 0.38;
  --projection-x: 50%;
  --projection-y: 50%;
  --projection-perspective: 900px;
  --projection-scale: 1;
  --projection-rotation-x: 58deg;
  --projection-rotation-y: 0deg;
  --projection-rotation-z: -4deg;
  position: absolute;
  left: var(--projection-x);
  top: var(--projection-y);
  z-index: 4;
  width: min(var(--projection-width), 1200px);
  aspect-ratio: 12 / 9;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  clip-path: polygon(13% 0, 87% 0, 100% 100%, 0 100%);
  mix-blend-mode: plus-lighter;
  /* filter: saturate(0.7) sepia(0.22) contrast(1.12); */
  transform:
    translate(-50%, -35%)
    perspective(var(--projection-perspective))
    rotateX(var(--projection-rotation-x))
    rotateY(var(--projection-rotation-y))
    rotateZ(var(--projection-rotation-z))
    scale(var(--projection-scale));
  transform-origin: center bottom;
  transition: opacity 0.45s ease, transform 0.45s ease;
}

#terrain-video-projection.is-active {
  opacity: var(--projection-opacity);
}

#terrain-video-projection iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.loading-dot {
  width: 0.46rem;
  height: 0.46rem;
  border-radius: 50%;
  background: #ffc7a2;
  box-shadow: 0 0 12px #ff633f;
  animation: pulse 1.25s ease-in-out infinite;
}

#debug {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 5;
  min-width: 15rem;
  padding: 0.8rem 0.95rem;
  border: 1px solid rgba(255, 213, 193, 0.18);
  border-radius: 0.75rem;
  color: rgba(255, 232, 218, 0.82);
  background: rgba(12, 2, 4, 0.62);
  backdrop-filter: blur(12px);
  font: 0.75rem/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

#debug strong,
#debug span,
#debug small {
  display: block;
}

#debug small {
  margin-top: 0.35rem;
  color: rgba(255, 232, 218, 0.5);
}

#scene-controls {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 6;
  width: min(20rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 0.85rem;
  border: 1px solid rgba(255, 213, 193, 0.2);
  border-radius: 0.75rem;
  color: rgba(255, 232, 218, 0.9);
  background: rgba(12, 2, 4, 0.72);
  backdrop-filter: blur(12px);
  font: 0.75rem/1.4 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

#scene-controls[hidden] {
  display: none;
}

#scene-controls fieldset {
  margin: 0.7rem 0 0;
  padding: 0.55rem 0.65rem 0.65rem;
  border: 1px solid rgba(255, 213, 193, 0.15);
  border-radius: 0.5rem;
}

#scene-controls label {
  display: grid;
  grid-template-columns: 1.6rem 1fr 3.5rem;
  align-items: center;
  gap: 0.5rem;
}

#scene-controls input,
#scene-controls select {
  width: 100%;
}

#scene-controls input[type="checkbox"] {
  width: auto;
  justify-self: start;
}

#scene-controls select {
  min-width: 0;
  color: inherit;
  background: #240a0c;
}

#scene-controls output {
  text-align: right;
}

#scene-controls button {
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.5rem;
  border: 1px solid rgba(255, 213, 193, 0.22);
  border-radius: 0.45rem;
  color: inherit;
  background: rgba(139, 44, 29, 0.35);
  cursor: pointer;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.88);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

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

@media (max-width: 600px) {
  #youtube-player {
    left: 0.85rem;
    bottom: 0.85rem;
    width: min(340px, calc(100vw - 1.7rem));
    border-radius: 0.5rem;
    pointer-events: auto;
    touch-action: manipulation;
  }

  #terrain-video-projection {
    display: none !important;
  }

  #wireframe-control {
    top: 0.65rem;
    right: 0.65rem;
    bottom: auto;
    left: auto;
    transform: none;
  }

  #youtube-visibility-control {
    top: 0.65rem;
    right: 3.65rem;
    bottom: auto;
    left: auto;
    margin-left: 0;
    transform: none;
  }

  #site-footer {
    right: 0.65rem;
    bottom: 0.3rem;
    font-size: 0.62rem;
  }

}
