:root {
  --torch-x: 50vw;
  --torch-y: 50vh;
  --ink: #2d1709;
  --paper: rgba(246, 221, 166, 0.94);
  --paper-edge: #8d5b25;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  cursor: none;
  background:
    radial-gradient(circle at center, #2f2114 0, #100c08 52%, #050403 100%);
  color: var(--ink);
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

button {
  cursor: none;
  font: inherit;
}

.game {
  display: grid;
  width: 100vw;
  height: 100vh;
  place-items: center;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #070503;
  box-shadow: 0 0 55px rgba(0, 0, 0, 0.7);
  isolation: isolate;
}

.intro-screen {
  position: absolute;
  inset: 0;
  z-index: 14;
  display: grid;
  place-items: center;
  padding: clamp(14px, 3vw, 34px);
  background:
    radial-gradient(circle at 50% 44%, rgba(92, 52, 20, 0.1), rgba(5, 3, 2, 0.54) 70%),
    linear-gradient(rgba(9, 5, 3, 0.24), rgba(4, 2, 1, 0.42)),
    url("assets/intro-abbey-wall.png") center / cover no-repeat,
    #090604;
}

.intro-screen.is-hidden {
  display: none;
}

.intro-scroll {
  position: relative;
  display: grid;
  align-content: center;
  width: min(68%, 720px);
  height: min(64%, 520px);
  min-height: 0;
  padding: clamp(62px, 7vw, 78px) clamp(34px, 6vw, 72px) clamp(48px, 6vw, 66px);
  border: 6px solid #7b4a1d;
  border-radius: 28px;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 246, 197, 0.62), transparent 31%),
    linear-gradient(90deg, rgba(116, 67, 24, 0.18), transparent 11%, transparent 89%, rgba(116, 67, 24, 0.22)),
    linear-gradient(135deg, #f2d891, #d8a85a 52%, #efcf82);
  box-shadow:
    0 28px 70px rgba(0, 0, 0, 0.58),
    inset 0 0 52px rgba(85, 43, 13, 0.32);
  color: #2a1608;
  gap: 12px;
}

.intro-scroll::before,
.intro-scroll::after {
  position: absolute;
  left: 5%;
  width: 90%;
  height: clamp(38px, 6vw, 64px);
  border: 5px solid #764719;
  border-radius: 999px;
  background:
    linear-gradient(90deg, #bf7c32, #e0ad5b 18%, #c78436 50%, #e3b767 82%, #a56327);
  content: "";
  box-shadow: inset 0 0 20px rgba(68, 32, 8, 0.38);
}

.intro-scroll::before {
  top: calc(clamp(38px, 6vw, 64px) / -2);
}

.intro-scroll::after {
  bottom: calc(clamp(38px, 6vw, 64px) / -2);
}

.intro-scroll h1 {
  margin: 0 0 18px;
  font-family: Papyrus, "Apple Chancery", "Palatino Linotype", Georgia, serif;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
}

.intro-text-scroller {
  position: relative;
  width: min(78%, 600px);
  height: 6.8em;
  margin: 0 auto;
  overflow-y: auto;
  padding: 0 18px;
  perspective: 760px;
  perspective-origin: 50% 42%;
  scrollbar-color: rgba(80, 45, 17, 0.65) rgba(255, 236, 174, 0.18);
  scrollbar-width: thin;
  -webkit-mask-image: linear-gradient(transparent 0, black 14%, black 86%, transparent 100%);
  mask-image: linear-gradient(transparent 0, black 14%, black 86%, transparent 100%);
}

.intro-text-scroller:focus-visible {
  outline: 2px solid rgba(88, 48, 17, 0.55);
  outline-offset: 5px;
}

.intro-text {
  padding: 46px 0 140px;
  transform: rotateX(18deg);
  transform-origin: 50% 0;
}

.intro-text p {
  max-width: 430px;
  margin: 0 auto 16px;
  font-size: clamp(13px, 1.08vw, 15px);
  line-height: 1.34;
  text-align: center;
  text-shadow: none;
  transform: none;
}

.begin-adventure {
  justify-self: center;
  min-width: 138px;
  margin-top: 18px;
  padding: 7px 20px;
  border: 2px solid #6d411a;
  border-radius: 7px;
  background: rgba(55, 28, 9, 0.82);
  color: #ffe8ad;
  font-family: Papyrus, "Apple Chancery", "Palatino Linotype", Georgia, serif;
  font-size: 20px;
  letter-spacing: 0;
}

.begin-adventure:focus-visible,
.begin-adventure:hover {
  outline: 2px solid rgba(255, 229, 160, 0.9);
  outline-offset: 3px;
}

.scene-image,
.scene-video {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

.scene-image {
  object-fit: cover;
}

.scene-video {
  object-fit: cover;
}

.scene-video {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: #000;
}

.scene-video[hidden] {
  display: none;
}

.hotspots {
  position: absolute;
  inset: 0;
  z-index: 6;
}

.scene-text {
  position: absolute;
  top: clamp(12px, 2.2vw, 26px);
  left: clamp(12px, 2.2vw, 26px);
  z-index: 5;
  width: min(40vw, 560px);
  max-height: 42vh;
  overflow-y: auto;
  padding: 13px 16px 14px;
  border: 2px solid rgba(129, 82, 34, 0.82);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 240, 190, 0.94), rgba(226, 180, 99, 0.9));
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.42),
    inset 0 0 21px rgba(92, 49, 14, 0.22);
  color: #291407;
  font-family: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  font-size: clamp(13px, 1.08vw, 16px);
  line-height: 1.25;
  pointer-events: auto;
  scrollbar-color: rgba(80, 45, 17, 0.65) rgba(255, 236, 174, 0.18);
  scrollbar-width: thin;
}

