/* ==========================================================================
   HALLOWEEN MYSTERY V3 - GIAO DIỆN CHÍNH THỨC & STATE MACHINE
   Dựa sát bố cục, màu sắc và phong cách 3D hoạt hình từ ảnh tham chiếu:
   - Giao diện 1: Màn hình chào huyền diệu (Tím đêm, sao trăng, ma phù thủy)
   - Giao diện 2: Lựa chọn 3 cánh cổng (Bí ngô, Ngôi nhà ma, Lâu đài phép thuật)
   ========================================================================== */

/* 1. DESIGN TOKENS & BIẾN MÀU */
:root {
  /* Bảng màu chuẩn từ ảnh tham chiếu */
  --bg-deep-night: #10081e;
  --bg-purple-dark: #1b0e33;
  --bg-purple-card: #271444;
  --bg-purple-card-hover: #351c5c;

  --accent-gold: #ffbe59;
  --accent-orange: #ff893b;
  --accent-peach: #ff9e75;
  --accent-pink: #ff7bc6;
  --accent-purple-glow: #c78aff;
  --accent-yellow-light: #fff2b2;

  --text-pure: #ffffff;
  --text-soft: #fce8ff;
  --text-muted: #d0bee6;
  --text-dim: #9d8db3;

  /* Typography */
  --font-display: 'Fredoka', cursive, system-ui, sans-serif;
  --font-body: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Shadows & Glows */
  --glow-orange: 0 8px 30px rgba(255, 137, 59, 0.55);
  --glow-purple: 0 10px 35px rgba(199, 138, 255, 0.45);
  --glow-pink: 0 10px 35px rgba(255, 123, 198, 0.45);
  --shadow-card: 0 14px 40px rgba(0, 0, 0, 0.6);

  /* Headers */
  --header-height: clamp(50px, 6.5vh, 64px);

  /* Transitions */
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --ease-smooth: cubic-bezier(0.16, 1, 0.3, 1);
}

/* 2. RESET CƠ BẢN */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  background-color: var(--bg-deep-night);
  color: var(--text-pure);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden !important;
  position: fixed;
  inset: 0;
  -webkit-font-smoothing: antialiased;
}

/* Tiện ích tiếp cận */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--accent-gold);
  outline-offset: 3px;
}

/* 3. HEADER ĐIỀU KHIỂN CỐ ĐỊNH (COMPACT & GLASSMORPHIC) */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(16, 8, 30, 0.65);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(199, 138, 255, 0.2);
  z-index: 1000;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #ff9e42 0%, #ea580c 100%);
  border: 2px solid #ffd494;
  border-radius: 12px;
  font-size: 1.3rem;
  box-shadow: 0 4px 15px rgba(234, 88, 12, 0.4);
}

.brand-text {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #ffffff 0%, #ffcbe5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 6px rgba(199, 138, 255, 0.4));
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.mute-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0.4rem 1rem;
  background: rgba(43, 21, 75, 0.7);
  color: var(--text-soft);
  border: 1.5px solid rgba(199, 138, 255, 0.35);
  border-radius: 9999px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--ease-smooth);
}

.mute-btn:hover {
  background: rgba(70, 32, 120, 0.85);
  border-color: var(--accent-gold);
  box-shadow: 0 0 15px rgba(255, 190, 89, 0.35);
  transform: translateY(-1px);
}

.state-badge {
  display: none !important;
}

.state-badge span {
  font-weight: bold;
  color: var(--accent-gold);
}

/* ==========================================================================
   LỚP NỀN 3D TOÀN MÀN HÌNH (TASK 04C) - CHẠY PHÍA SAU WEBSITE VÀ GAME KẸO
   ========================================================================== */
.forest-3d-bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.forest-3d-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.forest-3d-viewport canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
}

.forest-3d-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(16, 8, 28, 0.4) 80%, rgba(8, 3, 16, 0.82) 100%);
  z-index: 1;
}

