/* Quest Academy — Distinctive identity layer
 *
 * Theme-specific personality, signature motion, illustrated decoration.
 * Designed to feel like a hand-crafted children's book that gradually
 * comes alive — never generic web component soup.
 */

:root {
  /* Refined multi-layer shadows */
  --shadow-soft:
    0 1px 0 rgba(43,38,32,.04),
    0 2px 4px -2px rgba(43,38,32,.08),
    0 12px 28px -16px rgba(43,38,32,.18);
  --shadow-lift:
    0 1px 0 rgba(43,38,32,.05),
    0 4px 8px -4px rgba(43,38,32,.10),
    0 20px 48px -20px rgba(43,38,32,.28);
  --shadow-pop:
    0 2px 0 rgba(43,38,32,.06),
    0 8px 16px -8px rgba(43,38,32,.18),
    0 28px 64px -24px rgba(43,38,32,.32);
  --shadow-gold-glow: 0 0 0 4px rgba(217,164,65,.18), 0 12px 32px -8px rgba(217,164,65,.42);

  --hero-warm: linear-gradient(135deg, #F8E9C8 0%, #EBC9B2 60%, #F8E9C8 100%);
  --hero-cool: linear-gradient(135deg, #DCEAD4 0%, #C6D6E0 60%, #DCEAD4 100%);
  --hero-gold: linear-gradient(135deg, #F2DFA8 0%, #E5C779 50%, #F2DFA8 100%);

  --ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
  --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-in-out-quart: cubic-bezier(0.76, 0, 0.24, 1);

  /* Theme-personality knob — overridden per theme below */
  --theme-mood: "cozy";
}

/* ============================================================
 * GLOBAL — paper grain + subtle vignette + branded selection
 * ============================================================ */
html, body {
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(154,90,55,.038) 0 1.5px, transparent 2px),
    radial-gradient(circle at 76% 64%, rgba(133,166,113,.030) 0 1px, transparent 1.5px),
    radial-gradient(circle at 38% 88%, rgba(120,90,50,.026) 0 1px, transparent 1.5px),
    radial-gradient(circle at 88% 22%, rgba(43,38,32,.020) 0 1px, transparent 1.5px);
  background-size: 220px 220px, 160px 160px, 280px 280px, 320px 320px;
  background-attachment: fixed;
}
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none; z-index: -2;
  background:
    radial-gradient(ellipse 100% 60% at 50% 0%, rgba(255,245,220,.5) 0%, transparent 70%),
    radial-gradient(ellipse 80% 50% at 50% 100%, rgba(43,38,32,.06) 0%, transparent 60%);
}
::selection { background: var(--gold); color: var(--ink); }

h1, h2 {
  font-feature-settings: "ss01" 1, "case" 1;
  letter-spacing: -0.018em;
}

/* ============================================================
 * SIGNATURE WORDMARK — gradient ink + drawn-on underline
 * ============================================================ */
.qa-wordmark {
  display: inline-block;
  font-family: var(--font-display);
  font-weight: 600;
  background: linear-gradient(135deg, var(--ink) 0%, var(--terra-deep) 60%, var(--gold) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  position: relative;
}
.qa-wordmark::after {
  content: "";
  position: absolute;
  left: 6%; right: 6%;
  bottom: -2px;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--gold) 30%, var(--terra) 70%, transparent 100%);
  border-radius: 2px;
  transform-origin: left center;
  animation: wordmark-stroke 1.2s var(--ease-out-cubic) 0.3s both;
}
@keyframes wordmark-stroke {
  0% { transform: scaleX(0); }
  100% { transform: scaleX(1); }
}

/* ============================================================
 * BUTTONS — refined; primary CTAs get a press-and-glow
 * ============================================================ */
.qa-btn {
  position: relative;
  transition:
    transform 180ms var(--ease-out-back),
    box-shadow 220ms var(--ease-out-cubic),
    background 200ms ease,
    border-color 200ms ease,
    filter 200ms ease;
  overflow: hidden;
}
.qa-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* Primary-CTA shine: a soft sweep on hover */
.qa-btn--primary::before,
.qa-btn--sage::before,
.qa-btn--terra::before {
  content: "";
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent);
  transition: left 600ms var(--ease-out-cubic);
}
.qa-btn--primary:hover::before,
.qa-btn--sage:hover::before,
.qa-btn--terra:hover::before { left: 100%; }

