:root {
  --bg-deep: #102517;
  --bg-mid: #27412b;
  --glass: rgba(12, 20, 14, 0.28);
  --glass-strong: rgba(18, 28, 20, 0.70);
  --border: rgba(220, 255, 170, 0.18);
  --border-strong: rgba(255, 245, 159, 0.34);
  --text: #f7fff2;
  --muted: rgba(247, 255, 242, 0.82);
  --accent: #dfff6c;
  --accent-strong: #f5ff9e;
  --accent-deep: #98d764;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(6, 11, 7, 0.10), rgba(6, 11, 7, 0.22)),
    url('assets/images/korok-forest.png') center center / cover fixed no-repeat;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(214, 255, 114, 0.08), transparent 24%),
    radial-gradient(circle at 80% 20%, rgba(144, 255, 199, 0.06), transparent 22%),
    linear-gradient(180deg, rgba(4, 14, 8, 0.02), rgba(4, 14, 8, 0.06));
  pointer-events: none;
}

.ambient {
  position: fixed;
  border-radius: 999px;
  filter: blur(70px);
  pointer-events: none;
  opacity: 0.18;
  z-index: 0;
}
.ambient-a {
  width: 300px; height: 300px;
  top: -50px; left: -40px;
  background: rgba(157, 255, 118, 0.78);
}
.ambient-b {
  width: 360px; height: 360px;
  bottom: -110px; right: -100px;
  background: rgba(80, 221, 154, 0.68);
}

.leaf-float {
  position: fixed;
  width: 14px;
  height: 14px;
  border-radius: 5px 14px 5px 14px;
  background: rgba(210, 255, 123, 0.32);
  opacity: 0.3;
  animation: drift 9s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}
.leaf-1 { top: 18%; left: 8%; animation-delay: -2s; }
.leaf-2 { top: 62%; left: 16%; animation-delay: -5s; }
.leaf-3 { top: 34%; right: 10%; animation-delay: -1s; }

.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
}

.scene {
  width: min(1180px, 100%);
  border: 1px solid var(--border);
  border-radius: 34px;
  background: linear-gradient(180deg, rgba(11, 20, 14, 0.22), rgba(10, 18, 14, 0.38));
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 34px);
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.scene::before {
  content: '';
  position: absolute;
  inset: 0;
  backdrop-filter: blur(7px) saturate(1.04);
  border-radius: inherit;
  z-index: -1;
  pointer-events: none;
}

.scene-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 255, 255, 0.04), transparent 26%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.01), transparent 40%);
  pointer-events: none;
}

.header {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 0;
  font-family: 'Cinzel Decorative', Georgia, serif;
  font-weight: 900;
  font-size: clamp(2.7rem, 5.8vw, 5.8rem);
  line-height: 0.92;
  letter-spacing: 0.03em;
}
.subtitle {
  max-width: 46ch;
  margin-bottom: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1rem, 1.3vw, 1.28rem);
  line-height: 1.35;
  color: rgba(245, 255, 240, 0.84);
}

.story-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: clamp(16px, 3vw, 28px);
  align-items: stretch;
}

/* Portrait column: self-contained, image capped by max-height */
.portrait-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-width: 0;
  /* No overflow:hidden needed — image is max-height constrained directly */
}

.portrait-glow {
  position: absolute;
  inset: 14% 12% 12%;
  border-radius: 50% 50% 44% 44%;
  background: radial-gradient(circle, rgba(241, 255, 153, 0.20), rgba(128, 255, 182, 0.04) 55%, transparent 72%);
  filter: blur(18px);
  animation: breathe 4.5s ease-in-out infinite;
  z-index: -1;
}

/* Portrait images: max-height keeps them from ever overflowing */
.portrait {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 520px;
  height: auto;
  background: transparent;
  filter: drop-shadow(0 28px 42px rgba(0, 0, 0, 0.33));
  transition: opacity 260ms ease, transform 360ms ease, filter 360ms ease;
  transform-origin: 50% 70%;
  pointer-events: none;
}

.portrait-sad {
  position: relative;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.portrait-happy {
  position: absolute;
  top: 0;
  left: 50%;
  opacity: 0;
  transform: translateX(-50%) translateY(6px) scale(0.96);
}

.scene.is-happy .portrait-sad {
  opacity: 0;
  transform: translateY(10px) scale(0.94);
}
.scene.is-happy .portrait-happy {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  animation: hop 1.8s ease-in-out infinite;
}
.scene.is-angry .portrait-happy,
.scene.is-angry .portrait-sad {
  filter: drop-shadow(0 28px 42px rgba(0, 0, 0, 0.38)) saturate(0.9) contrast(1.06);
}

.sparkle {
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 1), rgba(232, 255, 142, 0.6) 42%, transparent 70%);
  animation: sparkle 2.7s ease-in-out infinite;
}
.sparkle-a { width: 16px; height: 16px; left: 18%; top: 18%; animation-delay: 0s; }
.sparkle-b { width: 12px; height: 12px; right: 16%; top: 36%; animation-delay: .8s; }
.sparkle-c { width: 14px; height: 14px; left: 72%; bottom: 24%; animation-delay: 1.5s; }
.scene.is-happy .sparkle { opacity: 1; }

