/* ============================================================
   米奇学习大闯关 - 组件样式系统
   包含：导航栏、弹窗、Toast、加载、骨架屏、空状态、错误状态、
        徽章、进度条、标签页、输入框组、标签芯片
   ============================================================ */

/* ============================================================
   1. 导航栏 navbar
   ============================================================ */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(64px + var(--safe-top, 0px));
  padding: var(--safe-top, 0px) 20px 0;
  background-color: #ffffff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: var(--shadow-soft);
}

/* 导航栏左侧：Logo 区 */
.navbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: linear-gradient(135deg, var(--color-bg-blue), var(--color-bg-green));
  border-radius: var(--radius-button);
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-text-dark);
}

/* 导航栏中间：导航项容器 */
.navbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 导航项：图标 + 文字 */
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 64px;
  min-height: var(--min-touch);
  padding: 6px 12px;
  border-radius: var(--radius-small);
  color: var(--color-text-light);
  font-size: 0.75rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}

.nav-item svg,
.nav-item .nav-icon {
  width: 24px;
  height: 24px;
}

/* 导航项悬停 */
.nav-item:hover {
  background-color: var(--color-bg-blue);
  color: var(--color-primary-blue);
}

/* 导航项激活态高亮 */
.nav-item.active {
  background-color: var(--color-bg-blue);
  color: var(--color-primary-blue);
  font-weight: 700;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background-color: var(--color-primary-blue);
  border-radius: 2px;
}

.nav-item {
  position: relative;
}

/* 导航栏右侧：用户信息 */
.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 用户名 */
.navbar-username {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-dark);
}

/* 积分徽章 */
.navbar-points {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: linear-gradient(135deg, var(--color-accent-yellow), var(--color-accent-orange));
  color: var(--color-white);
  border-radius: var(--radius-small);
  font-size: 0.75rem;
  font-weight: 700;
}

/* 退出按钮 */
.navbar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--color-bg-blue);
  color: var(--color-text-light);
  transition: var(--transition);
}

/* 通知铃铛（家长） */
.navbar-notif {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--color-bg-blue);
  color: var(--color-text-light);
  cursor: pointer;
  transition: var(--transition);
}

.navbar-notif:hover {
  background-color: var(--color-accent-orange);
  color: var(--color-white);
}

.navbar-notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background-color: var(--color-accent-red);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  line-height: 16px;
}

.navbar-logout:hover {
  background-color: var(--color-accent-red);
  color: var(--color-white);
}

/* 模式切换按钮 */
.navbar-mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background-color: var(--color-bg-green);
  color: var(--color-text-dark);
  border-radius: var(--radius-button);
  font-size: 0.75rem;
  font-weight: 600;
  transition: var(--transition);
  cursor: pointer;
}

.navbar-mode-switch:hover {
  background-color: var(--color-primary-green);
  color: var(--color-white);
}

/* 移动端导航栏适配 */
@media (max-width: 768px) {
  .navbar {
    height: 56px;
    padding: 0 12px;
  }

  .navbar-nav {
    gap: 0;
  }

  .nav-item {
    min-width: 56px;
    padding: 4px 8px;
    font-size: 0.6875rem;
  }

  .navbar-username {
    display: none;
  }
}

/* ============================================================
   2. 弹窗 modal
   ============================================================ */

/* 遮罩层 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s ease;
  padding: 16px;
}

/* 弹窗卡片 */
.modal-content {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  background-color: var(--color-white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-hover);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* 弹窗头部 */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  border-bottom: 1px solid #F0F0F0;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-text-dark);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1.25rem;
  color: var(--color-text-light);
  transition: var(--transition);
}

.modal-close:hover {
  background-color: var(--color-bg-cream);
  color: var(--color-text-dark);
}

/* 弹窗主体 */
.modal-body {
  padding: 20px;
  font-size: 0.9375rem;
  color: var(--color-text-dark);
  line-height: 1.6;
}

/* 弹窗底部 */
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 20px 20px;
}

/* ============================================================
   3. Toast 提示条
   ============================================================ */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  max-width: 90vw;
  padding: 12px 20px;
  border-radius: var(--radius-button);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-white);
  box-shadow: var(--shadow-hover);
  animation: toastSlideIn 0.3s ease;
  pointer-events: auto;
}

