/* ============================================================================
   VIGILIA — design system
   "An illuminated manuscript for the end of the cosmos, rendered as living light."
   Fraunces (display) · Spectral (body) · IBM Plex Mono (the instrument voice)
   ========================================================================== */

@import url('../fonts/vigilia-fonts.css');

:root {
  /* palette — deep ink void, warm ember, cold spectral. --accent re-tints per world. */
  --void: #06060b;
  --void-2: #0b0b13;
  --panel: rgba(12, 12, 20, 0.46);
  --panel-edge: rgba(220, 205, 170, 0.14);
  --ink: #ece5d6;          /* warm off-white body text */
  --ink-dim: #b3ac9d;      /* secondary text — AA on the panel */
  --ink-faint: #8a857a;    /* labels/attribution — kept at ~AA, not decorative-only */
  --ember: #e8b06a;        /* the light: warm gold */
  --ember-deep: #c98a3e;
  --accent: #c9b596;       /* set by JS from the current world palette */
  --accent-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Code', monospace;
  --serif: 'Spectral', Georgia, 'Times New Roman', serif;
  --display: 'Fraunces', 'Spectral', Georgia, serif;
  --measure: 60ch;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --slow: 1100ms;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--void);
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(17px, 1.05vw + 14px, 21px);
  line-height: 1.72;
  overflow: hidden;                 /* the app owns the viewport; scene scrolls internally */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  cursor: default;
}

/* ---- background layers ---------------------------------------------------- */
#stage {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
  touch-action: none;
}
.scrim {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 30%, rgba(0,0,0,0.42) 100%),
    linear-gradient(180deg, rgba(0,0,0,0.28), rgba(0,0,0,0.10) 40%, rgba(0,0,0,0.42));
}
.grain {
  position: fixed; inset: -50%; z-index: 2; 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='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 7s steps(6) infinite;
}
@keyframes grain {
  0%,100% { transform: translate(0,0); } 20% { transform: translate(-4%,3%); }
  40% { transform: translate(3%,-4%); } 60% { transform: translate(-3%,2%); }
  80% { transform: translate(4%,3%); }
}
.cursor-glow {
  position: fixed; top: 0; left: 0; z-index: 3; pointer-events: none;
  width: 340px; height: 340px; margin: -170px 0 0 -170px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 40%, transparent) 0%, transparent 62%);
  mix-blend-mode: screen; opacity: 0; transition: opacity 600ms var(--ease);
  will-change: transform;
}

/* ---- app frame ------------------------------------------------------------ */
.app { position: relative; z-index: 5; height: 100%; display: flex; flex-direction: column; }

/* ============================= HUD / instrument ============================ */
.hud {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: clamp(0.7rem, 2vw, 1.2rem) clamp(1rem, 3.5vw, 2.4rem);
  padding-top: calc(clamp(0.7rem, 2vw, 1.2rem) + env(safe-area-inset-top));
  padding-left: calc(clamp(1rem, 3.5vw, 2.4rem) + env(safe-area-inset-left));
  padding-right: calc(clamp(1rem, 3.5vw, 2.4rem) + env(safe-area-inset-right));
  font-family: var(--mono);
  opacity: 0; transition: opacity var(--slow) var(--ease);
}
.hud.show { opacity: 1; }
.hud__brand {
  font-family: var(--mono); font-weight: 500; font-size: 0.72rem; letter-spacing: 0.42em;
  text-transform: uppercase; color: var(--ink-dim); white-space: nowrap;
  background: none; border: 0; cursor: pointer; padding: 0.2rem 0.1rem;
}
.hud__brand b { color: var(--accent); font-weight: 500; }
.hud__brand:hover { color: var(--ink); }

.hud__lumen { display: flex; align-items: center; gap: 0.55rem; }
.flame {
  --l: 0.6;
  position: relative; width: 13px; height: 13px; border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, #fff7e0, var(--ember) 55%, transparent 72%);
  box-shadow: 0 0 calc(6px + 22px * var(--l)) calc(1px + 4px * var(--l)) color-mix(in srgb, var(--ember) 70%, transparent);
  transform: scale(calc(0.55 + 0.75 * var(--l)));
  transition: transform 900ms var(--ease), box-shadow 900ms var(--ease), opacity 900ms;
  animation: flicker 3.6s ease-in-out infinite;
}
@keyframes flicker { 0%,100% { opacity: 0.92; } 45% { opacity: 1; } 70% { opacity: 0.82; } }
.hud__lumen-val { font-size: 0.7rem; letter-spacing: 0.12em; color: var(--ink-dim); min-width: 2.4ch; }