.scene-text p {
  margin: 0 0 0.7em;
}

.scene-text p:last-child {
  margin-bottom: 0;
}

.scene-text.right {
  right: clamp(12px, 2.2vw, 26px);
  left: auto;
}

.scene-text[hidden] {
  display: none;
}

.continue-scene {
  position: absolute;
  right: clamp(16px, 2.4vw, 30px);
  bottom: clamp(16px, 2.4vw, 30px);
  z-index: 9;
  padding: 8px 18px;
  border: 2px solid #7c4d1f;
  border-radius: 6px;
  background:
    linear-gradient(135deg, rgba(255, 237, 174, 0.95), rgba(191, 126, 48, 0.92));
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.36);
  color: #2a1608;
  font-family: Papyrus, "Apple Chancery", "Palatino Linotype", Georgia, serif;
  font-size: 18px;
}

.continue-scene[hidden] {
  display: none;
}

.hotspot {
  position: absolute;
  display: block;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: transparent;
  padding: 0;
  outline: 0;
}

.hotspot:focus-visible,
.hotspot:hover {
  border-color: rgba(255, 222, 139, 0.62);
  background: rgba(255, 224, 142, 0.12);
  box-shadow: 0 0 18px rgba(255, 185, 80, 0.45);
}

.hotspot:not(.choice-zone):focus-visible,
.hotspot:not(.choice-zone):hover {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.head-zone {
  border-radius: 50%;
}

.choice-zone {
  cursor: none;
}

.choice-zone:focus-visible,
.choice-zone:hover {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.choice-zone::after {
  position: absolute;
  inset: -3px 0;
  border: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(255, 229, 147, 0.18), rgba(255, 229, 147, 0.58), rgba(255, 229, 147, 0.16));
  box-shadow: 0 0 12px rgba(255, 209, 106, 0.32);
  content: "";
  opacity: 0;
}

.choice-zone:focus-visible::after,
.choice-zone:hover::after {
  opacity: 1;
}

.debug-choice-zones .choice-zone::after {
  opacity: 1;
  background: rgba(80, 255, 130, 0.32);
  box-shadow: inset 0 0 0 1px rgba(20, 100, 50, 0.75);
}

.bubble-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

.speech-bubble {
  position: absolute;
  z-index: 0;
  isolation: isolate;
  width: max-content;
  max-width: 285px;
  min-width: 118px;
  padding: 11px 16px;
  border: 2px solid var(--paper-edge);
  border-radius: 48% 52% 46% 54% / 58% 54% 46% 42%;
  background:
    linear-gradient(135deg, rgba(255, 242, 196, 0.98), var(--paper));
  box-shadow:
    0 9px 24px rgba(0, 0, 0, 0.34),
    inset 0 0 18px rgba(124, 74, 25, 0.22);
  color: var(--ink);
  font-family: Papyrus, "Apple Chancery", "Palatino Linotype", Georgia, serif;
  font-size: 17px;
  line-height: 1.22;
  letter-spacing: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px) scale(0.98);
  transition:
    opacity 360ms ease,
    transform 360ms ease;
}

.speech-bubble.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.speech-bubble::before,
.speech-bubble::after {
  position: absolute;
  left: var(--tail-x, 50%);
  content: "";
  transform: translateX(-50%);
}

