/* ==========================================================================
   七年级上册生物互动学习系列 — 全局共享主题与基础组件样式
   零外链依赖 | 护眼米白 + 清新草绿 / 天蓝 | 触控优先 (>= 44px)
   ========================================================================== */

:root {
  /* 背景与表面色（护眼米白体系） */
  --bg-page: #f7f5ee;
  --bg-surface: #ffffff;
  --bg-soft: #f0ede2;
  --bg-muted: #e9e4d6;

  /* 品牌强调色（清新草绿 + 天蓝） */
  --primary: #2d9a62;
  --primary-hover: #248252;
  --primary-dark: #1b653f;
  --primary-soft: #e3f5eb;
  --primary-border: #a9dfc1;

  --accent: #2b92d1;
  --accent-hover: #217bb3;
  --accent-dark: #185e8a;
  --accent-soft: #e4f3fc;
  --accent-border: #a7d6f2;

  /* 语义色 */
  --success: #249a5d;
  --success-soft: #e3f6ec;
  --success-border: #9bdab9;

  --warning: #d98218;
  --warning-soft: #fef4e4;
  --warning-border: #f4cf96;

  --danger: #d94b4b;
  --danger-soft: #fdecec;
  --danger-border: #f3b3b3;

  --purple: #8559b8;
  --purple-soft: #f3ecfa;

  /* 文字色（高对比度护眼深墨绿灰） */
  --text-main: #1d2d26;
  --text-secondary: #4a5f56;
  --text-muted: #74887f;
  --text-inverse: #ffffff;

  /* 边框与分割线 */
  --border-subtle: #e4dfd1;
  --border-strong: #cbc4b1;

  /* 圆角 */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  /* 柔和暖调阴影 */
  --shadow-xs: 0 1px 3px rgba(31, 46, 40, 0.06);
  --shadow-sm: 0 3px 10px rgba(31, 46, 40, 0.07);
  --shadow-md: 0 8px 24px rgba(31, 46, 40, 0.09);
  --shadow-lg: 0 14px 36px rgba(31, 46, 40, 0.12);

  /* 字号系统 */
  --fs-xs: 0.78rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.08rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.85rem;

  /* 间距与触控尺寸 */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --tap-min: 44px;

  /* 布局尺寸 */
  --container-max: 1080px;
  --header-height: 64px;
  --bottom-nav-height: 66px;

  /* 字体栈（纯本地系统字体，微信/iOS/Android/Windows 秒开） */
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* 动效 */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

/* 基础重置 */
*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.6;
  color: var(--text-main);
  background-color: var(--bg-page);
  background-image:
    radial-gradient(circle at 12% 8%, rgba(45, 154, 98, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 90% 18%, rgba(43, 146, 209, 0.06) 0%, transparent 42%);
  min-height: 100vh;
  overflow-x: hidden;
}

button,
input,
select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  touch-action: manipulation;
  user-select: none;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

h1, h2, h3, h4, p {
  margin-top: 0;
}

/* 容器 */
.app-shell {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* 顶部栏 */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(247, 245, 238, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.app-header-inner {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.brand-badge {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(45, 154, 98, 0.25);
}

.brand-text {
  min-width: 0;
}

.brand-kicker {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.brand-title {
  font-size: var(--fs-md);
  font-weight: 800;
  color: var(--text-main);
  margin: 0;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* 通用按钮体系（强制 >= 44px 触控面积） */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1.2;
  transition: transform 0.14s var(--ease-out), background-color 0.16s ease,
    border-color 0.16s ease, box-shadow 0.16s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
}

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

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: 0 3px 0 var(--primary-dark), 0 6px 14px rgba(45, 154, 98, 0.22);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: var(--text-inverse);
  box-shadow: 0 3px 0 var(--accent-dark), 0 6px 14px rgba(43, 146, 209, 0.22);
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-soft {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1.5px solid var(--border-subtle);
  box-shadow: var(--shadow-xs);
}

.btn-soft:hover:not(:disabled) {
  border-color: var(--primary-border);
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.btn-warning-soft {
  background: var(--warning-soft);
  color: #9e5a07;
  border: 1.5px solid var(--warning-border);
}

.btn-warning-soft:hover:not(:disabled) {
  background: #fdeac9;
}

.btn-icon {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: 0 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
  transition: all 0.16s ease;
}

.btn-icon:hover {
  border-color: var(--accent-border);
  color: var(--accent-dark);
}

.btn-icon.is-muted {
  background: var(--bg-soft);
  color: var(--text-muted);
}

/* 卡片基础样式 */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.card-title {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--text-main);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.card-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin: 4px 0 0;
}

/* 标签 / 徽章 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.badge-green {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: 1px solid var(--primary-border);
}

.badge-blue {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid var(--accent-border);
}

.badge-amber {
  background: var(--warning-soft);
  color: #9b5908;
  border: 1px solid var(--warning-border);
}

.badge-red {
  background: var(--danger-soft);
  color: #a82b2b;
  border: 1px solid var(--danger-border);
}

/* 数组配置驱动的标签导航栏 */
.tab-nav-wrapper {
  margin-top: var(--space-4);
  margin-bottom: var(--space-5);
}

.tab-nav {
  display: flex;
  gap: var(--space-2);
  padding: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.tab-btn {
  flex: 1;
  min-height: 46px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-secondary);
  transition: all 0.2s var(--ease-out);
  position: relative;
}

.tab-btn:hover:not(.is-active) {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.55);
}

.tab-btn.is-active {
  background: var(--bg-surface);
  color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

.tab-btn .tab-badge-count {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 面板显隐 */
.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 进度条 */
.progress-track {
  width: 100%;
  height: 10px;
  background: var(--bg-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  transition: width 0.35s var(--ease-out);
}

/* 主内容区 */
.app-main {
  padding-bottom: 48px;
}

/* 辅助提示条 */
.callout {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  line-height: 1.55;
  border: 1px solid transparent;
}

.callout-info {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #164f74;
}

.callout-warning {
  background: var(--warning-soft);
  border-color: var(--warning-border);
  color: #7c4706;
}

.callout-success {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: #165e39;
}

.callout-danger {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: #8f2424;
}

/* 通用隐藏类 */
.is-hidden {
  display: none !important;
}

/* 移动端竖屏优化：底部固定 Tab 栏 + 留出底部安全距离 */
@media (max-width: 767px) {
  .app-shell {
    padding: 0 var(--space-3);
  }

  .card {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }

  .brand-badge {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .brand-group {
    gap: 8px;
  }

  .brand-kicker {
    font-size: 0.72rem;
    white-space: nowrap;
  }

  .brand-title {
    font-size: 0.94rem;
  }

  .header-actions {
    gap: 6px;
  }

  #mute-label {
    display: none;
  }

  .btn-icon {
    padding: 0;
    width: var(--tap-min);
  }

  .app-main {
    padding-top: var(--space-4);
    padding-bottom: calc(var(--bottom-nav-height) + 28px + env(safe-area-inset-bottom, 0px));
  }

  .tab-nav-wrapper {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    margin: 0;
    padding: 8px var(--space-3) calc(8px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-subtle);
    box-shadow: 0 -4px 18px rgba(31, 46, 40, 0.08);
  }

  .tab-nav {
    background: var(--bg-soft);
    padding: 4px;
  }

  .tab-btn {
    min-height: 48px;
    font-size: var(--fs-sm);
    padding: 6px 10px;
  }
}
