:root {
  --primary: #4d9ef2;
  --primary-dark: #2f7fd6;
  --grad: linear-gradient(135deg, #4d9ef2 0%, #74b9fb 100%);
  --bg: #f3f7fc;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6f87a3;
  --border: #e1ebf7;
  --danger: #e5484d;
  --danger-bg: #fdecec;
  --ok: #18a058;
  --ok-bg: #e6f7ef;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(43, 110, 210, 0.06);
  --shadow-lg: 0 8px 30px rgba(43, 110, 210, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 86px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body.no-scroll { overflow: hidden; }
.hidden { display: none !important; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: var(--grad);
  color: #fff;
  box-shadow: 0 4px 18px rgba(77, 158, 242, 0.25);
}

.topbar h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }

.badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

/* ---------- 主内容 ---------- */
main {
  padding: 16px 14px 24px;
  max-width: 720px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: 1px solid rgba(232, 235, 243, 0.7);
}

.card h2 { font-size: 17px; margin-bottom: 6px; font-weight: 700; }
.card h3 { font-size: 15px; margin: 14px 0 6px; font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; margin-bottom: 10px; }
.small { font-size: 12px; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.daily-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- 上传区 ---------- */
.upload-row { display: flex; gap: 10px; margin: 14px 0; }
.upload-btn {
  flex: 1;
  text-align: center;
  padding: 16px 8px;
  border-radius: 14px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.upload-btn:active { transform: scale(0.97); }
.upload-btn.primary { background: var(--grad); color: #fff; box-shadow: 0 4px 14px rgba(77, 158, 242, 0.3); }
.upload-btn.secondary { background: #e8f2fd; color: var(--primary-dark); border: 1px solid #d3e6fa; }

#preview-wrap img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin: 10px 0;
  background: #f8fbff;
}

/* ---------- 拍照后裁剪 ---------- */
.crop-modal .modal-head { margin-bottom: 4px; }
.crop-modal .muted.small { margin: 0 0 10px; }
#crop-wrap {
  position: relative;
  width: 100%;
  max-height: 58vh;
  overflow: hidden;
  border-radius: 14px;
  background: #10162b;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#crop-img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 58vh;
  object-fit: contain;
}
#crop-box {
  position: absolute;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 9999px rgba(10, 16, 32, 0.58);
  cursor: move;
  touch-action: none;
}
.crop-grid {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(255,255,255,0.55) 1px, transparent 1px) 33.333% 0 / 34% 100%,
              linear-gradient(to left, rgba(255,255,255,0.55) 1px, transparent 1px) 33.333% 0 / 34% 100%,
              linear-gradient(to bottom, rgba(255,255,255,0.55) 1px, transparent 1px) 0 33.333% / 100% 34%,
              linear-gradient(to top, rgba(255,255,255,0.55) 1px, transparent 1px) 0 33.333% / 100% 34%;
  pointer-events: none;
  opacity: 0.75;
}
.crop-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  background: #fff;
  border: 2px solid #4d9ef2;
  border-radius: 50%;
  z-index: 2;
  touch-action: none;
}
.h-nw { left: -11px; top: -11px; cursor: nwse-resize; }
.h-ne { right: -11px; top: -11px; cursor: nesw-resize; }
.h-sw { left: -11px; bottom: -11px; cursor: nesw-resize; }
.h-se { right: -11px; bottom: -11px; cursor: nwse-resize; }
.h-n { left: 50%; top: -11px; transform: translateX(-50%); cursor: ns-resize; width: 28px; }
.h-s { left: 50%; bottom: -11px; transform: translateX(-50%); cursor: ns-resize; width: 28px; }
.h-w { top: 50%; left: -11px; transform: translateY(-50%); cursor: ew-resize; height: 28px; }
.h-e { top: 50%; right: -11px; transform: translateY(-50%); cursor: ew-resize; height: 28px; }
.crop-actions { margin-top: 14px; }

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px;
  font-size: 14px;
  line-height: 1.7;
  font-family: inherit;
  resize: vertical;
  background: #f8fbff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(77, 158, 242, 0.12);
  background: #fff;
}

/* 答案手动修正 */
.answer-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  flex-wrap: wrap;
}
.answer-input {
  width: 110px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #f8fbff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.answer-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(77, 158, 242, 0.12);
  background: #fff;
}