/* Khi cảnh 3D đã kích hoạt thành công: Cho phép cảnh 3D hiển thị xuyên qua */
body.has-3d-bg .welcome-bg-layer {
  background: radial-gradient(circle at 50% 40%, rgba(26, 11, 48, 0.25) 0%, rgba(16, 8, 30, 0.75) 90%);
}

body.has-3d-bg .game-bg-layer {
  background: radial-gradient(circle at 50% 35%, rgba(22, 11, 42, 0.3) 0%, rgba(10, 5, 20, 0.78) 95%);
}

/* 4. SÂN KHẤU CHÍNH (STAGE CONTAINER) */
.stage-container {
  height: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  position: relative;
  z-index: 2;
  overflow: hidden !important;
}

/* Quản lý ẩn hiện màn hình theo State Machine */
.screen {
  display: none;
  opacity: 0;
  width: 100%;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  transition: opacity 0.4s var(--ease-smooth);
}

.screen:not(.is-active) {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  max-height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  margin: 0 !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.screen.is-active {
  display: flex !important;
  opacity: 1 !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  height: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

/* ==========================================================================
   5. GIAO DIỆN 1: MÀN HÌNH CHÀO (WELCOME SCREEN)
   ========================================================================== */
.screen-welcome {
  position: relative;
  align-items: center;
  justify-content: center;
  padding: calc(var(--header-height) + clamp(0.25rem, 1vh, 0.75rem)) clamp(0.75rem, 2vw, 1.5rem) clamp(0.5rem, 1.2vh, 1rem);
  width: 100%;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  box-sizing: border-box;
}

.welcome-bg-layer {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 40%, rgba(26, 11, 48, 0.2) 0%, rgba(16, 8, 30, 0.8) 90%),
    url('../assets/images/welcome_bg.webp') center center / cover no-repeat;
  z-index: 1;
}

.magical-sparks-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.spark {
  position: absolute;
  color: var(--accent-gold);
  font-size: 1.2rem;
  filter: drop-shadow(0 0 8px var(--accent-gold));
  animation: sparkPulse 2.5s infinite ease-in-out;
}

.spark.s1 {
  top: 22%;
  left: 18%;
  animation-delay: 0s;
  font-size: 1.5rem;
}

.spark.s2 {
  top: 28%;
  right: 22%;
  animation-delay: 0.7s;
  color: var(--accent-pink);
}

.spark.s3 {
  bottom: 35%;
  left: 32%;
  animation-delay: 1.4s;
  font-size: 1.1rem;
}

.spark.s4 {
  top: 15%;
  right: 38%;
  animation-delay: 0.4s;
  font-size: 1.3rem;
}

.spark.s5 {
  bottom: 25%;
  right: 15%;
  animation-delay: 1.8s;
  color: var(--accent-purple-glow);
}

@keyframes sparkPulse {

  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }

  50% {
    opacity: 1;
    transform: scale(1.3) rotate(25deg);
  }
}

.welcome-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 1300px;
  max-height: calc(100dvh - var(--header-height) - 1rem);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto;
  box-sizing: border-box;
}

/* Nhân vật ma phù thủy nổi bên trái */
.welcome-side-character {
  position: absolute;
  left: clamp(0.75rem, 3.5vw, 3.5rem);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 5;
  pointer-events: none;
  width: clamp(90px, 15vw, 220px);
}

.floating-witch-ghost {
  width: 100%;
  max-width: 220px;
  height: auto;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.6)) drop-shadow(0 0 30px rgba(199, 138, 255, 0.35));
  animation: ghostFloat 3.8s ease-in-out infinite;
}

.character-shadow {
  width: 60%;
  height: 16px;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.6) 0%, transparent 70%);
  border-radius: 50%;
  margin-top: 10px;
  animation: shadowPulse 3.8s ease-in-out infinite;
}

@keyframes ghostFloat {

  0%,
  100% {
    transform: translateY(0) rotate(-1.5deg);
  }

  50% {
    transform: translateY(-18px) rotate(2deg);
  }
}

@keyframes shadowPulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 0.6;
  }

  50% {
    transform: scale(0.8);
    opacity: 0.3;
  }
}

