/* =============================================================================
 * style.css — Thornwell / Neverland sorting microsite
 * Colors + fonts come from config.js (applyBrandToCss). The values below are
 * fallbacks so the page still renders if JS is slow/off.
 * ========================================================================== */

:root {
  /* Neverland app palette (app.neverland.money; config.js mirrors these live). */
  --bg: #10002C;
  --bg-soft: #2a0b51;
  --ink: #ffffff;
  --ink-soft: #D4CEDC;
  --ink-muted: #A194B3;
  --gold: #C757D8;        /* app primary gradient top */
  --gold-deep: #9A00B2;   /* app primary gradient bottom */
  --line: rgba(255, 255, 255, 0.1);
  --danger: #FF7E98;
  --pink: #d685ff;        /* app primary-surface pink, for highlights */
  --font-display: "Cinzel", Georgia, serif;
  --font-body: "Quicksand", system-ui, sans-serif;

  --maxw: 640px;
  --radius: 28px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --glow: 0 16px 40px rgba(118, 17, 140, 0.28);
  --btn-primary: linear-gradient(180deg, var(--gold), var(--gold-deep));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #200041;
  color: var(--ink);
  font-family: var(--font-body);
  font-feature-settings: "rlig" 1, "calt" 1;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

/* =============================================================================
 * Stage — layered crossroads background + Thornwell foreground
 * ========================================================================== */

.stage {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Background scene layer (real image set by JS if present, else placeholder shows).
   Centered on the signpost; kept mostly crisp for immersion. */
.stage__bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center 42%;
  background-color: var(--bg);
  transform: scale(1.06) translate3d(var(--bgx, 0px), var(--bgy, 0px), 0);
  transition: filter 0.6s ease, transform 0.25s ease-out;
  will-change: transform;
}

/* Gently dim the scene (no blur) once past the intro so the box wins focus. */
.stage[data-screen="quiz"] .stage__bg,
.stage[data-screen="reading"] .stage__bg,
.stage[data-screen="result"] .stage__bg {
  filter: brightness(0.72) saturate(0.95);
}

/* Scrim: soft top vignette for the title + heavy bottom gradient behind the box. */
.stage__scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(130% 70% at 50% 8%, transparent 0%, rgba(5, 7, 13, 0.28) 55%, transparent 75%),
    linear-gradient(to bottom, rgba(5, 7, 13, 0.35) 0%, transparent 22%, transparent 42%, rgba(5, 7, 13, 0.55) 72%, rgba(5, 7, 13, 0.92) 100%);
  pointer-events: none;
}
/* Faint grid texture, as on the app shell (.nl-shell-noise). */
.stage__scrim::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.075;
  mix-blend-mode: soft-light;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.08) 0.5px, transparent 0),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0.5px, transparent 0);
  background-size: 36px 36px;
  -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.75), transparent);
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.75), transparent);
}

/* ---- CSS/SVG placeholder crossroads: hidden by default, only shown if the
       real assets/crossroads.jpg fails to load (so it never flashes first) ---- */
.crossroads-placeholder {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(90% 60% at 50% 8%, #26314f 0%, #141a2c 45%, #090d17 100%);
  overflow: hidden;
  display: none;
}
.stage.crossroads-failed .crossroads-placeholder { display: block; }
.crossroads-placeholder::after { /* horizon glow */
  content: "";
  position: absolute;
  left: 50%; top: 44%;
  width: 120vmax; height: 120vmax;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgba(181, 6, 245, 0.16), transparent 70%);
}
.crossroads-placeholder .path {
  position: absolute;
  left: 50%; top: 58%;
  width: 3px; height: 55vh;
  transform-origin: top center;
  background: linear-gradient(to bottom, rgba(181, 6, 245, 0.3), transparent);
}
.path--n { transform: translateX(-50%) rotate(180deg); opacity: 0.5; }
.path--e { transform: translateX(-50%) rotate(115deg); }
.path--w { transform: translateX(-50%) rotate(-115deg); }
.path--s { transform: translateX(-50%) rotate(0deg); }

/* Once the real crossroads image loads, hide the CSS placeholder art. */

/* ---- Thornwell: planted on the grass patch at the middle of the crossroads ----
   `background-position: 50% 42%` pins the scene's crossroads point to the same
   spot in the viewport at any size, so anchoring his pot to a fixed viewport
   position keeps his base sitting on that grass patch. The bottom dialogue box
   (z3) overlaps his lower body on the taller screens ("counter" look). */
