/* Spawnquest — "Mythic Oracle" presentation layer.
   Self-hosted fonts only; no third-party font CDN, no external requests. */

/* ---------- Self-hosted fonts ---------- */
@font-face {
  font-family: "Cinzel";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/cinzel-700.woff2") format("woff2");
}
@font-face {
  font-family: "Cinzel";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/cinzel-600.woff2") format("woff2");
}
@font-face {
  font-family: "Cormorant Garamond";
  font-style: italic;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/cormorant-garamond-500-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/space-grotesk-400.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/space-grotesk-500.woff2") format("woff2");
}

/* ---------- Palette ---------- */
:root {
  --teal-black: #041C1C;      /* background */
  --teal-deep:  #03100F;      /* derived darker */
  --teal-mid:   #0a2b2a;      /* derived lighter panel */
  --teal-line:  #1b4140;      /* derived hairline */
  --amber:      #FFBD38;      /* accent */
  --amber-soft: #e0a52e;      /* derived */
  --cream:      #ffe6cb;      /* text */
  --pale:       #ffff89;      /* highlight */
  --glow:       rgba(255, 189, 56, 0.25);
}

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

html, body { height: 100%; }

body {
  min-height: 100vh;
  background: var(--teal-black);
  color: var(--cream);
  font-family: "Space Grotesk", system-ui, sans-serif;
  display: flex;
  /* Auto margins on the flex child (.oracle) center it when it fits, but
     collapse to 0 / top-align and stay scrollable when it overflows — avoids
     the classic align/justify-center overflow-clipping bug (unreachable top). */
  padding: clamp(1.25rem, 4vw, 3rem);
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Atmosphere: amber glow + vignette + grain ---------- */
.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
/* radial amber glow behind content */
.atmosphere::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 42%;
  width: min(120vw, 1000px);
  height: min(120vw, 1000px);
  transform: translate(-50%, -50%);
  background: radial-gradient(
    circle at center,
    var(--glow) 0%,
    rgba(255, 189, 56, 0.08) 32%,
    rgba(255, 189, 56, 0) 62%
  );
}
/* gentle vignette toward the edges */
.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(4, 28, 28, 0) 45%,
    rgba(2, 12, 11, 0.55) 88%,
    rgba(2, 12, 11, 0.85) 100%
  );
}
/* very subtle CSS noise/grain */
.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Main composition ---------- */
.oracle {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 540px;
  /* auto margins center vertically/horizontally when there's room, and
     collapse when content is taller than the viewport (keeps top reachable). */
  margin: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(1.4rem, 3.5vw, 2.1rem);
}

/* language toggle pills */
.lang {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0.25rem;
  border: 1px solid var(--teal-line);
  border-radius: 999px;
  background: rgba(3, 16, 15, 0.5);
}
.lang-btn {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cream);
  background: transparent;
  border: 0;
  padding: 0.42rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.lang-btn:hover { opacity: 0.85; }
.lang-btn.is-active {
  opacity: 1;
  color: var(--teal-black);
  background: linear-gradient(180deg, var(--amber) 0%, var(--amber-soft) 100%);
  box-shadow: 0 0 14px rgba(255, 189, 56, 0.35);
}