/* Toast 成功：绿色 */
.toast.success {
  background: linear-gradient(135deg, var(--color-primary-green), #6BC99A);
}

/* Toast 错误：红色 */
.toast.error {
  background: linear-gradient(135deg, var(--color-accent-red), #E55353);
}

/* Toast 信息：蓝色 */
.toast.info {
  background: linear-gradient(135deg, var(--color-primary-blue), #4DB6E9);
}

/* Toast 退出动画 */
.toast.toast-out {
  animation: toastSlideOut 0.3s ease forwards;
}

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

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

/* ============================================================
   4. 加载动画 loading
   ============================================================ */

/* 全屏加载遮罩 */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* 旋转圆圈 */
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--color-bg-blue);
  border-top-color: var(--color-primary-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* 内联小加载圈 */
.loading-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.loading-inline .loading-spinner {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

.loading-text {
  font-size: 0.875rem;
  color: var(--color-text-light);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   5. 骨架屏 skeleton
   ============================================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    #F0F0F0 25%,
    #E0E0E0 50%,
    #F0F0F0 75%
  );
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s ease infinite;
  border-radius: var(--radius-small);
}

.skeleton-line {
  height: 16px;
  margin-bottom: 8px;
}

.skeleton-line:last-child {
  margin-bottom: 0;
}

.skeleton-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-block {
  height: 100px;
}

@keyframes skeletonShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   6. 空状态 empty-state
   ============================================================ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.empty-state-icon {
  width: 80px;
  height: 80px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 0.9375rem;
  color: var(--color-text-light);
}

/* ============================================================
   7. 错误状态 error-state
   ============================================================ */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.error-state-icon {
  width: 80px;
  height: 80px;
  margin-bottom: 16px;
  color: var(--color-accent-red);
}

.error-state-text {
  font-size: 0.9375rem;
  color: var(--color-text-light);
  margin-bottom: 16px;
}

/* ============================================================
   8. 徽章 badge
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--color-white);
  background-color: var(--color-accent-red);
  border-radius: 10px;
  line-height: 1;
}

.badge-primary {
  background-color: var(--color-primary-blue);
}

.badge-success {
  background-color: var(--color-primary-green);
}

.badge-warning {
  background-color: var(--color-accent-yellow);
  color: var(--color-text-dark);
}

.badge-purple {
  background-color: var(--color-purple);
}

/* ============================================================
   9. 进度条 progress-bar
   ============================================================ */
.progress-bar {
  width: 100%;
  height: 12px;
  background-color: #F0F0F0;
  border-radius: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--color-primary-blue),
    var(--color-primary-green)
  );
  border-radius: 6px;
  transition: width 0.5s ease;
}

/* 进度条带动画条纹 */
.progress-bar-fill.striped {
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.2) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.2) 75%,
    transparent 75%,
    transparent
  );
  background-size: 16px 16px;
  animation: progressStripes 1s linear infinite;
}

@keyframes progressStripes {
  from { background-position: 0 0; }
  to { background-position: 16px 0; }
}

/* ============================================================
   10. 标签页 tab
   ============================================================ */
.tab-list {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #F0F0F0;
  padding: 0 16px;
  overflow-x: auto;
}

.tab {
  position: relative;
  padding: 12px 20px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-text-light);
  white-space: nowrap;
  transition: var(--transition);
  cursor: pointer;
}

.tab:hover {
  color: var(--color-primary-blue);
}

/* 标签激活态：底部下划线 */
.tab.active {
  color: var(--color-primary-blue);
  font-weight: 700;
}

.tab.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--color-primary-blue),
    var(--color-primary-green)
  );
  border-radius: 2px;
}

/* ============================================================
   11. 输入框组 input-group
   ============================================================ */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.input-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-dark);
}

.input-label .required {
  color: var(--color-accent-red);
  margin-left: 2px;
}

.input-field {
  width: 100%;
  min-height: var(--min-touch);
  padding: 0 14px;
  border: 2px solid #E0E0E0;
  border-radius: var(--radius-small);
  font-size: 0.9375rem;
  color: var(--color-text-dark);
  background-color: var(--color-white);
  transition: var(--transition);
  outline: none;
}

.input-field::placeholder {
  color: #BDBDBD;
}

.input-field:focus {
  border-color: var(--color-primary-blue);
  box-shadow: 0 0 0 3px rgba(93, 199, 245, 0.15);
}

.input-field.error {
  border-color: var(--color-accent-red);
}

.input-error {
  font-size: 0.75rem;
  color: var(--color-accent-red);
  min-height: 1em;
}

.input-hint {
  font-size: 0.75rem;
  color: var(--color-text-light);
}

