/* ── Reset & Base ─────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #0a0a14;
  --color-text: #e8e0d0;
  --color-muted: #8a8070;
  --color-accent-cold: #4a7fa5;   /* ice/mist — Niflheim */
  --color-accent-fire: #c04a1a;   /* fire — Muspelheim */
  --color-accent-earth: #5a7a4a;  /* roots/giants — Jotunheim */
  --color-accent-light: #9a8a5a;  /* upper realms */
  --font-heading: Georgia, 'Times New Roman', serif;
  --font-body: system-ui, sans-serif;
  --nav-width: 160px;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  min-height: 100vh;
}

/* ── Nav ──────────────────────────────────────────── */
#realm-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--nav-width);
  height: 100vh;
  background: rgba(10, 10, 20, 0.92);
  border-right: 1px solid #222;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  z-index: 100;
  overflow-y: auto;
}

.nav-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  letter-spacing: 0.1em;
  color: var(--color-text);
}

#realm-nav ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#realm-nav a {
  color: var(--color-muted);
  text-decoration: none;
  font-size: 0.875rem;
  letter-spacing: 0.05em;
  transition: color 0.2s;
}

#realm-nav a:hover,
#realm-nav a.active {
  color: var(--color-text);
}

/* ── Main trunk ───────────────────────────────────── */
#trunk {
  margin-left: var(--nav-width);
  position: relative;
}

/* Yggdrasil tree spanning the full scroll height */
.trunk__bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}

/* ── Realm sections ───────────────────────────────── */
.realm {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 5vw;
  border-bottom: 1px solid #1a1a2e;
  position: relative;
  z-index: 1;
}

.realm--light {
  background: linear-gradient(160deg, rgba(15,15,30,0.82) 0%, rgba(10,10,20,0.82) 100%);
}

.realm--light .realm__content h2 {
  color: var(--color-accent-light);
}

/* Jotunheim */
#jotunheim {
  background: linear-gradient(160deg, rgba(10,20,8,0.82) 0%, rgba(10,10,20,0.82) 100%);
}
#jotunheim .realm__content h2 { color: var(--color-accent-earth); }

/* Niflheim */
#niflheim {
  background: linear-gradient(160deg, rgba(8,14,20,0.82) 0%, rgba(4,8,15,0.82) 100%);
}
#niflheim .realm__content h2 { color: var(--color-accent-cold); }

/* Muspelheim */
#muspelheim {
  background: linear-gradient(160deg, rgba(24,8,0,0.82) 0%, rgba(10,10,20,0.82) 100%);
}
#muspelheim .realm__content h2 { color: var(--color-accent-fire); }

.realm__content {
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.realm__content h2 {
  font-family: var(--font-heading);
  font-size: clamp(2rem, 5vw, 3.5rem);
  letter-spacing: 0.05em;
}

.realm__subtitle {
  font-size: 1rem;
  color: var(--color-muted);
  font-style: italic;
}

.realm__body {
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--color-text);
}

/* ── Modal ────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.modal.is-open {
  opacity: 1;
  pointer-events: all;
}

.modal__box {
  background: #12121f;
  border: 1px solid #2a2a40;
  border-radius: 6px;
  max-width: 640px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
}

.modal__close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--color-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal__close:hover {
  color: var(--color-text);
}

/* ── Scroll-activated fade-in ─────────────────────── */
.realm__content {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.realm__content.visible {
  opacity: 1;
  transform: none;
}

/* ── Story card grid ──────────────────────────────── */
.story-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.5rem;
}

/* ── Story cards ──────────────────────────────────── */
.story-card {
  display: inline-block;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid #2a2a40;
  max-width: 280px;
}

.story-card img {
  display: block;
  width: 100%;
  height: auto;
  transition: transform 0.35s ease, filter 0.35s ease;
}

.story-card:hover img {
  transform: scale(1.04);
  filter: brightness(0.75);
}

.story-card__caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem 0.75rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  font-family: var(--font-heading);
  font-size: 0.9rem;
  color: var(--color-text);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.story-card:hover .story-card__caption {
  opacity: 1;
  transform: none;
}

/* ── Story card modal content ─────────────────────── */
.story-modal__img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.story-modal__title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
  color: var(--color-text);
}

.story-modal__body {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--color-text);
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 640px) {
  :root { --nav-width: 0px; }

  #realm-nav {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid #222;
    padding: 0.75rem 1rem;
  }

  #realm-nav ul {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
  }

  #trunk {
    margin-left: 0;
  }
}
