.mythology-page {
  --pulse-brightness: 1;
  --pulse-saturation: 1;
  --pulse-star-scale: 1;
  --pulse-hue: 0deg;
  --pulse-overlay-strength: 0;
  --pulse-rgb: 134 148 214;
  --pulse-drift-x: 0px;
  --pulse-drift-y: 0px;
  --pulse-activation-duration: 1.2s;
  --pulse-ambient-duration: 0.8s;
  --pulse-activation-ease: cubic-bezier(0.22, 0.68, 0.23, 1);
  --pulse-ambient-ease: ease-in-out;
  --pulse-rotation: 0deg;
}

body.mythology-page .mythology-underlay {
  transform-origin: 50% 26%;
  transform: translate(var(--pulse-drift-x), var(--pulse-drift-y)) scale(var(--pulse-star-scale)) rotate(var(--pulse-rotation));
  filter: brightness(var(--pulse-brightness)) saturate(var(--pulse-saturation)) hue-rotate(var(--pulse-hue));
  transition: transform 1.2s ease, filter 1.2s ease;
}

body.mythology-page::before {
  box-shadow: inset 0 0 220px rgb(var(--pulse-rgb) / calc(var(--pulse-overlay-strength) * 0.22));
  transition: box-shadow 1.2s ease, filter 1.2s ease;
  filter: hue-rotate(var(--pulse-hue));
}

body.mythology-page::after {
  opacity: calc(0.34 + (var(--pulse-overlay-strength) * 0.52));
  background:
    radial-gradient(circle at 50% 18%, transparent 0 23%, rgba(228, 199, 127, 0.13) 24% 24.4%, transparent 24.5% 100%),
    radial-gradient(circle at 50% 18%, transparent 0 33%, rgba(90, 111, 168, 0.08) 34% 34.4%, transparent 34.5% 100%),
    radial-gradient(circle at 50% 18%, transparent 0 44%, rgba(163, 71, 60, 0.08) 45% 45.4%, transparent 45.5% 100%),
    radial-gradient(circle at 50% 44%, rgb(var(--pulse-rgb) / calc(var(--pulse-overlay-strength) * 0.36)), transparent 62%),
    radial-gradient(circle at 50% 74%, rgb(var(--pulse-rgb) / calc(var(--pulse-overlay-strength) * 0.24)), transparent 56%);
  transition: opacity 1.2s ease, filter 1.2s ease;
  filter: hue-rotate(var(--pulse-hue));
}

body.mythology-page.is-activation-pulsing {
  --pulse-brightness: 1.16;
  --pulse-saturation: 1.14;
  --pulse-star-scale: 1.045;
  --pulse-overlay-strength: 1;
}

body.mythology-page.is-ambient-pulsing {
  --pulse-brightness: 1.05;
  --pulse-saturation: 1.06;
  --pulse-star-scale: 1.02;
  --pulse-overlay-strength: 0.46;
}

body.mythology-page.is-activation-pulsing .seed-glyph,
body.mythology-page.is-activation-pulsing .star {
  filter: drop-shadow(0 0 12px rgb(var(--pulse-rgb) / 0.42));
}

body.mythology-page.pulse-earth {
  --pulse-hue: -14deg;
  --pulse-rgb: 120 158 112;
  --pulse-drift-y: 12px;
  --pulse-drift-x: -1px;
  --pulse-activation-duration: 1.3s;
}

body.mythology-page.pulse-forest {
  --pulse-hue: -20deg;
  --pulse-rgb: 94 140 92;
  --pulse-drift-y: 6px;
  --pulse-drift-x: 5px;
  --pulse-activation-duration: 1.24s;
}

body.mythology-page.pulse-sky,
body.mythology-page.pulse-air {
  --pulse-hue: -7deg;
  --pulse-rgb: 162 193 236;
  --pulse-drift-y: -10px;
  --pulse-drift-x: 2px;
  --pulse-activation-duration: 1.06s;
}

body.mythology-page.pulse-water {
  --pulse-hue: -16deg;
  --pulse-rgb: 90 124 206;
  --pulse-drift-y: 0px;
  --pulse-drift-x: 12px;
  --pulse-activation-duration: 1.16s;
}