/* Khối nội dung trung tâm */
.welcome-center-hero {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: min(680px, 92vw);
  margin: 0 auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.4rem, 1.8vh, 1.35rem);
}

.hero-top-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 1.4rem;
  background: rgba(39, 20, 68, 0.75);
  border: 1.5px solid rgba(255, 190, 89, 0.4);
  border-radius: 9999px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.hero-top-badge span {
  font-size: 1.4rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.welcome-title {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 4.8vw, 3.4rem);
  font-weight: 700;
  line-height: 1.25;
  color: #ffffff;
  text-shadow:
    0 4px 15px rgba(255, 123, 198, 0.55),
    0 10px 35px rgba(120, 40, 200, 0.65),
    0 2px 4px rgba(0, 0, 0, 0.8);
}

.title-hat-accent {
  display: inline-block;
  font-size: 1.1em;
  transform: rotate(-10deg) translateY(-4px);
  filter: drop-shadow(0 0 10px var(--accent-gold));
}

.welcome-intro-text {
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  color: var(--text-soft);
  max-width: 580px;
  line-height: 1.6;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

/* Nút hành động chính (Bắt đầu khám phá) */
.welcome-cta-wrap {
  margin-top: 0.5rem;
}

.btn-start-explore {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  min-height: 64px;
  padding: 0.85rem 2.75rem;
  background: linear-gradient(135deg, #ffaa66 0%, #ff833b 50%, #f46220 100%);
  color: #2e1003;
  border: none;
  border-radius: 9999px;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow:
    0 10px 30px rgba(244, 98, 32, 0.6),
    inset 0 3px 4px rgba(255, 255, 255, 0.8),
    inset 0 -3px 6px rgba(160, 45, 0, 0.4);
  transition: all 0.3s var(--ease-spring);
  position: relative;
  overflow: hidden;
}

.btn-start-explore::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -60%;
  width: 50%;
  height: 200%;
  background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: rotate(30deg);
  animation: btnShine 4s infinite linear;
}

@keyframes btnShine {
  0% {
    left: -60%;
  }

  35% {
    left: 130%;
  }

  100% {
    left: 130%;
  }
}

.btn-start-explore:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow:
    0 16px 40px rgba(244, 98, 32, 0.8),
    inset 0 3px 4px rgba(255, 255, 255, 0.9);
}

.btn-start-explore:active {
  transform: translateY(-1px) scale(0.99);
}

