/* ===== 主题变量 ===== */
:root {
  --bg: #0b0f17;
  --bg-blur: rgba(11, 15, 23, 0.88);
  --card: #141b29;
  --card-2: #1a2233;
  --line: #232c3f;
  --line-soft: #1b2434;
  --text: #e8edf7;
  --muted: #8b96ab;
  --faint: #5b6579;
  --accent: #6b9bff;
  --accent-soft: rgba(107, 155, 255, 0.16);
  --good: #3ecf8e;
  --warn: #f0a24a;
  --bad: #f26d8e;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --tab-h: 62px;
  --maxw: 560px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-blur: rgba(244, 246, 251, 0.9);
  --card: #ffffff;
  --card-2: #eef2f9;
  --line: #dde4ef;
  --line-soft: #e8edf5;
  --text: #1a2233;
  --muted: #5f6b80;
  --faint: #8b96ab;
  --accent: #3b6fe0;
  --accent-soft: rgba(59, 111, 224, 0.12);
  --shadow: 0 10px 30px rgba(26, 34, 51, 0.08);
}

/* ===== 基础 ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent); }

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== 顶栏 ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 10px 16px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg-blur);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.hd-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.hd-date { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
.hd-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hd-count { text-align: right; font-size: 12px; color: var(--muted); line-height: 1.35; }
.hd-count b { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }

/* ===== 主体 ===== */
.app-main {
  flex: 1;
  padding: 16px 16px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom));
}

/* ===== 底部导航 ===== */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--maxw);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--bg-blur);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 30;
}
.tabbar button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  min-width: 0;
}
.tabbar button svg { width: 22px; height: 22px; }
.tabbar button.active { color: var(--accent); }

/* ===== 卡片 ===== */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title { font-size: 14px; font-weight: 700; letter-spacing: 0.2px; }
.card-sub { font-size: 12px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.stack > * + * { margin-top: 10px; }

/* ===== 今日环 ===== */
.today-top { display: flex; align-items: center; gap: 18px; }
.ring-wrap { position: relative; width: 118px; height: 118px; flex: 0 0 auto; }
.ring-wrap svg { width: 118px; height: 118px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.5s ease; }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-label b { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ring-label span { font-size: 11px; color: var(--muted); }
.today-meta { flex: 1; min-width: 0; }
.today-meta .big { font-size: 20px; font-weight: 700; }
.today-meta .line { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ===== 科目 chip ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip.mini { padding: 4px 10px; min-height: 30px; font-size: 12px; }

/* ===== 按钮 ===== */
.btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: rgba(242, 109, 142, 0.4); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ===== 进度条 ===== */
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.4s ease; }
.subject-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.subject-row + .subject-row { border-top: 1px solid var(--line-soft); }
.subject-name { font-size: 13px; font-weight: 600; }
.subject-hours { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.subject-bar { flex: 1; }

/* ===== 列表 ===== */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 11px 0; }
.list-item + .list-item { border-top: 1px solid var(--line-soft); }
.list-item .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.list-item .what { flex: 1; min-width: 0; }
.list-item .what b { font-size: 13px; font-weight: 600; }
.list-item .what span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .mins { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); }
.icon-btn {
  border: 0; background: transparent; color: var(--faint);
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--card-2); }

/* ===== 建议任务 ===== */
.task { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.task + .task { border-top: 1px solid var(--line-soft); }
.task .slot { font-size: 10px; color: var(--faint); width: 34px; flex: 0 0 auto; }
.task .what { flex: 1; min-width: 0; font-size: 13px; }
.task .what span { display: block; font-size: 11px; color: var(--muted); }

/* ===== 徽标 ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  white-space: nowrap;
}
.badge.good { background: rgba(62, 207, 142, 0.14); color: var(--good); }
.badge.warn { background: rgba(240, 162, 74, 0.14); color: var(--warn); }

/* ===== 统计格 ===== */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card-2); border-radius: 12px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }

/* ===== 日历 ===== */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 15px; font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-wd { text-align: center; font-size: 10px; color: var(--faint); padding: 4px 0; }
.cal-cell {
  position: relative; aspect-ratio: 1 / 1; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.cal-cell.blank { pointer-events: none; }
.cal-cell.today { outline: 1.5px solid var(--accent); outline-offset: -1.5px; color: var(--text); }
.cal-cell.sel { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--text); }
.cal-cell.l1 { background: rgba(107, 155, 255, 0.14); color: var(--text); }
.cal-cell.l2 { background: rgba(107, 155, 255, 0.3); color: var(--text); }
.cal-cell.l3 { background: rgba(107, 155, 255, 0.52); color: #fff; }
.cal-cell.l4 { background: var(--accent); color: #fff; font-weight: 700; }
.cal-legend { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 10px; font-size: 10px; color: var(--faint); }
.cal-legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

/* ===== 周柱状 ===== */
.week-bars { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 8px; }
.wb { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 5px; min-width: 0; }
.wb-bar { width: 100%; max-width: 34px; background: var(--card-2); border-radius: 7px 7px 3px 3px; position: relative; display: flex; align-items: flex-end; flex: 1 1 auto; min-height: 0; }
.wb-bar i { display: block; width: 100%; background: var(--accent); border-radius: 7px 7px 3px 3px; min-height: 2px; }
.wb-bar i.hit { background: var(--good); }
.wb-label { font-size: 10px; color: var(--faint); white-space: nowrap; }
.wb-val { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ===== 章节 ===== */
details.chapter-group { border-top: 1px solid var(--line-soft); }
details.chapter-group summary {
  list-style: none; cursor: pointer; padding: 12px 0;
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
}
details.chapter-group summary::-webkit-details-marker { display: none; }
details.chapter-group summary .chev { margin-left: auto; color: var(--faint); transition: transform 0.2s; }
details.chapter-group[open] summary .chev { transform: rotate(90deg); }
.chapter-item { display: flex; align-items: center; gap: 10px; padding: 8px 0 8px 4px; font-size: 13px; }
.chapter-item input { width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto; }
.chapter-item span { flex: 1; min-width: 0; }
.chapter-item.done span { color: var(--faint); text-decoration: line-through; }
.chapter-item .badge { font-size: 10px; padding: 1px 7px; }

/* ===== 弹层 ===== */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.18s ease;
}
.sheet {
  width: 100%; max-width: var(--maxw); max-height: 88dvh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
  animation: rise 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-title { font-size: 16px; font-weight: 700; }
.sheet-close { border: 0; background: var(--card-2); color: var(--muted); width: 32px; height: 32px; border-radius: 50%; font-size: 18px; line-height: 1; }
@keyframes rise { from { transform: translateY(24px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ===== 表单 ===== */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input, .select, textarea.input {
  width: 100%; background: var(--card-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 11px 12px; min-height: 44px; outline: none;
}
.input:focus, .select:focus, textarea.input:focus { border-color: var(--accent); }
textarea.input { min-height: 70px; resize: vertical; }
.quick-mins { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.quick-mins button { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); font-size: 13px; }
.quick-mins button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.seg { display: flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); border-radius: 9px; min-height: 38px; font-size: 13px; }
.seg button.active { background: var(--accent); color: #fff; font-weight: 700; }

/* ===== 提示 ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 26px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  background: #222c40; color: #fff; border: 1px solid #33405a;
  padding: 9px 16px; border-radius: 999px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: all 0.22s ease; z-index: 80;
  max-width: calc(100vw - 48px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-theme="light"] .toast { background: #1a2233; }

/* ===== 计时悬浮条 ===== */
.timer-pill {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: calc(100% - 32px); max-width: calc(var(--maxw) - 32px);
  background: var(--card); border: 1px solid var(--accent);
  border-radius: 14px; padding: 10px 12px; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
}
.timer-pill .t { font-family: var(--mono); font-size: 18px; font-weight: 700; flex: 1; }
.timer-pill .s { font-size: 11px; color: var(--muted); }
.timer-pill[hidden] { display: none; }

/* ===== 空状态 ===== */
.empty { text-align: center; color: var(--faint); font-size: 13px; padding: 26px 0; }
.empty b { display: block; font-size: 15px; color: var(--muted); margin-bottom: 4px; }

/* ===== 分段标题 ===== */
.section-title { font-size: 12px; color: var(--muted); font-weight: 600; margin: 18px 2px 8px; letter-spacing: 0.3px; }
.section-title:first-child { margin-top: 0; }

/* ===== 阶段卡 ===== */
.phase-card { display: flex; align-items: center; gap: 12px; }
.phase-no { font-family: var(--mono); font-size: 22px; font-weight: 700; color: var(--accent); }
.phase-info { flex: 1; min-width: 0; }
.phase-info b { font-size: 14px; }
.phase-info span { display: block; font-size: 11px; color: var(--muted); }

/* ===== 倒计时 ===== */
.exam-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.exam { background: var(--card-2); border-radius: 13px; padding: 12px; }
.exam .name { font-size: 11px; color: var(--muted); }
.exam .days { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; }
.exam .days small { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.exam.past .days { color: var(--faint); }

/* ===== 设置行 ===== */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.setting-row + .setting-row { border-top: 1px solid var(--line-soft); }
.setting-row .txt b { font-size: 13px; font-weight: 600; display: block; }
.setting-row .txt span { font-size: 11px; color: var(--muted); }
.setting-row input[type="date"], .setting-row input[type="number"] {
  background: var(--card-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 9px; min-height: 38px; width: 150px;
}
.switch { position: relative; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: 0.2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }

/* ===== 工具 ===== */
.hr { height: 1px; background: var(--line-soft); margin: 12px 0; border: 0; }
.nowrap { white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