body.mythology-page.pulse-fire {
  --pulse-hue: 20deg;
  --pulse-rgb: 207 121 77;
  --pulse-drift-y: -4px;
  --pulse-drift-x: 3px;
  --pulse-activation-duration: 0.98s;
}

body.mythology-page.pulse-light {
  --pulse-hue: 8deg;
  --pulse-rgb: 225 196 112;
  --pulse-drift-y: -2px;
  --pulse-drift-x: 0px;
  --pulse-activation-duration: 1.14s;
}

body.mythology-page.pulse-ethos {
  --pulse-hue: 24deg;
  --pulse-rgb: 156 118 214;
  --pulse-drift-y: -3px;
  --pulse-drift-x: -4px;
  --pulse-rotation: 0.42deg;
  --pulse-activation-duration: 1.2s;
}

body.mythology-page.pulse-earth.is-activation-pulsing .mythology-underlay {
  animation: pulseEarthHeavy var(--pulse-activation-duration) var(--pulse-activation-ease);
}

body.mythology-page.pulse-forest.is-activation-pulsing .mythology-underlay {
  animation: pulseForestBranch var(--pulse-activation-duration) var(--pulse-activation-ease);
}

body.mythology-page.pulse-sky.is-activation-pulsing .mythology-underlay,
body.mythology-page.pulse-air.is-activation-pulsing .mythology-underlay {
  animation: pulseSkyLift var(--pulse-activation-duration) var(--pulse-activation-ease);
}

body.mythology-page.pulse-water.is-activation-pulsing .mythology-underlay {
  animation: pulseWaterTide var(--pulse-activation-duration) var(--pulse-activation-ease);
}

body.mythology-page.pulse-fire.is-activation-pulsing .mythology-underlay {
  animation: pulseFireFlare var(--pulse-activation-duration) var(--pulse-activation-ease);
}

body.mythology-page.pulse-light.is-activation-pulsing .mythology-underlay {
  animation: pulseLightRadiant var(--pulse-activation-duration) var(--pulse-activation-ease);
}

body.mythology-page.pulse-ethos.is-activation-pulsing .mythology-underlay {
  animation: pulseEthosSpiral var(--pulse-activation-duration) var(--pulse-activation-ease);
}

body.mythology-page.pulse-earth.is-ambient-pulsing .mythology-underlay {
  animation: ambientEarthDrop var(--pulse-ambient-duration) var(--pulse-ambient-ease);
}

body.mythology-page.pulse-forest.is-ambient-pulsing .mythology-underlay {
  animation: ambientForestSway var(--pulse-ambient-duration) var(--pulse-ambient-ease);
}

body.mythology-page.pulse-sky.is-ambient-pulsing .mythology-underlay,
body.mythology-page.pulse-air.is-ambient-pulsing .mythology-underlay {
  animation: ambientSkyLift var(--pulse-ambient-duration) var(--pulse-ambient-ease);
}

body.mythology-page.pulse-water.is-ambient-pulsing .mythology-underlay {
  animation: ambientWaterDrift var(--pulse-ambient-duration) var(--pulse-ambient-ease);
}

body.mythology-page.pulse-fire.is-ambient-pulsing .mythology-underlay {
  animation: ambientFireFlicker var(--pulse-ambient-duration) var(--pulse-ambient-ease);
}

body.mythology-page.pulse-light.is-ambient-pulsing .mythology-underlay {
  animation: ambientLightBloom var(--pulse-ambient-duration) var(--pulse-ambient-ease);
}

body.mythology-page.pulse-ethos.is-ambient-pulsing .mythology-underlay {
  animation: ambientEthosSpiral var(--pulse-ambient-duration) var(--pulse-ambient-ease);
}

.spirit-card {
  cursor: pointer;
}

.entity-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.entity-toolbar h2 {
  margin: 0;
}

