/* ============================================================
   米奇学习大闯关 - 基础样式系统
   包含：CSS 变量、全局重置、通用工具类
   ============================================================ */

/* ---------- CSS 变量：全局设计令牌 ---------- */
:root {
  /* 安全区（PWA 全屏适配）：刘海/状态栏与底部手势条 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* 背景色 */
  --color-bg-cream: #FFF9F0;       /* 暖奶油背景 */
  --color-bg-blue: #E8F4FD;        /* 浅蓝背景 */
  --color-bg-green: #E8F8E8;       /* 浅绿背景 */

  /* 主色调 */
  --color-primary-blue: #5DC7F5;   /* 主蓝 */
  --color-primary-green: #7DDBA8;  /* 主绿 */

  /* 强调色 */
  --color-accent-orange: #FF8A65;  /* 橙色 */
  --color-accent-yellow: #FFD54F;  /* 黄色 */
  --color-accent-red: #FF6B6B;     /* 红色 */

  /* 文字色 */
  --color-text-dark: #37474F;      /* 深色文字 */
  --color-text-light: #78909C;     /* 浅色文字 */

  /* 其他 */
  --color-purple: #B39DDB;         /* 紫色 */
  --color-white: #FFFFFF;          /* 白色 */

  /* 圆角 */
  --radius-card: 16px;             /* 卡片圆角 */
  --radius-button: 12px;           /* 按钮圆角 */
  --radius-small: 8px;             /* 小圆角 */

  /* 阴影 */
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.08);    /* 柔和阴影 */
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);  /* 悬停阴影 */

  /* 过渡 */
  --transition: all 0.3s ease;     /* 通用过渡 */

  /* 触控目标最小尺寸 */
  --min-touch: 44px;               /* 最小可点击高度 */
}

/* ---------- 全局重置 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Microsoft YaHei", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text-dark);
  background-color: var(--color-bg-cream);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 链接默认样式 */
a {
  color: var(--color-primary-blue);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  color: var(--color-primary-blue);
  opacity: 0.8;
}

/* 列表重置 */
ul,
ol {
  list-style: none;
}

/* 图片自适应 */
img {
  max-width: 100%;
  display: block;
}

/* 按钮基础重置 */
button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* 输入框基础重置 */
input,
textarea,
select {
  font-family: inherit;
  font-size: inherit;
}

/* ---------- 通用工具类 ---------- */

/* 容器：居中限宽 */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* 卡片：圆角 + 阴影 */
.card {
  background-color: var(--color-white);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-soft);
  padding: 20px;
  transition: var(--transition);
}

/* ---------- 按钮系列 ---------- */

/* 主按钮：蓝色渐变 */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--min-touch);
  padding: 0 24px;
  background: linear-gradient(135deg, var(--color-primary-blue), #4DB6E9);
  color: var(--color-white);
  border-radius: var(--radius-button);
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow-soft);
  transition: var(--transition);
  cursor: pointer;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  opacity: 0.95;
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* 次按钮：白底蓝边 */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--min-touch);
  padding: 0 24px;
  background-color: var(--color-white);
  color: var(--color-primary-blue);
  border: 2px solid var(--color-primary-blue);
  border-radius: var(--radius-button);
  font-size: 1rem;
  font-weight: 600;
  transition: var(--transition);
  cursor: pointer;
}

.btn-secondary:hover {
  background-color: var(--color-bg-blue);
  transform: translateY(-2px);
}

.btn-secondary:active {
  transform: translateY(0);
}

/* 危险按钮：红色 */
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--min-touch);
  padding: 0 24px;
  background: linear-gradient(135deg, var(--color-accent-red), #E55353);
  color: var(--color-white);
  border-radius: var(--radius-button);
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow-soft);
  transition: var(--transition);
  cursor: pointer;
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  opacity: 0.95;
}

.btn-danger:active {
  transform: translateY(0);
}

/* ---------- 文字与布局工具类 ---------- */

/* 文字居中 */
.text-center {
  text-align: center;
}

/* 隐藏元素（保留占位用 visibility:hidden，完全移除用 .hidden） */
.hidden {
  display: none !important;
}