.dialogue-stack {
  display: grid;
  gap: 14px;
  align-content: start;
}
.dialogue-box {
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--border-strong);
  border-radius: 30px;
  background: linear-gradient(180deg, rgba(18, 31, 21, 0.76), rgba(9, 18, 13, 0.80));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), 0 18px 45px rgba(0, 0, 0, 0.24);
  text-align: left;
  padding: clamp(20px, 3vw, 30px);
  color: var(--text);
  cursor: pointer;
  display: grid;
  align-content: start;
  gap: 18px;
  position: relative;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.dialogue-box:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 245, 159, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 22px 50px rgba(0, 0, 0, 0.28);
}
.dialogue-box:focus-visible,
.choice:focus-visible,
.riddle-toggle:focus-visible {
  outline: 3px solid rgba(241, 255, 153, 0.82);
  outline-offset: 4px;
}
.dialogue-box::after {
  content: '';
  position: absolute;
  inset: 12px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  pointer-events: none;
}
.dialogue-topline {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}
.speaker {
  font-family: 'Uncial Antiqua', Georgia, serif;
  font-size: 1.08rem;
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.advance-hint {
  color: rgba(245, 255, 240, 0.5);
  font-size: 0.69rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.dialogue-text {
  margin: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.35rem, 2vw, 2rem);
  line-height: 1.42;
  color: rgba(247, 255, 243, 0.96);
  max-width: 32ch;
  text-wrap: pretty;
}
.dialogue-box.is-popping .dialogue-text {
  animation: popText 220ms ease;
}
.dialogue-box.is-popping {
  transform: translateY(-1px) scale(1.004);
}

.choices {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.choice {
  border: 1px solid transparent;
  border-radius: 18px;
  padding: 14px 20px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 180ms ease, opacity 180ms ease, background 180ms ease, border-color 180ms ease;
}
.choice:hover { transform: translateY(-1px); }
.choice.primary {
  color: #122413;
  background: linear-gradient(180deg, #e7ff83, #b7ff54);
  border-color: rgba(255, 255, 255, 0.18);
}
.choice.primary:hover { background: linear-gradient(180deg, #f3ff9c, #c6ff65); }
.choice.ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
}
.choice.ghost:hover { background: rgba(255, 255, 255, 0.11); }

.mission-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}
.mission-card {
  min-width: 0;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: linear-gradient(180deg, rgba(18, 31, 21, 0.72), rgba(9, 18, 13, 0.74));
  padding: 20px 20px 22px;
}
.mission-label {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.76rem;
  font-weight: 800;
  margin-bottom: 10px;
}
.mission-card h2 {
  font-family: 'Cinzel Decorative', Georgia, serif;
  font-size: clamp(1.22rem, 2vw, 1.85rem);
  line-height: 1.12;
  margin-bottom: 12px;
  color: var(--text);
  overflow-wrap: anywhere;
}
.mission-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.65;
}

.riddle-card {
  display: grid;
  gap: 12px;
}
.riddle-toggle {
  border: 1px solid rgba(255, 245, 159, 0.28);
  background: linear-gradient(180deg, rgba(235, 255, 150, 0.18), rgba(191, 255, 89, 0.12));
  color: var(--accent-strong);
  border-radius: 18px;
  padding: 14px 18px;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}
.riddle-toggle:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(235, 255, 150, 0.24), rgba(191, 255, 89, 0.16));
  border-color: rgba(255, 245, 159, 0.44);
}
.riddle-panel {
  border: 1px solid rgba(255, 245, 159, 0.34);
  border-radius: 22px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 247, 180, 0.20), rgba(17, 28, 20, 0.85)),
    rgba(17, 28, 20, 0.9);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.25);
}
.riddle-kicker {
  margin-bottom: 10px;
  color: rgba(247, 255, 242, 0.72);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 800;
}
.riddle-text {
  margin-bottom: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.25rem, 1.8vw, 2rem);
  line-height: 1.4;
  color: #fffef3;
}

.footer-note {
  color: rgba(245, 255, 240, 0.5);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  padding: 0 4px;
}
.hidden { display: none !important; }

.scene.is-angry .speaker,
.scene.is-angry .dialogue-text {
  color: #fff2a7;
}
.scene.is-angry .dialogue-box {
  border-color: rgba(255, 190, 96, 0.5);
}

@keyframes hop {
  0%, 100% { transform: translateX(-50%) translateY(0) scale(1); }
  50% { transform: translateX(-50%) translateY(-8px) scale(1.01); }
}
@keyframes popText {
  from { opacity: 0.2; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.72; }
  50% { transform: scale(1.04); opacity: 1; }
}
@keyframes sparkle {
  0%, 100% { transform: scale(0.7) translateY(0); opacity: 0; }
  20% { opacity: 1; }
  50% { transform: scale(1.05) translateY(-10px); opacity: 1; }
  80% { opacity: 0.2; }
}
@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg); }
  50% { transform: translate3d(18px, -22px, 0) rotate(22deg); }
}

@media (max-width: 980px) {
  .story-grid {
    grid-template-columns: 1fr;
  }
  .portrait-wrap {
    justify-content: center;
  }
  .portrait {
    max-height: 360px;
  }
  .dialogue-text {
    max-width: none;
  }
  .mission-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .scene {
    border-radius: 26px;
    padding: 16px;
  }
  .header { margin-bottom: 14px; }
  .dialogue-box {
    min-height: 250px;
    border-radius: 22px;
  }
  .choice,
  .riddle-toggle {
    width: 100%;
  }
  .choices {
    flex-direction: column;
  }
}