.entity-refresh {
  border: 1px solid rgba(228, 199, 127, 0.34);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  background: rgba(228, 199, 127, 0.11);
  color: rgba(248, 236, 214, 0.94);
  font-family: "Source Code Pro", monospace;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.entity-refresh:hover {
  background: rgba(228, 199, 127, 0.2);
}

.entity-grid {
  margin-top: 0.9rem;
}

.entity-card {
  transition: box-shadow 360ms ease, transform 360ms ease;
}

.entity-card[data-archetype="earth"] {
  animation: entityEarthBreath 9.5s ease-in-out infinite;
}

.entity-card[data-archetype="forest"] {
  animation: entityForestBreath 8.8s ease-in-out infinite;
}

.entity-card[data-archetype="sky"],
.entity-card[data-archetype="air"] {
  animation: entitySkyBreath 8s ease-in-out infinite;
}

.entity-card[data-archetype="water"] {
  animation: entityWaterBreath 8.6s ease-in-out infinite;
}

.entity-card[data-archetype="fire"] {
  animation: entityFireBreath 6.7s ease-in-out infinite;
}

.entity-card[data-archetype="light"] {
  animation: entityLightBreath 7.7s ease-in-out infinite;
}

.entity-card[data-archetype="ethos"] {
  animation: entityEthosBreath 8.2s ease-in-out infinite;
}

.spirit-preview {
  margin-top: 0.65rem;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  border: 1px solid rgba(228, 199, 127, 0.18);
  background: linear-gradient(160deg, rgba(17, 17, 24, 0.65), rgba(29, 25, 36, 0.45));
  overflow: hidden;
  display: grid;
  place-items: center;
  color: rgba(232, 215, 189, 0.65);
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.spirit-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.spirit-preview.is-missing {
  border-style: dashed;
  color: rgba(255, 190, 190, 0.74);
}

.myth-viewer {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
}

.myth-viewer.is-hidden {
  display: none;
}

.viewer-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 22% 18%, rgba(142, 157, 255, 0.2), transparent 32%),
    radial-gradient(circle at 80% 16%, rgba(104, 168, 184, 0.14), transparent 28%),
    radial-gradient(circle at 50% 80%, rgba(120, 109, 207, 0.16), transparent 38%),
    linear-gradient(180deg, rgba(8, 12, 30, 0.96), rgba(7, 10, 25, 0.98));
  backdrop-filter: blur(6px);
  animation: chamberFadeIn 480ms ease;
}

.viewer-panel {
  position: relative;
  z-index: 2;
  width: min(1120px, calc(100% - 2rem));
  min-height: min(86vh, 900px);
  border-radius: 16px;
  padding: 1rem 1rem 0.9rem;
  background:
    linear-gradient(160deg, rgba(9, 12, 31, 0.92), rgba(21, 21, 48, 0.82)),
    radial-gradient(circle at 84% 14%, rgba(228, 199, 127, 0.08), transparent 30%);
  overflow: hidden;
}

.viewer-atmosphere {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.45) 0 1px, transparent 1px),
    radial-gradient(circle at 24% 68%, rgba(212, 226, 255, 0.38) 0 1px, transparent 1px),
    radial-gradient(circle at 63% 26%, rgba(212, 226, 255, 0.4) 0 1px, transparent 1px),
    radial-gradient(circle at 88% 36%, rgba(212, 226, 255, 0.34) 0 1px, transparent 1px),
    radial-gradient(circle at 78% 74%, rgba(255, 255, 255, 0.36) 0 1px, transparent 1px);
  opacity: 0.42;
  animation: viewerStarsDrift 36s ease-in-out infinite alternate;
}

.viewer-impact {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  left: var(--pulse-x, 50%);
  top: var(--pulse-y, 50%);
  background: rgba(255, 237, 208, 0.9);
  box-shadow: 0 0 0 rgba(255, 237, 208, 0.7);
  transform: translate(-50%, -50%) scale(0.5);
  opacity: 0;
}

.viewer-impact.is-pulsing {
  animation: viewerImpact 860ms ease-out;
}