.reliquary { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; flex-wrap: wrap; }
.relic {
  position: relative; font-family: var(--serif); font-size: 1.05rem; line-height: 1;
  color: var(--accent); opacity: 0.85; cursor: pointer;
  text-shadow: 0 0 10px color-mix(in srgb, var(--accent) 45%, transparent);
}
.relic:hover { opacity: 1; }
.relic__tip {
  position: absolute; top: 150%; left: 50%; transform: translateX(-50%) translateY(4px);
  width: max-content; max-width: 240px; padding: 0.5rem 0.7rem;
  background: rgba(8,8,14,0.94); border: 1px solid var(--panel-edge); border-radius: 4px;
  font-family: var(--serif); font-size: 0.8rem; line-height: 1.4; color: var(--ink);
  opacity: 0; visibility: hidden; transition: opacity 200ms, transform 200ms; z-index: 40;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6); pointer-events: none;
}
.relic__tip b { display: block; font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 0.25rem; font-weight: 500; }
.relic { background: none; border: 0; padding: 0.1rem 0.15rem; }
.relic:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.relic:hover .relic__tip, .relic:focus-visible .relic__tip { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

.hud__tools { display: flex; align-items: center; gap: 0.3rem; margin-left: auto; }
.tool {
  background: none; border: 1px solid transparent; border-radius: 4px; cursor: pointer;
  color: var(--ink-dim); font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.14em;
  text-transform: uppercase; padding: 0.4rem 0.6rem; transition: all 220ms var(--ease);
}
.tool:hover, .tool:focus-visible { color: var(--ink); border-color: var(--panel-edge); background: rgba(255,255,255,0.03); }
.tool[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-soft); }

/* ================================ main stage =============================== */
.stage-wrap {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto; overflow-x: hidden;
  padding: clamp(1rem, 3vw, 3rem);
  padding-bottom: calc(clamp(1rem, 3vw, 3rem) + env(safe-area-inset-bottom));
  padding-left: calc(clamp(1rem, 3vw, 3rem) + env(safe-area-inset-left));
  padding-right: calc(clamp(1rem, 3vw, 3rem) + env(safe-area-inset-right));
  scrollbar-width: thin; scrollbar-color: var(--ink-faint) transparent;
}
.stage-wrap::-webkit-scrollbar { width: 8px; }
.stage-wrap::-webkit-scrollbar-thumb { background: var(--ink-faint); border-radius: 4px; }

/* ------------------------------- title screen ----------------------------- */
.title {
  text-align: center; max-width: min(92vw, 62rem); margin: auto;
  animation: rise 1400ms var(--ease) both;
}
.title__mark {
  font-family: var(--display); font-weight: 300; font-optical-sizing: auto;
  font-size: clamp(3.2rem, 13vw, 8.6rem); line-height: 0.92; letter-spacing: 0.05em;
  margin: 0; color: var(--ink); white-space: nowrap;
  text-shadow: 0 0 60px color-mix(in srgb, var(--ember) 30%, transparent);
}
.title__mark span { display: inline-block; animation: ignite 1200ms var(--ease) both; }
.title__rule { width: 0; height: 1px; margin: 1.6rem auto 1.4rem;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: rule 1400ms 500ms var(--ease) forwards; }
@keyframes rule { to { width: 62%; } }
.title__tagline {
  font-family: var(--mono); font-weight: 300; font-size: clamp(0.72rem, 2.4vw, 0.86rem);
  letter-spacing: 0.34em; text-transform: uppercase; color: var(--ink-dim);
  margin: 0 0 2.6rem; animation: fade 1400ms 800ms var(--ease) both;
}
.title__lede {
  font-family: var(--serif); font-style: italic; font-weight: 300;
  font-size: 1.06rem; color: var(--ink-dim); margin: 0 auto 2.8rem; max-width: 40ch;
  animation: fade 1400ms 1000ms var(--ease) both;
}
.title__actions { display: flex; flex-direction: column; align-items: center; gap: 0.9rem;
  animation: fade 1400ms 1200ms var(--ease) both; }
