/**
 * NiHao HSK - Little Cat Mascot (小猫) & Chinese Culture Notification System
 * Phong cách thiết kế Á Đông ấm áp kết hợp biểu tượng chú mèo Tiểu Miêu (小猫):
 * - Linh vật: Chú mèo đen Tiểu Miêu (小猫 🐱) mắt hổ phách thông minh, nũng nịu nhắc học
 * - Biểu tượng: Chú mèo ngắm trăng tròn (cat-moon) & Chú mèo con đáng yêu (cat-cute)
 * - Tông màu: Vàng hổ phách (#f59e0b), Cam vầng trăng (#ea580c), Đỏ son (#e11d48), Đen tuyền (#0f172a)
 * - Nút bấm 3D nổi khối sang trọng, bóng đổ đậm chất Á Đông cao cấp
 */

/* ================================================================
   1. PROMPT BANNER / GỢI Ý BẬT THÔNG BÁO TỰ ĐỘNG KHI VÀO WEB
   ================================================================ */
.panda-prompt-banner,
.cat-prompt-banner {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(140px);
  z-index: 10001;
  background: #ffffff;
  border: 2.5px solid #fed7aa; /* Viền cam hổ phách ấm áp */
  border-radius: 24px;
  padding: 16px 20px;
  max-width: 520px;
  width: calc(100% - 32px);
  box-shadow: 0 16px 36px rgba(234, 88, 12, 0.16), 0 4px 0 #fdba74;
  display: flex;
  align-items: center;
  gap: 16px;
  box-sizing: border-box;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.panda-prompt-banner.show,
.cat-prompt-banner.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.panda-prompt-avatar,
.cat-prompt-avatar {
  width: 68px;
  height: 68px;
  flex-shrink: 0;
  background: radial-gradient(circle, #fff7ed 60%, #ffedd5 100%);
  border: 2px solid #fed7aa;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-sizing: border-box;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.1));
}

.cat-prompt-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  animation: catWiggle 3.2s infinite ease-in-out;
}

@keyframes catWiggle {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-3px) rotate(-4deg); }
  75% { transform: translateY(-1px) rotate(4deg); }
}

.panda-prompt-content {
  flex: 1;
  min-width: 0;
}

.panda-prompt-title {
  margin: 0 0 4px;
  font-size: 15.5px;
  font-weight: 800;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 6px;
}

.panda-prompt-desc {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: #64748b;
}

.panda-prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.panda-btn-allow,
.cat-btn-allow {
  background: linear-gradient(135deg, #ea580c, #c2410c);
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 #9a3412;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.panda-btn-allow:hover,
.cat-btn-allow:hover {
  filter: brightness(1.08);
}

.panda-btn-allow:active,
.cat-btn-allow:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 #9a3412;
}

.panda-btn-dismiss {
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  color: #64748b;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 0 #cbd5e1;
  transition: all 0.15s ease;
}

.panda-btn-dismiss:hover {
  background: #f1f5f9;
  color: #334155;
}

.panda-btn-dismiss:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 #cbd5e1;
}

/* ================================================================
   2. POPUP MODAL DIALOG - TIỂU MIÊU (小猫)
   ================================================================ */
.panda-popup-overlay,
.cat-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.panda-popup-overlay.active,
.cat-popup-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.panda-card,
.cat-card {
  position: relative;
  background: #ffffff;
  background-image: radial-gradient(#fff7ed 1.2px, transparent 1.2px);
  background-size: 18px 18px;
  width: 100%;
  max-width: 450px;
  border: 2.5px solid #fed7aa;
  border-radius: 28px;
  padding: 28px 24px 22px;
  box-shadow: 0 20px 50px rgba(234, 88, 12, 0.2), 0 5px 0 #f97316;
  text-align: center;
  transform: translateY(30px) scale(0.92);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-sizing: border-box;
}

.panda-popup-overlay.active .panda-card,
.cat-popup-overlay.active .cat-card {
  transform: translateY(0) scale(1);
}

/* Nút đóng góc phải */
.panda-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid #fed7aa;
  background: #fff7ed;
  color: #ea580c;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.panda-close-btn:hover {
  background: #ea580c;
  border-color: #c2410c;
  color: #ffffff;
  transform: scale(1.08);
}

/* Khung linh vật Tiểu Miêu */
.panda-mascot-wrapper,
.cat-mascot-wrapper {
  position: relative;
  width: 145px;
  height: 145px;
  margin: -14px auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cat-mascot-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.16));
  animation: catFloat 3.2s infinite ease-in-out;
  cursor: pointer;
  transition: transform 0.25s ease;
}

.cat-mascot-img:hover {
  transform: scale(1.06);
}

