/* ===================== 基础 ===================== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #f5f7fa; --panel: #ffffff; --line: #e3e8ef; --text: #1f2733;
  --muted: #6b7785; --primary: #2f6fed; --primary-d: #2257c4;
  --ok: #1f9d55; --warn: #e0a106; --danger: #e0533d; --chip: #eef3ff;
  --shadow: 0 2px 10px rgba(20,40,80,.06);
}
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; }
.btn {
  border: none; border-radius: 10px; padding: 10px 16px; font-size: 15px;
  background: var(--primary); color: #fff; font-weight: 600; transition: .15s;
}
.btn:hover { background: var(--primary-d); }
.btn.ghost { background: #fff; color: var(--primary); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--chip); }
.btn.danger { background: #fff; color: var(--danger); border: 1px solid #f3c4bb; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  /* 必须 ≥16px：iOS Safari 对小于 16px 的输入框会在聚焦时把整页放大（M8） */
  border-radius: 10px; font-size: 16px; font-family: inherit; background: #fff; color: var(--text);
}
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

/* ===================== 布局 ===================== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: 0 0 248px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 800; font-size: 17px; padding: 6px 8px 12px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.nav-section-title { font-size: 12px; color: var(--muted); margin: 14px 8px 6px; font-weight: 700; letter-spacing: .04em; }
.nav-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px;
  color: var(--text); cursor: pointer; font-size: 15px; user-select: none;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--chip); color: var(--primary-d); font-weight: 700; }
.nav-item .ic { width: 20px; text-align: center; opacity: .8; }
.nav-item .edit { margin-left: auto; opacity: 0; color: var(--muted); font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.nav-item:hover .edit { opacity: 1; }
.nav-item .edit:hover { background: #e6ebf2; color: var(--primary); }
.nav-item .caret { width: 16px; flex: 0 0 auto; text-align: center; cursor: pointer; color: var(--muted); user-select: none; }
.nav-item .caret-placeholder { width: 16px; flex: 0 0 auto; display: inline-block; }

/* 积分获得弹窗 */
.point-pop {
  position: fixed; z-index: 999; transform: translate(-50%, 0);
  background: linear-gradient(135deg, #ff9d2f, #ff6a3d); color: #fff;
  padding: 8px 16px; border-radius: 999px; font-weight: 800; font-size: 16px;
  box-shadow: 0 6px 20px rgba(255,120,60,.4); pointer-events: none;
  animation: popUp 1.3s ease forwards;
}
/* 积分扣减弹窗（兑换） */
.point-pop.minus {
  background: linear-gradient(135deg, #6b7280, #374151);
  box-shadow: 0 6px 20px rgba(55,65,81,.35);
}
@keyframes popUp {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(.8); }
  18% { opacity: 1; transform: translate(-50%, -8px) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -64px) scale(1); }
}