.btn {
  font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.24em; text-transform: uppercase;
  color: var(--ink); background: none; border: 1px solid var(--panel-edge); border-radius: 3px;
  padding: 0.9rem 2.2rem; cursor: pointer; transition: all 300ms var(--ease); position: relative;
}
.btn:hover, .btn:focus-visible {
  color: var(--void); background: var(--accent); border-color: var(--accent);
  box-shadow: 0 0 40px color-mix(in srgb, var(--accent) 40%, transparent); letter-spacing: 0.28em;
}
.btn--ghost { border-color: transparent; color: var(--ink-dim); padding: 0.6rem 1rem; }
.btn--ghost:hover { color: var(--ink); background: none; box-shadow: none; }
.title__meta { margin-top: 1.6rem; font-family: var(--mono); font-size: 0.66rem;
  letter-spacing: 0.16em; color: var(--ink-faint); }
.title__meta b { color: var(--accent); font-weight: 500; }

/* --------------------------------- scene ---------------------------------- */
.scene {
  position: relative; width: 100%; max-width: 720px; margin: auto;
  padding: clamp(1.4rem, 4vw, 3rem) clamp(1.4rem, 4vw, 3.2rem);
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 6px;
  backdrop-filter: blur(14px) saturate(1.1); -webkit-backdrop-filter: blur(14px) saturate(1.1);
  box-shadow: 0 30px 90px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.04);
}
.scene.enter { animation: sceneIn 900ms var(--ease) both; }
@keyframes sceneIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.scene.leave { animation: sceneOut 420ms var(--ease) both; }
@keyframes sceneOut { to { opacity: 0; transform: translateY(-10px); } }

.scene__numeral {
  position: absolute; top: -0.35em; right: 0.3em; z-index: -1;
  font-family: var(--display); font-weight: 300; font-size: clamp(7rem, 22vw, 15rem);
  line-height: 1; color: var(--accent); opacity: 0.07; pointer-events: none; user-select: none;
}
.scene__kicker {
  font-family: var(--mono); font-weight: 500; font-size: 0.66rem; letter-spacing: 0.34em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 0.9rem;
}
.scene__title {
  font-family: var(--display); font-weight: 400; font-optical-sizing: auto;
  font-size: clamp(1.9rem, 5vw, 3rem); line-height: 1.06; letter-spacing: 0.005em;
  margin: 0 0 1.8rem; color: var(--ink);
  text-shadow: 0 0 44px color-mix(in srgb, var(--accent) 22%, transparent);
}
.scene__title + .prose { margin-top: 0; }

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1.15rem; }
.prose p:last-child { margin-bottom: 0; }
.prose em { font-style: italic; color: #f4eeDf; }
.prose strong { font-weight: 500; font-style: normal; color: var(--ink);
  text-shadow: 0 0 20px color-mix(in srgb, var(--accent) 34%, transparent); }
/* the instrument voice */
.prose .mono {
  display: block; font-family: var(--mono); font-weight: 300; font-size: 0.86em;
  letter-spacing: 0.01em; line-height: 1.6; color: var(--ink-dim);
  border-left: 1px solid var(--accent-soft); padding-left: 1rem; margin: 1.4rem 0;
}
.prose .mono-inline { font-family: var(--mono); font-weight: 300; font-size: 0.9em; color: var(--ink-dim); }
.prose[data-dropcap] > p:first-of-type::first-letter {
  font-family: var(--display); font-weight: 400; font-size: 3.5em; line-height: 0.72;
  float: left; padding: 0.05em 0.12em 0 0; color: var(--accent);
  text-shadow: 0 0 30px color-mix(in srgb, var(--accent) 40%, transparent);
}
/* typewriter reveal */
.prose p, .prose .mono { transition: opacity 700ms var(--ease), filter 700ms var(--ease); }
.prose .reveal-pending { opacity: 0; filter: blur(3px); }

.scene__speaker {
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink-faint); margin: 1.8rem 0 0.4rem;
}

