/* ============================================================
   To100AI 未来课堂 · 全局主题系统（theme.css）
   1) 品牌色：从 TO100 绿色飞鸟品牌资产出发，取代 Tailwind 默认 indigo+slate
   2) 学段主题：低年级暖亮大圆角 → 高中冷静紧凑，按 data-stage 切换
   3) 触控区：全站交互元素 ≥44px（Apple HIG / Material 规范）
   4) 流式字号：手机自动放大，桌面不臃肿
   5) 暗色模式：跟随系统，护眼（住校晚自习场景）
   6) 无障碍：尊重 prefers-reduced-motion
   本文件由 play.html 引入（壳层）并注入 iframe（模块内容），两端同时生效。
   ============================================================ */

:root {
  /* ---------- 品牌基础 ---------- */
  --brand: #0f9d58;          /* TO100 品牌绿 */
  --brand-2: #14b8a6;        /* 辅助青绿 */
  --brand-ink: #065f46;      /* 品牌深色（文字/描边） */
  --brand-soft: #e7f8ef;     /* 品牌浅底 */
  --btn: #0b7a43;            /* 按钮用绿（比品牌绿深一档，保证白字对比度 ≥4.5:1） */

  /* ---------- 学段默认（小学中段） ---------- */
  --c1: #0ea5e9;
  --c2: #14b8a6;
  --radius: 14px;
  --radius-sm: 10px;
  --fs-body: 15px;
  --fs-title: 18px;
  --tap: 44px;               /* 最小触控热区 */
  --gap: 12px;
}

/* ---------- 学段主题包 ---------- */

/* 小学低年级（1-2）：暖亮、大圆角、更大字号，重游戏化与安全感 */
[data-stage="low"] {
  --brand: #22c55e;
  --brand-2: #fb923c;
  --brand-ink: #15803d;
  --brand-soft: #fff4e6;
  --c1: #f97316;
  --c2: #22c55e;
  --radius: 18px;
  --radius-sm: 14px;
  --fs-body: 16px;
  --fs-title: 19px;
  --gap: 14px;
}

/* 小学中段（3-4）：清亮青绿，游戏化与秩序感平衡 */
[data-stage="mid"] {
  --brand: #0d9488;
  --brand-2: #22c55e;
  --c1: #0ea5e9;
  --c2: #14b8a6;
  --radius: 14px;
  --fs-body: 15px;
  --fs-title: 18px;
}

/* 小学高段（5-6）：蓝青，收敛装饰，强调自主 */
[data-stage="high"] {
  --brand: #0284c7;
  --brand-2: #0d9488;
  --c1: #0284c7;
  --c2: #38bdf8;
  --radius: 12px;
  --radius-sm: 9px;
  --fs-body: 15px;
  --fs-title: 18px;
}

/* 初中（7-9）：靛蓝，信息密度提升，去幼稚感 */
[data-stage="jh"] {
  --brand: #4f46e5;
  --brand-2: #0ea5e9;
  --c1: #4f46e5;
  --c2: #6366f1;
  --radius: 10px;
  --radius-sm: 8px;
  --fs-body: 14.5px;
  --fs-title: 17px;
  --gap: 10px;
}

/* 高中（10-12）：深石板，专业工具感，为暗色优化 */
[data-stage="sh"] {
  --brand: #334155;
  --brand-2: #0f766e;
  --c1: #1e293b;
  --c2: #0f766e;
  --radius: 8px;
  --radius-sm: 6px;
  --fs-body: 14.5px;
  --fs-title: 17px;
  --gap: 10px;
}

/* ============================================================
   P1 · 触控区：所有可交互元素 ≥44px 高（手机端尤其关键）
   ============================================================ */
/* 触屏/窄屏统一生效：只抬高 min-height，绝不改 padding
   （曾因重写 padding 把 65px 的按钮压到 54px，反而更难点） */