.btn-icon {
  font-size: 1.6rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.btn-arrow {
  font-size: 1.5rem;
  transition: transform 0.25s ease;
}

.btn-start-explore:hover .btn-arrow {
  transform: translateX(6px);
}

/* Biển gỗ bên phải - dạng ô vuông xinh xắn */
.welcome-side-sign {
  position: absolute;
  right: clamp(1rem, 3.5vw, 3.5rem);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 5;
  pointer-events: none;
  width: clamp(135px, 12vw, 175px);
}

.wooden-sign-board {
  width: 100%;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  padding: clamp(0.6rem, 1.3vh, 0.95rem) clamp(0.5rem, 0.9vw, 0.85rem);
  background: linear-gradient(145deg, #4d261b 0%, #32160e 100%);
  border: 3px solid #844c35;
  border-radius: 18px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.7), inset 0 0 12px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  transform: rotate(3deg);
  position: relative;
}

/* Đinh tán trang trí 4 góc bảng gỗ */
.wooden-sign-board::before,
.wooden-sign-board::after {
  content: '✦';
  position: absolute;
  font-size: 10px;
  color: #c48a58;
  opacity: 0.65;
  line-height: 1;
}

.wooden-sign-board::before {
  top: 7px;
  left: 8px;
}

.wooden-sign-board::after {
  bottom: 7px;
  right: 8px;
}

.sign-text {
  font-family: var(--font-display);
  font-size: clamp(0.78rem, 1vw, 0.92rem);
  color: #ffdeb8;
  line-height: 1.32;
  font-weight: 600;
  margin: 0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.sign-heart {
  display: inline-block;
  margin-top: 0.3rem;
  font-size: clamp(1.05rem, 1.3vw, 1.3rem);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.sign-post {
  width: 14px;
  height: clamp(24px, 4vh, 42px);
  background: linear-gradient(to right, #2b130c, #482317, #2b130c);
  border-radius: 4px;
  margin-top: -4px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   6. GIAO DIỆN 2: CHỌN 3 CÁNH CỔNG (DOOR SELECTION SCREEN)
   ========================================================================== */
.screen-door-select {
  position: relative;
  align-items: center;
  justify-content: center;
  padding: calc(var(--header-height) + 1rem) 1.5rem 2.5rem;
}

.doors-bg-layer {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 30%, rgba(26, 11, 48, 0.3) 0%, rgba(16, 8, 30, 0.85) 90%),
    url('../assets/images/doors_bg.webp') center center / cover no-repeat;
  z-index: 1;
}

.doors-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 1260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  margin: auto 0;
}

/* Bảng tiêu đề trang trí cổ tích */
.doors-storybook-plaque {
  position: relative;
  padding: 1rem 2.5rem 1.15rem;
  background: linear-gradient(180deg, #371b56 0%, #200f36 100%);
  border: 3px solid var(--accent-gold);
  border-radius: 28px;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.7),
    0 0 25px rgba(255, 190, 89, 0.25),
    inset 0 2px 4px rgba(255, 255, 255, 0.4);
  text-align: center;
  max-width: 680px;
  width: 90%;
}

.plaque-pumpkin-crest {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #ff9e42, #ea580c);
  border: 2px solid #ffd494;
  border-radius: 50%;
  font-size: 1.4rem;
  box-shadow: 0 4px 15px rgba(234, 88, 12, 0.6);
}

.plaque-stars {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 1.25rem;
  color: var(--accent-gold);
  font-size: 1.2rem;
}

.doors-main-title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3.2vw, 2.2rem);
  font-weight: 700;
  color: #ffffff;
  text-shadow:
    0 2px 10px rgba(255, 190, 89, 0.6),
    0 4px 20px rgba(199, 138, 255, 0.4);
  margin-top: 0.25rem;
}

.doors-main-subtitle {
  font-size: clamp(0.9rem, 1.6vw, 1.05rem);
  color: var(--text-soft);
  margin-top: 0.35rem;
  line-height: 1.4;
}

/* Lưới 3 Cánh Cổng (3-Door Grid) */
.doors-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 1.85rem;
  width: 100%;
}

/* Thẻ cánh cổng tương tác (Interactive Door Button) */
.door-card-btn {
  all: unset;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  transition: transform 0.35s var(--ease-spring);
}

.door-illustration-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  overflow: hidden;
  position: relative;
  border: 3.5px solid rgba(255, 190, 89, 0.35);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.6);
  background: var(--bg-purple-dark);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.door-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.45s var(--ease-smooth);
}