/* -------------------------------- choices --------------------------------- */
.choices { list-style: none; margin: 2rem 0 0; padding: 0;
  border-top: 1px solid var(--panel-edge); }
.choice {
  display: flex; align-items: baseline; gap: 0.9rem; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--panel-edge);
  padding: 1.05rem 0.4rem 1.05rem 0.2rem; cursor: pointer; color: var(--ink);
  font-family: var(--serif); font-size: 1.02rem; line-height: 1.45;
  transition: all 260ms var(--ease); position: relative;
  animation: choiceIn 600ms var(--ease) both;
}
@keyframes choiceIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.choice__sigil { font-family: var(--serif); color: var(--ink-faint); font-size: 0.95rem;
  transition: all 260ms var(--ease); flex-shrink: 0; width: 1.1em; }
.choice__label { flex: 1; }
.choice__note {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-faint); opacity: 0; transition: opacity 260ms var(--ease); white-space: nowrap;
  align-self: center;
}
.choice__key { font-family: var(--mono); font-size: 0.6rem; color: var(--ink-faint);
  opacity: 0.5; align-self: center; }
.choice:hover, .choice:focus-visible {
  color: #fff; padding-left: 1rem; outline: none;
  background: linear-gradient(90deg, var(--accent-soft), transparent 70%);
}
.choice:hover .choice__sigil, .choice:focus-visible .choice__sigil {
  color: var(--accent); transform: scale(1.25);
  text-shadow: 0 0 16px color-mix(in srgb, var(--accent) 60%, transparent);
}
.choice:hover .choice__note, .choice:focus-visible .choice__note { opacity: 1; color: var(--accent); }
.choice.chosen { animation: chosen 500ms var(--ease) forwards; }
@keyframes chosen { 0% { background: var(--accent-soft); } 100% { opacity: 0.35; transform: translateX(6px); } }

/* ------------------------------- end card --------------------------------- */
.endcard { text-align: center; max-width: 44ch; }
.endcard .scene__kicker { text-align: center; }
.endcard__reliquary { margin: 2rem 0; padding: 1.4rem 0; border-top: 1px solid var(--panel-edge);
  border-bottom: 1px solid var(--panel-edge); }
.endcard__reliquary h4 { font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.24em;
  text-transform: uppercase; color: var(--ink-dim); margin: 0 0 1rem; font-weight: 500; }
.endcard__relics { display: flex; flex-wrap: wrap; gap: 0.9rem; justify-content: center; }
.endcard__relic { font-family: var(--mono); font-size: 0.8rem; color: var(--ink-dim); }
.endcard__relic span { color: var(--accent); font-family: var(--serif); font-size: 1.1rem;
  margin-right: 0.35rem; }
.endcard__none { font-style: italic; color: var(--ink-faint); }
.endcard__found { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.16em;
  color: var(--ink-faint); margin-top: 1.2rem; }