.viewer-head {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

.viewer-head-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.viewer-head h3 {
  margin: 0;
  font-size: clamp(1.25rem, 2.5vw, 1.8rem);
  letter-spacing: 0.02em;
}

.viewer-close,
.viewer-btn {
  border: 1px solid rgba(228, 199, 127, 0.35);
  background: rgba(228, 199, 127, 0.09);
  color: #f5e7cf;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}

.viewer-meta {
  position: relative;
  z-index: 3;
  margin: 0.5rem 0 0.75rem;
  color: rgba(244, 238, 230, 0.84);
  font-size: 0.9rem;
}

.viewer-image-wrap {
  position: relative;
  z-index: 2;
  width: 100%;
  min-height: min(68vh, 740px);
  border-radius: 14px;
  border: 1px solid rgba(228, 199, 127, 0.2);
  background:
    radial-gradient(circle at 50% 42%, rgba(130, 146, 232, 0.16), rgba(12, 14, 32, 0.92));
  display: grid;
  place-items: center;
  overflow: hidden;
}

.viewer-halo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-family: "Cormorant Garamond", serif;
  font-size: min(40vw, 380px);
  line-height: 1;
  color: var(--halo-color, rgba(243, 208, 151, 0.18));
  text-shadow: 0 0 44px var(--halo-glow, rgba(243, 208, 151, 0.24));
  opacity: 0.45;
  pointer-events: none;
  animation: haloPulse 9s ease-in-out infinite;
}

#viewer-image {
  position: relative;
  z-index: 2;
  max-width: 100%;
  max-height: min(70vh, 640px);
  object-fit: contain;
}