.door-inner-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 60%, rgba(255, 170, 70, 0.15) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* Bảng nhãn thông tin dưới chân cổng */
.door-info-plaque {
  position: relative;
  width: 90%;
  margin-top: -34px;
  z-index: 5;
  padding: 1.35rem 1rem 1rem;
  background: linear-gradient(180deg, #32174f 0%, #1c0d2e 100%);
  border: 2.5px solid var(--accent-gold);
  border-radius: 20px;
  box-shadow:
    0 10px 25px rgba(0, 0, 0, 0.7),
    inset 0 1px 3px rgba(255, 255, 255, 0.4);
  text-align: center;
  transition: all 0.3s ease;
}

.plaque-badge {
  position: absolute;
  top: -19px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4d237b 0%, #2b1149 100%);
  border: 2px solid var(--accent-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.badge-symbol {
  font-size: 1.15rem;
}

.door-card-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffeed6;
  margin-top: 0.2rem;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.door-card-desc {
  font-size: 0.88rem;
  color: var(--text-soft);
  margin-top: 0.3rem;
  line-height: 1.35;
}

/* Hiệu ứng Hover & Focus trên từng cổng */
.door-card-btn:hover {
  transform: translateY(-9px);
}

.door-card-btn:hover .door-img {
  transform: scale(1.06);
}

.door-card-btn:hover .door-inner-glow {
  opacity: 1;
}

/* Biến thể màu viền & ánh hào quang riêng cho từng cổng */
.door-pumpkin-card:hover .door-illustration-wrap {
  border-color: #ffa347;
  box-shadow: var(--glow-orange);
}

.door-pumpkin-card:hover .door-info-plaque {
  border-color: #ffa347;
  box-shadow: 0 8px 25px rgba(255, 140, 50, 0.4);
}

.door-cottage-card:hover .door-illustration-wrap {
  border-color: var(--accent-pink);
  box-shadow: var(--glow-pink);
}

.door-cottage-card:hover .door-info-plaque {
  border-color: var(--accent-pink);
  box-shadow: 0 8px 25px rgba(255, 123, 198, 0.4);
}

.door-castle-card:hover .door-illustration-wrap {
  border-color: var(--accent-purple-glow);
  box-shadow: var(--glow-purple);
}

.door-castle-card:hover .door-info-plaque {
  border-color: var(--accent-purple-glow);
  box-shadow: 0 8px 25px rgba(199, 138, 255, 0.4);
}

.door-card-btn:focus-visible {
  outline: 3px solid var(--accent-gold);
  border-radius: 26px;
}

/* ==========================================================================
   7. GIAO DIỆN GAMEPLAY: CƠN MƯA KẸO HALLOWEEN (TASK 04)
   ========================================================================== */
.screen-game-playing {
  position: relative;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  box-sizing: border-box;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--header-height) + clamp(0.4rem, 1vh, 0.75rem)) clamp(0.75rem, 2vw, 1.5rem) clamp(0.5rem, 1.2vh, 0.85rem);
  overflow: hidden;
}

.screen-game-playing.is-active {
  display: flex;
  opacity: 1;
}

.game-bg-layer {
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(circle at 50% 30%, rgba(26, 11, 48, 0.45) 0%, rgba(16, 8, 30, 0.92) 90%),
    url('../assets/images/doors_bg.webp') center center / cover no-repeat;
  z-index: 1;
}

.game-container {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 880px;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-height: 0;
  gap: 0.5rem;
}

/* Bảng HUD trên đỉnh màn chơi */
.game-hud {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 1.25rem;
  background: rgba(39, 20, 68, 0.85);
  backdrop-filter: blur(8px);
  border: 2px solid var(--accent-gold);
  border-radius: 9999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 15px rgba(255, 190, 89, 0.2);
  flex-shrink: 0;
}

.hud-score-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 1.6vw, 1.35rem);
  font-weight: 700;
  color: #ffffff;
}

.hud-candy-icon {
  font-size: 1.4rem;
  filter: drop-shadow(0 0 6px rgba(255, 123, 198, 0.7));
}

.hud-score-count {
  color: var(--accent-gold);
  text-shadow: 0 0 10px rgba(255, 190, 89, 0.8);
}

.hud-instructions {
  font-size: clamp(0.75rem, 1.1vw, 0.88rem);
  color: var(--text-soft);
  font-weight: 500;
}

.hud-inst-mobile {
  display: none;
}

/* Sân khấu chơi chính (Arena) */
.game-arena {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  background: rgba(18, 9, 34, 0.65);
  border: 2.5px solid rgba(199, 138, 255, 0.35);
  border-radius: 24px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
  box-shadow: 
    inset 0 0 35px rgba(0, 0, 0, 0.85),
    0 10px 30px rgba(0, 0, 0, 0.6);
}

.game-arena.is-dragging-basket {
  cursor: grabbing !important;
}

.game-items-layer,
.game-effects-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Chiếc giỏ hứng kẹo bí ngô */
.game-basket {
  position: absolute;
  bottom: 10px;
  left: 0;
  width: clamp(84px, 12vw, 105px);
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
  z-index: 20;
}