.cat-mascot-img.moon-mode {
  filter: drop-shadow(0 12px 24px rgba(234, 88, 12, 0.3));
}

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

/* Ấn triện đỏ vuông góc dưới linh vật */
.panda-seal-badge,
.cat-seal-badge {
  position: absolute;
  bottom: 0;
  right: 6px;
  background: #be123c;
  color: #fef08a;
  border: 2px solid #fed7aa;
  box-shadow: 0 3px 0 #881337;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 900;
  font-family: STKaiti, KaiTi, 'KaiTi SC', serif;
  letter-spacing: 1px;
  animation: catBadgePop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes catBadgePop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* Bong bóng thoại phong cách Thư pháp Á Đông */
.panda-bubble,
.cat-bubble {
  position: relative;
  background: #fffaf5;
  border: 2px solid #fed7aa;
  border-radius: 20px;
  padding: 16px 18px;
  margin-bottom: 20px;
  text-align: left;
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.05);
}

.panda-bubble::after,
.panda-bubble::before,
.cat-bubble::after,
.cat-bubble::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 0 10px 12px 10px;
  border-style: solid;
  border-color: transparent transparent #fffaf5 transparent;
  display: block;
  width: 0;
}

.panda-bubble::before,
.cat-bubble::before {
  top: -15px;
  border-color: transparent transparent #fed7aa transparent;
}

.panda-title {
  margin: 0 0 6px;
  font-size: 18.5px;
  font-weight: 900;
  color: #1e293b;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panda-message {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.55;
  color: #475569;
  font-weight: 500;
}

/* Thanh hiển thị Chuỗi ngày & Điểm XP */
.panda-stats-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
}

.panda-stat-pill {
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 800;
  color: #334155;
  box-shadow: 0 3px 0 #e2e8f0;
}

.panda-stat-pill.streak {
  border-color: #fed7aa;
  color: #c2410c;
  background: #fff7ed;
  box-shadow: 0 3px 0 #fed7aa;
}

.panda-stat-pill.xp {
  border-color: #fde68a;
  color: #b45309;
  background: #fefce8;
  box-shadow: 0 3px 0 #fde68a;
}

/* Nút bấm 3D nổi khối phong cách NiHao HSK */
.panda-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panda-btn {
  width: 100%;
  padding: 13px 20px;
  border-radius: 16px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.6px;
  cursor: pointer;
  border: none;
  outline: none;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
  user-select: none;
}

/* Nút chính sắc Cam Vầng Trăng & Đỏ Hán Tự */
.panda-btn-primary,
.cat-btn-primary {
  background: linear-gradient(135deg, #ea580c, #c2410c);
  color: #ffffff;
  box-shadow: 0 4px 0 #9a3412;
}

.panda-btn-primary:hover,
.cat-btn-primary:hover {
  filter: brightness(1.08);
}

.panda-btn-primary:active,
.cat-btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #9a3412;
}

/* Nút màu Cam Lửa Chuỗi ngày */
.panda-btn-orange {
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #ffffff;
  box-shadow: 0 4px 0 #c2410c;
}

.panda-btn-orange:hover {
  filter: brightness(1.06);
}

.panda-btn-orange:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #c2410c;
}

/* Nút phụ Viền Thư Pháp */
.panda-btn-secondary {
  background: #ffffff;
  color: #64748b;
  border: 2px solid #cbd5e1;
  box-shadow: 0 4px 0 #cbd5e1;
}

.panda-btn-secondary:hover {
  background: #f8fafc;
  color: #334155;
}

.panda-btn-secondary:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 #cbd5e1;
}

/* ================================================================
   3. TOAST THÔNG BÁO GÓC MÀN HÌNH (TIỂU MIÊU)
   ================================================================ */
.panda-toast,
.cat-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  background: #ffffff;
  border: 2.5px solid #f97316;
  border-radius: 22px;
  padding: 14px 18px;
  box-shadow: 0 14px 35px rgba(234, 88, 12, 0.2), 0 4px 0 #ea580c;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 400px;
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-sizing: border-box;
}

.panda-toast.show,
.cat-toast.show {
  transform: translateX(0);
}

.panda-toast-mascot,
.cat-toast-mascot {
  width: 54px;
  height: 54px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cat-toast-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
}

.panda-toast-content {
  flex: 1;
  text-align: left;
}

.panda-toast-title {
  margin: 0 0 3px;
  font-size: 14.5px;
  font-weight: 800;
  color: #1e293b;
}

.panda-toast-body {
  margin: 0;
  font-size: 12.5px;
  color: #475569;
  line-height: 1.4;
}