/* 星期选择 chips */
.wk-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.wk-chip { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; cursor: pointer; user-select: none; background: #fff; }
.wk-chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
/* 可折叠区块（弹窗内用，如休息日设置） */
.collapse { border: 1px solid var(--line); border-radius: 12px; margin: 12px 0 4px; overflow: hidden; }
.collapse-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; cursor: pointer; font-weight: 600; font-size: 14px; background: var(--chip); user-select: none; }
.collapse-head:hover { background: #e6ebf2; }
.collapse-head .caret { color: var(--muted); flex: 0 0 auto; }
.collapse-body { padding: 12px; border-top: 1px solid var(--line); }
.sub-tree { margin-left: 14px; border-left: 1px dashed var(--line); padding-left: 4px; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.quick-grid .btn { font-size: 13px; padding: 9px 6px; }
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.hamburger { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.back-btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 12px; color: var(--primary); font-weight: 600; }
.back-btn:hover { background: var(--chip); }
.content { padding: 20px; max-width: 1100px; width: 100%; }

/* ===================== 卡片 / 网格 ===================== */
.cards { display: grid; gap: 14px; }
.cards.c3 { grid-template-columns: repeat(3, 1fr); }
.cards.c2 { grid-template-columns: repeat(2, 1fr); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .big { font-size: 30px; font-weight: 800; margin: 6px 0; }
.muted { color: var(--muted); font-size: 13px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: #e6f6ec; color: var(--ok); }
.pill.warn { background: #fdf3da; color: var(--warn); }
.pill.neutral { background: #eef1f5; color: var(--muted); }

/* 科目汇总三栏 */
.subject-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 8px; }
.section-title { font-size: 16px; font-weight: 700; margin: 22px 0 10px; }

/* 任务列表 */
.task-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.task-row:hover { border-color: var(--primary); box-shadow: 0 2px 10px rgba(37,99,235,.08); }
.task-row .chk { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); flex: 0 0 auto; }
.task-row.done .chk { background: var(--ok); border-color: var(--ok); }
.task-row.done .ttl { text-decoration: line-through; color: var(--muted); }
.task-row .ttl { flex: 1; font-weight: 600; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--chip); color: var(--primary-d); }

/* 标签切换 */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.tab { padding: 6px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.tab.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* 计划打卡卡片 */
.plan-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 10px; }
.pc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pc-head b { font-size: 15px; }
.pc-meta { color: var(--muted); font-size: 13px; margin: 6px 0; }
.pc-prog { height: 8px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.pc-bar { height: 100%; background: linear-gradient(90deg, #2f6fed, #5b8def); border-radius: 999px; transition: width .3s; }
.pc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; gap: 8px; flex-wrap: wrap; }
.pc-btns { display: flex; gap: 6px; margin-left: auto; }
.pc-sub { font-size: 12px; margin-top: 2px; }
/* 首页今日任务：复用任务详情卡片样式 */
.plan-card.done { opacity: .6; }
.plan-card.done .pc-head b { text-decoration: line-through; }
.plan-card.clickable { cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.plan-card.clickable:hover { border-color: var(--primary); box-shadow: 0 2px 10px rgba(37,99,235,.08); }
.pc-jump-hint { font-size: 12px; color: var(--primary); margin-top: 8px; }
.pc-src { display: inline-block; font-size: 12px; color: var(--primary-d); background: var(--chip); border-radius: 6px; padding: 2px 8px; margin-top: 6px; }

/* 首页 · 全局总览四卡（大字主指标 + 小字细分，可点进全局管理页） */
.ov-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.ov-card { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.ov-card:hover { box-shadow: 0 6px 18px rgba(0,0,0,.09); transform: translateY(-1px); }
/* 首页 · 第三大块可点卡片（积分总览 → 积分管理页）沿用 ov-card 的点按反馈 */
.card[data-goto] { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.card[data-goto]:hover { box-shadow: 0 6px 18px rgba(0,0,0,.09); transform: translateY(-1px); }
.ov-card .big { margin-bottom: 10px; }
.ov-rows { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.ov-row { display: inline-flex; align-items: baseline; gap: 5px; font-size: 13px; }
.ov-row i { font-style: normal; color: var(--muted); }
.ov-row b { font-size: 15px; }
.ov-hint { margin-top: 10px; font-size: 12px; color: var(--primary-d); }

/* 练习卷页 · 生成任务固定入口 */
.m-tasklink { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; padding: 12px 14px; background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; }

/* 打卡卡片：色块 + 编辑/删除图标按钮 + 打卡表单 */
.pc-dot { width: 13px; height: 13px; border-radius: 4px; background: var(--ok); flex: 0 0 auto; }
.pc-head { gap: 8px; }
.icon-btn { border: 1px solid var(--line); background: #fff; width: 34px; height: 34px; border-radius: 10px; font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--chip); color: var(--primary); }
.pc-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; }
.pc-form .f { flex: 1; min-width: 92px; }
.pc-form label { margin: 0 0 4px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-form input, .pc-form select { padding: 9px 10px; font-size: 14px; border-radius: 9px; }
.pc-form .btn { flex: 0 0 auto; padding: 9px 20px; }
.btn:disabled, .btn:disabled:hover { background: #c9d2de; color: #fff; cursor: not-allowed; }
.pc-form input:disabled, .pc-form select:disabled { background: #f2f4f8; color: #a6b0bd; cursor: not-allowed; }
.pc-bar.full { background: linear-gradient(90deg, #1f9d55, #34c072); }

/* 周期历史记录卡片 */
.plan-card.cycle-record { opacity: .88; }
.plan-card.cycle-record.overdue { border-color: var(--danger); background: #fff8f7; }
.plan-card.cycle-record.done { opacity: .72; }
.cycle-info { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 8px; font-size: 12px; font-weight: 500; margin-top: 6px; }
.cycle-info.overdue { background: #fde8e5; color: var(--danger); border: 1px solid #f3c4bb; }
.cycle-info.done { background: #e6f6ec; color: var(--ok); border: 1px solid #c8e6d5; }

/* 历史列表页工具栏 */
.history-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 12px 0; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.history-toolbar .date-range { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.history-toolbar .date-range input[type="date"] { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); font-size: 13px; }
.selected-count { font-size: 13px; color: var(--muted); min-width: 60px; }

/* 历史列表项 */
.list-item { display: flex; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 10px; }
.list-item.overdue { border-color: var(--danger); background: #fff8f7; }
.list-item.done { opacity: .85; }
.list-item input[type="checkbox"] { width: 18px; height: 18px; margin-top: 3px; cursor: pointer; flex-shrink: 0; }
.list-item-content { flex: 1; min-width: 0; }

/* 加载更多按钮 */
.load-more-btn { display: block; width: 100%; padding: 12px; margin-top: 10px; border: 1px dashed var(--line); background: transparent; border-radius: 12px; font-size: 14px; color: var(--muted); cursor: pointer; transition: all .15s; }
.load-more-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--chip); }

/* 分页控件 */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 20px 0; margin-top: 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pagination button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; font-size: 14px; font-family: inherit; cursor: pointer; color: var(--text); transition: all .15s; min-width: 36px; text-align: center; }
.pagination button:hover:not(:disabled):not(.active) { background: var(--chip); border-color: var(--primary); color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .dots { color: var(--muted); padding: 0 4px; }


/* ===================== 弹窗 ===================== */
.modal-mask { position: fixed; inset: 0; background: rgba(20,30,50,.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 420px; padding: 22px; box-shadow: 0 12px 40px rgba(0,0,0,.2); max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .actions .btn { flex: 1; }
.field-row { display: flex; gap: 10px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1f2733; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 99; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* 移动端 / iPad 抽屉 */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s;
    box-shadow: 0 0 40px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 1px solid var(--line); background: #fff; border-radius: 10px; font-size: 18px; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 35; }
  .cards.c3, .cards.c2, .subject-summary { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}

/* ===================== M3 错题本 ===================== */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.m-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.m-head-title { font-size: 17px; font-weight: 800; }
.m-head-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.m-pendbar { display: flex; align-items: center; gap: 10px; background: #fdf6e3; border: 1px solid #f0e0b0; border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }

.m-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.m-chip { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 13px; color: var(--muted); cursor: pointer; user-select: none; }
.m-chip:hover { border-color: var(--primary); color: var(--primary); }
.m-chip.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.m-chip.sm { padding: 4px 10px; font-size: 12px; }
.m-chip input { width: auto; margin: 0; }

.m-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.m-qcard { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer; text-align: left; transition: .15s; box-shadow: var(--shadow); }
.m-qcard:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(47,111,237,.14); transform: translateY(-1px); }
.m-qcard.picked { border-color: var(--primary); background: var(--chip); }
.m-thumb { height: 120px; border-radius: 10px; overflow: hidden; background: #f2f4f8; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.m-thumb img { width: 100%; height: 100%; object-fit: cover; }
.m-ph { font-size: 13px; color: var(--muted); padding: 10px; text-align: center; line-height: 1.5; max-height: 100%; overflow: hidden; }
.m-ph.big { font-size: 16px; }
.m-qrow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.kp-namerow { display: flex; gap: 12px; align-items: flex-end; }
.kp-namerow > div { min-width: 0; }
.kp-namecell { flex: 1 1 auto; }
.kp-catcell { flex: 0 0 38%; max-width: 220px; }
@media (max-width: 360px) { .kp-catcell { flex: 0 0 44%; max-width: none; } }
.m-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.m-badge { font-size: 12px; padding: 2px 8px; border-radius: 6px; font-weight: 700; white-space: nowrap; }
.mb-wrong { background: #fdecea; color: #c0392b; }
.mb-good { background: #fdf6e3; color: #b7791f; }
.mb-weak { background: #efeafa; color: #6b46c1; }
.mb-corr { background: #e6f6ec; color: var(--ok); }
.mb-none { background: #eef1f5; color: var(--muted); }
.mb-todo { background: #fdecea; color: #c0392b; }
.m-kn { font-size: 13px; font-weight: 600; color: var(--primary-d); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-kn.empty { color: #a6b0bd; font-weight: 400; }
.m-pick { position: absolute; top: 10px; left: 10px; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 2px solid #cfd8dc; color: #fff; font-size: 13px; display: flex; align-items: center; justify-content: center; z-index: 2; }
.m-qcard.picked .m-pick { background: var(--primary); border-color: var(--primary); }

/* 详情 */
.m-detail { display: flex; gap: 20px; align-items: flex-start; }
.m-detail-img { flex: 1 1 46%; min-width: 0; }
.m-detail-info { flex: 1 1 54%; min-width: 0; }
.m-bigimg { width: 100%; min-height: 300px; max-height: 520px; border-radius: 14px; background: #f2f4f8; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: hidden; cursor: zoom-in; }
.m-bigimg img { max-width: 100%; max-height: 480px; border-radius: 8px; }
.m-thumbs { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.m-ts { width: 92px; height: 70px; border-radius: 10px; background: #f2f4f8; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); cursor: pointer; overflow: hidden; }
.m-ts img { width: 100%; height: 100%; object-fit: cover; }
.m-ts.add { border-style: dashed; color: var(--primary); }
.m-actions { position: sticky; top: 0; z-index: 3; background: var(--bg); display: flex; gap: 8px; flex-wrap: wrap; padding: 0 0 12px; }
.m-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.m-typebtns { display: flex; gap: 8px; }
.m-typebtn { flex: 1; padding: 12px 6px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-size: 14px; font-weight: 700; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.m-typebtn.on { border-color: var(--tc); color: var(--tc); background: #fff; }
.m-stars { display: flex; gap: 6px; }
.m-star { font-size: 26px; color: #dfe4ea; cursor: pointer; line-height: 1; }
.m-star.on { color: #e0a106; }
.m-ai { background: var(--chip); border: 1px solid #cdddff; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.m-ai .hd { font-size: 13px; font-weight: 800; color: var(--primary-d); margin-bottom: 6px; }
.m-ai .bd { font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.m-derived-entry { cursor: pointer; margin-top: 12px; }
.m-derived-entry:hover { border-color: var(--primary); }

/* 复习 */
.m-review { max-width: 720px; margin: 0 auto; }
.m-rv-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
.m-rv-bar { flex: 1; height: 8px; background: #e6eaf0; border-radius: 999px; overflow: hidden; }
.m-rv-bar i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.m-rv-img { width: 100%; min-height: 300px; background: #fff; border-radius: 16px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; padding: 20px; margin-bottom: 14px; overflow: hidden; }
.m-rv-img img { max-width: 100%; max-height: 440px; }
.m-rv-img.ans { background: #f1f8e9; }
.m-markbtns { display: flex; gap: 10px; }
.m-markbtns button { flex: 1; padding: 18px 8px; border: none; border-radius: 14px; color: #fff; font-size: 17px; font-weight: 800; }

/* 练习 / 生成预览 */
.m-pq { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: #fff; }
.m-pq-h { font-weight: 800; font-size: 15px; color: var(--primary-d); margin-bottom: 8px; }
.m-pq-q { font-size: 15px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.m-opts { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 4px; }
.m-opt { display: flex; align-items: flex-start; gap: 10px; text-align: left; width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 14px; line-height: 1.5; cursor: pointer; }
.m-opt b { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; background: #eef1f5; color: var(--muted); display: flex; align-items: center; justify-content: center; font-size: 12px; }
.m-opt.on { border-color: var(--primary); background: var(--chip); }
.m-opt.on b { background: var(--primary); color: #fff; }
.m-opt.static { cursor: default; background: #fafbfc; }
.m-opt.correct { border-color: #16a34a; background: #f0fdf4; }
.m-opt.picked { border-color: var(--primary); background: #eff6ff; }
.m-pq-ans { display: none; margin-top: 10px; background: #f1f8e9; border-radius: 10px; padding: 11px 14px; font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.m-pq-ans.show { display: block; }
.m-pq-ansbox { margin-top: 8px; font-size: 14px; }

/* 表格（题本管理） */
.m-tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.m-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.m-table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px; border-bottom: 1px solid var(--line); }
.m-table td { padding: 10px; border-bottom: 1px solid #f5f7fa; font-size: 13px; vertical-align: middle; }
.m-table tr:last-child td { border-bottom: none; }
.m-table tr:hover td { background: #fafcff; }
.m-selbox { width: auto; margin: 0; }
.m-minithumb { width: 48px; height: 38px; border-radius: 6px; background: #f2f4f8; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); overflow: hidden; }
.m-minithumb img { width: 100%; height: 100%; object-fit: cover; }

/* 拍照裁剪 */
.crop-mask { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: none; flex-direction: column; z-index: 120; }
.crop-mask.on { display: flex; }
.crop-tip { color: #cfcfcf; font-size: 12px; text-align: center; padding: 8px 10px; background: #0c0c0c; }
#lcCropStage { flex: 1; position: relative; overflow: hidden; touch-action: none; background: #000; }
#lcCropCanvas { display: block; width: 100%; height: 100%; }
.crop-bar { display: flex; gap: 10px; padding: 12px; background: #111; }
.crop-bar .btn { flex: 1; }

/* 打印 */
.m-print-modal { max-width: 900px; width: 100%; }
.print-area { background: #fff; padding: 10px; max-height: 66vh; overflow: auto; }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; max-height: none; overflow: visible; padding: 0; }
  .no-print { display: none !important; }
  @page { margin: 16mm; }
}

/* 知识提炼（M4） */
.kp-card { padding-left: 44px; }
.kp-title { font-size: 15px; font-weight: 800; color: var(--text); margin-bottom: 4px; word-break: break-word; }
.kp-brief { font-size: 13px; color: var(--text); font-weight: 600; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.kp-desc { font-size: 13px; color: var(--muted); line-height: 1.55; white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.kp-val { white-space: pre-wrap; word-break: break-word; }
.kp-meta { font-size: 12px; color: #a6b0bd; margin-top: 8px; }
.kp-line { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; font-size: 14px; line-height: 1.6; }
.kp-label { flex: 0 0 68px; color: var(--muted); font-size: 13px; }
.kp-val { flex: 1; word-break: break-word; }
.kp-rv-title { font-size: 21px; margin: 8px 0 14px; }
.kp-rel { padding: 8px 0; border-bottom: 1px solid #f5f7fa; font-size: 14px; }
.kp-rel:last-child { border-bottom: none; }
.kp-pickbar { position: sticky; bottom: 0; z-index: 4; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; margin-top: 14px; box-shadow: var(--shadow); }
.kp-picklist { max-height: 52vh; overflow-y: auto; margin-top: 6px; }

@media (max-width: 820px) {
  .m-detail { flex-direction: column; }
  .m-head-btns { margin-left: 0; }
  .m-table { min-width: 640px; }
  .kp-label { flex-basis: 60px; }
  .kp-pickbar .btn { flex: 1; }
}

/* ===================== M7：登录门 / 账号与成员 ===================== */
.lc-auth {
  position: fixed; inset: 0; z-index: 9999; overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.lc-auth-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 26px 22px 22px; box-shadow: var(--shadow);
}
.lc-auth-brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 800; }
.lc-auth-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.lc-auth-sub { color: var(--muted); font-size: 13px; margin: 4px 0 16px; }
.lc-auth-step { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.lc-field { margin-bottom: 10px; }
.lc-input { width: 100%; }
.lc-auth .btn.block { margin-top: 8px; }
.lc-auth-err {
  background: #fdecea; color: var(--danger); border: 1px solid #f6cfc9;
  border-radius: 10px; padding: 8px 10px; font-size: 13px; margin: 8px 0; line-height: 1.5;
}
.lc-auth-hint { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin-top: 12px; }
.lc-members { display: flex; flex-direction: column; gap: 8px; }
.lc-member {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; color: var(--text); text-align: left;
}
.lc-member:hover { border-color: var(--primary); background: var(--chip); }
.lc-member-avatar { font-size: 18px; }
.lc-member-name { flex: 1; font-weight: 600; }
.lc-member-role { font-size: 12px; color: var(--muted); }

.acc-line { font-size: 14px; margin-bottom: 6px; }
.acc-line code { background: var(--chip); padding: 1px 7px; border-radius: 6px; font-size: 13px; }
.mem-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 0; border-bottom: 1px solid #f5f7fa; font-size: 14px;
}
.mem-row:last-of-type { border-bottom: none; }
.mem-ic { font-size: 17px; }
.mem-name { font-weight: 600; flex: 1; min-width: 80px; }

/* ===================== M8：跨端适配（iPad / 触屏收尾） ===================== */

/* ① 消除双击缩放与点击 300ms 延迟（iPad 上双击表单区域不再把页面放大） */
.btn, .tab, .m-chip, .wk-chip, .nav-item, .collapse-head, .lc-member, .hamburger,
.task-row, .ov-card, .m-qcard, .m-opt, .m-star, .caret {
  touch-action: manipulation;
}

/* ② 触屏没有 hover —— 修掉依赖 hover 的交互 */
@media (hover: none) {
  /* 真 bug：科目「编辑 ✎」原本只在 :hover 显示，iPad 上等于永远看不见、点不到 */
  .nav-item .edit { opacity: .55; }
  /* 中和触屏「点一下 hover 就粘住」的假高亮 */
  .btn:hover { background: var(--primary); color: #fff; }
  .btn.ghost:hover { background: #fff; color: var(--primary); }
  .btn.danger:hover { background: #fff; color: var(--danger); }
  .back-btn:hover { background: #fff; }
  .tab:hover { background: #fff; color: var(--muted); }
  .lc-member:hover { border-color: var(--line); background: #fff; }
  .task-row:hover { border-color: var(--line); box-shadow: none; }
}

/* ③ 按压反馈：触屏上唯一看得见的点击反馈 */
.btn:active { transform: translateY(1px); filter: brightness(.94); }
.tab:active, .m-chip:active, .wk-chip:active, .m-opt:active { background: var(--chip); }
.nav-item:active { background: var(--bg); }

/* ④ 触屏放大热区到可点尺寸（桌面端保持紧凑不变） */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn.sm { min-height: 36px; padding: 8px 13px; }
  .nav-item { min-height: 44px; }
  .caret { min-width: 34px; min-height: 34px; display: inline-flex; align-items: center; justify-content: center; }
  .tab, .m-chip, .wk-chip { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; }
  .lc-member { min-height: 52px; }
  .m-star { padding: 2px 5px; }
  input, select, textarea { min-height: 44px; }
}

/* ⑤ 抽屉打开时锁住背后滚动（iPad 上背后跟着滚很难受） */
body.drawer-open { overflow: hidden; }

/* ⑥ 安全区：避开圆角 / Home Indicator / 地址栏（viewport-fit=cover 已在 <meta> 打开） */
.topbar { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
.content { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
.toast { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
.modal-mask { padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.lc-auth { padding: calc(20px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px)); }
.sidebar { padding-left: calc(12px + env(safe-area-inset-left, 0px)); padding-right: calc(12px + env(safe-area-inset-right, 0px)); }
@media (max-width: 820px) {
  .content { padding: 14px; padding-left: calc(14px + env(safe-area-inset-left, 0px)); padding-right: calc(14px + env(safe-area-inset-right, 0px)); padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .sidebar { padding-top: calc(14px + env(safe-area-inset-top, 0px)); padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
}

/* ⑦ iOS 地址栏收起/展开会让 100vh 跳，配 dvh 兜底 */
@supports (height: 100dvh) { .app { min-height: 100dvh; } .sidebar { height: 100dvh; } }
@supports (height: 100svh) { .sidebar { max-height: 100svh; } }

/* ⑧ iOS 惯性滚动 */
.sidebar, .modal, .kp-picklist, .m-tablewrap { -webkit-overflow-scrolling: touch; }

/* ⑨ 顶栏同步状态小标（点一下进设置页） */
.sync-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--muted); background: var(--chip);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; white-space: nowrap; flex: 0 0 auto;
}
.sync-chip .d { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.sync-chip.local { background: #f2f4f8; }
.sync-chip.local .d { background: var(--muted); }
.sync-chip.warn .d { background: var(--warn); }
.sync-chip.err .d { background: var(--danger); }
.sync-chip.off { opacity: .6; }
@media (max-width: 560px) { .sync-chip .t { display: none; } .sync-chip { padding: 5px 8px; } }

/* ⑩ 孩子账号的只读态（积分配置等「仅家长可改」项 → 置灰） */
.card.locked { opacity: .72; }
.card.locked input[disabled], .card.locked button[disabled] { cursor: not-allowed; }
.card.locked label { color: var(--muted); }

/* ==== 生成练习迁移 + 填空题（2026-09-25） ==== */
.m-fill { margin-top: 6px; }
.m-fill input {
  width: 100%;
  max-width: 420px;
  font-size: 16px;          /* iOS 聚焦防放大铁律 */
  padding: 10px 12px;
  border: 1.5px solid var(--line, #d9d9d9);
  border-radius: 8px;
  background: #fff;
  touch-action: manipulation;
}
.m-fill input:focus { outline: none; border-color: var(--primary, #4a7dff); }

/* ==== 统一 AI 对话入口（2026-09-26） ==== */
/* 侧栏常驻按钮：对齐现有 quick 按钮观感，固定醒目 */
.btn-ai {
  width: 100%; margin: 8px 0 4px; padding: 12px 14px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, #2f6fed, #5b8def); color: #fff; font-size: 15px; font-weight: 700;
  box-shadow: 0 2px 8px rgba(47,111,237,.28); cursor: pointer; touch-action: manipulation;
}
.btn-ai:active { transform: translateY(1px); }
@media (max-width: 720px) { .btn-ai { font-size: 14px; padding: 10px 12px; } }

/* 抽屉浮层 */
.ask-mask {
  position: fixed; inset: 0; background: rgba(20,30,50,.32); z-index: 9999;
  display: none; /* 仅在 .open 时显示 */
}
.ask-mask.open { display: block; }
.ask-drawer {
  position: absolute; top: 0; right: 0; height: 100%; width: 420px; max-width: 92vw;
  background: var(--panel); box-shadow: -6px 0 24px rgba(20,40,80,.18);
  display: flex; flex-direction: column; animation: askIn .18s ease;
}
@keyframes askIn { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.ask-head {
  display: flex; align-items: center; gap: 8px; padding: 14px 16px;
  border-bottom: 1px solid var(--line); font-weight: 700; color: var(--text);
}
.ask-title { font-size: 16px; }
.ask-x { margin-left: auto; border: none; background: #f0f3f8; color: var(--muted); width: 34px; height: 34px; border-radius: 50%; font-size: 16px; cursor: pointer; touch-action: manipulation; }
.ask-ctx { padding: 8px 16px; border-bottom: 1px solid var(--line); background: #fafbfe; }
.ask-ctx summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.ask-ctx pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; color: var(--muted); max-height: 160px; overflow: auto; margin: 8px 0 0; font-family: inherit; }
.ask-msgs { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.ask-msgs.busy::after { content: '思考中…'; color: var(--muted); font-size: 13px; align-self: flex-start; }
.ask-row { display: flex; }
.ask-user { justify-content: flex-end; }
.ask-ai, .ask-sys { justify-content: flex-start; }
.ask-bubble { max-width: 82%; padding: 10px 13px; border-radius: 14px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.ask-user .ask-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.ask-ai .ask-bubble { background: #f0f3f8; color: var(--text); border-bottom-left-radius: 4px; }
.ask-sys { font-size: 13px; }
.ask-sys .ask-bubble { background: #eafaf0; color: var(--ok); border-radius: 10px; padding: 7px 11px; }
.ask-upimg { max-width: 120px; max-height: 90px; border-radius: 8px; margin-top: 6px; display: block; }
.ask-act {
  align-self: flex-start; max-width: 90%; border: 1.5px solid var(--primary); border-radius: 12px;
  background: #f5f8ff; padding: 10px 12px;
}
.ask-act-t { font-size: 12px; color: var(--primary); font-weight: 700; margin-bottom: 4px; }
.ask-act-l { font-size: 14px; color: var(--text); font-weight: 600; }
.ask-act-d { font-size: 13px; color: var(--muted); margin-top: 4px; }
.ask-act-b { display: flex; gap: 8px; margin-top: 10px; }
.ask-imgs { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px; }
.ask-imgchip { position: relative; display: inline-flex; align-items: center; background: #eef3ff; border-radius: 8px; padding: 4px 8px; font-size: 13px; }
.ask-imgchip button { border: none; background: transparent; color: var(--danger); font-size: 13px; margin-left: 4px; cursor: pointer; }
.ask-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: #fff; }
.ask-attach { border: none; background: #f0f3f8; width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer; touch-action: manipulation; }
.ask-input { flex: 1; font-size: 16px; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; touch-action: manipulation; }
.ask-input:focus { outline: none; border-color: var(--primary); }
.ask-send { border: none; background: var(--primary); color: #fff; font-weight: 700; padding: 10px 18px; border-radius: 10px; font-size: 15px; cursor: pointer; touch-action: manipulation; }
/* AI 建议卡片：应用失败常驻红字错因 + in-flight 置灰（R2/R3） */
.ask-err { margin-top: 6px; font-size: 12.5px; color: var(--danger, #d9534f); line-height: 1.4; word-break: break-word; }
.ask-act-busy .ask-apply { opacity: .5; cursor: not-allowed; }