.game-basket:focus-visible {
  outline: 2px solid var(--accent-gold);
  border-radius: 16px;
}

.game-basket.is-dragging {
  cursor: grabbing;
}

/* Lớp vỏ bọc hình ảnh bên trong giỏ: Đảm bảo animation bounce/hit không ghi đè vị trí translateX của .game-basket */
.basket-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: center bottom;
  pointer-events: none;
}

.basket-img {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.8));
  pointer-events: none;
}

.basket-inner.basket-bounce {
  animation: basketPop 0.25s var(--ease-spring);
}

@keyframes basketPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15, 0.88); }
  100% { transform: scale(1); }
}

.basket-inner.basket-hit {
  animation: basketWobble 0.4s ease-in-out;
  filter: drop-shadow(0 0 25px #ff4757) drop-shadow(0 0 10px #ff793f) !important;
}

@keyframes basketWobble {
  0%, 100% { transform: scale(1) rotate(0deg); }
  20% { transform: scale(1.12) rotate(-12deg); }
  45% { transform: scale(1.15) rotate(12deg); }
  70% { transform: scale(1.08) rotate(-6deg); }
  85% { transform: scale(1.04) rotate(4deg); }
}

/* Hiệu ứng nổ bom hoạt hình tại đúng tọa độ va chạm thực tế */
.bomb-explosion-fx {
  position: absolute;
  pointer-events: none;
  z-index: 35;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.explosion-flash {
  position: absolute;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7ed 0%, #ff793f 35%, #ff4757 70%, transparent 100%);
  animation: explosionFlash 0.45s ease-out forwards;
}

.explosion-shockwave {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid #ff9f43;
  box-shadow: 0 0 20px #ff4757;
  animation: explosionShockwave 0.5s ease-out forwards;
}

.explosion-text {
  position: relative;
  z-index: 2;
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 
    0 0 12px #ff4757,
    0 0 25px #ff3838,
    0 3px 6px rgba(0, 0, 0, 0.9);
  animation: explosionPopText 0.6s var(--ease-spring) forwards;
}

@keyframes explosionFlash {
  0% { transform: scale(0.2); opacity: 1; }
  60% { transform: scale(1.3); opacity: 0.9; }
  100% { transform: scale(1.6); opacity: 0; }
}

@keyframes explosionShockwave {
  0% { transform: scale(0.3); opacity: 1; border-width: 6px; }
  100% { transform: scale(2.2); opacity: 0; border-width: 1px; }
}

@keyframes explosionPopText {
  0% { transform: scale(0.2) rotate(-10deg); opacity: 0; }
  35% { transform: scale(1.25) rotate(4deg); opacity: 1; }
  75% { transform: scale(1.1) rotate(0deg); opacity: 1; }
  100% { transform: scale(1) translateY(-18px); opacity: 0; }
}

/* Vật thể rơi */
.falling-item {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  will-change: transform;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
}

.falling-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.item-candy img {
  filter: drop-shadow(0 0 10px rgba(255, 123, 198, 0.65));
}

.item-bomb img {
  filter: drop-shadow(0 0 12px rgba(255, 87, 87, 0.75));
}

.item-caught {
  transition: transform 0.15s ease-out, opacity 0.15s ease-out !important;
  transform: scale(1.4) !important;
  opacity: 0 !important;
}

/* Hiệu ứng nổi điểm +1 🍬 */
.catch-popup-text {
  position: absolute;
  pointer-events: none;
  z-index: 30;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: #ffd166;
  text-shadow: 
    0 0 10px rgba(255, 209, 102, 0.8),
    0 2px 4px rgba(0, 0, 0, 0.8);
  animation: floatUpFade 0.6s ease-out forwards;
}

@keyframes floatUpFade {
  0% {
    opacity: 1;
    transform: translate(-50%, 0) scale(0.8);
  }
  50% {
    transform: translate(-50%, -25px) scale(1.2);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -45px) scale(1);
  }
}

/* Các màn hình kết thúc tạm thời (Pending screens) */
.victory-box {
  background: rgba(30, 16, 56, 0.92);
  border-color: var(--accent-gold);
  box-shadow: 0 0 30px rgba(255, 190, 89, 0.35);
}

.victory-icon, .bomb-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.victory-title {
  color: #ffd494;
}

.bomb-box {
  background: rgba(32, 10, 25, 0.92);
  border-color: #ff6b6b;
  box-shadow: 0 0 30px rgba(255, 107, 107, 0.35);
}

.bomb-title {
  color: #ff6b6b;
}

.pending-notice {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
}

/* ==========================================================================
   8. CÁC MÀN HÌNH KHÁC (GIỮ NGUYÊN KHUNG STATE MACHINE CỦA TASK 02)
   ========================================================================== */
#screen-door-opening.is-active,
#screen-forest-cute.is-active,
#screen-forest-creepy.is-active,
#screen-forest-warning.is-active,
#screen-jumpscare.is-active,
#screen-outro.is-active {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  height: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  padding: calc(var(--header-height) + clamp(0.4rem, 1vh, 0.85rem)) clamp(0.75rem, 2vw, 1.5rem) clamp(0.5rem, 1.2vh, 1rem) !important;
}