/* 弹性布局 */
.flex {
  display: flex;
}

/* 弹性布局：两端对齐 */
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* 弹性布局：垂直方向 */
.flex-col {
  display: flex;
  flex-direction: column;
}

/* 弹性布局：居中 */
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 间距工具类 */
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }

/* 内边距工具类 */
.p-8 { padding: 8px; }
.p-12 { padding: 12px; }
.p-16 { padding: 16px; }
.p-20 { padding: 20px; }
.p-24 { padding: 24px; }

/* 外边距工具类 */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

/* 文字大小 */
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }

/* 文字颜色 */
.text-primary { color: var(--color-primary-blue); }
.text-success { color: var(--color-primary-green); }
.text-danger { color: var(--color-accent-red); }
.text-light { color: var(--color-text-light); }
.text-dark { color: var(--color-text-dark); }

/* 圆角工具类 */
.rounded { border-radius: var(--radius-small); }
.rounded-lg { border-radius: var(--radius-card); }
.rounded-full { border-radius: 9999px; }

/* 阴影工具类 */
.shadow { box-shadow: var(--shadow-soft); }
.shadow-lg { box-shadow: var(--shadow-hover); }

/* ---------- 响应式断点辅助 ---------- */
@media (max-width: 768px) {
  .container {
    padding: 0 12px;
  }

  /* 移动端隐藏元素 */
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 769px) {
  /* 桌面端隐藏元素 */
  .hide-desktop {
    display: none !important;
  }
}

/* ---------- 动画工具类 ---------- */

/* 淡入动画 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 从下往上滑入 */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 弹跳动画 */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* 摇摆动画 */
@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

/* 脉冲动画 */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.animate-fadeIn { animation: fadeIn 0.3s ease; }
.animate-slideUp { animation: slideUp 0.4s ease; }
.animate-bounce { animation: bounce 0.6s ease infinite; }
.animate-wiggle { animation: wiggle 0.5s ease; }
.animate-pulse { animation: pulse 2s ease infinite; }

/* ---------- 可访问性 ---------- */

/* 仅屏幕阅读器可见 */
.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(--color-primary-blue);
  outline-offset: 2px;
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ 移动端触控适配（375px 起步） ============ */

/* 小屏：触控目标最小高度 44px（苹果 HIG 标准） */
@media (max-width: 768px) {
  button,
  .btn,
  .btn-primary,
  .btn-secondary,
  .btn-mini-primary,
  .btn-mini-success,
  .btn-mini-danger,
  .btn-sm,
  .shop-buy-btn,
  .navbar-mode-switch,
  .navbar-logout,
  .quiz-option,
  .quiz-tf-btn,
  .task-checkbox,
  .habit-checkin-btn {
    min-height: 44px;
  }

  /* 筛选标签（chip）：紧凑型触控目标，略矮但可点 */
  .chip,
  .category-chip {
    min-height: 40px;
    padding: 6px 12px;
  }
}

@media (max-width: 480px) {
  /* 全局容器 */
  .container,
  .main-container,
  .page-container {
    width: 100%;
    padding: 12px;
    box-sizing: border-box;
  }

  /* 防装饰性元素（背景圆等）撑宽页面：需同时作用于 html 根元素 */
  html,
  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* 导航：移动端导航已由 components.css 切换为底部 Tab 栏，这里仅兜底 */
  .navbar-nav {
    min-width: 0;
  }
  .navbar-nav a,
  .navbar-item,
  .nav-item {
    white-space: nowrap;
  }

  /* 大标题 */
  h1 { font-size: 22px; }
  h2 { font-size: 18px; }
  .page-title { font-size: 20px; }

  /* 网格：双列 */
  .grid,
  .card-grid,
  .subject-grid,
  .task-grid,
  .goods-grid,
  .shop-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  /* 表单输入放大（防 iOS 自动缩放） */
  .input-field,
  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px;
    padding: 10px 12px;
  }

  /* 弹窗：近全屏 */
  .modal-content,
  .modal-box {
    width: 92%;
    max-width: 92%;
    max-height: 85vh;
    overflow-y: auto;
  }

  /* 表格横向滚动 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
