:root {
  --ink: #1c2b3a;
  --paper: rgba(255, 255, 255, 0.92);
  --accent: #ff5c7a;
  --accent2: #ffb347;
  --shadow: 0 6px 24px rgba(20, 30, 60, 0.25);
  font-size: 17px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: ui-rounded, "Trebuchet MS", Verdana, "Segoe UI", sans-serif;
  background: #0b1220;
  color: var(--ink);
}

#app {
  position: fixed;
  inset: 0;
}

#app canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hud button {
  pointer-events: auto;
  font-family: inherit;
}

/* loading screen */
#loader {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, rgba(14, 24, 46, 0.55), rgba(32, 16, 52, 0.66));
  backdrop-filter: blur(9px) saturate(1.15);
  -webkit-backdrop-filter: blur(9px) saturate(1.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 100;
  transition: opacity 0.8s ease;
  color: #fff;
}

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

#loader .helix-spin {
  font-size: 64px;
  animation: tumble 2.2s ease-in-out infinite;
}

@keyframes tumble {
  0%, 100% { transform: rotate(-14deg) scale(1); }
  50% { transform: rotate(14deg) scale(1.12); }
}

#loader h1 {
  font-size: 1.7rem;
  letter-spacing: 0.02em;
}

#loader p {
  opacity: 0.85;
  font-size: 1rem;
}

#start-btn {
  font-size: 1.25rem;
  padding: 14px 34px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}

#start-btn:hover {
  transform: scale(1.07);
}

/* captions */
#caption {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(24px);
  max-width: min(680px, calc(100vw - 24px));
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}

#caption.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

#caption-text {
  font-size: 1.05rem;
  line-height: 1.35;
}

#caption-next {
  flex-shrink: 0;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: bold;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

#caption-next:hover {
  background: #e4486a;
}

/* speech bubble floating near a 3D object */
#bubble {
  position: absolute;
  left: 0;
  top: 0;
  background: #fff;
  border-radius: 16px;
  padding: 8px 13px;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  max-width: 230px;
  text-align: center;
  will-change: transform;
}

#bubble.visible {
  opacity: 1;
}

#bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  margin-left: -8px;
  border: 8px solid transparent;
  border-top-color: #fff;
  border-bottom: none;
}

/* progress strip */
#progress {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: rgba(10, 18, 34, 0.45);
  border-radius: 999px;
  padding: 5px 8px;
  backdrop-filter: blur(6px);
  pointer-events: auto;
  max-width: calc(100vw - 190px);
  overflow-x: auto;
  scrollbar-width: none;
}

#progress::-webkit-scrollbar {
  display: none;
}

.progress-stop {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.65);
  font-size: 1.15rem;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.progress-stop .progress-label {
  font-size: 0.78rem;
  font-weight: bold;
  display: none;
}

.progress-stop.active {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
}

.progress-stop.active .progress-label {
  display: inline;
}

.progress-stop:hover {
  background: rgba(255, 255, 255, 0.25);
}

.progress-stop.active:hover {
  background: rgba(255, 255, 255, 0.95);
}

/* big round dive button */
#dive-btn {
  position: absolute;
  right: 22px;
  bottom: 88px;
  border: none;
  background: linear-gradient(160deg, var(--accent), #c73cf0);
  color: #fff;
  font-size: 1.15rem;
  font-weight: bold;
  padding: 16px 24px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(255, 92, 122, 0.45);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  animation: none;
}

#dive-btn.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  animation: dive-pulse 2.4s ease-in-out infinite;
}

@keyframes dive-pulse {
  0%, 100% { box-shadow: 0 8px 28px rgba(255, 92, 122, 0.45); }
  50% { box-shadow: 0 8px 40px rgba(255, 92, 122, 0.85); }
}

#dive-btn .dive-arrow {
  display: inline-block;
  animation: bob 1.2s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

/* back button */
#back-btn {
  position: absolute;
  left: 18px;
  bottom: 88px;
  border: none;
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  font-weight: bold;
  padding: 12px 18px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

#back-btn.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

/* mute + keys */
#mute-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  border: none;
  background: rgba(10, 18, 34, 0.45);
  color: #fff;
  font-size: 1.1rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

#keys-hint {
  position: absolute;
  top: 12px;
  left: 14px;
  background: rgba(10, 18, 34, 0.45);
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.78rem;
  padding: 8px 12px;
  border-radius: 12px;
  backdrop-filter: blur(6px);
  line-height: 1.55;
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
}

#keys-hint .kbd {
  display: inline-block;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  padding: 0 6px;
  font-weight: bold;
  font-size: 0.72rem;
}

#keys-hint.collapsed .hint-rows {
  display: none;
}

/* toast */
#toast {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 20px;
  font-weight: bold;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

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

/* celebration overlay */
#celebration {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  top: -20px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(720deg);
  }
}

@media (max-width: 720px) {
  :root {
    font-size: 15px;
  }

  #keys-hint {
    display: none;
  }

  #dive-btn {
    right: 14px;
    bottom: 76px;
    padding: 13px 18px;
    font-size: 1rem;
  }

  #back-btn {
    left: 12px;
    bottom: 76px;
  }

  /* narrow screens: captions move up top so the dive/back buttons stay clear */
  #caption {
    top: 64px;
    bottom: auto;
    transform: translateX(-50%) translateY(-24px);
  }

  #caption.visible {
    transform: translateX(-50%) translateY(0);
  }
}