.screen-content {
  width: 100%;
  max-width: 620px;
  max-height: calc(100dvh - var(--header-height) - 1.5rem);
  margin: auto;
  padding: clamp(1rem, 2.5vh, 2rem) clamp(1rem, 2.5vw, 1.75rem);
  background: rgba(39, 20, 68, 0.88);
  border: 1.5px solid rgba(199, 138, 255, 0.25);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(0.6rem, 1.5vh, 1.25rem);
  backdrop-filter: blur(12px);
  overflow-y: auto;
  box-sizing: border-box;
}

.screen-title {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  color: var(--text-soft);
  font-weight: 700;
}

.screen-desc {
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 500px;
}

.door-animation-placeholder,
.forest-cute-placeholder,
.forest-creepy-placeholder,
.warning-placeholder,
.jumpscare-placeholder,
.outro-placeholder {
  font-size: 2.5rem;
  letter-spacing: 0.25rem;
}

.screen-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  width: 100%;
  margin-top: 0.5rem;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.65rem 1.75rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 14px;
  cursor: pointer;
  border: none;
  transition: all 0.25s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-orange), #ea580c);
  color: #fff;
  box-shadow: 0 4px 18px rgba(234, 88, 12, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(234, 88, 12, 0.6);
}

.btn-secondary {
  background: rgba(199, 138, 255, 0.2);
  color: var(--text-soft);
  border: 1px solid var(--accent-purple-glow);
}

.btn-secondary:hover {
  background: rgba(199, 138, 255, 0.35);
  transform: translateY(-2px);
}

