/* Fullscreen stage, step panels, scene stack and the persistent HUD. */

#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.step {
  position: absolute;
  inset: 0;
}

.step[data-inert='true'] {
  pointer-events: none;
}

.scene {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
}

.scene__bg,
.scene__field,
.scene__art,
.scene__particles,
.scene__grain,
.scene__scrim {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scene__art {
  opacity: 0.78;
}

.scene__scrim {
  background: radial-gradient(85% 62% at 50% 46%, rgba(5, 8, 6, 0.72), rgba(5, 8, 6, 0.3) 68%, rgba(5, 8, 6, 0) 100%);
}

.scene__bg {
  background:
    radial-gradient(900px 620px at 78% 8%, rgba(49, 169, 0, 0.18), transparent 62%),
    linear-gradient(180deg, rgba(5, 8, 6, 0.2), rgba(5, 8, 6, 0.85));
}

.scene[data-tone='alert'] .scene__bg {
  background:
    radial-gradient(900px 620px at 50% 0%, rgba(255, 59, 48, 0.22), transparent 60%),
    linear-gradient(180deg, rgba(5, 8, 6, 0.35), rgba(5, 8, 6, 0.92));
}

.scene[data-tone='recipe'] .scene__bg {
  background:
    radial-gradient(900px 620px at 20% 0%, rgba(243, 177, 49, 0.14), transparent 60%),
    linear-gradient(180deg, rgba(5, 8, 6, 0.4), rgba(5, 8, 6, 0.94));
}

.scene__field {
  display: flex;
  align-items: flex-end;
  opacity: 0.6;
}

.scene__field svg {
  width: 100%;
  height: 60%;
}

.scene__art {
  display: grid;
  place-items: center;
}

.scene__art .art-scene {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scene__grain {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  opacity: 0.05;
  mix-blend-mode: overlay;
}

.scene__particles {
  overflow: hidden;
}

.scene__content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  justify-content: safe center; /* falls back to flex-start on overflow */
  gap: clamp(14px, 2.6vw, 22px);
  padding: calc(var(--hud-h) + 26px + env(safe-area-inset-top, 0px)) var(--gutter) calc(28px + env(safe-area-inset-bottom, 0px));
  max-width: min(720px, 92vw);
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.scene__content--intro {
  padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
}

.scene__content--recipe {
  justify-content: flex-start;
  padding-top: calc(var(--hud-h) + 40px + env(safe-area-inset-top, 0px));
}

/* Question screens: centred content with a reserved prop layer behind it
   (the layer is appended to the scene, so it never affects the content's scroll). */
.scene[data-tone='dossier'] .scene__content {
  justify-content: safe center;
  gap: clamp(10px, 2.4vw, 18px);
  padding-top: calc(var(--hud-h) + 10px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.scene__content::-webkit-scrollbar {
  width: 8px;
}
.scene__content::-webkit-scrollbar-thumb {
  background: rgba(126, 230, 90, 0.3);
  border-radius: 8px;
}

/* HUD */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px var(--gutter);
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
}

.hud__row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hud__row--logo {
  justify-content: flex-start;
}

.hud__row--controls {
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: nowrap;
}

.hud__logo {
  height: var(--hud-item-h);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0 12px;
  backdrop-filter: blur(10px);
  display: inline-flex;
  align-items: center;
  box-shadow: 0 0 30px rgba(49, 169, 0, 0.18);
}

.hud__logo img {
  height: 24px;
  width: auto;
}

.hud__logo-link {
  display: inline-flex;
  align-items: center;
}

/* Always-visible skip link to the plan screen (hidden on the plan itself). */
.hud__skip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--hud-item-h);
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: rgba(49, 169, 0, 0.12);
  color: var(--brand-3);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  transition:
    background var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}
.hud__skip:hover {
  background: rgba(49, 169, 0, 0.2);
  box-shadow: var(--glow-brand);
}
.hud__skip svg {
  width: 16px;
  height: 16px;
}
/* Author `display` would otherwise override the UA `[hidden]` rule. */
.hud__skip[hidden] {
  display: none;
}

.hud__progress {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 108px;
  height: var(--hud-item-h);
}

.hud__progress-label,
.hud__gauge-label {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.hud__progress-track {
  display: block;
  height: 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.hud__progress-bar {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(var(--progress, 0.1));
  background: linear-gradient(90deg, var(--brand), var(--brand-3));
  transition: transform var(--dur-base) var(--ease-out);
}

.hud__gauge {
  height: var(--hud-item-h);
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0 12px;
  backdrop-filter: blur(10px);
  min-width: 132px;
}

.hud__gauge-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.hud__gauge-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  color: var(--brand-3);
}

.hud__gauge-track {
  display: block;
  margin-top: 5px;
  height: 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.hud__gauge-bar {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(var(--meter, 0));
  background: linear-gradient(90deg, var(--gold), var(--alert), var(--brand));
  transition: transform var(--dur-base) var(--ease-out);
}

.hud__toggle {
  width: var(--hud-item-h);
  height: var(--hud-item-h);
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-dim);
}

.hud__toggle svg {
  width: 20px;
  height: 20px;
}

.hud__toggle.is-on {
  color: var(--brand-3);
  border-color: var(--border-strong);
  box-shadow: var(--glow-brand);
}

@media (max-width: 640px) {
  /* Second row takes the full width, items spaced across it. */
  .hud__row--controls {
    justify-content: space-between;
    gap: 6px;
  }
  .hud__progress {
    min-width: 0;
  }
  .hud__gauge {
    min-width: 0;
    padding: 0 8px;
  }
  /* Labels are shown on mobile now the countdown has left the HUD. */
  .hud__progress-label,
  .hud__gauge-label {
    font-size: 9px;
    letter-spacing: 0.08em;
  }
  .hud__logo img {
    height: 22px;
  }
}
