/* 刷题计时器 Web 版 — iOS 风格主题（移植自桌面版 theme.py QSS） */
:root {
  --accent: #0A84FF;
  --accent-hover: #0873E6;
  --accent-light: #E8F1FF;
  --success: #34C759;
  --success-hover: #2BB44E;
  --danger: #FF3B30;
  --danger-hover: #E63A30;
  --warning: #FF9F0A;
  --purple: #AF52DE;
  --page-bg: #F2F2F7;
  --card-bg: #FFFFFF;
  --border: #E6E6EB;
  --text-primary: #1C1C1E;
  --text-secondary: #8E8E93;
  --sidebar-bg: #EDEDF3;
  --sidebar-hover: #E2E2EA;
  --sidebar-text: #4A4A50;
  --table-alt: #FAFAFC;
  --slow-bg: #FDECEC;
  --slowest-bg: #FAD5D7;
  --radius: 16px;
  --font: "Microsoft YaHei UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--page-bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #2C2C34; color: #fff; padding: 10px 20px; border-radius: 12px;
  font-size: 13px; z-index: 9999; opacity: 0; pointer-events: none;
  transition: opacity .25s; max-width: 80vw;
}
#toast.show { opacity: 1; }
#toast.toast-error { background: #D73A2E; }

/* ---------- 按钮 ---------- */
.btn {
  font-family: var(--font); font-size: 13px; cursor: pointer;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 16px; color: var(--text-primary);
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: #F7F7FA; }
.btn:disabled { color: #C7C7CC; background: #F0F0F4; border-color: #EAEAEE; cursor: not-allowed; }
.btn.primary { background: var(--accent); border: none; color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:disabled { background: #9CC3F5; }
.btn.accent { background: var(--success); border: none; color: #fff; font-weight: 600; }
.btn.accent:hover { background: var(--success-hover); }
.btn.accent:disabled { background: #A9DDB9; }
.btn.danger { background: var(--danger); border: none; color: #fff; font-weight: 600; }
.btn.danger:hover { background: var(--danger-hover); }
.btn.danger:disabled { background: #F0A9A6; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn.ghost:hover { background: #F1F1F6; color: var(--text-primary); }
.btn.block { width: 100%; padding: 12px; font-size: 15px; border-radius: 12px; }
.btn.big { padding: 13px 26px; font-size: 15px; border-radius: 12px; min-height: 46px; }

/* ---------- 登录 ---------- */
.login-overlay {
  position: fixed; inset: 0; background: var(--page-bg); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px;
  padding: 40px 36px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.06);
  display: flex; flex-direction: column; gap: 14px;
}
.login-brand { font-size: 24px; font-weight: 700; text-align: center; }
.login-sub { text-align: center; color: var(--text-secondary); font-size: 13px; margin-bottom: 4px; }
.login-card input {
  font-family: var(--font); font-size: 15px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px; outline: none;
}
.login-card input:focus { border: 2px solid var(--accent); }
.login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------- 应用框架 ---------- */
.app { display: flex; height: 100vh; }

.sidebar {
  width: 210px; background: var(--sidebar-bg); padding: 22px 16px 16px;
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-brand { font-size: 20px; font-weight: 700; }
.sidebar-sub { font-size: 12px; color: var(--text-secondary); margin: 2px 0 22px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  font-family: var(--font); font-size: 14px; text-align: left; cursor: pointer;
  background: transparent; border: none; color: var(--sidebar-text);
  padding: 12px 18px; border-radius: 10px;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--text-secondary); }

.main { flex: 1; overflow: auto; }

.page {
  padding: 20px 24px; max-width: 1280px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 14px; min-height: 100%;
}

/* ---------- 标题 ---------- */
.page-header { display: flex; align-items: flex-start; gap: 12px; }
.page-title { font-size: 17px; font-weight: 700; }
.page-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.page-header .spacer { flex: 1; }
.page-header .btn { flex-shrink: 0; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.card-title { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.card .hint { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }

/* ---------- 表单 ---------- */
.field-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--text-secondary); }
.field input, .field select, .field textarea, .field-row input, .field-row select {
  font-family: var(--font); font-size: 13px; padding: 7px 12px;
  border: 1px solid var(--border); border-radius: 10px; outline: none; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus,
.field-row input:focus, .field-row select:focus { border: 2px solid var(--accent); }

/* ---------- 分段选择 ---------- */
.seg {
  display: inline-flex; background: #E4E4EA; border-radius: 11px; padding: 4px; gap: 2px;
}
.seg button {
  font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer;
  background: transparent; border: none; color: var(--text-secondary);
  padding: 8px 26px; border-radius: 8px;
}
.seg button:hover { color: var(--text-primary); }
.seg button.active { background: #fff; color: var(--text-primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---------- 大号时间 ---------- */
.timer-display {
  text-align: center; font-size: 92pt; font-weight: 700; color: #111;
  line-height: 1.1; font-variant-numeric: tabular-nums; word-break: keep-all;
}
.timer-precise { text-align: center; font-size: 15px; color: var(--text-secondary); font-family: Consolas, var(--font); }
.progress { height: 12px; background: #E4E4EA; border-radius: 6px; overflow: hidden; }
.progress .bar { height: 100%; background: var(--accent); border-radius: 6px; width: 0; transition: width .2s; }
.hotkey-hint { text-align: center; font-size: 12px; color: var(--text-secondary); }
.action-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.action-row .spacer { flex: 1; }

/* ---------- 表格 ---------- */
table.grid {
  width: 100%; border-collapse: collapse; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  font-size: 13px;
}
table.grid th {
  background: #F8F8FC; border-bottom: 1px solid var(--border); padding: 9px 8px;
  font-weight: 600; color: var(--text-secondary); text-align: left; user-select: none;
}
table.grid th.center, table.grid td.center { text-align: center; }
table.grid td { padding: 10px 8px; border-bottom: 1px solid #F0F0F4; vertical-align: middle; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr:nth-child(even) { background: var(--table-alt); }
table.grid tbody tr:hover { background: #F3F6FF; }
table.grid tbody tr.selected { background: var(--accent-light); }
table.grid td .btn { font-size: 12px; padding: 4px 10px; border-radius: 8px; }

/* Excel 式可拖拽列宽 */
table.grid th { resize: horizontal; overflow: hidden; position: relative; }

/* 慢题高亮 */
td.slow { background: var(--slow-bg) !important; }
td.slowest { background: var(--slowest-bg) !important; }

/* ---------- 对/错 与 A/B/C/D 按钮 ---------- */
.corr-toggle { display: inline-flex; gap: 4px; }
.corr-toggle button {
  font-family: var(--font); font-size: 12px; cursor: pointer; padding: 3px 14px;
  border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--text-secondary);
}
.corr-toggle button.right.active { background: var(--success); color: #fff; border: none; font-weight: 600; }
.corr-toggle button.wrong.active { background: var(--danger); color: #fff; border: none; font-weight: 600; }

.opt-picker { display: inline-flex; gap: 3px; }
.opt-picker button {
  width: 24px; height: 24px; font-family: var(--font); font-size: 12px; font-weight: 600;
  cursor: pointer; border: 1px solid #D8DCE4; border-radius: 6px; background: #fff; color: #6B7280;
}
.opt-picker button:hover { background: #F1F1F6; }
.opt-picker button.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.opt-picker button:disabled { color: #C7C7CC; background: #F5F5F8; border-color: #E8E8EC; cursor: not-allowed; }

/* ---------- 统计 KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.kpi {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px;
}
.kpi .value { font-size: 28px; font-weight: 700; }
.kpi .caption { font-size: 12px; color: var(--text-secondary); }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-box { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.chart-box .chart { width: 100%; height: 320px; }
@media (max-width: 980px) { .chart-row { grid-template-columns: 1fr; } }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--page-bg); border-radius: 20px; width: 960px; max-width: 98vw;
  max-height: 92vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-head { padding: 18px 22px 8px; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 8px 22px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 22px 18px; display: flex; align-items: center; gap: 10px; }
.modal-foot .spacer { flex: 1; }
.modal-foot .stats { font-size: 12px; color: var(--text-secondary); }

/* ---------- 复盘弹窗 ---------- */
.dlg-info { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 8px 10px; align-items: center; }
.dlg-info label { font-size: 12px; color: var(--text-secondary); }
.review-table-wrap { overflow: auto; max-height: 40vh; }
.review-table td { padding: 6px 6px; }
.review-table td input[type=number] { width: 80px; font-family: var(--font); padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; }
.review-table td input[type=text] { width: 100%; font-family: var(--font); padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; }
.review-table th, .review-table td { white-space: nowrap; }
.review-table td.col-note { white-space: normal; min-width: 160px; }
textarea.analysis { width: 100%; min-height: 90px; font-family: var(--font); font-size: 13px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; outline: none; resize: vertical; }
textarea.analysis:focus { border: 2px solid var(--accent); }

/* ---------- 设置页 ---------- */
.hotkey-row { display: grid; grid-template-columns: 140px 90px 120px; gap: 10px; align-items: center; margin-bottom: 8px; }
.key-badge { background: #F1F1F6; border-radius: 6px; padding: 5px 12px; font-weight: 600; text-align: center; font-size: 12px; }
.subject-list { list-style: none; border: 1px solid var(--border); border-radius: 12px; background: #fff; max-height: 180px; overflow: auto; }
.subject-list li { padding: 7px 12px; cursor: pointer; border-bottom: 1px solid #F0F0F4; }
.subject-list li:last-child { border-bottom: none; }
.subject-list li.selected { background: var(--accent-light); color: var(--accent); }
.setting-grid { display: flex; gap: 14px; flex-wrap: wrap; }
.setting-grid > .card { flex: 1; min-width: 320px; }

/* ============================================================
   移动端 / 平板 响应式布局
   - 竖屏手机：底部固定操作栏，导航横向滑动
   - 横屏手机：数字缩小避免被截断，模式切换不竖排
   - 平板：保留侧栏，但用触屏友好的尺寸
   ============================================================ */

/* ---------- 手机（窄屏）通用 ---------- */
@media (max-width: 720px) {
  .app { flex-direction: column; }
  /* 品牌与账号一行 + 导航横向滑动，避免挤压换行 */
  .sidebar {
    width: 100%; padding: 10px 14px; flex-direction: column;
    align-items: stretch; gap: 8px; flex-shrink: 0;
  }
  .sidebar-brand { font-size: 17px; }
  .sidebar-sub { display: none; }
  .sidebar-foot {
    order: -1;                    /* 账号放最上面一行 */
    flex-direction: row; align-items: center; justify-content: space-between;
    gap: 8px; font-size: 11px; margin: 0;
  }
  .sidebar-user { flex-wrap: nowrap; }
  .user-chip { font-size: 11px; padding: 3px 9px; }
  .sidebar nav {
    flex-direction: row; margin-left: 0; gap: 6px;
    overflow-x: auto; overflow-y: hidden; padding-bottom: 2px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .nav-item {
    padding: 9px 14px; font-size: 13px; white-space: nowrap;
    flex: 0 0 auto;                /* 不被压缩，靠横向滑动查看 */
    border: 1px solid var(--border); background: #fff; text-align: center;
  }
  .nav-item.active { background: var(--accent); border-color: var(--accent); color: #fff; }
  .main { padding: 12px; }
  .page-header { flex-wrap: wrap; gap: 8px; }
  .page-title { font-size: 16px; }
  .page-sub { font-size: 11px; }
  .card { padding: 12px; }
  .dlg-info { grid-template-columns: 1fr 1fr; }
  .timer-precise { font-size: 12px; }

  /* 模式切换按钮：保证"正计时/倒计时"横排，不被压成竖排 */
  .seg { flex-shrink: 0; }
  .seg button { padding: 8px 16px; white-space: nowrap; }

  /* 操作按钮换行时保持整齐 */
  .action-row { gap: 8px; }
  .action-row .btn.big { flex: 1 1 auto; min-width: 0; padding: 13px 14px; }

  /* 表单在小屏改为单列（每个字段占满一行），避免输入框被截断。
     注意：不要用 !important 覆盖 min-width，否则内联 flex:1 会把字段压成 0 宽度，
     导致 label 竖排成一字一行。 */
  .field-row { flex-wrap: wrap; }
  .field-row .field { flex: 1 1 100%; min-width: 0; }
  .field-row .field input, .field-row .field select { width: 100%; }

  /* 图表在小屏单列 */
  .chart-row { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .kpi .value { font-size: 22px; }
  .an-table { min-width: 100%; }

  /* 设置页：按钮组允许换行，避免超出屏幕 */
  .field-row { flex-wrap: wrap; }
  .field-row .btn { flex: 0 1 auto; white-space: normal; text-align: center; }
  /* 快捷键行：三列网格在窄屏改为两行（名称 / 按键+按钮） */
  .hotkey-row { grid-template-columns: 1fr auto auto; gap: 8px; }
  .hotkey-row > span:first-child { font-size: 12px; }
  /* 弹窗内表单在窄屏单列 */
  .modal { max-width: calc(100vw - 24px) !important; width: auto !important; }
  .modal-body { padding: 14px; }
}

/* ---------- 平板（宽屏 + 触屏）：放大触控目标 ---------- */
/* 注意 min-height 排除横屏手机：横屏手机宽度也 >721px，
   否则页头元素顺序会被改写（全屏按钮跑到模式切换左边）。 */
@media (min-width: 721px) and (max-width: 1180px) and (min-height: 501px) {
  .sidebar { width: 176px; padding: 18px 14px 14px; }
  .sidebar-brand { font-size: 18px; }
  .nav-item { padding: 11px 14px; font-size: 13.5px; }
  .main { padding: 18px; }
  /* 平板通常用触控，按钮做大一点 */
  .btn { padding: 9px 16px; }
  .seg button { padding: 9px 22px; white-space: nowrap; }
  .timer-display { font-size: 76pt; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  /* 平板上页头允许换行，模式切换不被挤压 */
  .page-header { flex-wrap: wrap; row-gap: 10px; }
}

/* ---------- 大屏平板 / 桌面窄窗：内容居中，避免过宽拉伸 ---------- */
@media (min-width: 1181px) {
  .main > .page { max-width: 1100px; margin: 0 auto; }
}

/* 平板横屏：数字适当缩小，避免过高 */
@media (min-width: 900px) and (max-width: 1400px) and (orientation: landscape) {
  .timer-display { font-size: 64pt; }
}

/* ---------- 触屏通用：放大可点区域 ---------- */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .nav-item { min-height: 40px; }
  .seg button { min-height: 38px; }
  table.grid td, table.grid th { padding-top: 11px; padding-bottom: 11px; }
  select, input[type="text"], input[type="number"], input[type="password"],
  input[type="date"], input[type="time"] { min-height: 40px; }
}

/* ---------- 模块分析页 ---------- */
.an-section { margin-top: 8px; }
.an-section-title { font-size: 15px; font-weight: 700; margin: 14px 0 2px; }
.an-section-sub { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
.an-filter { margin-bottom: 4px; }
.an-chip {
  display: inline-block; background: var(--accent-light); color: var(--accent);
  border-radius: 20px; padding: 5px 12px; font-size: 12px; font-weight: 600;
  margin-left: 6px; white-space: nowrap;
}
.an-kpi-sub { font-size: 11px; color: var(--text-secondary); margin-top: 3px; line-height: 1.5; }
.an-scope { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }

.an-table-card { margin-top: 14px; padding: 14px; }
.an-table-title { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.an-table-scroll { overflow-x: auto; }
.an-table { min-width: 1080px; }
.an-table th { font-size: 12px; white-space: nowrap; }
.an-table td { font-size: 12px; white-space: nowrap; padding: 9px 10px; }
.an-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 6px; vertical-align: middle;
}

/* 分析页图表在窄屏下的自适应 */
@media (max-width: 980px) {
  .an-table { min-width: 900px; }
}

/* ---------- 权限 / 用户 ---------- */
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.sidebar-user { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-chip {
  font-size: 11px; padding: 4px 10px; border-radius: 20px;
  background: #E4E4EA; color: var(--sidebar-text); font-weight: 600;
}
.user-chip.admin { background: #FFF3D6; color: #8A6100; }
.logout-btn {
  font-family: var(--font); font-size: 11px; cursor: pointer;
  background: transparent; border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px; color: var(--text-secondary);
}
.logout-btn:hover { background: #fff; color: var(--danger); border-color: #F3C6C3; }

.readonly-banner {
  background: #FFF8E6; border: 1px solid #FFE1A3; color: #8A6100;
  border-radius: 10px; padding: 9px 14px; font-size: 12px; margin-bottom: 10px;
}

.user-table-wrap { overflow-x: auto; }
.user-table { min-width: 780px; }
.user-table td { vertical-align: middle; }
.role-tag {
  display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 600;
}
.role-tag.admin { background: #FFF3D6; color: #8A6100; }
.role-tag.guest { background: #EDEDF3; color: #5A5A64; }
.me-tag {
  font-size: 10px; background: var(--accent-light); color: var(--accent);
  border-radius: 20px; padding: 2px 7px; margin-left: 5px; font-weight: 600;
}
.perm-pill {
  display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 20px;
  margin: 2px 4px 2px 0; background: #F1F1F6; color: #5A5A64;
}
.perm-pill.on { background: #E3F6E8; color: #1F7A3A; font-weight: 600; }
.perm-pill.off { background: #F6F6F9; color: #B0B0B8; text-decoration: line-through; }
.perm-pill.base { background: var(--accent-light); color: var(--accent); }
.perm-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.perm-item {
  display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer;
  background: #FAFAFC; border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px;
}
.perm-item:hover { background: #F4F4F8; }
.perm-item input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.btn.sm { font-size: 12px; padding: 4px 10px; border-radius: 8px; }
.btn.ghost.danger { color: var(--danger); }
.btn.ghost.danger:hover { background: #FDECEC; border-color: #F3C6C3; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- 手动补录 ---------- */
.src-tag {
  display: inline-block; font-size: 10px; padding: 2px 7px;
  border-radius: 20px; margin-left: 5px; font-weight: 600; vertical-align: middle;
}
.src-tag.manual { background: #FFF3D6; color: #8A6100; }
.page-header .btn { flex-shrink: 0; }

/* 手动补录表单：3 列网格，避免时长输入框换行错位 */
.mn-form {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px 12px; align-items: center;
}
.mn-form label { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.mn-form input, .mn-form select {
  font-family: var(--font); font-size: 13px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 10px; outline: none;
  background: #fff; width: 100%; min-width: 0;
}
.mn-form input:focus, .mn-form select:focus { border: 2px solid var(--accent); }
.mn-form .dur-inputs { display: flex; align-items: center; gap: 5px; }
.mn-form .dur-inputs input { width: 58px; flex: 0 0 auto; }
.mn-form .dur-inputs .hint { white-space: nowrap; }
@media (max-width: 720px) {
  .mn-form { grid-template-columns: auto minmax(0, 1fr); }
}

/* ---------- 移动端 / 外接硬件按键 ---------- */
/* 移动端专属元素默认隐藏，由 JS 判定后在手机上显示 */
.mobile-only { display: none; }

/* 底部固定操作栏：拇指可达，边做题边点 */
.mobile-actionbar { display: none; }
.mab-btn.pulse {
  transform: scale(0.94);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, .28);
}

body.mobile-mode .mobile-only { display: block; }
body.mobile-mode .mobile-actionbar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 900;
}
body.mobile-mode .main { padding-bottom: 92px; }   /* 给底栏留空间 */

.mab-btn {
  font-family: var(--font); font-size: 16px; font-weight: 700;
  padding: 15px 8px; border-radius: 14px; border: 1px solid var(--border);
  background: #fff; color: var(--text-primary); cursor: pointer;
  transition: transform .12s, background .15s, color .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mab-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.mab-btn.accent { background: var(--warning); border-color: var(--warning); color: #fff; }
.mab-btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.mab-btn:disabled { opacity: .38; }
.mab-btn:not(:disabled):active { transform: scale(.95); }

/* 触屏下把主操作按钮也放大，方便点按 */
body.mobile-mode .btn.big { padding: 15px 22px; font-size: 15px; }
body.mobile-mode .action-row { gap: 10px; }
body.mobile-mode .timer-display { font-size: 52pt; }
body.mobile-mode .hotkey-hint { font-size: 12px; line-height: 1.7; }

@media (max-width: 720px) {
  body.mobile-mode .timer-display { font-size: 44pt; }
  body.mobile-mode .action-row { flex-wrap: wrap; }
}

/* ---------- 手机横屏（矮屏）：压缩纵向空间 ---------- */
@media (max-width: 980px) and (max-height: 500px) {
  /* 横屏时侧栏已是顶栏，进一步压缩 */
  .sidebar { padding: 6px 12px; gap: 6px; }
  .sidebar-brand { font-size: 15px; }
  .sidebar nav { gap: 5px; }
  .nav-item { padding: 6px 11px; font-size: 12px; }
  .main { padding: 10px; }

  /* 关键：横屏时数字必须缩小，否则会被底部操作栏截断。
     加 body.mobile-mode 前缀保持同等特异性，确保覆盖上方 52pt 规则。 */
  .timer-display, body.mobile-mode .timer-display { font-size: 38pt; line-height: 1.05; }
  .timer-precise, body.mobile-mode .timer-precise { font-size: 11px; }

  /* 隐藏次要提示，给计时数字腾空间 */
  .hotkey-hint { display: none; }
  body.mobile-mode .hotkey-hint { display: none; }
  .page-sub { display: none; }

  /* 卡片内边距收紧 */
  .card { padding: 10px 12px; }
  .card-title { font-size: 13px; margin-bottom: 6px; }

  /* 开始前设置：横屏排成一行，套题名称给足空间，不被截断 */
  .field-row { flex-wrap: nowrap; }
  .field-row .field { flex: 1 1 auto; min-width: 0; }
  .field-row .field:nth-child(1) { flex: 0 0 150px; }   /* 模块 */
  .field-row .field:nth-child(2) { flex: 1 1 auto; }     /* 套题名称：占满剩余 */
  .field-row .field:nth-child(3) { flex: 0 0 96px; }     /* 预期题数 */
  /* 输入框允许收缩，避免撑破容器 */
  .field-row .field input, .field-row .field select { width: 100%; min-width: 0; }

  /* 操作按钮压扁 */
  .action-row .btn.big { padding: 10px 14px; font-size: 14px; }

  /* 底部操作栏变矮 */
  body.mobile-mode .mobile-actionbar {
    padding: 7px 12px calc(7px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }
  body.mobile-mode .mab-btn { padding: 11px 8px; font-size: 15px; }
  body.mobile-mode .main { padding-bottom: 74px; }

  /* 图表在横屏可以排两列（宽度够） */
  .chart-row { grid-template-columns: 1fr 1fr; }
  .chart-box .chart { height: 260px; }
}

/* ============================================================
   移动端表格：宽表格在自己的容器里横向滚动（不撑破页面）
   ============================================================ */
@media (max-width: 900px) {
  /* 历史记录 / 用户管理等宽表：容器可滚动 + 细滚动条 */
  .main table.grid {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .main table.grid thead,
  .main table.grid tbody { display: table; width: max-content; min-width: 100%; }
  .main table.grid th, .main table.grid td { white-space: nowrap; }
  .main table.grid::-webkit-scrollbar { height: 4px; }
  .main table.grid::-webkit-scrollbar-thumb { background: #C7C7CC; border-radius: 4px; }

  /* 复盘弹窗的表格也允许滚动（已有 .review-table-wrap） */
  .review-table-wrap { max-height: 46vh; }

  /* 弹出的复盘/补录弹窗在手机上铺满 */
  .modal-mask { padding: 10px; }
  .modal { width: 100% !important; max-width: 100% !important; }
  .modal-title { font-size: 15px; }
  .dlg-info { grid-template-columns: 1fr; gap: 6px; }

  /* 分析页的明细表：小屏隐藏次要列，避免横向滚动过长 */
  .an-table th:nth-child(n+9), .an-table td:nth-child(n+9) { display: none; }
}

/* 手机竖屏：分析页图表高度收紧，减少滚动 */
@media (max-width: 720px) {
  .chart-box .chart { height: 280px; }
  .an-section-title { font-size: 14px; }
  .an-section-sub { font-size: 11px; }
  /* 复盘表格的输入框在窄屏缩一点 */
  .review-table td input[type=number] { width: 62px; }
  .corr-toggle button, .opt-picker button { padding: 4px 8px; font-size: 12px; }
}

/* 平板：分析页图表两列更舒展（同样排除横屏手机） */
@media (min-width: 721px) and (max-width: 1180px) and (min-height: 501px) {
  .chart-row { grid-template-columns: 1fr 1fr; }
  .chart-box .chart { height: 300px; }
}