.thornwell {
  position: fixed;
  z-index: 2;                 /* below the dialogue box (z3): box overlaps his pot */
  left: 50%;
  bottom: 50vh;               /* pot sits on the crossroads grass patch */
  transform: translateX(-50%);
  height: min(52vh, 520px);
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: sway 6s ease-in-out infinite;
  transition: bottom 0.45s ease, height 0.45s ease, opacity 0.5s ease;
}
.thornwell__img {
  height: 100%;
  width: auto;
  filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.5));
}
/* --parx-x set by the pointer-parallax in main.js (0 when unused) */
@keyframes sway {
  0%, 100% { transform: translateX(calc(-50% + var(--parx-x, 0px))) rotate(-1deg); }
  50%      { transform: translateX(calc(-50% + var(--parx-x, 0px))) rotate(1.1deg); }
}
/* On the result he's done pointing; hide him so the pass gets the whole stage. */
.stage[data-screen="result"] .thornwell { opacity: 0; }

/* Short/landscape screens (laptops): shrink Thornwell so the box gets the room. */
@media (max-height: 820px) {
  .thornwell { height: min(40vh, 360px); }
}
@media (max-height: 640px) {
  .thornwell { height: min(32vh, 280px); }
}

/* Fallback CSS cactus — only visible when assets/thornwell.png is missing. */
.thornwell__fallback { display: none; }
.thornwell.is-missing .thornwell__img { display: none; }
.thornwell.is-missing .thornwell__fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  height: 100%;
  justify-content: flex-end;
  filter: drop-shadow(0 12px 30px rgba(0, 0, 0, 0.55));
}
.cactus {
  position: relative;
  width: 64px;
  height: 78%;
  background: linear-gradient(180deg, #6ba043, #3c5c26);
  border-radius: 34px 34px 14px 14px;
}
.cactus__arm {
  position: absolute;
  width: 26px;
  height: 46px;
  background: linear-gradient(180deg, #6ba043, #3c5c26);
  border-radius: 16px;
}
.cactus__arm--l { left: -30px; top: 32%; border-top-left-radius: 20px; box-shadow: 14px 22px 0 -2px #4c7a30; }
.cactus__arm--r { right: -30px; top: 22%; border-top-right-radius: 20px; box-shadow: -14px 26px 0 -2px #4c7a30; }
.cactus__label {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: rgba(13, 18, 32, 0.7);
  padding: 3px 8px;
  border-radius: 6px;
}

/* =============================================================================
 * Dialogue dock (visual-novel layout)
 * ========================================================================== */

/* Dock: pins the dialogue box to the bottom of the screen. */
.dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
  pointer-events: none;
}

/* Each screen IS a dialogue box. Sized to its content, capped so it always
   leaves headroom for Thornwell but rarely needs to scroll on a laptop. */
.screen {
  display: none;
  position: relative;
  pointer-events: auto;
  width: 100%;
  max-width: 700px;
  max-height: calc(100dvh - 96px); /* leave a little room up top for Thornwell */
  overflow-y: auto;
  padding: 1.35rem 1.4rem 1.3rem;
  /* App panel surface: violet gradient glass + soft top-right lavender glow. */
  background:
    radial-gradient(circle at top right, rgba(177, 110, 255, 0.14) 0, transparent 36%),
    linear-gradient(180deg, rgba(55, 15, 100, 0.92), rgba(42, 11, 81, 0.92));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: 0 26px 56px -20px rgba(3, 7, 18, 0.78),
              0 0 84px -30px rgba(177, 110, 255, 0.25),
              inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(26px) saturate(132%);
  -webkit-backdrop-filter: blur(26px) saturate(132%);
  animation: box-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.screen.is-active { display: flex; flex-direction: column; }

/* Speech tail: a small triangle on the box's top edge, pointing up at Thornwell. */
.screen::before {
  content: "";
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 12px solid rgba(255, 255, 255, 0.08);
}
.screen::after {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 11px solid rgb(55, 15, 100);
}

/* Name-plate tab. */
.box__name {
  align-self: flex-start;
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: #fff;
  background: var(--btn-primary);
  padding: 0.3rem 0.95rem;
  border-radius: 999px;
  margin: 0 0 0.8rem;
  box-shadow: 0 8px 20px rgba(118, 17, 140, 0.28);
}

.box__foot {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-top: 1.15rem;
}

@keyframes box-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =============================================================================
 * Intro
 * ========================================================================== */

.title {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: 0.02em;
  font-size: clamp(1.4rem, 4.8vw, 2rem);
  line-height: 1.12;
  margin: 0 0 0.8rem;
}
.speech {
  color: var(--ink);
  font-size: 1.02rem;
  line-height: 1.5;
}
.speech p { margin: 0 0 0.6rem; }
.speech p:last-child { margin-bottom: 0; }
.speech strong {
  color: var(--pink);        /* app pink, for the four path names */
  font-weight: 600;
  white-space: nowrap;
}
.fineprint {
  color: var(--ink-muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

/* =============================================================================
 * Quiz
 * ========================================================================== */

.progress { margin-bottom: 1rem; }
.progress__track {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  border-radius: 99px;
  transition: width 0.4s var(--ease);
}
/* App section-label spec (.nl-section-label). */
.progress__label {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(212, 206, 220, 0.9);
}

.question {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: clamp(1.15rem, 3.4vw, 1.45rem);
  line-height: 1.3;
  margin: 0 0 1rem;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.options { display: flex; flex-direction: column; gap: 0.6rem; }
.option {
  text-align: left;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.98rem;
  line-height: 1.35;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: transform 150ms var(--ease), border-color 150ms var(--ease),
              background 150ms var(--ease), box-shadow 150ms var(--ease);
}
.option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}
.option:active { transform: translateY(0); }
.option.is-picked {
  border-color: var(--gold);
  background: rgba(199, 87, 216, 0.18);
  box-shadow: 0 8px 20px rgba(118, 17, 140, 0.22);
}

.quiz-nav { margin-top: 1.1rem; }

/* =============================================================================
 * Reading transition
 * ========================================================================== */

.reading {
  text-align: center;
  padding: 1.5rem 0 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.3rem;
}
.reading__spinner {
  width: 54px; height: 54px;
  border: 4px solid rgba(199, 87, 216, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.reading__line {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--ink);
  font-style: italic;
  transition: opacity 0.22s ease;
  min-height: 1.6em;
}

/* =============================================================================
 * Result
 * ========================================================================== */

/* Result screen fills the whole stage (Thornwell is hidden here) and fits its
   content with no scrolling: the pass shrinks to take the leftover height. */
.screen[data-screen="result"] {
  max-height: calc(100dvh - 24px);
  overflow: hidden;
}
.screen[data-screen="result"]::before,
.screen[data-screen="result"]::after { display: none; } /* no speech tail here */

.result {
  --accent: var(--gold);
  --accent-deep: var(--gold-deep);
  text-align: center;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.result__sendoff {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.4;
  color: var(--ink);
  margin: 0.55rem 0 1.1rem; /* breathing room below the THORNWELL name-plate */
  flex: none;
}
.result__mixed[hidden] { display: none; }
.result__mixed {
  align-self: center;
  background: rgba(255, 126, 152, 0.14);
  border: 1px solid rgba(255, 126, 152, 0.4);
  color: #ffe0e7;
  border-radius: 99px;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  margin: 0 0 0.9rem;
  flex: none;
}

/* The pass is the hero; it scales to fit the available height (no scroll). */
.result__card {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 auto 1rem;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#share-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  /* drop-shadow follows the transparent ticket's shape (not the canvas box) */
  filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.45));
}

.result__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  flex: none;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}
.result__actions .btn { flex: 1 1 200px; } /* equal halves; stack on narrow screens */
.share-status {
  min-height: 1.2em;
  margin: 0.4rem 0 0;
  color: var(--pink);
  font-size: 0.9rem;
  flex: none;
}
.btn--retake { margin-top: 0.7rem; flex: none; }

a.btn { text-decoration: none; display: inline-block; }
.btn--continue {
  width: 100%;
  max-width: 420px;         /* matches the Download + Share row above */
  margin: 0.7rem auto 0;     /* margin auto centers the flex item */
  flex: none;
}

/* =============================================================================
 * Buttons
 * ========================================================================== */

.btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.45px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.85rem 1.5rem;
  cursor: pointer;
  transition: transform 150ms var(--ease), background 150ms var(--ease),
              border-color 150ms var(--ease), color 150ms var(--ease);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* App primary: orchid-to-magenta pill (.bg-primary-button). */
.btn--primary {
  background: var(--btn-primary);
  color: #fff;
  align-self: flex-start;
  box-shadow: var(--glow);
}
.btn--primary:hover { background: linear-gradient(180deg, #cf6edd, #b500d1); }
.btn--primary:active { background: linear-gradient(180deg, #9125a1, #9a00b2); }
.result .btn--primary { align-self: auto; }
/* App glass icon-button style. */
.btn--secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.btn--secondary:hover { background: rgba(255, 255, 255, 0.12); }
.btn--ghost {
  background: transparent;
  color: rgba(255, 255, 255, 0.9);
  border-color: var(--line);
}
.btn--ghost:hover { background: rgba(255, 255, 255, 0.04); border-color: rgba(255, 255, 255, 0.3); }

/* =============================================================================
 * Responsive
 * ========================================================================== */

@media (max-width: 520px) {
  .screen { max-height: 62vh; padding: 1.3rem 1.15rem 1.2rem; }
  /* Give the box more room on small screens by lifting Thornwell higher. */
  .thornwell { height: min(46vh, 380px); bottom: clamp(34vh, 40vh, 46vh); }
  .stage[data-screen="quiz"] .thornwell,
  .stage[data-screen="reading"] .thornwell,
  .stage[data-screen="result"] .thornwell { height: min(34vh, 320px); bottom: clamp(46vh, 52vh, 58vh); }

  .result__actions .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .thornwell { animation: none; }
  .screen { animation: none; }
  .stage__bg { transition: filter 0.6s ease; }
}