.speech-bubble::before {
  bottom: -17px;
  z-index: -2;
  width: 34px;
  height: 28px;
  background: var(--paper-edge);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.speech-bubble::after {
  bottom: -12px;
  z-index: -1;
  width: 28px;
  height: 24px;
  background: rgba(246, 221, 166, 0.98);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.speech-bubble.below::before {
  top: -17px;
  bottom: auto;
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
}

.speech-bubble.below::after {
  top: -12px;
  bottom: auto;
  clip-path: polygon(50% 0, 0 100%, 100% 100%);
}

.speech-bubble.rect {
  border-radius: 3px;
  font-size: 15px;
  padding: 9px 12px;
}

.speech-bubble.rect::before,
.speech-bubble.rect::after {
  display: none;
}

.level2-fallback {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background:
    linear-gradient(rgba(16, 10, 7, 0.55), rgba(16, 10, 7, 0.78)),
    radial-gradient(circle at center, #9b6a32 0, #24150b 70%);
  color: #f8e5b8;
}

.level2-fallback[hidden] {
  display: none;
}

.level2-fallback h1 {
  margin: 0 0 10px;
  font-family: Papyrus, "Apple Chancery", "Palatino Linotype", Georgia, serif;
  font-size: 44px;
  letter-spacing: 0;
}

.level2-fallback p {
  max-width: 420px;
  margin: 0;
  font-size: 17px;
}

.fade-overlay {
  position: absolute;
  inset: 0;
  z-index: 18;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1000ms ease;
}

.fade-overlay.is-visible {
  opacity: 1;
}

.audio-toggle {
  display: none;
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 40;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 221, 145, 0.72);
  border-radius: 7px;
  background: rgba(39, 23, 12, 0.72);
  color: #ffe8ad;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.35);
}

.audio-toggle.is-muted {
  color: #9f8a68;
  border-color: rgba(159, 138, 104, 0.55);
}

.torch {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background:
    radial-gradient(
      circle at var(--torch-x) var(--torch-y),
      rgba(255, 232, 152, 0.4) 0,
      rgba(255, 174, 64, 0.2) 90px,
      rgba(0, 0, 0, 0.36) 210px,
      rgba(0, 0, 0, 0.82) 100%
    );
}

.flame-cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  width: 34px;
  height: 48px;
  background: url("assets/flame/frame-00.svg") center / contain no-repeat;
  filter: drop-shadow(0 0 12px rgba(255, 166, 55, 0.92));
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(-7deg);
  transition: opacity 140ms ease;
  animation: flame-flicker 620ms steps(10, end) infinite;
}

.flame-cursor::before {
  content: none;
}

.flame-cursor.is-visible {
  opacity: 0.9;
}

@keyframes flame-flicker {
  0% {
    width: 31px;
    height: 47px;
    filter: blur(0.1px) drop-shadow(0 0 10px rgba(255, 150, 45, 0.86));
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-9deg) scale(0.96);
  }
  10% {
    width: 35px;
    height: 50px;
    filter: blur(0.2px) drop-shadow(0 0 15px rgba(255, 190, 60, 0.95));
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-5deg) scale(1.04);
  }
  20% {
    width: 32px;
    height: 46px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-12deg) scale(0.98);
  }
  30% {
    width: 37px;
    height: 49px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-4deg) scale(1.02);
  }
  40% {
    width: 33px;
    height: 51px;
    filter: blur(0.1px) drop-shadow(0 0 17px rgba(255, 212, 78, 0.98));
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-8deg) scale(1.05);
  }
  50% {
    width: 30px;
    height: 45px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-15deg) scale(0.94);
  }
  60% {
    width: 36px;
    height: 52px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-3deg) scale(1.06);
  }
  70% {
    width: 32px;
    height: 48px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-10deg) scale(0.97);
  }
  80% {
    width: 38px;
    height: 50px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-2deg) scale(1.03);
  }
  90% {
    width: 31px;
    height: 46px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-13deg) scale(0.96);
  }
  100% {
    width: 34px;
    height: 48px;
    transform: translate(var(--flame-x, -999px), var(--flame-y, -999px)) rotate(-7deg) scale(1);
  }
}

.embers {
  position: fixed;
  inset: 0;
  z-index: 29;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

@media (max-width: 680px) {
  .scene-text,
  .scene-text.right {
    right: auto;
    left: 10px;
    width: calc(100vw - 20px);
    max-height: 24vh;
    padding: 10px 12px;
    font-size: 13px;
  }

  .speech-bubble {
    max-width: 250px;
    min-width: 96px;
    padding: 8px 10px;
    font-size: 14px;
  }

  .speech-bubble.rect {
    font-size: 13px;
  }

  .audio-toggle {
    width: 38px;
    height: 38px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flame-cursor,
  .embers {
    display: none;
  }
}