@media (max-width: 768px) {
  button, a.btn, .btn, [role="button"], input[type="button"], input[type="submit"],
  nav.tabs button, .tabs button, .tab, .kcLvBtn, .kcLvIn, .kcLvQ .kcLvH,
  .opt, .choice, .pick, label.opt, .kcQ .opt, .kcOpt, .choiceItem, .qopt,
  .playBar button, .mfoot button {
    min-height: var(--tap) !important;
  }
  /* 课程页里有的按钮写死了 height（如 height:34px），min-height 赢不了，
     必须同时放开 height 才能让 44px 生效 */
  .kcLvIn, .kcLvBtn, .kcQ .opt, .kcOpt, .opt, .qopt,
  nav.tabs button, .tabs button, .tab,
  .homebtn, .homeBtn, a[class*="home"] {
    height: auto !important;
    min-height: var(--tap) !important;
  }
}

/* ============================================================
   P2 · 流式字号：手机自动放大到 14px 起，桌面维持原设计
   ============================================================ */
/* 下限必须高于课程页原有的 16px，否则"优化"反而把字变小了 */
:root { --fs-fluid: clamp(16px, 4.6vw, 18px); }
[data-stage="low"] { --fs-fluid: clamp(17px, 5vw, 19px); }

@media (max-width: 480px) {
  body { font-size: var(--fs-fluid) !important; }
  /* 辅助小字在手机上不低于 12.5px */
  small, .muted, .hint, .sub, #subTtl, .kcLvA small {
    font-size: 12.5px !important;
  }
  /* 页签横向可滚：8 个页签在窄屏不挤压 */
  nav.tabs, .tabs {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-snap-type: x proximity;
    flex-wrap: nowrap !important;
  }
  nav.tabs button, .tabs button {
    scroll-snap-align: center;
    flex: 0 0 auto !important;
    min-height: var(--tap) !important;
    padding: 8px 12px !important;
  }
  /* P1-5：9 个课内页签不再被压成「导学…/动画…」，保留 3~4 字并单行横滑 */
  nav.tabs button, .tabs button {
    white-space: nowrap !important; text-overflow: clip !important;
    overflow: visible !important; max-width: none !important;
    font-size: 12.5px !important; letter-spacing: 0 !important;
  }
  /* 隐藏滚动条但保留滚动能力 */
  nav.tabs::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
}

/* 平板：页签平铺即可，不做横滑 */
@media (min-width: 768px) {
  nav.tabs, .tabs { overflow: visible !important; flex-wrap: wrap !important; }
}

/* ============================================================
   平板横屏：两侧留白太多，改为加宽内容区 + 同级卡片双栏
   （竖屏保持单列，避免窄边挤坏内容）
   ============================================================ */
@media (min-width: 900px) and (max-width: 1400px) and (orientation: landscape) {
  :root { --shell-w: 1120px; }
  /* 课程页内容区：在横屏下让"同级并列的卡片"排成两列，利用横向空间 */
  .kcLvQ, .kcQ, .card, .panel > .card, .dfCard, .xywCard, .peCard {
    display: block;
  }
  /* 列表型容器双栏（只对明确是"多张并列卡"的容器生效，避免破坏单块长文） */
  .grid2, .cols2, .cardList, .lessonList, .modList, .subList,
  .kcList, .dfList, .listCards, .tiles {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px !important;
  }
  /* 学习中心：学科/课程卡双栏 */
  .stu .card, .stu .field { max-width: none; }
}

