:root {
  color-scheme: dark;
  --ink: #f8f1df;
  --muted: #d3c7b8;
  --dark: #120f20;
  --panel: rgba(24, 20, 39, 0.88);
  --line: rgba(255, 255, 255, 0.18);
  --gold: #f7c557;
  --rose: #df5f87;
  --blue: #49a8d8;
  --green: #50b783;
  --violet: #8f71ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #070711;
  color: var(--ink);
}

button {
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 0 18px;
  background: linear-gradient(135deg, #df5f87, #8f71ff);
  color: white;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
  touch-action: manipulation;
}

button:active {
  transform: translateY(1px);
}

.game {
  min-height: 100vh;
  display: grid;
  padding: 14px;
  background:
    radial-gradient(circle at 12% 12%, rgba(73, 168, 216, 0.22), transparent 28%),
    radial-gradient(circle at 82% 18%, rgba(223, 95, 135, 0.24), transparent 30%),
    #070711;
}

.game-stage {
  position: relative;
  min-height: calc(100vh - 28px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #161a2d;
  box-shadow: var(--shadow);
}

.hud {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
}

.hud > div {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 9, 20, 0.62);
  backdrop-filter: blur(10px);
}

.hud-label,
.chapter {
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud strong {
  font-size: clamp(0.9rem, 2.4vw, 1.1rem);
}

.world {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(#91d8f0 0%, #dff7ff 48%, #73b66e 49%, #3f8c55 100%);
  transition: background 700ms ease;
}

.game-stage.magic-world .world,
.game-stage.admission-mode .world,
.game-stage.avatar-mode .world,
.game-stage.course-mode .world {
  background:
    radial-gradient(circle at 70% 19%, rgba(247, 197, 87, 0.96) 0 38px, transparent 40px),
    linear-gradient(#151433 0%, #37245b 44%, #be7688 70%, #473360 100%);
}

.moon,
.stars,
.school,
.magic-gate {
  opacity: 0;
  transition: opacity 700ms ease;
}

.magic-world .moon,
.magic-world .stars,
.magic-world .school,
.magic-world .magic-gate,
.admission-mode .moon,
.admission-mode .stars,
.admission-mode .school,
.admission-mode .magic-gate,
.avatar-mode .moon,
.avatar-mode .stars,
.avatar-mode .school,
.avatar-mode .magic-gate,
.course-mode .moon,
.course-mode .stars,
.course-mode .school,
.course-mode .magic-gate {
  opacity: 1;
}

.moon {
  position: absolute;
  right: 15%;
  top: 14%;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: #f7c557;
  box-shadow: 0 0 48px rgba(247, 197, 87, 0.62);
}

.stars {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 22%, #fff 0 2px, transparent 3px),
    radial-gradient(circle at 28% 36%, #fff 0 2px, transparent 3px),
    radial-gradient(circle at 52% 18%, #fff 0 2px, transparent 3px),
    radial-gradient(circle at 82% 30%, #fff 0 2px, transparent 3px);
}

.road {
  position: absolute;
  left: -12%;
  right: -12%;
  bottom: -2vh;
  height: 24vh;
  background: #565061;
  transform: skewY(-4deg);
}

.road::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 48%;
  border-top: 7px dashed rgba(255, 248, 224, 0.72);
}

.house {
  position: absolute;
  left: 8%;
  bottom: 20vh;
  width: 150px;
  height: 110px;
  background: #f2c99f;
  border: 4px solid rgba(18, 15, 32, 0.18);
}

.house::before {
  content: "";
  position: absolute;
  left: -16px;
  top: -70px;
  border-left: 91px solid transparent;
  border-right: 91px solid transparent;
  border-bottom: 74px solid #a94452;
}

.house::after {
  content: "";
  position: absolute;
  left: 58px;
  bottom: 0;
  width: 38px;
  height: 58px;
  border-radius: 8px 8px 0 0;
  background: #674130;
}

.school {
  position: absolute;
  right: 8%;
  bottom: 19vh;
  width: 230px;
  height: 150px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(#dfd2ff, #9582d9);
}

.school::before,
.school::after {
  content: "";
  position: absolute;
  bottom: 0;
  width: 58px;
  height: 214px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(#f0e9ff, #a899e4);
}

.school::before {
  left: -38px;
}

.school::after {
  right: -38px;
}

.magic-gate {
  position: absolute;
  left: 48%;
  bottom: 20vh;
  width: 120px;
  height: 170px;
  border: 8px solid rgba(73, 168, 216, 0.86);
  border-bottom: 0;
  border-radius: 70px 70px 0 0;
  box-shadow: 0 0 28px rgba(73, 168, 216, 0.75);
}

.bus {
  position: absolute;
  left: -270px;
  bottom: 18vh;
  width: 220px;
  height: 92px;
  border-radius: 18px 24px 14px 14px;
  background: linear-gradient(#f7c557, #d98b2d);
  box-shadow: 0 18px 28px rgba(0, 0, 0, 0.28);
  transition:
    left 1300ms ease,
    bottom 1300ms ease,
    transform 1300ms ease;
}

.bus::before,
.bus::after {
  content: "";
  position: absolute;
  bottom: -17px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #171224;
  box-shadow: inset 0 0 0 8px #777184;
}

.bus::before {
  left: 34px;
}

.bus::after {
  right: 34px;
}

.bus-window {
  position: relative;
  top: 17px;
  left: 18px;
  display: inline-block;
  width: 44px;
  height: 28px;
  margin-right: 7px;
  border-radius: 7px;
  background: #dff8ff;
}

.bus-door {
  position: absolute;
  right: 18px;
  bottom: 0;
  width: 34px;
  height: 62px;
  border-radius: 8px 8px 0 0;
  background: rgba(18, 15, 32, 0.22);
}

.wing {
  position: absolute;
  top: 18px;
  width: 100px;
  height: 45px;
  border-radius: 80% 20% 80% 20%;
  background: rgba(255, 248, 231, 0.92);
  opacity: 0;
  transform: scale(0.4);
  transition:
    opacity 500ms ease,
    transform 500ms ease;
}

.wing-left {
  left: -74px;
}

.wing-right {
  right: -74px;
  transform: scale(0.4) rotateY(180deg);
}

.bus-arrives .bus {
  left: 36%;
}

.bus-flies .bus {
  left: 56%;
  bottom: 58vh;
  transform: rotate(-8deg);
}

.bus-flies .wing {
  opacity: 1;
  transform: scale(1);
}

.bus-flies .wing-right {
  transform: scale(1) rotateY(180deg);
}

.hero,
.big-hero {
  position: absolute;
  width: 82px;
  height: 154px;
}

.hero {
  left: 24%;
  bottom: 21vh;
  transition:
    left 900ms ease,
    bottom 900ms ease,
    transform 900ms ease;
}

.hero.on-bus {
  left: 43%;
  bottom: 31vh;
  transform: scale(0.72);
}

.bus-flies .hero {
  left: 61%;
  bottom: 66vh;
  transform: scale(0.68) rotate(-8deg);
}

.head,
.hair,
.body,
.wand {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.head {
  top: 30px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f0bc8e;
}

.hair {
  top: 20px;
  width: 58px;
  height: 38px;
  border-radius: 50% 50% 26px 26px;
  background: #5b3148;
  z-index: 1;
}

.body {
  top: 76px;
  width: 64px;
  height: 74px;
  border-radius: 24px 24px 10px 10px;
  background: linear-gradient(#8f71ff, #473c9d);
}

.wand {
  top: 70px;
  left: 72px;
  width: 6px;
  height: 78px;
  border-radius: 99px;
  background: #5a3829;
  transform: rotate(-18deg);
}

.wand::before {
  content: "";
  position: absolute;
  left: -7px;
  top: -11px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 24px var(--gold);
}

.letter {
  position: absolute;
  left: 20%;
  bottom: 43vh;
  width: 164px;
  height: 102px;
  display: grid;
  place-items: center;
  border: 2px solid #d5aa55;
  border-radius: 6px;
  background:
    linear-gradient(35deg, transparent 49%, rgba(213, 170, 85, 0.45) 50%, transparent 51%),
    linear-gradient(-35deg, transparent 49%, rgba(213, 170, 85, 0.45) 50%, transparent 51%),
    #fff0c7;
  color: #6e4825;
  font-family: Georgia, serif;
  font-weight: 900;
  opacity: 0;
  transform: translateY(15px) rotate(-5deg);
  transition:
    opacity 450ms ease,
    transform 450ms ease;
}

.show-letter .letter {
  opacity: 1;
  transform: translateY(0) rotate(-5deg);
}

.dialogue,
.panel {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 18px;
  width: min(860px, calc(100% - 28px));
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.dialogue {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 18px;
  padding: 18px;
}

.chapter {
  margin: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  line-height: 1.05;
}

h1 {
  grid-column: 1 / -1;
  font-size: clamp(1.45rem, 4vw, 2.6rem);
}

h2 {
  font-size: clamp(1.35rem, 4vw, 2.25rem);
}

.dialogue p:not(.chapter),
.panel p:not(.chapter):not(.seal) {
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.12rem);
  line-height: 1.45;
}

#storyText {
  align-self: center;
}

#nextButton {
  min-width: 170px;
  align-self: end;
}

.panel {
  display: none;
  top: 86px;
  bottom: auto;
  padding: 20px;
}

.panel.is-visible {
  display: grid;
  gap: 14px;
}

.admission {
  text-align: center;
}

.seal {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  justify-self: center;
  border-radius: 50%;
  background: var(--gold);
  color: #5a2b46;
  font-size: 2rem;
  box-shadow: 0 0 34px rgba(247, 197, 87, 0.58);
}

.actions,
.choice-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

#avatarButton,
#saveAvatarButton {
  background: linear-gradient(135deg, #50b783, #49a8d8);
}

#courseButton,
#backButton {
  background: linear-gradient(135deg, #49a8d8, #8f71ff);
}

.avatar-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: stretch;
}

.avatar-preview {
  min-height: 260px;
  position: relative;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.big-hero {
  position: relative;
  transform: scale(1.45);
}

.hair-rose .hair {
  background: #df5f87;
}

.hair-night .hair {
  background: #1b1937;
}

.hair-gold .hair {
  background: #f7c557;
}

.magic-light .wand::before {
  background: #fff2a6;
  box-shadow: 0 0 28px #fff2a6;
}

.magic-nature .wand::before {
  background: #50b783;
  box-shadow: 0 0 28px #50b783;
}

.magic-shadow .wand::before {
  background: #8f71ff;
  box-shadow: 0 0 28px #8f71ff;
}

.choice-list {
  display: grid;
  align-content: center;
  gap: 10px;
}

.choice-list p {
  color: var(--ink);
  font-weight: 900;
}

.choice {
  min-width: 116px;
  background: rgba(255, 255, 255, 0.12);
}

.choice.is-selected {
  outline: 3px solid var(--gold);
}

.spark-board {
  position: relative;
  min-height: 280px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at center, rgba(73, 168, 216, 0.18), transparent 58%),
    rgba(255, 255, 255, 0.08);
}

.spark {
  position: absolute;
  width: 56px;
  height: 56px;
  min-height: 56px;
  padding: 0;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 28px var(--gold);
}

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

.fade-out .fade {
  opacity: 1;
}

.is-hidden {
  display: none;
}

@media (max-width: 760px) {
  .game {
    padding: 0;
  }

  .game-stage {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .hud {
    grid-template-columns: 1fr;
  }

  .hud > div {
    min-height: 46px;
  }

  .house {
    left: 5%;
    width: 108px;
    height: 82px;
  }

  .house::before {
    left: -12px;
    top: -50px;
    border-left-width: 66px;
    border-right-width: 66px;
    border-bottom-width: 54px;
  }

  .hero {
    left: 34%;
    bottom: 20vh;
    transform: scale(0.8);
  }

  .letter {
    left: 8%;
    bottom: 48vh;
  }

  .bus {
    width: 174px;
    height: 76px;
  }

  .bus-arrives .bus {
    left: 30%;
  }

  .bus-flies .bus {
    left: 26%;
    bottom: 58vh;
  }

  .bus-flies .hero {
    left: 45%;
    bottom: 65vh;
  }

  .school {
    right: 8%;
    width: 128px;
    height: 102px;
  }

  .school::before,
  .school::after {
    width: 38px;
    height: 150px;
  }

  .school::before {
    left: -24px;
  }

  .school::after {
    right: -24px;
  }

  .dialogue {
    grid-template-columns: 1fr;
    bottom: 10px;
    padding: 14px;
  }

  #nextButton {
    width: 100%;
  }

  .panel {
    top: 170px;
    width: calc(100% - 20px);
    padding: 14px;
  }

  .avatar-layout {
    grid-template-columns: 1fr;
  }

  .avatar-preview {
    min-height: 190px;
  }

  .big-hero {
    transform: scale(1.15);
  }
}