.qa-btn--primary,
.qa-btn--sage,
.qa-btn--terra {
  box-shadow:
    0 2px 0 currentColor,
    0 8px 16px -8px rgba(43,38,32,.3);
}
.qa-btn--primary:hover,
.qa-btn--sage:hover,
.qa-btn--terra:hover {
  transform: translateY(-1px);
  box-shadow:
    0 3px 0 currentColor,
    0 14px 26px -10px rgba(43,38,32,.36);
}
.qa-btn--primary:active,
.qa-btn--sage:active,
.qa-btn--terra:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 currentColor;
}

.qa-btn--paper {
  background: linear-gradient(180deg, var(--paper) 0%, color-mix(in srgb, var(--paper) 95%, var(--bg-2)) 100%);
}
.qa-btn--paper:hover {
  border-color: var(--rule-strong);
  transform: translateY(-1px);
  box-shadow:
    0 2px 0 rgba(43,38,32,.05),
    0 12px 22px -10px rgba(43,38,32,.22);
}

.qa-btn--lg.qa-btn--sage:hover,
.qa-btn--lg.qa-btn--terra:hover {
  box-shadow:
    0 3px 0 currentColor,
    0 18px 32px -10px rgba(43,38,32,.38),
    0 0 0 4px color-mix(in srgb, currentColor 22%, transparent);
}

/* ============================================================
 * CARDS — multi-layer shadow + parallax-ready transitions
 * ============================================================ */
.qa-card {
  transition:
    transform 280ms var(--ease-out-cubic),
    box-shadow 280ms var(--ease-out-cubic);
}
.qa-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lift);
}

/* Gold-edge treatment for important cards */
.qa-pop {
  animation: pop 380ms cubic-bezier(.2,.8,.2,1.25) both;
}
@keyframes pop {
  0% { transform: scale(.9) translateY(8px); opacity: 0; }
  60% { transform: scale(1.02) translateY(-2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* ============================================================
 * CHIPS — gradient + tabular nums
 * ============================================================ */
.qa-chip {
  background: linear-gradient(180deg, var(--bg-2) 0%, color-mix(in srgb, var(--bg-2) 90%, var(--bg)) 100%);
  letter-spacing: 0.03em;
  font-feature-settings: "tnum" 1;
}
.qa-chip--sage { background: linear-gradient(180deg, var(--sage-soft) 0%, color-mix(in srgb, var(--sage-soft) 88%, white) 100%); }
.qa-chip--terra { background: linear-gradient(180deg, var(--terra-soft) 0%, color-mix(in srgb, var(--terra-soft) 88%, white) 100%); }
.qa-chip--gold {
  background: linear-gradient(180deg, var(--gold-soft) 0%, color-mix(in srgb, var(--gold-soft) 86%, white) 100%);
  box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 2px 6px -2px rgba(217,164,65,.4);
}

/* ============================================================
 * INPUTS — focus glow
 * ============================================================ */
input, textarea {
  transition: border-color 160ms ease, box-shadow 200ms ease;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--sage-deep) !important;
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--sage) 25%, transparent),
    inset 0 1px 0 rgba(43,38,32,.04);
}

/* ============================================================
 * SCROLLBAR — premium thin
 * ============================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--rule-strong) 0%, var(--rule) 100%);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--ink-mute);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* ============================================================
 * COMPANION ART — soft glow halo, tiny breathing motion
 * ============================================================ */
@keyframes companion-breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-2px) scale(1.012); }
}
svg[viewBox="0 0 100 100"] {
  filter: drop-shadow(0 4px 12px rgba(43,38,32,.12));
  transition: filter 320ms var(--ease-out-cubic), transform 420ms var(--ease-out-back);
  animation: companion-breathe 4.5s ease-in-out infinite;
}
[style*="cursor: pointer"]:hover svg[viewBox="0 0 100 100"] {
  filter:
    drop-shadow(0 8px 22px rgba(133,166,113,.32))
    drop-shadow(0 0 12px rgba(217,164,65,.18));
  transform: translateY(-3px) scale(1.05) rotate(-1.5deg);
}

/* ============================================================
 * ADVENTURE-MAP HERO — radial light bloom + pinch corners
 * ============================================================ */
[data-qa-section="hero"] {
  position: relative; isolation: isolate;
}
[data-qa-section="hero"]::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 85% 18%, rgba(217,164,65,0.22) 0%, transparent 45%),
    radial-gradient(circle at 12% 88%, rgba(111,138,95,0.16) 0%, transparent 50%);
  pointer-events: none; z-index: -1; border-radius: inherit;
}

/* Decorative golden corner brackets on hero */
[data-qa-section="hero"]::after {
  content: "";
  position: absolute;
  top: 14px; left: 14px; right: 14px; bottom: 14px;
  border: 1.5px solid transparent;
  border-radius: 24px;
  background:
    linear-gradient(135deg, var(--gold) 0%, transparent 12%, transparent 88%, var(--gold) 100%) border-box,
    linear-gradient(45deg, var(--gold) 0%, transparent 12%, transparent 88%, var(--gold) 100%) border-box;
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none; opacity: 0.4;
}