/* ============================================================
   P1 · 暗色模式（跟随系统，护眼）
   只覆盖"容器/文字/边框"类 token，不动学科内容里已经很好的彩色图形
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --page-bg: #0f172a;
    --card-bg: #1e293b;
    --ink: #e2e8f0;
    --ink-soft: #94a3b8;
    --line: #334155;
    --btn: #0a6b3b;          /* 暗色下按钮再深一档，保证白字 ≥4.5:1 */
  }
  html, body { background: #0f172a !important; color: #e2e8f0 !important; }
  /* app.css 里有写死的深色文字（如 rgb(49,46,129) 深蓝紫），在深色底上只有 1.5:1，
     必须提高优先级强制转浅色；带彩色语义的类（成功/警示）另行提亮。 */
  h1, h2, h3, h4, h5, p, li, span, div, td, th, label, dt, dd, figcaption {
    color: #e2e8f0 !important;
  }
  .muted, small, .hint, .sub, .tip, .desc, .secondary { color: #a8b3c4 !important; }
  /* 链接与强调色在暗底上要提亮，否则出现"绿字绿底 = 1:1"完全看不见的情况 */
  a, a:visited { color: #7dd3a8 !important; }
  .brand, .hl, .accent, [class*="brand"], [class*="highlight"] { color: #6ee7b7 !important; }
  /* 通用容器与卡片 */
  .card, .panel, .kcLvQ, .kcQ, .wrap, .kcLvA, .mfoot, .playBar {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #e2e8f0 !important;
  }
  h1, h2, h3, h4, p, li, span, div, td, th { color: #e2e8f0; }
  .muted, small, .hint { color: #94a3b8 !important; }
  input, textarea, select {
    background: #0f172a !important;
    color: #e2e8f0 !important;
    border-color: #475569 !important;
  }
  /* 降低强色块在夜间的刺眼程度 */
  .playBar { box-shadow: none !important; }
  img, svg { opacity: .92; }
}

/* ============================================================
   P2 · 无障碍：尊重"减少动效"（前庭敏感 / ADHD 学生）
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* 键盘可达性：统一可见焦点环（对使用键盘/读屏的学生） */
:focus-visible {
  outline: 3px solid var(--brand) !important;
  outline-offset: 2px !important;
  border-radius: 6px;
}

/* ============================================================
   壳层品牌化：顶栏改用品牌色系（取代 indigo→sky 的 AI 默认渐变）
   ============================================================ */
.playBar {
  background: linear-gradient(135deg, var(--brand), var(--brand-2) 70%) !important;
  box-shadow: 0 8px 26px rgba(15, 157, 88, .22) !important;
}
[data-stage="low"] .playBar { border-radius: 0 0 26px 26px !important; }
[data-stage="jh"] .playBar,
[data-stage="sh"] .playBar { border-radius: 0 0 14px 14px !important; }
.blogo { box-shadow: 0 2px 8px rgba(15, 23, 42, .2) !important; }

/* 主按钮统一品牌色。
   注意：按钮绿比品牌绿深一档（--btn），因为白字在 #0f9d58 上只有 3.51:1，
   达不到 WCAG AA 的 4.5:1；深一档后亮/暗色都能达标。 */
.btn, button.btn, .btn.primary, a.btn {
  background: var(--btn) !important;
  border-color: var(--btn) !important;
  color: #fff !important;              /* 防止出现"绿字绿底"完全不可见 */
  border-radius: var(--radius-sm) !important;
  min-height: var(--tap);
}

/* 幽灵按钮：恢复"浅底+深绿字+绿描边"的风格。
   上面的 .btn 实心规则会把 ghost 的透明底填成绿底，而 ghost 自身的绿字
   （.btn.ghost 两个类优先级更高）盖不掉，就出现"绿字绿底"只剩 emoji 可见。 */
.btn.ghost, a.btn.ghost, button.btn.ghost {
  background: #fff !important;
  color: var(--btn) !important;
  border: 1.5px solid var(--btn) !important;
}
@media (prefers-color-scheme: dark) {
  .btn.ghost, a.btn.ghost, button.btn.ghost {
    background: #16261e !important;
    color: #7dd3a8 !important;
    border-color: #0a6b3b !important;
  }
}
.btn.gray, .btn.gray:hover {
  background: #64748b !important;
  border-color: #64748b !important;
}
