/* ============ 页面专属（Layer 4 · pages） ============
 * 仅容纳「练习页(practice.html)专用、不被其他页面复用」的布局与必要覆写。
 * 共享组件(题目卡片/按钮/题型卡片等)一律在 components 层；本层只做页面级布局与覆写。
 * 依赖顺序：tokens → base → components → states → toolbar → pages → subjects
 * （本层高于 toolbar，可安全覆写练习页工具栏样式；subjects 层仅在二级题型页启用，为本层序最高）。
 *
 * 注：旧版练习页样式由 renderCard 类化方案替代，属死代码，未搬入本层。当前仅保留综合练习仍在用的
 *     .questions-grid / .q-wrap / .q-badge 容器类。
 */
@layer pages {

  body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: linear-gradient(180deg, #eaf2ff 0%, var(--bg) 220px, var(--bg) 100%);
    color: var(--ink); line-height: 1.6;
  }
  .wrap { max-width: 1100px; margin: 0 auto; padding: var(--spacing-md) var(--spacing-md) 60px; }

  /* ===== 三级页面布局（practice.html）=====
   * Layer 1: .quick-switch  顶部悬浮快速切换（fixed，见下方）
   * Layer 2: .panel.controls 工具栏（题型/题量/难度 + 操作按钮，@layer toolbar）
   * Layer 3: .exercise-content 正式内容区
   *          ├─ .exercise-header  第一行：主题标题（年级+题型+题量）+ 计时器
   *          └─ #problemsArea     第二行起：序号题目卡网格
   */

  /* 正式内容区容器 */
  .exercise-content { margin-top: var(--spacing-sm); }

  /* 第一行：主题标题 + 计时器 */
  .exercise-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 10px 4px 14px;
  }
  .exercise-header h1 { margin: 0; font-size: 24px; letter-spacing: 1px;
    background: linear-gradient(90deg, #5b8def, #7c5cff); -webkit-background-clip: text; background-clip: text; color: transparent; }
  .exercise-header .timer { font-size: 15px; font-weight: 800; color: var(--brand-d); background: var(--brand-bg);
    border-radius: 12px; padding: 8px 14px; font-variant-numeric: tabular-nums;
    white-space: nowrap; flex-shrink: 0; }

  /* ===== 三级工具栏视觉精炼（覆写 @layer toolbar，不改色系）=====
   * 面板本体样式已集中到本文件底部「工具栏集中管理」段（自 practice.html 迁移）。 */
  .controls-grid { gap: calc(var(--spacing-lg) + 4px); }
  .controls-settings .row { gap: 14px; }
  /* 设置标签胶囊化：抬升从属层级、增强与内容的对比（颜色沿用 --ink / --soft-bg / --line） */
  .group .lbl {
    background: var(--soft-bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 13px;
  }
  /* chip：更顺滑过渡 + 键盘焦点环；激活态加深投影，强化“选中”层级 */
  .chip { transition: .2s ease; }
  .chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
  .chip.active { box-shadow: var(--toolbar-chip-active-shadow), 0 2px 8px rgba(20, 40, 90, .12); }
  /* 按钮：统一过渡 + 键盘焦点环 + 轻微字距 */
  .btn { transition: .2s ease; }
  .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
  .btn-primary { letter-spacing: .3px; }
  .controls-actions { gap: 14px; }

  /* 左上角快速切换（醒目、悬浮常驻） */
  .quick-switch { position: fixed; top: 14px; left: 14px; z-index: 1200; }
  .qs-btn { cursor: pointer; border: none; border-radius: 999px; padding: 9px 20px; font-size: 14px;
    font-weight: 800; color: #fff; letter-spacing: .5px;
    background: linear-gradient(120deg, #ffb347 0%, #ff8a5c 55%, #ff6b6b 100%);
    box-shadow: 0 4px 14px rgba(255, 130, 90, .35); }
  .qs-btn:hover { filter: brightness(1.07); }
  .qs-btn:active { transform: scale(.97); }
  .qs-menu { position: absolute; top: calc(100% + 8px); left: 0; width: 420px; max-width: 86vw;
    background: var(--card); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 14px 40px rgba(20, 40, 90, .2); padding: 12px 14px 14px; }
  .qs-hd { font-size: 12px; color: var(--muted); margin: 10px 2px 6px; font-weight: 700; }
  .qs-hd:first-child { margin-top: 2px; }
  .qs-row { display: flex; flex-wrap: wrap; gap: 7px; }
  .qs-link { flex: 1 1 100%; cursor: pointer; border: 1.5px solid #f0d3a8; background: #fff3e0;
    color: #b06a10; border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 600;
    text-align: center; text-decoration: none; transition: .15s; }
  .qs-link:hover { border-color: #e39a3f; }
  .qs-subj, .qs-grade { cursor: pointer; border: 1.5px solid #f0d3a8; background: #fff3e0;
    color: #b06a10; border-radius: 10px; padding: 7px 12px; font-size: 13px; font-weight: 600;
    text-decoration: none; transition: .15s; }
  .qs-subj:hover, .qs-grade:hover { border-color: #e39a3f; }
  .qs-subj.active, .qs-grade.active { background: #e8890c; border-color: #e8890c; color: #fff; }
  @media (max-width: 760px) {
    .exercise-header { padding-left: 108px; flex-wrap: wrap; }
    .exercise-header .timer { order: -1; margin-left: auto; }
  }

  .sheet-title {
    display: flex; align-items: baseline; justify-content: center;
    gap: 10px; margin-bottom: 14px; padding: 4px 0;
  }
  .sheet-title .sheet-title-text {
    font-size: 28px; font-weight: 900; letter-spacing: 2px; margin: 0;
    background: linear-gradient(90deg, #4A90D9, #F5A623);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    text-shadow: 0 2px 10px rgba(90,140,220,.18);
  }
  .meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px;
    color: var(--muted); margin-bottom: 12px; }
  .meta .pill { background: var(--brand-bg); color: var(--brand-d); border-radius: 999px; padding: 4px 12px; font-weight: 600; }
  .meta .title-pill { background: #dcebfa; color: #2b5cbf; font-weight: 800; }

  /* 题目区域 */
  #problemsArea .empty { text-align: center; color: var(--muted); padding: 46px 10px; font-size: 14px; }
  .q-grid { display: grid; gap: 14px; grid-template-columns: repeat(var(--grid-cols, 1), 1fr); }
  /* 响应式断点：<480px 强制单列，其他由 JS 通过 --grid-cols 设定 */
  @media (max-width: 480px) { .q-grid { grid-template-columns: 1fr !important; } }

  /* ===== 响应式布局（断点令牌见 tokens.css：--bp-sm=640 / --bp-md=768 / --bp-lg=1024；
     @media 条件无法引用 var()，此处硬编码同值）===== */

  /* ≤ --bp-sm（手机）：标题缩放；2+1 分栏工具栏（见 toolbar.css ≤760 断点），
     按钮不挤压换行文字，状态条提示允许折行 */
  @media (max-width: 640px) {
    .exercise-header { padding-left: 108px; }
    .exercise-header h1 { font-size: 19px; letter-spacing: 0; }
    .control-row { gap: 6px; }
    .right-group .btn { white-space: nowrap; }
  }

  /* --bp-md ~ --bp-lg（平板）：中档标题 */
  @media (min-width: 641px) and (max-width: 1023px) {
    .exercise-header h1 { font-size: 22px; }
  }

  /* ≥ --bp-lg（桌面）：标题放大，内容区留白加宽 */
  @media (min-width: 1024px) {
    .exercise-header { padding-top: var(--spacing-md); }
    .exercise-header h1 { font-size: 26px; }
  }

  /* 屏幕端：卡片/文字网格按 A4 竖版思路自适应（打印端由 JS 按题目长度设定列数） */
  @media (max-width: 480px) {
    #problemsArea .questions-grid { grid-template-columns: 1fr !important; }
    #problemsArea .q-badge { position: static; display: inline-block; margin: 2px 0 6px; }
  }

  /* 练习页题目卡片覆写：强制左对齐（覆盖部分插件内联 text-align:center）+ 紧凑内边距 */
  #problemsArea .questions-grid .question-card,
  #problemsArea .q-grid .question-card { text-align: left !important; padding: var(--card-padding-screen) !important; }
  @media print {
    #problemsArea .questions-grid .question-card,
    #problemsArea .q-grid .question-card { padding: var(--card-padding-print) !important; }
    #problemsArea .questions-grid .question-card,
    #problemsArea .q-grid .question-card { text-align: left !important; }
  /* M13 提前预习：乘除法表静态卡片（单卡通栏 + 表格边框） */
  #problemsArea .preview-table-card { grid-column: 1 / -1; text-align: center !important; }
  .preview-table { border-collapse: collapse; margin: 10px auto 2px; font-size: 13px; }
  .preview-table caption { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
  .preview-table td { border: 1px solid var(--line); padding: 4px 8px; white-space: nowrap; }
  /* 批改反馈：空时不占高（基础字号/字重由 components 层 .question-card .feedback 提供） */
  .question-card .feedback { min-height: 0; margin-top: 4px; }
  .question-card .feedback:empty { display: none; }
} /* /@media print */

  .correct-answer { font-size: 12px; color: var(--bad); font-weight: 700; margin-top: 6px; }
  /* 答案输入框状态（基础宽高在 components 层 .answer-inp） */
  .answer-inp:focus { border-color: var(--brand); background: var(--card); }
  .answer-inp.correct { border-color: var(--ok); background: var(--ok-bg); }
  .answer-inp.wrong   { border-color: var(--bad); background: var(--bad-bg); }

  /* 结果面板 */
  .result-panel { display: none; }
  .result-panel.show { display: block; }
  .result { background: linear-gradient(135deg, #eef4ff, #f6efff); border: 1px solid var(--line);
    border-radius: 16px; padding: var(--spacing-lg); margin: var(--spacing-md) 0; text-align: center; box-shadow: var(--shadow); }
  .result .score { font-size: 36px; font-weight: 800; color: var(--brand-d); }
  .result .detail { font-size: 14px; color: var(--ink); margin-top: 6px; }
  .result .tips { font-size: 13px; color: var(--muted); margin-top: 4px; }
  .result .redo-wrap { margin-top: 14px; }

  /* 综合练习：来源题型徽标容器（math-comprehensive 实时渲染） */
  .questions-grid { display: grid; gap: 18px 25px; margin: 15px 0; }
  .q-wrap { position: relative; display: flex; flex-direction: column; }
  .q-badge {
    position: absolute; top: 8px; right: 10px; z-index: 3;
    font-size: 11px; color: #5a6b8c; background: #f0f4fb;
    border: 1px solid #e0e7f3; border-radius: 10px; padding: 1px 9px;
  }

  /* 自定义数量/难度输入框占位符（原 practice.html body 内联 style 迁移） */
  #customCount::placeholder, #difficultyInput::placeholder { color: #b0b8c6; font-weight: 400; font-size: 12px; }

  footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 12px; }

  /* 期末模拟卷（exam 子类型）：分部分区块，打印时各大部分间合理分页 */
  .exam-paper { display: block; }
  .exam-part {
    break-inside: avoid; page-break-inside: avoid;
    margin: 6px 0 14px;
  }
  .exam-part-title {
    font-size: 16px; line-height: 1.5; margin: 8px 0 6px;
    padding-left: 9px; border-left: 4px solid var(--brand, #3b5bdb);
    font-weight: 700;
  }
  .exam-part-items { display: block; }
  .exam-part-items .q-wrap { margin: 4px 0; }

  /* ============ 工具栏集中管理（自 practice.html 内联样式迁移，任务3） ============
   * 练习页工具栏全部覆写样式统一维护于此；同层后置 → 覆盖上方精炼段与 @layer toolbar。 */

  /* 面板本体：粘性置顶 + 卡片描边（合并原精炼段的 padding） */
  .panel.controls {
    position: sticky; top: 8px; z-index: 60;
    background: var(--card, #fff); border: 1px solid var(--line, #e3e8f0); border-radius: 14px;
    box-shadow: 0 6px 18px rgba(40, 70, 120, .10);
    padding: calc(var(--spacing-md) + 2px) var(--spacing-md);
  }
  @media print { .panel.controls { position: static; box-shadow: none; } }

  /* ===== 知识点卡片题量占比（可调整）===== */
  .kp-ratio { display: flex; flex-direction: column; gap: 8px; width: 100%; }
  .kp-ratio-empty { font-size: 13px; font-weight: 600; color: var(--muted); padding: 4px 2px; }
  .kp-ratio-list { display: flex; flex-direction: column; gap: 8px; }
  .kp-ratio-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--soft-bg);
  }
  .kp-ratio-item .nm { flex: 1 1 auto; min-width: 0; font-size: 13px; font-weight: 700; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap; }
  .kp-ratio-item .bar { flex: 2 1 auto; min-width: 90px; height: 10px; border-radius: 999px;
    background: var(--soft-bg); border: 1px solid var(--line); overflow: hidden; }
  .kp-ratio-item .bar i { display: block; height: 100%; background: linear-gradient(90deg, #4A90D9, #2bb6a3); }
  .kp-ratio-item .cnt { flex: 0 0 70px; font-size: 12px; font-weight: 800; color: var(--brand-d);
    text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .kp-ratio-item.sep { display: flex; align-items: center; gap: 8px; border: none; background: none; padding: 2px 0; }
  .kp-ratio-item.sep .acts { display: flex; gap: 6px; }
  .kp-ratio-item .acts button {
    border: 1px solid var(--line); background: var(--card); cursor: pointer; border-radius: 8px;
    color: var(--brand-d); font-weight: 800; font-size: 14px; line-height: 1; padding: 6px 10px;
  }
  .kp-ratio-item .acts button:hover { border-color: var(--brand); background: var(--brand-bg); }
  .kp-ratio-item .total { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--muted); }
  /* 快速模式分项：仅「题型名称 + 题量」胶囊，靠左成流、排满一行自动换行，不居中 */
  .kp-ratio-types { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-start; }
  .kp-ratio-types .kp-ratio-item { width: auto; flex: 0 1 auto; }
  .kp-ratio-types .kp-ratio-item .nm { flex: 0 1 auto; }
  .kp-ratio-types .kp-ratio-item .cnt { flex: 0 0 auto; }

  /* ===== 自定义题量同框：chip 变输入框，占位灰字「自定义」，键入即消失 ===== */
  .custom-chip { position: relative; padding: 0; }
  .custom-chip .custom-label { padding: var(--toolbar-chip-pad); display: inline-flex; align-items: center; }
  .custom-chip .custom-num {
    border: none; background: transparent; outline: none; text-align: center; font: inherit;
    color: var(--toolbar-chip-ink); font-weight: 700; width: 64px; min-height: 22px;
    padding: var(--toolbar-chip-pad);
  }
  .custom-chip .custom-num::placeholder { color: var(--muted, #99a); opacity: 0.75; font-weight: 400; }
  .custom-chip.custom-chip-input { padding: 0; }
  /* 自定义题量：激活后不显示蓝色高亮选中态（仅视觉中性化，active 类与交互逻辑保留） */
  #countGroup .custom-chip.active {
    background: var(--toolbar-chip-bg); color: var(--toolbar-chip-ink);
    border-color: var(--toolbar-chip-border); box-shadow: none;
  }

  /* ===== 专业（教师）模式：知识点题量填空，横向排列、自动换行、换行缩进 ===== */
  .kp-ratio-flow { display: flex; flex-wrap: wrap; gap: 8px; padding-left: 12px; margin-bottom: 8px; }
  .kp-blank {
    display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
    padding: 4px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--soft-bg);
    cursor: text;
  }
  .kp-blank-nm { font-size: 12px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; max-width: 200px; }
  .kp-blank-num { width: 58px; border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px;
    text-align: center; font-size: 13px; font-weight: 800; color: var(--brand-d);
    font-variant-numeric: tabular-nums; background: var(--card); }
  .kp-blank-num:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
  .kp-blank-unit { font-size: 12px; font-weight: 700; color: var(--muted); }

} /* /@layer pages */