/* ------------------------------- overlays --------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: clamp(1rem, 4vw, 3rem); background: rgba(4,4,8,0.72);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade 400ms var(--ease) both;
}
.overlay[hidden] { display: none; }
.overlay__panel {
  position: relative; width: 100%; max-width: 640px; max-height: 84vh; overflow-y: auto;
  background: rgba(10,10,16,0.96); border: 1px solid var(--panel-edge); border-radius: 8px;
  padding: clamp(1.6rem, 4vw, 2.8rem); box-shadow: 0 40px 120px rgba(0,0,0,0.7);
  scrollbar-width: thin; scrollbar-color: var(--ink-faint) transparent;
}
.overlay__title { font-family: var(--display); font-weight: 400; font-size: 2rem; margin: 0 0 0.3rem; color: var(--ink); }
.overlay__sub { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.24em;
  text-transform: uppercase; color: var(--accent); margin: 0 0 1.8rem; }
.overlay__close {
  position: absolute; top: 1rem; right: 1rem; width: 34px; height: 34px; border-radius: 50%;
  background: none; border: 1px solid var(--panel-edge); color: var(--ink-dim); cursor: pointer;
  font-size: 1rem; line-height: 1; transition: all 220ms var(--ease);
}
.overlay__close:hover { color: var(--ink); border-color: var(--accent); transform: rotate(90deg); }

.codex-entry { padding: 1.3rem 0; border-top: 1px solid var(--panel-edge); }
.codex-entry:first-of-type { border-top: 0; }
.codex-entry h3 { font-family: var(--display); font-weight: 400; font-size: 1.3rem; margin: 0 0 0.2rem; color: var(--ink); }
.codex-entry .from { font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 0.7rem; }
.codex-entry p { margin: 0; font-size: 0.96rem; color: var(--ink-dim); }
.codex-entry.sealed h3 { color: var(--ink-faint); font-style: italic; }
.codex-entry.sealed p { color: var(--ink-faint); font-style: italic; opacity: 0.6; }

.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 1rem 0; border-top: 1px solid var(--panel-edge); }
.settings-row:first-of-type { border-top: 0; }
.settings-row label { font-family: var(--serif); font-size: 1rem; color: var(--ink); }
.settings-row .desc { font-family: var(--mono); font-size: 0.64rem; color: var(--ink-faint);
  letter-spacing: 0.08em; margin-top: 0.2rem; }
.switch { flex-shrink: 0; }

.danger { color: #d98a6a; }

/* ---------------------------- the constellation --------------------------- */
.overlay__panel--wide { max-width: 820px; }
.constellation {
  position: relative; width: 100%; aspect-ratio: 16 / 10; margin: 1.4rem 0 1rem;
  border: 1px solid var(--panel-edge); border-radius: 8px; overflow: hidden;
  background:
    radial-gradient(60% 60% at 50% 40%, rgba(30,26,44,0.5), transparent 70%),
    radial-gradient(100% 100% at 50% 50%, #0a0912, #05050a 90%);
}
.star {
  position: absolute; transform: translate(-50%, -50%); width: 34px; height: 34px;
  display: grid; place-items: center; background: none; border: 0; cursor: pointer; padding: 0;
  border-radius: 50%;
}
.star .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); opacity: 0.45;
  transition: transform 300ms var(--ease), opacity 300ms var(--ease), box-shadow 300ms var(--ease);
}
.star--found .dot {
  width: 11px; height: 11px; background: var(--ember); opacity: 1;
  box-shadow: 0 0 18px 4px color-mix(in srgb, var(--ember) 55%, transparent);
  animation: starpulse 4s ease-in-out infinite;
}
.star--secret .dot { opacity: 0.10; }
.star--secret.star--found .dot { background: #c9b7ff; box-shadow: 0 0 20px 5px rgba(201,183,255,0.55); }
.star:hover .dot, .star:focus-visible .dot { transform: scale(1.5); opacity: 1; }
.star:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
.star.is-active .dot { transform: scale(1.6); }
@keyframes starpulse { 0%,100% { box-shadow: 0 0 14px 3px color-mix(in srgb, var(--ember) 45%, transparent); } 50% { box-shadow: 0 0 22px 6px color-mix(in srgb, var(--ember) 65%, transparent); } }

.constellation__detail { min-height: 6.5rem; text-align: center; padding: 0.4rem 1rem 0.2rem; }
.constellation__detail .cname { font-family: var(--display); font-size: 1.5rem; color: var(--ink); margin: 0 0 0.4rem; }
.constellation__detail .cepigraph { font-family: var(--serif); font-style: italic; color: var(--ink-dim); margin: 0 auto; max-width: 46ch; }
.constellation__detail .chint { font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.04em; color: var(--ink-faint); max-width: 46ch; margin: 0 auto; }
.constellation__detail .cdim { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-faint); }
.constellation__count { font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.16em; color: var(--accent); text-align: center; }

/* -------------------------------- toast ----------------------------------- */
/* kept permanently in the DOM (never display:none) so the aria-live status is
   reliably announced; visibility is driven by the .show class, not `hidden`. */