.btn-danger {
  background: linear-gradient(135deg, #ff6b6b, #c92a2a);
  color: #fff;
}

.jumpscare-box {
  background: rgba(12, 5, 22, 0.95);
  border-color: rgba(255, 107, 107, 0.4);
}

.jumpscare-title {
  color: #ff6b6b;
}

/* ==========================================================================
   8. RESPONSIVE DESIGN (MOBILE & TABLET TỐI ƯU)
   ========================================================================== */
@media (max-width: 1024px) {
  .welcome-side-character {
    left: clamp(0.5rem, 2vw, 1.5rem);
    width: clamp(80px, 12vw, 140px);
  }

  .welcome-side-sign {
    right: clamp(0.5rem, 2vw, 1.5rem);
    width: clamp(120px, 13vw, 150px);
  }

  .doors-grid {
    gap: 1.25rem;
  }
}

@media (max-width: 900px) {
  .welcome-side-sign {
    display: none !important;
  }
}

@media (max-width: 820px) {
  .welcome-container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: clamp(0.25rem, 1.2vh, 0.75rem);
  }

  .welcome-side-character {
    position: static !important;
    transform: none !important;
    order: 1;
    flex: 0 0 auto;
    width: auto;
    max-width: clamp(70px, 14vh, 100px);
    margin: 0 auto;
  }

  .floating-witch-ghost {
    max-width: clamp(65px, 13vh, 95px);
    height: auto;
  }

  .character-shadow {
    width: clamp(45px, 8vh, 70px);
    height: 8px;
    margin-top: 2px;
  }

  .welcome-center-hero {
    position: static;
    order: 2;
    gap: clamp(0.35rem, 1.2vh, 0.85rem);
    max-width: 92%;
  }

  .hero-top-badge {
    padding: clamp(0.2rem, 0.8vh, 0.35rem) clamp(0.6rem, 2vw, 1rem);
    font-size: clamp(0.75rem, 1.5vh, 0.9rem);
  }

  .hero-top-badge span {
    font-size: clamp(0.9rem, 2vh, 1.2rem);
  }

  .welcome-title {
    font-size: clamp(1.25rem, 3.5vh, 1.85rem);
    line-height: 1.2;
  }

  .welcome-intro-text {
    font-size: clamp(0.8rem, 1.8vh, 0.95rem);
    line-height: 1.35;
    max-width: 340px;
  }

  .welcome-cta-wrap {
    margin-top: clamp(0.2rem, 1vh, 0.5rem);
  }

  .btn-start-explore {
    min-height: clamp(44px, 6.5vh, 54px);
    padding: clamp(0.45rem, 1.2vh, 0.75rem) clamp(1.25rem, 3vw, 2rem);
    font-size: clamp(0.95rem, 2.2vh, 1.15rem);
    width: auto;
    max-width: 100%;
  }

  .welcome-side-sign {
    order: 3;
    flex: 0 0 auto;
    display: none; /* Ẩn biển gỗ trên mobile để tối ưu hóa không gian dọc, không gây cuộn */
  }

  .sign-post {
    display: none;
  }

  /* Chuyển 3 Cổng thành cột cân đối trên Mobile */
  .doors-grid {
    grid-template-columns: 1fr;
    max-width: 380px;
    gap: 1.5rem;
  }

  .doors-storybook-plaque {
    padding: 1rem 1.25rem;
    width: 95%;
  }

  .plaque-stars {
    padding: 0 0.75rem;
  }
}

@media (max-width: 600px) {
  .game-hud {
    padding: 0.35rem 0.85rem;
  }

  .hud-inst-desktop {
    display: none;
  }

  .hud-inst-mobile {
    display: inline;
    font-size: clamp(0.72rem, 2.2vw, 0.82rem);
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 0 0.85rem;
  }

  .brand-text {
    font-size: 1.1rem;
  }

  .mute-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 380px) {
  .brand-text {
    font-size: 0.95rem;
  }

  .brand-badge-icon {
    width: 32px;
    height: 32px;
    font-size: 1.1rem;
  }

  .mute-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
  }
}

@media (max-height: 720px) {
  :root {
    --header-height: clamp(46px, 7vh, 56px);
  }

  .welcome-side-character {
    width: clamp(70px, 13vh, 120px);
  }

  .welcome-side-sign {
    width: clamp(120px, 18vh, 150px);
  }

  .floating-witch-ghost {
    max-width: clamp(65px, 12vh, 100px);
  }

  .character-shadow {
    width: clamp(45px, 8vh, 75px);
    height: 8px;
  }

  .welcome-title {
    font-size: clamp(1.25rem, 3.5vh, 1.75rem);
  }

  .welcome-center-hero {
    gap: clamp(0.3rem, 1.2vh, 0.75rem);
  }
}

/* ==========================================================================
   9. HỖ TRỢ PREFERS-REDUCED-MOTION (A11Y)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }

  .floating-witch-ghost,
  .character-shadow,
  .spark,
  .btn-start-explore::after {
    animation: none !important;
  }

  .door-card-btn:hover {
    transform: none !important;
  }

  .door-card-btn:hover .door-img {
    transform: none !important;
  }
}