:root {
  --bg-night: #080b14;
  --amber: #ff9e4a;
  --amber-soft: rgba(255, 158, 74, 0.22);
  --text-main: #f3efe6;
  --text-muted: #b5b0a6;
  --glass-bg: rgba(12, 16, 28, 0.72);
  --glass-border: rgba(255, 185, 118, 0.22);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  scrollbar-color: var(--amber-soft) transparent;
  scrollbar-width: thin;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-night);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open {
  overflow: hidden;
}

body.modal-open #world {
  touch-action: none;
}

/* Native scroll track driving the 3D journey */
#scroll-track {
  position: relative;
  width: 100%;
  height: 1750vh;
  pointer-events: none;
}

#world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: pan-y;
}

#world.is-interactive {
  cursor: pointer;
}

/* Loading overlay */
#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: radial-gradient(circle at center, #141c30 0%, #070a12 80%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#loader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-fox {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 158, 74, 0.35);
  border-top-color: var(--amber);
  animation: spin 1s linear infinite;
  display: grid;
  place-items: center;
}

.loader-text {
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Top HUD */
.hud-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  pointer-events: none;
}

.brand-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 8px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-main);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
}

.brand-pill img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.chapter-nav {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow-x: auto;
  max-width: calc(100vw - 170px);
  scrollbar-width: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.chapter-nav::-webkit-scrollbar {
  display: none;
}

.chapter-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease;
}

.chapter-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

.chapter-btn.active {
  color: #140c06;
  background: var(--amber);
  font-weight: 600;
}

/* Progress bar along bottom edge */
.progress-rail {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  z-index: 25;
  pointer-events: none;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #60a5fa, #ff9e4a, #fbbf24);
  transition: width 0.08s linear;
}

/* Scroll hint */
.scroll-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: calc(100vw - 32px);
  gap: 6px;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-main);
  font-size: 0.85rem;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.scroll-hint.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(12px);
}

.scroll-arrow {
  width: 14px;
  height: 14px;
  border-right: 2px solid var(--amber);
  border-bottom: 2px solid var(--amber);
  transform: rotate(45deg);
  animation: bounceArrow 1.5s infinite ease-in-out;
}

@keyframes bounceArrow {
  0%, 100% {
    transform: rotate(45deg) translate(0, 0);
  }
  50% {
    transform: rotate(45deg) translate(3px, 3px);
  }
}

/* Hover / focus pill for interactive wall frames */
.wall-tooltip {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 22;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(15, 20, 34, 0.88);
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: #fef3c7;
  font-size: 0.84rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.wall-tooltip.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(5, 8, 15, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  overflow-y: auto;
  background: linear-gradient(160deg, #161d2f 0%, #0e1320 100%);
  border: 1px solid rgba(255, 158, 74, 0.35);
  border-radius: 18px;
  padding: 28px 26px 24px;
  color: var(--text-main);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(12, 16, 28, 0.86);
  color: var(--text-main);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s ease;
}

.modal-close:hover {
  background: rgba(255, 158, 74, 0.25);
}

.modal-body h2 {
  margin: 0 0 12px;
  font-size: 1.45rem;
  color: var(--amber);
  padding-right: 32px;
}

.modal-body h3 {
  margin: 16px 0 8px;
  font-size: 1.05rem;
  color: #fde68a;
}

.modal-body p {
  margin: 0 0 12px;
  line-height: 1.6;
  color: #e2dfd7;
}

.modal-body ul {
  margin: 0 0 14px;
  padding-left: 20px;
  line-height: 1.6;
  color: #d6d3cb;
}

.modal-body a {
  color: #7dd3fc;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.modal-body a:hover {
  color: #bae6fd;
}

.modal-body img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  margin: 14px auto 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.modal-hero {
  position: relative;
  margin: -6px -4px 16px;
  border-radius: 14px;
  overflow: hidden;
  max-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d111c;
}

.modal-hero img {
  width: auto;
  max-width: 100%;
  max-height: 240px;
  height: auto;
  object-fit: contain;
  margin: 0;
  border: none;
  border-radius: 0;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 62%, transparent 100%);
  mask-image: radial-gradient(ellipse at center, #000 62%, transparent 100%);
}

@media (max-width: 640px) {
  .hud-top {
    padding: 10px 12px;
  }

  .brand-pill span {
    display: none;
  }

  .brand-pill {
    padding: 5px;
  }

  .chapter-nav {
    max-width: calc(100vw - 72px);
  }

  .modal-card {
    padding: 22px 18px 18px;
  }
}
