/* =========================================================================================
 * 🌟 MAIN STYLES - MOBILE-FIRST & 100DVH OPTIMIZED
 * ========================================================================================= */
@import url('https://fonts.googleapis.com/css2?family=Dancing+Script:wght@700&family=Quicksand:wght@500;600;700&display=swap');

:root {
  --primary-pink: #ff4081;
  --accent-gold: #ffd54f;
  --bg-dark: #070415;
  --text-light: #ffffff;
  --app-height: 100dvh;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  height: var(--app-height);
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: 'Quicksand', sans-serif;
  color: var(--text-light);
  touch-action: none; /* Ngăn iOS Safari tự zoom/cuộn */
  overscroll-behavior: none;
}

#webgl-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: var(--app-height);
  z-index: 1;
}

/* =========================================================================================
 * 📱 TOP NAVIGATION: THANH ĐIỀU HƯỚNG 5 ĐẢO CHUYÊN NGHIỆP
 * ========================================================================================= */
.top-nav {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(18, 10, 32, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 6px 10px;
  border-radius: 30px;
  border: 1px solid rgba(255, 215, 0, 0.35);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  max-width: 95vw;
  overflow-x: auto;
  scrollbar-width: none;
}
.top-nav::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-family: 'Quicksand', sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.nav-tab.active {
  background: linear-gradient(135deg, #ff4081, #7b1fa2);
  color: #fff;
  box-shadow: 0 0 15px rgba(255, 64, 129, 0.6);
  transform: scale(1.04);
}

.nav-tab.locked {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.6);
}

.nav-tab.locked:hover {
  background: transparent;
  color: rgba(255, 255, 255, 0.45);
}

/* Điện thoại: đủ chỗ cho cả 5 đảo. Đảo đang xem hiện cả biểu tượng lẫn tên, các đảo khác chỉ hiện biểu tượng */
@media (max-width: 600px) {
  .top-nav {
    gap: 4px;
    padding: 5px 7px;
  }
  .nav-tab {
    padding: 6px 10px;
    font-size: 12.5px;
  }
  .nav-tab:not(.active) .nav-label {
    display: none;
  }
  .nav-tab .nav-icon {
    font-size: 15px;
  }
}

/* NÚT ÂM THANH & CÔNG CỤ */
.hud-btn {
  position: fixed;
  bottom: 22px;
  right: 20px;
  z-index: 50;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(24, 12, 40, 0.85);
  border: 1.5px solid rgba(255, 215, 0, 0.5);
  color: #ffd54f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: transform 0.2s, background 0.3s;
}
.hud-btn:active {
  transform: scale(0.9);
}
.hud-btn.playing {
  animation: spinSlow 8s linear infinite;
  border-color: #ff4081;
  color: #ff4081;
}

@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* DÒNG GỢI Ý CHẠY CHỮ DƯỚI ĐÁY */
.bottom-hint {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  background: rgba(10, 6, 20, 0.65);
  padding: 6px 18px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  white-space: nowrap;
  transition: opacity 0.4s ease;
}

/* NÚT CHUYỂN ĐẢO KẾ TIẾP (STORY MODE NEXT BUTTON) */
.story-next-island-btn {
  position: fixed;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content; /* left: 50% làm nút tự co còn nửa màn hình, chữ bị xuống dòng */
  max-width: calc(100vw - 24px);
  white-space: nowrap;
  z-index: 45;
  background: linear-gradient(135deg, #ffd54f, #ff80ab);
  color: #211200;
  border: none;
  padding: 10px 24px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 6px 25px rgba(255, 213, 79, 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: pulseGlow 2.5s infinite;
}
.story-next-island-btn:active {
  transform: translateX(-50%) scale(0.95);
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 15px rgba(255, 213, 79, 0.4); }
  50% { box-shadow: 0 0 30px rgba(255, 128, 171, 0.8); }
}

/* =========================================================================================
 * 🕯️ BẢNG THỔI NẾN (ĐẢO SINH NHẬT)
 * ========================================================================================= */
.blow-hud {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 24px);
  width: min(92vw, 420px);
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(18, 10, 32, 0.82);
  border: 1px solid rgba(255, 213, 79, 0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 0 18px rgba(255, 167, 38, 0.25);
  color: #fff;
  text-align: center;
  z-index: 120;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.blow-hud.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}
.blow-hud-text {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
}
.blow-meter {
  height: 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
  margin-bottom: 12px;
}
.blow-meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, #80deea, #ffd54f, #ff7043);
  transition: width 0.08s linear;
}
.blow-hud-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.blow-hud-btn {
  flex: 1 1 140px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.blow-hud-btn.primary {
  border: none;
  background: linear-gradient(135deg, #ffd54f, #ff80ab);
  color: #211200;
}
.blow-hud-btn:active {
  transform: scale(0.97);
}

/* =========================================================================================
 * 🎬 CÂU CHUYỆN ĐẢO HÌNH THÀNH: khung thoại Heri & Shin-e (giống phong cách video cũ)
 * ========================================================================================= */
.story-sub-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.story-sub-wrap.active {
  opacity: 1;
}

.story-sub {
  position: absolute;
  left: 0;
  top: 0;
  max-width: min(76vw, 330px);
  width: max-content;
  background: #fffaf3;
  border: 3px solid #ff8fb6;
  border-radius: 18px;
  padding: 8px 14px 10px;
  color: #3a2236;
  font-family: "Quicksand", sans-serif;
  box-shadow: 0 6px 18px rgba(20, 8, 30, 0.45);
  opacity: 0;
  pointer-events: none;
  will-change: transform;
  transition: opacity 0.2s ease;
}

.story-sub-wrap.active .story-sub.show {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
  animation: bubblePop 0.28s cubic-bezier(0.2, 1.5, 0.4, 1);
}

@keyframes bubblePop {
  0% { scale: 0.7; }
  100% { scale: 1; }
}

.story-sub.shine {
  border-color: #ffc247;
}

/* Đuôi khung thoại: hai tam giác chồng nhau (viền màu + lõi kem) chỉ xuống nhân vật */
.story-sub-tail {
  position: absolute;
  bottom: -14px;
  width: 0;
  height: 0;
  margin-left: -11px;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 14px solid #ff8fb6;
}

.story-sub-tail::after {
  content: "";
  position: absolute;
  left: -7px;
  top: -18px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid #fffaf3;
}

.story-sub.shine .story-sub-tail {
  border-top-color: #ffc247;
}

.story-sub-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 1px;
  color: #e8467c;
}

.story-sub.shine .story-sub-name {
  color: #d88a00;
}

.story-sub-text {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.4;
}

.story-controls {
  position: absolute;
  top: calc(66px + env(safe-area-inset-top, 0px));
  right: 12px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.story-btn {
  background: rgba(18, 10, 32, 0.78);
  border: 1px solid rgba(255, 213, 79, 0.5);
  color: #ffe08a;
  font-family: "Quicksand", sans-serif;
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 18px;
  cursor: pointer;
}

/* Trong lúc diễn: ẩn nút sang đảo kế và dòng gợi ý để khung thoại không bị che */
body.story-mode .story-next-island-btn,
body.story-mode .bottom-hint {
  visibility: hidden;
  pointer-events: none;
}

/* Mới vào web (màn chào) cho tới khi xem xong câu chuyện Đảo Hình Thành: chưa hiện nút sang Đảo Kỷ Niệm */
body.pre-story .story-next-island-btn,
body.pre-party .story-next-island-btn {
  visibility: hidden;
  pointer-events: none;
}

/* =========================================================================================
 * 🧭 HERI & SHIN-E DẪN ĐƯỜNG: dòng "chạm để nghe tiếp" và nút sang đảo kế nhấp nháy khi đã xong đảo
 * ========================================================================================= */
.guide-wrap {
  z-index: 55;
}

.guide-more {
  margin-top: 3px;
  font-size: 10.5px;
  font-weight: 700;
  text-align: right;
  opacity: 0.55;
}

.story-next-island-btn.guide-pulse {
  animation: pulseGlow 2.5s infinite, guidePulse 1.4s ease-in-out infinite;
}

@keyframes guidePulse {
  0%, 100% { scale: 1; }
  50% { scale: 1.07; }
}

/* Khung thoại nằm dưới chân nhân vật: đuôi lật lên trên */
.story-sub.below .story-sub-tail {
  bottom: auto;
  top: -14px;
  border-top: none;
  border-bottom: 14px solid #ff8fb6;
}

.story-sub.below .story-sub-tail::after {
  top: 4px;
  border-top: none;
  border-bottom: 10px solid #fffaf3;
}

.story-sub.shine.below .story-sub-tail {
  border-bottom-color: #ffc247;
}