.viewer-path,
.viewer-orientation {
  position: absolute;
  bottom: 0.7rem;
  margin: 0;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  border: 1px solid rgba(213, 226, 255, 0.28);
  background: rgba(8, 12, 29, 0.64);
  color: rgba(236, 243, 255, 0.92);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  max-width: calc(50% - 1.4rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 3;
}

.viewer-path {
  left: 0.7rem;
}

.viewer-orientation {
  right: 0.7rem;
  text-align: right;
}

.viewer-controls {
  position: relative;
  z-index: 3;
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.viewer-index {
  color: rgba(244, 238, 230, 0.82);
  font-family: "Source Code Pro", monospace;
  letter-spacing: 0.06em;
  min-width: 64px;
  text-align: center;
}

.viewer-note {
  margin-left: 0;
  color: #f4dfb8;
  text-decoration: none;
  border: 1px solid rgba(228, 199, 127, 0.34);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.86rem;
  font-family: "Source Code Pro", monospace;
}

.viewer-note.is-disabled {
  pointer-events: none;
  opacity: 0.45;
}

.myth-viewer[data-element="fire"] {
  --halo-color: rgba(255, 166, 136, 0.24);
  --halo-glow: rgba(255, 145, 104, 0.38);
}

.myth-viewer[data-element="water"] {
  --halo-color: rgba(168, 198, 255, 0.24);
  --halo-glow: rgba(137, 180, 255, 0.38);
}

.myth-viewer[data-element="air"] {
  --halo-color: rgba(239, 230, 197, 0.24);
  --halo-glow: rgba(233, 224, 178, 0.36);
}

.myth-viewer[data-element="earth"] {
  --halo-color: rgba(202, 171, 132, 0.24);
  --halo-glow: rgba(171, 130, 91, 0.34);
}

.myth-viewer[data-element="light"] {
  --halo-color: rgba(254, 240, 178, 0.25);
  --halo-glow: rgba(253, 230, 135, 0.4);
}

@keyframes chamberFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes viewerStarsDrift {
  from {
    transform: translateX(-1.2%) translateY(-0.8%);
  }
  to {
    transform: translateX(1.2%) translateY(0.9%);
  }
}

@keyframes haloPulse {
  0% {
    opacity: 0.32;
    transform: translate(-50%, -50%) scale(0.96);
  }
  50% {
    opacity: 0.58;
    transform: translate(-50%, -50%) scale(1.03);
  }
  100% {
    opacity: 0.32;
    transform: translate(-50%, -50%) scale(0.96);
  }
}

@keyframes viewerImpact {
  0% {
    opacity: 0.9;
    box-shadow: 0 0 0 0 rgba(255, 237, 208, 0.8);
    transform: translate(-50%, -50%) scale(0.4);
  }
  100% {
    opacity: 0;
    box-shadow: 0 0 0 200px rgba(255, 237, 208, 0);
    transform: translate(-50%, -50%) scale(1.4);
  }
}

@keyframes pulseEarthHeavy {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  45% { transform: translate(-1px, 14px) scale(1.03) rotate(-0.08deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes pulseForestBranch {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  32% { transform: translate(5px, 4px) scale(1.028) rotate(0.18deg); }
  66% { transform: translate(-3px, 7px) scale(1.018) rotate(-0.16deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes pulseSkyLift {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  50% { transform: translate(2px, -12px) scale(1.04) rotate(0.06deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes pulseWaterTide {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  33% { transform: translate(11px, 1px) scale(1.03) rotate(0.03deg); }
  66% { transform: translate(-9px, -1px) scale(1.025) rotate(-0.03deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes pulseFireFlare {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  24% { transform: translate(2px, -5px) scale(1.05) rotate(0.08deg); }
  46% { transform: translate(-2px, 2px) scale(1.02) rotate(-0.08deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes pulseLightRadiant {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  50% { transform: translate(0, -2px) scale(1.055) rotate(0deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes pulseEthosSpiral {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  50% { transform: translate(-4px, -3px) scale(1.04) rotate(0.55deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes ambientEarthDrop {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-1px, 8px) scale(1.013); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes ambientForestSway {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(4px, 2px) scale(1.014); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes ambientSkyLift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(1px, -8px) scale(1.014); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes ambientWaterDrift {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(8px, 0) scale(1.013); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes ambientFireFlicker {
  0% { transform: translate(0, 0) scale(1); }
  40% { transform: translate(1px, -4px) scale(1.016); }
  70% { transform: translate(-1px, 1px) scale(1.01); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes ambientLightBloom {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(0, -1px) scale(1.02); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes ambientEthosSpiral {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  50% { transform: translate(-2px, -2px) scale(1.016) rotate(0.3deg); }
  100% { transform: translate(0, 0) scale(1) rotate(0deg); }
}

@keyframes entityEarthBreath {
  0%, 100% { transform: translateY(0); box-shadow: 0 12px 28px -26px rgba(120, 158, 112, 0.24); }
  50% { transform: translateY(2px); box-shadow: 0 16px 32px -22px rgba(120, 158, 112, 0.38); }
}

@keyframes entityForestBreath {
  0%, 100% { transform: translate(0, 0); box-shadow: 0 12px 28px -24px rgba(94, 140, 92, 0.22); }
  50% { transform: translate(2px, -1px); box-shadow: 0 16px 34px -22px rgba(94, 140, 92, 0.36); }
}

@keyframes entitySkyBreath {
  0%, 100% { transform: translateY(0); box-shadow: 0 12px 26px -24px rgba(162, 193, 236, 0.2); }
  50% { transform: translateY(-3px); box-shadow: 0 16px 34px -22px rgba(162, 193, 236, 0.34); }
}

@keyframes entityWaterBreath {
  0%, 100% { transform: translateX(0); box-shadow: 0 12px 26px -24px rgba(90, 124, 206, 0.22); }
  50% { transform: translateX(2px); box-shadow: 0 16px 34px -22px rgba(90, 124, 206, 0.35); }
}

@keyframes entityFireBreath {
  0%, 100% { transform: translate(0, 0); box-shadow: 0 12px 26px -24px rgba(207, 121, 77, 0.2); }
  30% { transform: translate(1px, -2px); box-shadow: 0 18px 38px -20px rgba(207, 121, 77, 0.4); }
  60% { transform: translate(-1px, 1px); box-shadow: 0 12px 26px -24px rgba(207, 121, 77, 0.22); }
}

@keyframes entityLightBreath {
  0%, 100% { transform: scale(1); box-shadow: 0 12px 26px -24px rgba(225, 196, 112, 0.22); }
  50% { transform: scale(1.01); box-shadow: 0 18px 38px -20px rgba(225, 196, 112, 0.38); }
}

@keyframes entityEthosBreath {
  0%, 100% { transform: rotate(0deg); box-shadow: 0 12px 26px -24px rgba(156, 118, 214, 0.22); }
  50% { transform: rotate(0.18deg); box-shadow: 0 18px 38px -20px rgba(156, 118, 214, 0.38); }
}

@media (max-width: 740px) {
  .viewer-panel {
    width: calc(100% - 0.8rem);
    min-height: calc(100vh - 0.8rem);
    border-radius: 12px;
    padding: 0.7rem;
  }

  .viewer-image-wrap {
    min-height: 64vh;
  }

  .viewer-path,
  .viewer-orientation {
    max-width: calc(100% - 1.4rem);
    bottom: 0.5rem;
  }

  .viewer-orientation {
    bottom: 2.4rem;
  }
}
