:root {
  --primary: #4f6df5;
  --primary-dark: #3b56c7;
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1f2330;
  --muted: #8a90a2;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --border: #e6e8f0;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.hidden { display: none !important; }

/* ---------- 密码门 ---------- */
.gate {
  position: fixed; inset: 0;
  background: linear-gradient(160deg, #4f6df5, #6a5df0);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 100;
}
.gate-card {
  background: #fff; border-radius: 20px; padding: 32px 24px;
  width: 100%; max-width: 320px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.gate-logo { font-size: 44px; }
.gate-card h2 { margin: 8px 0 4px; }
.gate-sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.gate input {
  width: 100%; padding: 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 16px; margin-bottom: 12px; text-align: center;
}
.gate input:focus { outline: none; border-color: var(--primary); }
.gate button {
  width: 100%; padding: 12px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 16px; font-weight: 600;
}
.gate button:active { background: var(--primary-dark); }
.gate-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ---------- 主框架 ---------- */
.app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: 76px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--primary); color: #fff;
  padding: 14px 18px; font-weight: 600; font-size: 17px;
  box-shadow: 0 2px 8px rgba(79,109,245,.25);
}
.topbar-sub { font-weight: 400; opacity: .9; }

.view { padding: 16px 14px 24px; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.view-head h1 { margin: 0; font-size: 22px; }
.today-date { color: var(--muted); font-size: 14px; }
.today-summary { color: var(--primary-dark); background: #eef1ff; border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }

.section-title { font-size: 15px; margin: 18px 2px 8px; color: var(--muted); }

/* ---------- 列表 / 卡片 ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05); border: 1px solid var(--border);
}
.card-row { display: flex; gap: 12px; align-items: flex-start; }
.card-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: #eee; flex-shrink: 0; }
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; word-break: break-word; }
.card-sub { color: var(--muted); font-size: 13px; word-break: break-word; }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 20px; margin-right: 6px; }
.tag-overdue { background: #fee2e2; color: #b91c1c; }
.tag-due { background: #fef3c7; color: #b45309; }
.tag-mastered { background: #dcfce7; color: #15803d; }
.tag-stage { background: #e0e7ff; color: #3730a3; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }
.empty .emoji { font-size: 36px; display: block; margin-bottom: 8px; }

/* ---------- 按钮 ---------- */
.btn-primary {
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  padding: 9px 14px; font-size: 14px; font-weight: 600;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-primary.block { width: 100%; padding: 12px; font-size: 16px; margin-top: 8px; }
.btn-ghost {
  background: #fff; color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 14px; font-size: 14px;
}
.btn-ok { background: var(--ok); color: #fff; border: none; border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.btn-bad { background: #fff; color: var(--danger); border: 1px solid var(--danger); border-radius: 10px; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row button { flex: 1; }

/* ---------- 筛选条 ---------- */
.filter-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.chip {
  background: #fff; border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 14px; font-size: 13px; color: var(--muted);
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- 任务勾选 ---------- */
.task-check {
  width: 22px; height: 22px; border: 2px solid var(--border); border-radius: 6px;
  flex-shrink: 0; margin-top: 2px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.task-check.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.task-check.done::after { content: "✓"; font-size: 14px; }
.task-card.done .card-title { text-decoration: line-through; color: var(--muted); }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px;
  background: #fff; border-top: 1px solid var(--border);
  display: flex; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 12px;
}
.tab.active { color: var(--primary); }
.tab-icon { font-size: 20px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
.modal-card {
  background: #fff; width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; max-height: 92vh; overflow-y: auto;
  animation: slideup .25s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff;
}
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--muted); }
.modal-body { padding: 16px 18px 24px; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type=text], .field input[type=date], .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 15px; font-family: inherit;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { resize: vertical; }
.photo-preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: 10px; margin-top: 8px; border: 1px solid var(--border); }
.form-msg { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.form-msg.ok { color: var(--ok); }

.detail-photo { width: 100%; border-radius: 10px; margin-bottom: 12px; border: 1px solid var(--border); }
.detail-block { margin-bottom: 12px; }
.detail-block .lbl { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.detail-block .val { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.review-progress { display: flex; gap: 6px; margin: 6px 0 14px; }
.rp-step { flex: 1; text-align: center; font-size: 12px; padding: 6px 0; border-radius: 8px; background: #f1f2f6; color: var(--muted); }
.rp-step.done { background: #dcfce7; color: #15803d; }
.rp-step.current { background: #fef3c7; color: #b45309; }

.loading { text-align: center; color: var(--muted); padding: 30px; }

/* AI 识别区 */
.ai-section { margin: 14px 0; padding: 14px; background: #f8faff; border-radius: 12px; border: 1px solid #e0e7ff; }
.ai-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ai-select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; font-family: inherit; }
.btn-ai { padding: 8px 16px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 14px; cursor: pointer; font-family: inherit; white-space: nowrap; }
.btn-ai:disabled { opacity: 0.5; cursor: default; }
.ocr-status { font-size: 13px; color: var(--muted); }

/* 做题区 */
.ai-practice { margin: 14px 0; padding: 14px; background: #fffdf5; border-radius: 12px; border: 1px solid #fef3c7; }
.ai-practice-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.ai-practice-row { display: flex; gap: 8px; }
.ai-input { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; font-family: inherit; }
.ai-input:focus { outline: none; border-color: var(--primary); }
.btn-ai-submit { padding: 10px 18px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 14px; cursor: pointer; font-family: inherit; white-space: nowrap; }

/* 辅导对话 */
.tutor-section { margin: 14px 0; }
.tutor-title { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.chat-msgs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; max-height: 320px; overflow-y: auto; }
.chat-bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; word-break: break-word; }
.chat-bubble.student { align-self: flex-end; background: #e8f5e9; color: #1b5e20; border-bottom-right-radius: 4px; }
.chat-bubble.tutor { align-self: flex-start; background: #e3f2fd; color: #0d47a1; border-bottom-left-radius: 4px; }
.chat-bubble.error { align-self: center; background: #ffebee; color: #b71c1c; font-size: 13px; }
.chat-bubble.loading { align-self: flex-start; background: #f5f5f5; color: var(--muted); font-style: italic; }
.chat-done { text-align: center; font-size: 16px; font-weight: 600; color: var(--ok); padding: 10px; }
.chat-bar { display: flex; gap: 8px; }

/* 做题区照片缩略图 */
.ai-practice-photo { margin-bottom: 10px; text-align: center; }
.ai-practice-photo img { max-width: 200px; max-height: 140px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; transition: transform 0.2s; object-fit: contain; }
.ai-practice-photo img.zoomed { max-width: 100%; max-height: 400px; }
.ai-hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* 语音按钮 */
.speak-btn { cursor: pointer; font-size: 15px; margin-left: 6px; user-select: none; display: inline-block; vertical-align: middle; }
.speak-btn:hover { transform: scale(1.15); }
.speak-btn:active { transform: scale(0.95); }