/* ============================================================
   12. 标签芯片 chip
   ============================================================ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-dark);
  background-color: var(--color-bg-blue);
  border-radius: 9999px;
  transition: var(--transition);
  cursor: pointer;
}

.chip:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.chip.active {
  background: linear-gradient(
    135deg,
    var(--color-primary-blue),
    var(--color-primary-green)
  );
  color: var(--color-white);
}

.chip-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 0.75rem;
  background-color: rgba(0, 0, 0, 0.1);
  color: var(--color-text-dark);
}

.chip-close:hover {
  background-color: var(--color-accent-red);
  color: var(--color-white);
}

/* 芯片颜色变体 */
.chip-orange { background-color: #FFE0D6; color: #E65100; }
.chip-green { background-color: #D4F0DC; color: #2E7D32; }
.chip-purple { background-color: #EDE7F6; color: #5E35B1; }
.chip-yellow { background-color: #FFF8E1; color: #F57F17; }

/* ============================================================
   13. 宠物精灵容器（配合 pet-sprite.js）
   ============================================================ */
.pet-sprite-container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pet-sprite-container svg {
  display: block;
}

/* 眨眼动画 */
@keyframes petBlink {
  0%, 90%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

.pet-eye {
  transform-origin: center;
  animation: petBlink 4s infinite;
}

/* 跳跃动画 */
@keyframes petJump {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

.pet-jump {
  animation: petJump 0.6s ease-in-out infinite;
}

/* 开心摇摆动画 */
@keyframes petHappy {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

.pet-happy {
  animation: petHappy 0.5s ease-in-out infinite;
  transform-origin: bottom center;
}

/* 尾巴摇摆动画 */
@keyframes tailWag {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

.pet-tail {
  transform-origin: bottom center;
  animation: tailWag 1.5s ease-in-out infinite;
}

/* 呼吸动画 */
@keyframes petBreathing {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.pet-body {
  transform-origin: center;
  animation: petBreathing 3s ease-in-out infinite;
}

/* 睡眠 Z 字飘动 */
@keyframes sleepZ {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(10px, -20px) scale(1.2);
  }
}

.pet-sleep-z {
  animation: sleepZ 2s ease-out infinite;
}

.pet-sleep-z:nth-child(2) { animation-delay: 0.7s; }
.pet-sleep-z:nth-child(3) { animation-delay: 1.4s; }

/* ============ 移动端组件适配 ============ */
@media (max-width: 480px) {
  .toast {
    width: 80%;
    left: 10%;
    right: auto;
  }
  .navbar-points { font-size: 13px; }
  .stat-card,
  .dashboard-card { min-width: calc(50% - 10px); }
  .quiz-option,
  .quiz-tf-btn { padding: 14px 12px; font-size: 15px; }
  .subject-card { min-height: 96px; }
  .habit-card,
  .task-card,
  .wq-card { padding: 12px; }
  .category-chip { padding: 8px 10px; font-size: 13px; }
}

@media (max-width: 768px) {
  .btn-mini-primary,
  .btn-mini-success,
  .btn-mini-danger {
    min-height: 40px;
    padding: 4px 14px;
  }

  /* ============ 移动端底部 Tab 导航（替代顶部横向导航） ============ */
  .navbar {
    /* 顶部高度 = 导航40px + 1px兜底 + 系统状态栏(safe-area) */
    height: calc(40px + 1px + var(--safe-top, 0px));
    padding: calc(1px + var(--safe-top, 0px)) 8px 0;
    /* 深色顶部导航：状态栏区域同为深色，白色状态栏文字清晰可见（适配打包App强制白字） */
    background-color: #2D3A4B;
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    /* 关键：backdrop-filter 会创建包含块，导致 fixed 子元素(.navbar-nav)相对 navbar 定位而非视口 */
    backdrop-filter: none;
  }
  /* 深色导航内元素适配 + 紧凑化（高度40px，隐藏用户名，缩小按钮） */
  .navbar .navbar-username {
    display: none;
  }
  .navbar .navbar-right {
    gap: 6px;
  }
  .navbar .navbar-logout {
    width: 32px;
    height: 32px;
    background-color: rgba(255, 255, 255, 0.15);
    color: #ffffff;
  }
  .navbar .navbar-notif {
    width: 32px;
    height: 32px;
    background-color: rgba(255, 255, 255, 0.15);
    color: #ffffff;
  }
  .navbar .navbar-mode-switch {
    padding: 4px 10px;
    font-size: 0.7rem;
    background-color: rgba(255, 255, 255, 0.15);
    color: #ffffff;
  }
  .navbar .navbar-logo {
    padding: 2px 6px;
  }
  /* Logo 只留狐狸图标，省宽度 */
  .navbar-logo {
    padding: 4px 8px;
  }
  .navbar-logo span:last-child {
    display: none;
  }
  /* 导航项容器：从顶部流中脱离，固定到底部成 Tab 栏 */
  .navbar-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    height: calc(58px + var(--safe-bottom, 0px));
    padding: 4px 0 var(--safe-bottom, 0px);
    gap: 0;
    background: #ffffff;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    overflow: visible;
    z-index: 1000;
  }
  /* Tab 项：5 等分，全部可见 */
  .nav-item {
    flex: 1 1 0;
    min-height: 0;
    padding: 6px 2px;
    font-size: 11px;
    gap: 2px;
    border-radius: 0;
  }
  .nav-icon svg {
    width: 22px;
    height: 22px;
  }
  .nav-item.active {
    background: linear-gradient(135deg, var(--color-bg-blue), var(--color-bg-green));
  }
  /* 页面底部留白，避免内容被 Tab 栏遮挡（含安全区） */
  .page-main,
  .main-content {
    padding-bottom: calc(72px + var(--safe-bottom, 0px));
    /* 顶部留白：对齐深色顶部导航高度(40+1+safe)，避免内容被遮挡 */
    padding-top: calc(52px + var(--safe-top, 0px));
  }
  /* .container 只留底部（顶部由页面自己的 main padding 控制，避免双重叠加） */
  .container {
    padding-bottom: calc(72px + var(--safe-bottom, 0px));
  }
}
