/* ================================================================
   小螺号 共享设计系统 · common.css
   适用于所有页面的基础 CSS 变量、重置、暗色模式、图片优化
   ================================================================ */

/* ===== 字体大小适配 ===== */
html {
  font-size: clamp(14px, 1vw + 12px, 18px);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
@media (max-width: 768px) {
  html { font-size: clamp(14px, 3.5vw, 16px); }
}

/* ===== 统一色彩系统（20260815 视觉统一：青绿主色 + 暖橙点缀 + 深灰蓝文字） ===== */
:root {
  /* 品牌色 */
  --brand-primary: #0d9488;
  --brand-primary-light: #ccfbf1;
  --brand-primary-dark: #0f766e;

  --brand-secondary: #14b8a6;
  --brand-secondary-light: #f0fdfa;
  --brand-secondary-dark: #0f766e;

  --brand-accent: #f97316;
  --brand-accent-light: #ffedd5;
  --brand-accent-dark: #c2410c;

  /* 语义色 */
  --text-primary: #1a2332;
  --text-secondary: #4a5568;
  --text-muted: #7a8699;
  --text-disabled: #b0b9c6;

  --bg-page: #fafbfc;
  --bg-surface: #ffffff;
  --bg-surface-hover: #f4f7f8;

  --border-subtle: rgba(26, 35, 50, 0.08);
  --border-default: #e6ebee;
  --border-strong: rgba(26, 35, 50, 0.15);

  /* 阴影 */
  --shadow-xs: 0 2px 8px rgba(26, 35, 50, 0.04);
  --shadow-sm: 0 4px 12px rgba(26, 35, 50, 0.06);
  --shadow-md: 0 8px 24px rgba(26, 35, 50, 0.08);
  --shadow-lg: 0 16px 40px rgba(26, 35, 50, 0.12);
  --shadow-xl: 0 24px 60px rgba(26, 35, 50, 0.16);

  /* 圆角 */
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-full: 999px;

  /* 间距 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;

  /* 字体 */
  --font-xs: 12px;
  --font-sm: 13px;
  --font-base: 15px;
  --font-lg: 17px;
  --font-xl: 20px;
  --font-2xl: 24px;

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --weight-extrabold: 800;

  /* 布局 */
  --phone: 480px;
  --content-max-width: var(--phone);

  /* 过渡 */
  --transition-fast: 0.15s ease;
  --transition-base: 0.25s ease;
  --transition-slow: 0.35s ease;

  /* 兼容旧变量名 */
  --orange: #f97316;
  --orange-deep: #c2410c;
  --orange-soft: #ffedd5;
  --teal: var(--brand-primary);
  --teal-deep: var(--brand-primary-dark);
  --teal-soft: var(--brand-primary-light);
  --blue: #4482c9;
  --blue-deep: #2e68aa;
  --blue-soft: #eef5ff;
  --rose: #e96b58;
  --rose-soft: #fce3de;
  --gold: #dda83a;
  --gold-soft: #fdf6e9;
  --ink: var(--text-primary);
  --body: var(--text-secondary);
  --muted: var(--text-muted);
  --line: var(--border-default);
  --bg: var(--bg-page);
  --card: var(--bg-surface);
  --shadow: var(--shadow-md);
  --shadow-soft: var(--shadow-sm);
  --radius: var(--radius-lg);
}

/* ===== 基础重置 ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Hiragino Sans GB", Arial, sans-serif;
  color: var(--text-secondary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ===== 图片优化：防 CLS（累积布局偏移） ===== */
img:not([width]):not([height]) {
  aspect-ratio: auto;
}

/* 对于没有设宽高的图片，提供一个安全的回退 */
img {
  content-visibility: auto;
}

/* 移动端触控优化 */
a, button, [role="button"], input[type="submit"], input[type="button"] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* 最小触控目标 */
@media (max-width: 768px) {
  a, button, [role="button"] {
    min-height: 44px;
    min-width: 44px;
  }
}

/* ===== 焦点可见性（无障碍） ===== */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ===== 流畅滚动（仅移动端） ===== */
@media (max-width: 768px) {
  .scroll-area {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .scroll-area::-webkit-scrollbar {
    display: none;
  }
}

/* ===== 骨架屏加载 ===== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--border-default) 25%,
    var(--bg-surface-hover) 50%,
    var(--border-default) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

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

.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
}

.skeleton-title {
  height: 1.4em;
  width: 60%;
  margin-bottom: 0.8em;
}

.skeleton-card {
  height: 140px;
  border-radius: var(--radius-lg);
}

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

.skeleton-btn {
  height: 44px;
  border-radius: var(--radius-full);
}

/* ===== 暗色模式 ===== */
@media (prefers-color-scheme: dark) {
  :root {
    /* 品牌色在暗色下微调 */
    --brand-primary: #2dd4bf;
    --brand-primary-light: #0f3d38;
    --brand-primary-dark: #14b8a6;

    --brand-secondary: #5eead4;
    --brand-secondary-light: #0f2e2b;
    --brand-secondary-dark: #2dd4bf;

    --brand-accent: #fb923c;
    --brand-accent-light: #331a0d;
    --brand-accent-dark: #fb923c;

    /* 语义色翻转 */
    --text-primary: #e6eaf0;
    --text-secondary: #b4bdc9;
    --text-muted: #79828f;
    --text-disabled: #565f6b;

    --bg-page: #14181f;
    --bg-surface: #1c222b;
    --bg-surface-hover: #232a35;

    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-default: #323b47;
    --border-strong: rgba(255, 255, 255, 0.12);

    /* 阴影在暗色下更不明显 */
    --shadow-xs: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.35);
    --shadow-xl: 0 24px 60px rgba(0, 0, 0, 0.4);

    /* 兼容旧变量在暗色下 */
    --rose: #f08070;
    --rose-soft: #2a1512;
    --gold: #e9b84a;
    --gold-soft: #2a2010;
    --orange: #fb923c;
    --orange-deep: #f97316;
    --orange-soft: #331a0d;
    --teal: var(--brand-primary);
    --teal-deep: var(--brand-primary-dark);
    --teal-soft: var(--brand-primary-light);
    --blue: #6ba3e0;
    --blue-deep: #6ba3e0;
    --blue-soft: #121f33;
    --ink: var(--text-primary);
    --body: var(--text-secondary);
    --muted: var(--text-muted);
    --line: var(--border-default);
    --bg: var(--bg-page);
    --card: var(--bg-surface);
    --shadow: var(--shadow-md);
    --shadow-soft: var(--shadow-sm);
  }

  /* 暗色下减少动画（减轻眼部疲劳） */
  @media (prefers-reduced-motion: no-preference) {
    .skeleton {
      opacity: 0.6;
    }
  }
}

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

/* ===== 底部导航栏（全站共享） ===== */
:root {
  --phone: 480px;
}
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 20;
  width: min(100%, var(--phone));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: var(--space-sm) var(--space-xs) calc(var(--space-sm) + env(safe-area-inset-bottom, 0));
  border-top: 1px solid var(--border-default);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow-lg);
}
.bottom-nav .nav-item {
  display: grid;
  justify-items: center;
  gap: var(--space-xs);
  color: var(--text-muted);
  font-size: var(--font-xs, 12px);
  line-height: 1;
  font-weight: var(--weight-semibold, 600);
  transition: color .2s, transform .2s;
  text-decoration: none;
}
.bottom-nav .nav-item.active { color: var(--brand-primary-dark); }
.bottom-nav .nav-item svg { width: 24px; height: 24px; stroke-width: 2.2; transition: transform .2s; }
.bottom-nav .nav-item:active svg { transform: scale(1.2); }
/* 5个导航项各自配色 */
.bottom-nav .nav-item[href="index.html"], .bottom-nav .nav-item[href="index.html"].active { color: #e8590c; }
.bottom-nav .nav-item[href*="rehab-workstation"] { color: #1971c2; }
.bottom-nav .nav-item[href*="成长营"] { color: #2f9e44; }
.bottom-nav .nav-item[href*="parent.html"] { color: #9c36b5; }
.bottom-nav .nav-item[href*="会员中心"] { color: #e8590c; }
/* 成长营动效 */
@keyframes campBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
@keyframes campWiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-8deg) scale(1.1); }
  75% { transform: rotate(8deg) scale(1.1); }
}
.bottom-nav .nav-item[href*="成长营"] svg {
  animation: campBounce 2.5s ease-in-out infinite;
}
.bottom-nav .nav-item[href*="成长营"]:hover svg {
  animation: campWiggle .6s ease-in-out;
}
.bottom-nav .nav-item[href*="成长营"]:active svg { transform: scale(1.3); }
/* 页面有底部导航时预留空间 */
.has-bottom-nav { padding-bottom: 80px; }
@media (max-width: 600px) {
  .has-bottom-nav { padding-bottom: 72px; }
}

/* ===== 打印优化 ===== */
@media print {
  body {
    background: #fff;
    color: #000;
  }
  .tabbar,
  .bottom-nav,
  .skeleton {
    display: none !important;
  }
}

/* ===== Shared back-link (gold pill, fixed bottom-left) ===== */
.back-link {
  position: fixed;
  bottom: 14px;
  left: 14px;
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 24px;
  background: linear-gradient(135deg, #D4A843, #B8860B, #8B6508);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(184,134,11,.28);
  transition: transform .15s;
}
.back-link:hover { transform: translateY(-1px); }
.back-link.back-link--top {
  bottom: auto;
  top: 12px;
}
@media (max-width: 600px) {
  .back-link {
    left: 10px;
    bottom: 10px;
    min-height: 38px;
    padding: 0 12px;
    font-size: 12px;
  }
  .back-link.back-link--top {
    top: 8px;
    bottom: auto;
  }
}