/* ---------- Sound toggle (fixed, top-right, unobtrusive) ---------- */
.sound-toggle {
  position: fixed;
  top: clamp(0.7rem, 2.5vw, 1.1rem);
  right: clamp(0.7rem, 2.5vw, 1.1rem);
  z-index: 3;
  width: 2.2rem;
  height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--teal-line);
  border-radius: 999px;
  background: rgba(3, 16, 15, 0.5);
  color: var(--amber);
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease,
    box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.sound-toggle:hover {
  opacity: 1;
  border-color: var(--amber);
  box-shadow: 0 0 14px rgba(255, 189, 56, 0.3);
}
.sound-toggle:focus-visible {
  opacity: 1;
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
.sound-icon {
  width: 1.15rem;
  height: 1.15rem;
}
/* ON state: show waves, hide slash. MUTED: hide waves, show slash + dim. */
.sound-toggle .slash { display: none; }
.sound-toggle.is-muted .waves { display: none; }
.sound-toggle.is-muted .slash { display: inline; }
.sound-toggle.is-muted { opacity: 0.4; }
.sound-toggle.is-muted:hover,
.sound-toggle.is-muted:focus-visible { opacity: 1; }

/* ornamental rule with central star */
.flourish {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  width: 100%;
  color: var(--amber);
  opacity: 0.85;
}
.flourish .rule {
  height: 1px;
  flex: 1;
  max-width: 110px;
  background: linear-gradient(
    90deg,
    rgba(255, 189, 56, 0) 0%,
    rgba(255, 189, 56, 0.6) 100%
  );
}
.flourish .rule.right {
  background: linear-gradient(
    270deg,
    rgba(255, 189, 56, 0) 0%,
    rgba(255, 189, 56, 0.6) 100%
  );
}
.flourish .star {
  font-size: 0.9rem;
  text-shadow: 0 0 10px rgba(255, 189, 56, 0.6);
}

/* engraved headline */
.title-wrap { margin-top: 0.2rem; }
.numeral {
  font-family: "Cinzel", serif;
  font-size: 0.7rem;
  letter-spacing: 0.5em;
  color: var(--amber);
  opacity: 0.7;
  margin-bottom: 0.7rem;
  padding-left: 0.5em; /* compensate trailing letter-spacing */
}
h1 {
  font-family: "Cinzel", serif;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: clamp(2.3rem, 9vw, 3.9rem);
  line-height: 1.02;
  padding-left: 0.16em; /* compensate trailing letter-spacing for centering */
  /* engraved / inscribed look: warm gradient + carved shadow */
  color: var(--cream);
  background: linear-gradient(175deg, var(--pale) 0%, var(--amber) 48%, var(--amber-soft) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  filter: drop-shadow(0 2px 12px rgba(255, 189, 56, 0.28));
}
/* rotating oracular epigraph (replaces the old uppercase descriptor) */
.epigraph {
  margin-top: 0.95rem;
  font-family: "Cormorant Garamond", "Cinzel", serif;
  font-style: italic;
  font-size: clamp(1.02rem, 3.6vw, 1.28rem);
  line-height: 1.35;
  letter-spacing: 0.02em;
  color: var(--cream);
  text-wrap: balance;
  /* Stable reserved height (set by JS to the tallest quote at the current
     width/language) so cross-fading between quotes of differing lengths
     never nudges the title above or the tablet below. */
  min-height: var(--epigraph-min-height, 0px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.epigraph-text {
  display: block;
  opacity: 0.78;
  /* Cross-fade between quotes. JS toggles .is-faded to fade out, swaps the
     text while invisible, then fades the new line back in. */
  transition: opacity 0.55s ease;
}
.epigraph-text.is-faded {
  opacity: 0;
}
.epigraph-text::first-letter {
  color: var(--amber);
}

/* the oracle tablet / inscribed decree */
.tablet {
  position: relative;
  width: 100%;
  padding: clamp(1.6rem, 5vw, 2.4rem) clamp(1.5rem, 5vw, 2.6rem);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(10, 43, 42, 0.85) 0%, rgba(3, 16, 15, 0.92) 100%);
  border: 1px solid var(--teal-line);
  box-shadow:
    inset 0 1px 0 rgba(255, 230, 203, 0.06),
    inset 0 0 40px rgba(0, 0, 0, 0.45),
    0 18px 50px rgba(0, 0, 0, 0.5);
}
/* inner engraved frame line */
.tablet::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(255, 189, 56, 0.22);
  border-radius: 3px;
  pointer-events: none;
}
/* corner marks */
.tablet .corner {
  position: absolute;
  width: 7px;
  height: 7px;
  border-color: rgba(255, 189, 56, 0.55);
  border-style: solid;
  border-width: 0;
}
.tablet .corner.tl { top: 14px;    left: 14px;    border-top-width: 1px;    border-left-width: 1px; }
.tablet .corner.tr { top: 14px;    right: 14px;   border-top-width: 1px;    border-right-width: 1px; }
.tablet .corner.bl { bottom: 14px; left: 14px;    border-bottom-width: 1px; border-left-width: 1px; }
.tablet .corner.br { bottom: 14px; right: 14px;   border-bottom-width: 1px; border-right-width: 1px; }

.tablet .label {
  position: relative;
  font-family: "Space Grotesk", monospace, sans-serif;
  font-size: 0.62rem;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--amber);
  opacity: 0.8;
  margin-bottom: 1rem;
  padding-left: 0.4em;
}
.tablet .quest {
  position: relative;
  font-family: "Cormorant Garamond", "Cinzel", serif;
  font-style: italic;
  font-size: clamp(1.35rem, 5.2vw, 1.85rem);
  line-height: 1.42;
  color: var(--cream);
  text-wrap: balance;
  /* Hard-capped slab: --quest-reserved-height is set by JS to
     min(tallest natural quest, 3-line cap) at the current width/language. We
     pin the box to EXACTLY that height (min + max + height) so it never grows
     for a long quest nor shrinks for a short one — the height is constant for
     every quest and every reveal flash. overflow:hidden is a safety net; the
     per-quest font shrink (--quest-fit-size) is what actually makes long
     quests fit, so real text is never clipped. Text is vertically centered. */
  height: var(--quest-reserved-height, auto);
  min-height: var(--quest-reserved-height, 0px);
  max-height: var(--quest-reserved-height, none);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tablet .quest .quest-text {
  display: block;
  /* Almost every quest renders at the inherited base font-size. For the rare
     over-long quest, JS sets --quest-fit-size to a smaller value so it fits
     within the (capped) reserved slab height — the slab never resizes. */
  font-size: var(--quest-fit-size, inherit);
}
.tablet .quest .quest-text::first-letter {
  color: var(--pale);
}

/* ---------- Oracle reveal: inscription / settle ---------- */
/* Smooth the tablet's glow + ornament so the reveal feels divined. */
.tablet,
.tablet .sigil,
.tablet .corner {
  transition: box-shadow 0.3s ease, opacity 0.3s ease,
    border-color 0.3s ease, text-shadow 0.3s ease;
}

/* While inscribing: flare the tablet glow, sigil + corners. The quest text
   itself is NOT blurred/dimmed here — each word kindles individually below. */
.tablet.is-revealing {
  box-shadow:
    inset 0 1px 0 rgba(255, 230, 203, 0.06),
    inset 0 0 60px rgba(255, 189, 56, 0.12),
    0 0 36px rgba(255, 189, 56, 0.3),
    0 18px 50px rgba(0, 0, 0, 0.5);
  animation: oracle-pulse 0.45s ease-in-out infinite alternate;
}
.tablet.is-revealing .sigil {
  opacity: 1;
  color: var(--pale);
  text-shadow: 0 0 12px rgba(255, 189, 56, 0.7);
}
.tablet.is-revealing .corner {
  border-color: rgba(255, 189, 56, 0.95);
}

@keyframes oracle-pulse {
  from { box-shadow:
    inset 0 1px 0 rgba(255, 230, 203, 0.06),
    inset 0 0 50px rgba(255, 189, 56, 0.08),
    0 0 24px rgba(255, 189, 56, 0.22),
    0 18px 50px rgba(0, 0, 0, 0.5); }
  to { box-shadow:
    inset 0 1px 0 rgba(255, 230, 203, 0.06),
    inset 0 0 70px rgba(255, 189, 56, 0.18),
    0 0 44px rgba(255, 189, 56, 0.4),
    0 18px 50px rgba(0, 0, 0, 0.5); }
}

/* Brief clean-start fade: the previous text dims out before the new quest is
   inscribed (~CLEAR_MS in app.js). */
.tablet .quest-text.is-clearing {
  opacity: 0;
  transition: opacity 0.12s ease;
}

/* Per-word inscription. Each word span begins hidden, kindles bright pale-gold
   as it appears, then settles to cream. JS toggles the classes in sequence. */
.tablet .quest-text .ink {
  opacity: 0;
  color: var(--cream);
  transition: opacity 0.22s ease, color 0.45s ease, text-shadow 0.45s ease;
}
.tablet .quest-text .ink.is-kindled {
  opacity: 1;
  color: var(--pale);
  text-shadow: 0 0 12px rgba(255, 189, 56, 0.7);
}
.tablet .quest-text .ink.is-settled {
  color: var(--cream);
  text-shadow: none;
}
/* Keep the decorative drop-cap on the first inscribed word too. */
.tablet .quest .quest-text .ink:first-child::first-letter {
  color: var(--pale);
}

/* The settle: a short amber glow-pulse on the tablet once the last word lands.
   Operates on box-shadow only so it never resets the just-inscribed words. */
.tablet.is-settled {
  animation: oracle-settle 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes oracle-settle {
  0% { box-shadow:
    inset 0 1px 0 rgba(255, 230, 203, 0.06),
    inset 0 0 40px rgba(0, 0, 0, 0.45),
    0 0 0 rgba(255, 189, 56, 0),
    0 18px 50px rgba(0, 0, 0, 0.5); }
  55% { box-shadow:
    inset 0 1px 0 rgba(255, 230, 203, 0.08),
    inset 0 0 70px rgba(255, 189, 56, 0.18),
    0 0 44px rgba(255, 189, 56, 0.45),
    0 18px 50px rgba(0, 0, 0, 0.5); }
  100% { box-shadow:
    inset 0 1px 0 rgba(255, 230, 203, 0.06),
    inset 0 0 40px rgba(0, 0, 0, 0.45),
    0 0 0 rgba(255, 189, 56, 0),
    0 18px 50px rgba(0, 0, 0, 0.5); }
}

/* CTA press treatment while inscribing. */
.cta.is-revealing {
  transform: translateY(1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 137, 0.5),
    inset 0 -1px 4px rgba(120, 70, 0, 0.5),
    inset 0 2px 8px rgba(120, 70, 0, 0.35),
    0 0 0 1px rgba(255, 189, 56, 0.55),
    0 0 22px rgba(255, 189, 56, 0.5);
  cursor: default;
}
.tablet .sigil {
  position: relative;
  margin-top: 1.1rem;
  color: var(--amber);
  font-size: 0.8rem;
  letter-spacing: 0.6em;
  opacity: 0.7;
  padding-left: 0.6em;
}

/* primary button */
.cta {
  position: relative;
  font-family: "Cinzel", serif;
  font-weight: 600;
  font-size: clamp(0.95rem, 3.2vw, 1.05rem);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #2a1a02;
  padding: 1rem 2.3rem;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  background: linear-gradient(180deg, #ffd062 0%, var(--amber) 45%, var(--amber-soft) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 137, 0.7),
    inset 0 -2px 6px rgba(120, 70, 0, 0.4),
    0 0 0 1px rgba(255, 189, 56, 0.4),
    0 8px 26px rgba(255, 189, 56, 0.28);
  transition: transform 0.15s ease, box-shadow 0.25s ease;
  padding-left: 2.43em;
}
.cta:hover {
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 137, 0.85),
    inset 0 -2px 6px rgba(120, 70, 0, 0.4),
    0 0 0 1px rgba(255, 189, 56, 0.55),
    0 10px 36px rgba(255, 189, 56, 0.45);
}
.cta:active { transform: translateY(0); }

.footnote {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.62rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--cream);
  opacity: 0.34;
  padding-left: 0.28em;
}

@media (max-width: 380px) {
  .flourish .rule { max-width: 60px; }
  h1 { letter-spacing: 0.1em; }
}

/* ---------- Reduced motion: skip the inscription, keep a simple fade -------- */
/* JS also skips the per-word build via matchMedia; this is the CSS safety net:
   no glow-pulse, no kindle, just a soft fade as the final quest text swaps. */
@media (prefers-reduced-motion: reduce) {
  .tablet.is-revealing,
  .tablet.is-settled,
  .cta.is-revealing {
    animation: none;
  }
  .tablet .quest-text {
    transition: opacity 0.2s ease;
  }
  .tablet .quest-text .ink {
    opacity: 1;
    color: var(--cream);
    text-shadow: none;
    transition: none;
  }
  /* Epigraph shows a single static quote; no cross-fade. */
  .epigraph-text {
    transition: none;
  }
}