.panda-toast-close {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.panda-toast-close:hover {
  color: #ea580c;
  background: #ffedd5;
}

/* ================================================================
   4. NÚT TRÒN LINH VẬT TIỂU MIÊU GÓC PHẢI DƯỚI (FLOATING WIDGET)
   ================================================================ */
/* Khi dock nghe thụ động mở, ẩn widget mèo nổi để không che giao diện nghe */
/* Nâng nhẹ widget linh vật nổi khi thanh TTS Audio đang phát ở góc dưới */
body:has(.hsk-audio-status:not([hidden])) .panda-floating-widget,
body:has(.hsk-audio-status:not([hidden])) .cat-floating-widget {
  bottom: calc(128px + env(safe-area-inset-bottom, 0px));
}

body.immersion-card-open .panda-floating-widget,
body.immersion-card-open .cat-floating-widget {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translateY(12px) scale(0.85);
}

.panda-floating-widget,
.cat-floating-widget {
  position: fixed;
  bottom: 82px;
  right: 24px;
  z-index: 9980;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
  transition: bottom 0.25s ease, right 0.25s ease, opacity 0.2s ease, transform 0.2s ease;
}

.panda-floating-btn,
.cat-floating-btn {
  pointer-events: auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #ffffff;
  border: 2.5px solid #f97316;
  box-shadow: 0 8px 25px rgba(234, 88, 12, 0.32), 0 4px 0 #c2410c;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  box-sizing: border-box;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.panda-floating-btn:hover,
.cat-floating-btn:hover {
  transform: scale(1.14) rotate(-5deg);
}

.panda-floating-btn:active,
.cat-floating-btn:active {
  transform: translateY(3px) scale(1.05);
  box-shadow: 0 1px 0 #c2410c;
}

.cat-floating-icon {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.panda-floating-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ea580c;
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 900;
  border-radius: 999px;
  padding: 2px 6px;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.4);
  animation: catPulse 1.8s infinite;
}

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

.panda-floating-hint,
.cat-floating-hint {
  pointer-events: auto;
  background: #ffffff;
  border: 2px solid #fed7aa;
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.14), 0 3px 0 #fdba74;
  border-radius: 14px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 800;
  color: #c2410c;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
}

/* ================================================================
   5. BỘ CHỌN & LƯU GIỜ NHẮC HỌC (CONTROL CARD)
   ================================================================ */
.cat-time-preset-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.cat-time-preset-btn {
  background: #ffffff;
  border: 1.5px solid #fed7aa;
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #c2410c;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.cat-time-preset-btn:hover {
  background: #fff7ed;
  border-color: #f97316;
  transform: translateY(-1px);
}

.cat-time-preset-btn.active {
  background: #ea580c;
  color: #ffffff;
  border-color: #c2410c;
  box-shadow: 0 2px 0 #9a3412;
}

.cat-time-saved-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #15803d;
  background: #dcfce7;
  border: 1px solid #86efac;
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 11.5px;
  font-weight: 800;
  animation: catFadeIn 0.25s ease;
}

@keyframes catFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .panda-prompt-banner,
  .cat-prompt-banner {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding: 14px 16px;
    flex-direction: column;
    text-align: center;
    gap: 10px;
    width: calc(100% - 24px);
    z-index: 10005;
  }
  .panda-prompt-actions {
    width: 100%;
    justify-content: center;
  }
  .panda-card,
  .cat-card {
    border-radius: 22px;
    padding: 22px 18px 18px;
  }
  /* Bố trí widget linh vật nổi phía trên nút nghe thụ động, không bao giờ bị đè */
  .panda-floating-widget,
  .cat-floating-widget {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    gap: 0;
    z-index: 9980;
  }
  .panda-floating-btn,
  .cat-floating-btn {
    width: 46px;
    height: 46px;
    padding: 2px;
    box-shadow: 0 4px 14px rgba(234, 88, 12, 0.28), 0 2px 0 #c2410c;
  }
  /* Trên mobile ẩn nhãn chữ nổi để tránh chiếm ngang màn hình và không đè nút khác */
  .panda-floating-hint,
  .cat-floating-hint {
    display: none !important;
  }
  .panda-floating-badge {
    top: -3px;
    right: -3px;
    font-size: 9.5px;
    padding: 1px 5px;
  }
  /* Toast thông báo đẩy lên trên cùng trên mobile giống thông báo hệ thống */
  .panda-toast,
  .cat-toast {
    bottom: auto;
    top: calc(14px + env(safe-area-inset-top, 0px));
    left: 14px;
    right: 14px;
    max-width: none;
    transform: translateY(-130%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  }
  .panda-toast.show,
  .cat-toast.show {
    transform: translateY(0);
  }
}
