:root {
  --ui-bg: rgba(15, 18, 41, 0.74);
  --ui-border: rgba(216, 245, 255, 0.6);
  --primary: #ff7fb0;
  --primary-strong: #ff4f95;
  --text: #f6f8ff;
  --subtext: #d0dcff;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
  --top-ui-reserve: 108px;
  --dialogue-reserve: 320px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: "YouYuan", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: #090d22;
}

#app,
#game-stage {
  width: 100%;
  height: 100%;
}

#game-stage {
  position: relative;
  overflow: hidden;
}

#bg-layer {
  position: absolute;
  inset: 0;
}

#bg-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.03);
  transition: opacity 550ms ease, transform 1.2s ease;
}

.bg-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 22% 20%, rgba(255, 255, 255, 0.15), transparent 35%),
    radial-gradient(circle at 80% 8%, rgba(255, 240, 205, 0.24), transparent 28%),
    linear-gradient(to top, rgba(7, 8, 16, 0.8), transparent 45%);
  pointer-events: none;
}

#character-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: var(--top-ui-reserve) 3.6vw var(--dialogue-reserve);
  z-index: 4;
  pointer-events: none;
}

#hero-sprite {
  width: min(30vw, 370px);
  max-height: calc(100vh - var(--top-ui-reserve) - var(--dialogue-reserve) - 40px);
  object-fit: contain;
  object-position: center top;
  border-radius: 22px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5);
  transition: opacity 320ms ease, transform 320ms ease, filter 280ms ease;
}

#dragon-sprite {
  width: min(24vw, 290px);
  max-height: calc(100vh - var(--top-ui-reserve) - var(--dialogue-reserve) - 52px);
  object-fit: contain;
  object-position: center top;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  filter: drop-shadow(0 12px 25px rgba(0, 0, 0, 0.45));
  transition: opacity 320ms ease, transform 320ms ease, filter 280ms ease;
  animation: dragonFloat 2.8s ease-in-out infinite;
}

#hero-sprite.dim,
#dragon-sprite.dim {
  opacity: 0.72;
  filter: grayscale(0.15) brightness(0.92);
}

@keyframes dragonFloat {
  0% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
  100% { transform: translateY(0); }
}

#top-ui {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(1280px, 96vw);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  z-index: 5;
}

#stat-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 999px;
  background: rgba(9, 14, 34, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(7px);
}

#stat-bar span {
  font-size: 0.92rem;
  color: #e8f0ff;
}

#stat-bar b {
  color: #ffd7ea;
}

#controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 100%;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(26, 35, 65, 0.76);
  color: #f2f5ff;
  border-radius: 11px;
  padding: 8px 12px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 160ms ease, background 180ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: rgba(39, 54, 98, 0.94);
}

button.active {
  background: linear-gradient(120deg, #ff7fb0, #ff5597);
}

.volume-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: 11px;
  background: rgba(26, 35, 65, 0.76);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

#volume-slider {
  width: 80px;
}

#dialogue-panel {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(1280px, 96vw);
  min-height: 205px;
  z-index: 6;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px 20px 14px;
  cursor: pointer;
  backdrop-filter: blur(9px);
}

#speaker {
  font-weight: 700;
  color: #ffd3e6;
  margin-bottom: 8px;
  font-size: 1.05rem;
}

#dialogue-text {
  font-size: 1.07rem;
  line-height: 1.75;
  min-height: 76px;
  color: #f4f7ff;
}

#next-hint {
  margin-top: 8px;
  font-size: 0.83rem;
  color: var(--subtext);
  opacity: 0.85;
}

#choice-container {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.choice-btn {
  text-align: left;
  border: 1px solid rgba(255, 188, 220, 0.72);
  background: rgba(80, 35, 73, 0.5);
  border-radius: 12px;
  padding: 10px 13px;
  color: #fff0fa;
  line-height: 1.4;
}

.choice-btn:hover {
  background: rgba(124, 52, 112, 0.72);
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 6, 14, 0.76);
  z-index: 20;
}

.overlay.visible {
  display: flex;
}

.title-card,
.modal-card {
  width: min(920px, 95vw);
  max-height: 90vh;
  overflow: auto;
  padding: 28px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background:
    radial-gradient(circle at top right, rgba(255, 141, 194, 0.3), transparent 30%),
    radial-gradient(circle at 20% 0, rgba(131, 199, 255, 0.28), transparent 25%),
    rgba(10, 14, 37, 0.88);
  box-shadow: var(--shadow);
}

.title-card h1 {
  margin: 8px 0 12px;
  font-size: clamp(2rem, 4vw, 3rem);
}

.eyebrow {
  color: #ffd3e8;
  letter-spacing: 0.06em;
  margin: 0;
}

.subtitle {
  color: #d5dfff;
  line-height: 1.75;
}

.hint {
  color: #bfd3ff;
  font-size: 0.92rem;
}

.start-actions {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary {
  background: linear-gradient(120deg, var(--primary), var(--primary-strong));
  border: 1px solid rgba(255, 255, 255, 0.55);
}

#history-list,
#ending-list {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.history-item,
.ending-item {
  border: 1px solid rgba(194, 214, 255, 0.33);
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.55;
  background: rgba(16, 23, 53, 0.64);
}

.ending-item.locked {
  opacity: 0.6;
}

.ending-item h3 {
  margin: 0 0 4px;
  color: #ffd8eb;
  font-size: 1.02rem;
}

.modal-close {
  margin-top: 10px;
}

#toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  bottom: 26px;
  opacity: 0;
  pointer-events: none;
  background: rgba(13, 18, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 10px 14px;
  border-radius: 11px;
  transition: opacity 240ms ease, transform 240ms ease;
  z-index: 30;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 980px) {
  #character-stage {
    padding-bottom: calc(var(--dialogue-reserve) + 16px);
    align-items: center;
  }

  #hero-sprite {
    width: min(38vw, 320px);
  }

  #dragon-sprite {
    width: min(30vw, 220px);
  }

  #top-ui {
    flex-direction: column;
    align-items: stretch;
    width: 98vw;
    top: 8px;
    gap: 8px;
  }

  #controls {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  #controls button,
  .volume-wrap {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  #stat-bar {
    gap: 8px;
    padding: 8px 10px;
  }

  #stat-bar span {
    font-size: 0.85rem;
  }

  #dialogue-panel {
    min-height: 255px;
    bottom: 10px;
  }
}

@media (max-width: 680px) {
  #character-stage {
    justify-content: center;
    gap: 6px;
    padding: var(--top-ui-reserve) 8px calc(var(--dialogue-reserve) + 6px);
  }

  #hero-sprite {
    width: min(45vw, 250px);
  }

  #dragon-sprite {
    width: min(33vw, 170px);
  }

  .volume-wrap {
    width: auto;
    justify-content: flex-start;
  }

  #volume-slider {
    width: 140px;
  }

  .title-card,
  .modal-card {
    padding: 18px;
  }
}