.toast {
  position: fixed; left: 50%; bottom: calc(2rem + env(safe-area-inset-bottom));
  z-index: 80; pointer-events: none;
  background: rgba(9, 9, 15, 0.95); border: 1px solid var(--accent-soft); border-radius: 5px;
  padding: 0.7rem 1.15rem; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em;
  color: var(--accent); box-shadow: 0 12px 44px rgba(0,0,0,0.6);
  opacity: 0; transform: translate(-50%, 12px);
  transition: opacity 380ms var(--ease), transform 380ms var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------ easter egg -------------------------------- */
.egg-bloom {
  position: fixed; inset: 0; z-index: 90; pointer-events: none;
  background: radial-gradient(circle at 50% 48%, color-mix(in srgb, var(--ember) 42%, transparent), transparent 62%);
  mix-blend-mode: screen; animation: eggBloom 2400ms var(--ease) forwards;
}
@keyframes eggBloom { 0% { opacity: 0; transform: scale(0.6); } 22% { opacity: 1; } 100% { opacity: 0; transform: scale(1.15); } }
.codex-entry--secret { border-top: 1px solid var(--accent); }
.codex-entry--secret h3 { color: var(--accent); text-shadow: 0 0 20px color-mix(in srgb, var(--accent) 40%, transparent); }
.codex-entry--secret a { color: var(--accent); text-underline-offset: 3px; }

/* --------------------- micro-interactions (flame / relic / world) --------- */
.flame.flare-up { animation: flareUp 1000ms var(--ease); }
.flame.flare-down { animation: flareDown 1000ms var(--ease); }
@keyframes flareUp {
  0% { transform: scale(calc(0.55 + 0.75 * var(--l))); }
  35% { transform: scale(calc(1.1 + 0.75 * var(--l))); box-shadow: 0 0 40px 10px color-mix(in srgb, var(--ember) 85%, transparent); }
  100% { transform: scale(calc(0.55 + 0.75 * var(--l))); }
}
@keyframes flareDown {
  0% { transform: scale(calc(0.55 + 0.75 * var(--l))); }
  30% { transform: scale(calc(0.3 + 0.75 * var(--l))); opacity: 0.4; }
  100% { transform: scale(calc(0.55 + 0.75 * var(--l))); opacity: 0.92; }
}
.relic.relic--new { animation: relicPulse 1200ms var(--ease); }
@keyframes relicPulse {
  0% { transform: scale(0.4); opacity: 0; text-shadow: 0 0 0 transparent; }
  40% { transform: scale(1.5); opacity: 1; text-shadow: 0 0 26px var(--accent); }
  100% { transform: scale(1); opacity: 0.85; }
}
#stage { transition: opacity 520ms var(--ease); }
#stage.dissolve { opacity: 0.12; }

/* ---- shared keyframes ----------------------------------------------------- */
@keyframes rise { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ignite { from { opacity: 0; filter: blur(10px); transform: translateY(8px); } to { opacity: 1; filter: none; transform: none; } }
[hidden] { display: none !important; }

/* ------------------------------ responsive -------------------------------- */
@media (max-width: 620px) {
  body { font-size: 17px; line-height: 1.68; }
  .hud { gap: 0.7rem; padding: 0.7rem 0.9rem; }
  .hud__brand { font-size: 0.6rem; letter-spacing: 0.28em; }
  .reliquary { order: 3; flex-basis: 100%; }
  .tool { padding: 0.4rem 0.5rem; letter-spacing: 0.08em; }
  .scene { padding: 1.5rem 1.2rem; }
  .choice { font-size: 1rem; }
  .choice__note { display: none; }
  .choice__key { display: none; }
  .cursor-glow { display: none; }
}
@media (pointer: coarse) {
  .cursor-glow { display: none; }
  .choice__key { display: none; }
  /* guarantee comfortable touch targets */
  .tool, .btn--ghost, .hud__brand { min-height: 44px; }
  .tool { display: inline-flex; align-items: center; }
  .overlay__close { width: 44px; height: 44px; }
  .relic { min-width: 30px; min-height: 30px; display: inline-flex; align-items: center; justify-content: center; }
  .star { width: 44px; height: 44px; } /* larger hit area on touch; the visible dot stays small */
}

/* legibility fallback where backdrop-filter is unsupported (older WebViews, data-saver) */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .scene { background: rgba(9, 9, 15, 0.93); }
}

/* --------------------------- reduced motion ------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important; scroll-behavior: auto !important;
  }
  .grain { animation: none; }
  .flame { animation: none; }
  .prose .reveal-pending { opacity: 1; filter: none; }
  .title__rule { width: 62%; }
}