/* ============================================================
 * AMBIENT ORBS — drift behind first screen (ProfilePick)
 * ============================================================ */
@keyframes orb-drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -20px) scale(1.05); }
  66% { transform: translate(-20px, 25px) scale(0.96); }
}
[data-qa-screen="profile-pick"]::before {
  content: "";
  position: fixed; top: 8%; left: 6%;
  width: 380px; height: 380px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(217,164,65,0.15), transparent 65%);
  filter: blur(50px);
  pointer-events: none; z-index: -1;
  animation: orb-drift 20s ease-in-out infinite;
}
[data-qa-screen="profile-pick"]::after {
  content: "";
  position: fixed; bottom: 6%; right: 8%;
  width: 440px; height: 440px;
  border-radius: 50%;
  background: radial-gradient(circle at 70% 70%, rgba(133,166,113,0.12), transparent 65%);
  filter: blur(60px);
  pointer-events: none; z-index: -1;
  animation: orb-drift 26s ease-in-out -10s infinite;
}

/* ============================================================
 * REWARD SCREEN — dramatic celebration treatment
 * ============================================================ */
@keyframes star-twinkle {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.18); opacity: 1; }
}
@keyframes gentle-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.012); }
}

[data-qa-section="reward-card"] {
  animation:
    pop 380ms cubic-bezier(.2,.8,.2,1.25) both,
    gentle-breathe 4s ease-in-out 1.2s infinite;
  position: relative;
}
[data-qa-section="reward-card"]::before {
  content: "";
  position: absolute;
  top: -6%; left: -6%; right: -6%; bottom: -6%;
  background: radial-gradient(ellipse at 50% 50%, rgba(217,164,65,.25), transparent 60%);
  filter: blur(30px);
  z-index: -1;
  border-radius: inherit;
  animation: gentle-breathe 4s ease-in-out infinite;
}

/* ============================================================
 * BOSS BATTLE — gilded banner treatment
 * ============================================================ */
.qa-fade-in[style*="gold-soft"] {
  position: relative;
}

/* ============================================================
 * THEME PERSONALITIES — each theme gets a distinct mood
 * ============================================================ */

/* COZY (default): warm candlelit, drifting embers */
[data-theme="cozy"], :root {
  --theme-mood: "cozy";
}
@keyframes cozy-ember-drift {
  0% { transform: translateY(0) translateX(0); opacity: 0; }
  10% { opacity: 0.6; }
  100% { transform: translateY(-100vh) translateX(40px); opacity: 0; }
}

/* PLAYFUL: punchier saturation, bouncier interactions */
[data-theme="playful"] {
  --theme-mood: "playful";
}
[data-theme="playful"] .qa-btn--primary,
[data-theme="playful"] .qa-btn--sage,
[data-theme="playful"] .qa-btn--terra {
  box-shadow:
    0 3px 0 currentColor,
    0 0 0 3px color-mix(in srgb, currentColor 18%, transparent),
    0 12px 24px -8px rgba(43,38,32,.3);
}
[data-theme="playful"] .qa-btn:hover {
  transform: translateY(-2px) rotate(-0.5deg);
}
[data-theme="playful"] .qa-pop {
  animation-timing-function: cubic-bezier(0.34, 1.8, 0.64, 1);
}
[data-theme="playful"] svg[viewBox="0 0 100 100"] {
  animation: companion-breathe 2.8s ease-in-out infinite;
}

/* FOCUSED: ink-and-paper minimalism, no animations */
[data-theme="focused"] {
  --theme-mood: "focused";
}
[data-theme="focused"] body::before { display: none; }
[data-theme="focused"] svg[viewBox="0 0 100 100"] { animation: none; }
[data-theme="focused"] .qa-btn::before { display: none; }
[data-theme="focused"] .qa-btn { box-shadow: none !important; border-width: 2px; }
[data-theme="focused"] .qa-btn:hover { transform: none; }

/* ============================================================
 * TEXT SHIMMER — for "thinking..." / loading states
 * ============================================================ */
@keyframes text-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.qa-shimmer {
  background: linear-gradient(90deg, var(--ink-mute) 25%, var(--ink) 50%, var(--ink-mute) 75%);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: text-shimmer 1.6s linear infinite;
}

/* ============================================================
 * REDUCED MOTION
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
 * iOS PWA — safe-area insets when installed
 * ============================================================ */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}