/* ---------- 按钮 ---------- */
.btn-row { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 4px 12px rgba(77, 158, 242, 0.25); }
.btn.primary:disabled { background: #bcd8f6; box-shadow: none; cursor: not-allowed; }
.btn.secondary { background: #eef5fc; color: var(--text); border: 1px solid var(--border); }
.btn.ok { background: var(--ok-bg); color: var(--ok); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.small { padding: 7px 13px; font-size: 13px; border-radius: 10px; }

.status {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 12px;
  background: #e8f2fd;
  color: var(--primary-dark);
  font-size: 13px;
}
.status.error { background: var(--danger-bg); color: var(--danger); }

/* ---------- 内容块 ---------- */
.block { margin-top: 14px; padding-top: 12px; border-top: 1px dashed #dce8f7; }
.block h4 { font-size: 14px; margin-bottom: 6px; font-weight: 600; }
.pre { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.75; }
.options { margin-top: 4px; color: #37405a; }

/* ---------- 标签 ---------- */
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 999px;
  background: #e8f2fd;
  color: var(--primary-dark);
}
.chip.kp { background: #eef5fc; color: #55719a; }
.chip.theory { background: #fdf1d7; color: #96640d; }
.chip.gongji { background: #fbf3c8; color: #7d5b0a; }
.chip.common { background: #fce4f1; color: #a11d62; }
.chip.verbal { background: #e0edff; color: #2457b6; }
.chip.math { background: #ddf4e7; color: #1c7a4a; }
.chip.logic { background: #ece6fc; color: #5b2fc0; }

/* ---------- 筛选 ---------- */
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 14px; }
.chip-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
  transition: all 0.15s ease;
}
.chip-btn.active {
  background: var(--grad);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 10px rgba(77, 158, 242, 0.25);
}

/* ---------- 错题卡片 ---------- */
.q-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 15px;
  margin-bottom: 12px;
  background: #fff;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.q-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.delete-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: transparent;
  color: #b3bacb;
  cursor: pointer;
  padding: 5px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.delete-btn:hover { color: var(--danger); background: var(--danger-bg); }
.q-card .q-preview { color: #37405a; }
.q-card .meta { margin-top: 9px; font-size: 12px; color: var(--muted); }
.empty { text-align: center; padding: 34px 0; color: var(--muted); }

/* ---------- 举一反三/答题 ---------- */
.mini-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 9px 0;
  background: #f8fbff;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.mini-card:hover { border-color: #b9d4f5; }
.opt-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.opt-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  line-height: 1.55;
  transition: all 0.15s ease;
}
.opt-btn:hover { border-color: #b9d4f5; }
.opt-key {
  flex-shrink: 0;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #e8f2fd;
  color: var(--primary-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.opt-btn.right { border-color: var(--ok); background: var(--ok-bg); }
.opt-btn.right .opt-key { background: var(--ok); color: #fff; }
.opt-btn.wrong { border-color: var(--danger); background: var(--danger-bg); }
.opt-btn.wrong .opt-key { background: var(--danger); color: #fff; }
.quiz-feedback { margin-top: 10px; font-weight: 700; font-size: 14px; }
.fb-right { color: var(--ok); }
.fb-wrong { color: var(--danger); }
.quiz-analysis { margin-top: 10px; border-top: 1px dashed #dce8f7; padding-top: 10px; }
.quiz-analysis h5 { font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.quiz-reset { margin-top: 10px; }

.last-result { margin-top: 8px; font-weight: 600; color: var(--muted); font-size: 13px; }
.replay-analysis { margin-top: 12px; }
.replay-reset { margin-top: 12px; }

/* ---------- 每日成语 ---------- */
.idiom-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #f8fbff 0%, #eff6fe 100%);
}
.idiom-word {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 4px;
}
.idiom-meaning { font-size: 13px; color: #37405a; line-height: 1.65; }
.idiom-example { font-size: 13px; color: var(--muted); line-height: 1.65; margin-top: 5px; }
.idiom-head { display: flex; justify-content: space-between; align-items: center; }
.fav-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  color: #c4cbdd;
  cursor: pointer;
  padding: 2px 6px;
  transition: transform 0.12s ease;
}
.fav-btn.on { color: #f5b642; }
.fav-btn:active { transform: scale(1.25); }
.idiom-question { font-size: 14px; font-weight: 600; margin-bottom: 4px; }

.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cal-month { font-size: 13px; font-weight: 600; color: #1c1c1c; }
.cal-legend { font-size: 10px; color: #999; display: flex; align-items: center; gap: 5px; }
.cal-legend .dot { width: 5px; height: 5px; border-radius: 50%; background: #111; display: inline-block; }
.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 10px;
  color: #a8a8a8;
  margin-bottom: 3px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  font-size: 11px;
  color: #333;
  border-radius: 50%;
}
.cal-cell.blank { visibility: hidden; }
.cal-cell.today { box-shadow: inset 0 0 0 1.5px #111; }
.cal-cell.on::after {
  content: "";
  position: absolute;
  bottom: 2px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #111;
}

#streak-card { padding: 12px 14px; }
.cal-head { margin-bottom: 8px; }
.streak-layout { display: flex; gap: 18px; align-items: stretch; }
#streak-calendar { max-width: 300px; flex: 1.1; flex-shrink: 0; }
#streak-side { flex: 1; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.side-stat { display: flex; flex-direction: column; gap: 2px; padding: 7px 0; border-bottom: 1px solid #f0f0f0; }
.side-stat:last-child { border-bottom: none; }
.side-stat b { font-size: 18px; color: #1c1c1c; line-height: 1.2; }
.side-stat span { font-size: 11px; color: #999; }
@media (max-width: 400px) {
  .streak-layout { flex-direction: column; }
  #streak-calendar { max-width: 100%; }
}

.weak-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 12px; }
.weak-info { width: 150px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weak-num { width: 110px; text-align: right; color: var(--muted); flex-shrink: 0; }

#trend-chart svg { width: 100%; height: auto; display: block; }
.chart-note { font-size: 12px; color: var(--muted); text-align: center; padding: 14px 0; }
.report-btn.active { background: var(--grad); color: #fff; border-color: transparent; }

/* ---------- 底部标签栏 ---------- */
.tabbar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 28px);
  max-width: 420px;
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(232, 235, 243, 0.9);
  border-radius: 20px;
  box-shadow: 0 8px 28px rgba(43, 110, 210, 0.14);
  z-index: 20;
  padding: 5px;
}
.tab {
  flex: 1;
  padding: 8px 0 7px;
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  border-radius: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all 0.18s ease;
}
.tab-icon { display: inline-flex; }
.tab-icon svg { width: 20px; height: 20px; }
.tab.active {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 4px 12px rgba(77, 158, 242, 0.3);
}

/* ---------- 弹层 ---------- */
.mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 46, 0.45);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.18s ease;
}
.modal {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px 30px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.22s ease;
}
.modal-grabber {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  background: #c9d9ee;
  margin: 0 auto 10px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h3 { font-size: 16px; font-weight: 700; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

/* ---------- 复盘遮答案 ---------- */
.answer-blur { filter: blur(7px); user-select: none; padding: 8px 0; }
.answer-toggle.revealed .answer-blur { filter: none; }
.answer-toggle.revealed .btn { display: none; }

/* ---------- 统计 ---------- */
.stat-grid { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-box {
  flex: 1;
  text-align: center;
  background: linear-gradient(135deg, #f8fbff, #e9f3fd);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 8px;
}
.stat-box b { display: block; font-size: 26px; color: var(--primary-dark); }
.stat-box span { font-size: 12px; color: var(--muted); }

.bar-row { display: flex; align-items: center; gap: 8px; margin: 9px 0; font-size: 13px; }
.bar-label { width: 68px; flex-shrink: 0; color: var(--muted); }
.bar { flex: 1; height: 10px; background: #e1ebf7; border-radius: 999px; overflow: hidden; }
.bar i {
  display: block;
  height: 100%;
  background: var(--grad);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.bar-num { width: 30px; text-align: right; color: var(--muted); }

/* ---------- 设置页 ---------- */
#view-settings h3 { margin: 18px 0 8px; font-size: 15px; }
#view-settings input[type="text"],
#view-settings input[type="password"] {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  font-size: 14px;
  background: #fff;
  margin: 6px 0 12px;
}
#view-settings label { display: block; font-size: 13px; color: var(--primary-dark); font-weight: 600; margin-top: 4px; }
#view-settings .muted.small { margin: -4px 0 10px; }
#backend-badge {
  background: #e8f2fd;
  color: var(--primary-dark);
  border: 1px solid #d3e6fa;
}
#backend-badge.supabase { background: #e6f9ef; color: #157a4a; border-color: #bfe8d3; }
