/* =====================================================================
 * 每日待办 · style.css
 * 视觉：暖米色纸面 + 衬线标题 + 1px 细线 + 陶土强调（Anthropic 风）
 * 约束：无阴影、无渐变、圆角 ≤4px、无外部字体与外链（仅内联 data: URI）
 * 布局（DESIGN §8.1，桌面优先）：
 *   ≥1024px   顶部栏横排；#main 两栏 3fr:2fr，左栏 提示+时段，右栏 里程碑卡片+复习题
 *   768–1023  同上，栏距 24px、两栏接近等宽
 *   <768px    单栏，DOM 自然顺序：任务 → 复习题 → 里程碑
 * ===================================================================== */

/* ---------- 1. 设计变量 ---------- */
:root {
  --bg: #F5F0E8;          /* 页面底色 */
  --paper: #FAF7F2;       /* 卡片纸面 */
  --ink: #1F1E1D;         /* 正文 */
  --ink-2: #5F5A54;       /* 次要文字：底色 6.0:1，悬停底 5.6:1 */
  --ink-done: #6E6962;    /* 已完成文字：底色 4.8:1，纸面 5.1:1 */
  --line: #E4DDD1;        /* 1px 细线 */
  --box-line: #8A847B;    /* 勾选框边框（非文字元素 ≥3:1） */
  --box-off: #CFC6B8;     /* 禁用勾选框边框（更淡） */
  --hover: #EFE8DC;       /* 行悬停底色 */
  --wash: #F3E6DC;        /* 横幅浅底 */
  --tint: #F0E9DE;        /* 公式源码底色 */
  --accent: #C96442;      /* 陶土：大号数字、填充、焦点环 */
  /* 小号强调文字。#B0532F 在 #F5F0E8 上实测 4.49:1、在横幅底上 4.16:1，
     不到 4.5，故同色相再压暗一级：底色 4.9 / 横幅 4.5 / 纸面 5.2 */
  --accent-ink: #A84E2C;

  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: 16px;         /* 页面左右内边距 */
  --block: 32px;          /* 区块间距 */
  --row-min: 44px;        /* 可点击行最小高度（触屏 ≥44px） */
}
@media (min-width: 768px)  { :root { --gutter: 32px; --block: 40px; } }
@media (min-width: 1024px) { :root { --gutter: 40px; --block: 48px; } }
/* 桌面精确指针：行高可降到 32px（DESIGN §8.1 桌面点击区 ≥32px） */
@media (min-width: 1024px) and (pointer: fine) { :root { --row-min: 32px; } }

/* ---------- 2. 基础重置 ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  overflow-wrap: anywhere;          /* 长串（链接、编号）可在任意处断行，不撑宽页面 */
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
a {
  color: var(--accent-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
::selection { background: rgba(201, 100, 66, .18); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 3. 页面容器 ---------- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--gutter) 80px;
  overflow-x: clip;                 /* 兜底：意外超宽内容也不产生页面横向滚动 */
}

/* ---------- 4. 横幅（内容未更新 / 回退提示） ---------- */
.banners { padding-top: 16px; }
.banners:empty { display: none; }
.banner {
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  background: var(--wash);
}
.banner + .banner { margin-top: 8px; }
/* 明日预览：中性提示，不用警示色 */
.banner.preview { border-left-color: var(--ink-2); background: var(--paper); border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.banner.preview .banner-title { color: var(--ink); }
.banner-title {
  display: block;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.5;
}
.banner-text { display: block; margin-top: 2px; font-size: 14px; color: var(--ink-2); }

/* ---------- 5. 顶部栏：标题、倒计时、日期、进度（手机为纵向堆叠） ---------- */
.masthead {
  padding: 28px 0 24px;
  border-bottom: 1px solid var(--line);
}
.masthead-title {
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: .24em;
  color: var(--ink-2);
}

/* 倒计时：大号衬线陶土数字 */
.countdown {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
  margin-top: 16px;
  font-family: var(--serif);
  color: var(--ink-2);
}
.cd-label, .cd-unit { font-size: 17px; }
.cd-days {
  font-size: 52px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.01em;
  color: var(--accent);             /* 大字号，3.4:1 满足大字要求 */
  font-variant-numeric: lining-nums tabular-nums;
}
/* v1.3：整句倒计时写在 .cd-label（数字隐藏）时，整句做大号陶土衬线 */
.countdown:has(.cd-days[hidden]) .cd-label {
  font-size: 40px; line-height: 1.2; font-weight: 500; color: var(--accent);
  font-variant-numeric: lining-nums tabular-nums;
}
.cd-days[hidden], .cd-unit[hidden] { display: none; }
/* D8 文字态（考试中 / 已考完）：文字写在 .cd-label，隐藏数字与单位 */
.countdown.is-exam .cd-days, .countdown.is-exam .cd-unit,
.countdown.is-after .cd-days, .countdown.is-after .cd-unit { display: none; }
.countdown.is-exam .cd-label,
.countdown.is-after .cd-label { font-size: 32px; line-height: 1.25; letter-spacing: .04em; }
.countdown.is-exam .cd-label { color: var(--accent); }
.countdown.is-after .cd-label { color: var(--ink); }

.exam-date {
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.sprint { margin-top: 2px; font-size: 14px; color: var(--ink-2); }
.exam-date:empty, .sprint:empty { display: none; }

/* 日期：今天 / 数据日期 */
.dates {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.date-item { display: flex; gap: 8px; min-width: 0; }
.dates dt, .gen-at { color: var(--ink-2); }

/* 进度：4px 细条，宽度由 JS 内联设置 */
.progress { margin-top: 16px; min-width: 0; }
.progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.progress-label { font-size: 13px; color: var(--ink-2); }
.progress-text {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.all-done .progress-text { color: var(--accent-ink); }
.bar {
  height: 4px;
  margin-top: 8px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.bar-fill {
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 300ms ease;
}

/* 同步状态（F3 预留）：小圆点 + 文字 */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
}
.sync-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: currentColor;
}
.sync-status:empty { display: none; }
.sync-status.is-pending, .sync-status.is-error { color: var(--accent-ink); }

/* ---------- 6. 主体与分组 ---------- */
.main > * { min-width: 0; }         /* 网格 / 单栏子项都不被内容撑宽 */

.notice {
  margin-top: var(--block);
  padding: 12px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  color: var(--ink-2);
}
/* 数据文本保留换行（F1 评审必须修） */
.notice, .note, .banner-text { white-space: pre-wrap; }
.notice-label { margin-right: 10px; font-weight: 600; color: var(--accent-ink); }

.sec { margin-top: var(--block); }
.sec-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  padding-bottom: 10px;
}
.sec-title {
  min-width: 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: .02em;
}
.sec-sub, .sec-count {
  font-size: 13px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.sec-count { margin-left: auto; }

/* 列表：行列表两侧外扩 8px，让悬停底色有呼吸感，文字仍与标题对齐 */
.rows { margin-inline: -8px; border-top: 1px solid var(--line); }
.rows > li { border-bottom: 1px solid var(--line); }
.cards > li + li { margin-top: 12px; }

/* 空状态（含 D7 “今天没有安排”）：衬线、次要色、居中、上下细线 */
.empty, .empty-day {
  padding: 24px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink-2);
  text-align: center;
}
.rows > .empty { border-top: 0; }  /* 行列表自带上边线，避免双线 */
.empty-day { margin-top: var(--block); }

/* ---------- 7. 可勾选行：整行 label 即点击区 ---------- */
.row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  min-height: var(--row-min);
  padding: 10px 8px;
  border-radius: 2px;
  cursor: pointer;
  transition: background-color 150ms ease;
  -webkit-tap-highlight-color: rgba(201, 100, 66, .08);
}
/* 只读 / 历史视图：禁用的勾选框不提示可点 */
.row:has(input:disabled) { cursor: default; -webkit-tap-highlight-color: transparent; }

.body { display: block; flex: 1; min-width: 0; }
.title { display: block; line-height: 1.5; transition: color 150ms ease; }
.meta {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--ink-2);
}
.meta .sep { margin: 0 6px; }
.subj {                              /* 科目小标签：细边框 + 次要文字色 */
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font-size: 12px;
  line-height: 18px;
  color: var(--ink-2);
}
.due-rel { font-variant-numeric: tabular-nums; }
.due-near { color: var(--accent-ink); }
.note {
  display: block;
  margin-top: 6px;
  padding-left: 10px;
  border-left: 2px solid var(--line);
  font-size: 13px;
  color: var(--ink-2);
}

/* 勾选框：保留原生 input，仅换外观；22px 方框，勾选后陶土实心 + 白色对勾（内联 SVG） */
.row input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 1px 0 0;                  /* 与首行文字（24px 行高）垂直居中 */
  border: 1px solid var(--box-line);
  border-radius: 3px;
  background-color: #FFFFFF;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 16px 16px;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.row input[type="checkbox"]:checked {
  border-color: var(--accent);
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.4l3 3 6-6.8' fill='none' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.row input[type="checkbox"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row input[type="checkbox"]:disabled {
  border-color: var(--box-off);
  background-color: #F3EEE6;
  cursor: default;
}
.row input[type="checkbox"]:checked:disabled { border-color: #D9A28C; background-color: #D9A28C; }

/* 悬停：仅限可用的勾选行、仅限支持悬停的设备 */
@media (hover: hover) {
  .row:has(input:not(:disabled)):hover {
    background-color: var(--hover);
    --ink-done: var(--ink-2);       /* 悬停底上已完成文字略加深，保持 ≥4.5:1 */
  }
  .row:hover input[type="checkbox"]:not(:disabled):not(:checked) { border-color: var(--accent); }
}

/* 已完成：标题划线 + 弱色 */
.item.done .title {
  color: var(--ink-done);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}
.item.done .meta,
.item.done .subj,
.item.done .note,
.item.done .due-near { color: var(--ink-done); }

/* ---------- 8. 复习题卡片 ---------- */
.review {
  padding: 4px 16px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.rv-head {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  margin: 0 -8px;                   /* 抵消行内边距，勾选框与卡片内容左缘对齐 */
}
.rv-head .row { flex: 1; }
.rv-head .fold { flex: none; padding: 0 8px; }

.content {
  margin-top: 2px;
  white-space: pre-wrap;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;                 /* 8em 恰为 5 行，截断落在整行 */
  transition: color 150ms ease;
}
.rv-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
  margin: 6px -4px 0;
}
.hint {
  margin-top: 6px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
}
.hint-label { display: block; margin-bottom: 2px; font-size: 12px; letter-spacing: .08em; }
.hint-text { white-space: pre-wrap; }
@media (min-width: 480px) {
  .rv-body { padding-left: 34px; } /* 22px 勾选框 + 12px 间距，题干与出处文字对齐 */
}

.review.done .content,
.review.done .hint { color: var(--ink-done); }

.review.collapsed .content { max-height: 8em; overflow: hidden; }
.review.collapsed .rv-actions,
.review.collapsed .hint { display: none; }

/* ---------- 9. 公式：KaTeX 结果 / TeX 源码，超宽只在自身内横向滚动 ---------- */
.math.display { display: block; max-width: 100%; }
.math:not(.tex-src) { white-space: normal; }
.math .katex-display {              /* 提高优先级，压过稍后加载的 katex.css */
  max-width: 100%;
  margin: .5em 0;
  padding: 2px 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.tex-src {
  max-width: 100%;
  padding: 0 .25em;
  border-radius: 2px;
  background: var(--tint);
  font-family: var(--mono);
  font-size: .875em;
  color: var(--ink-2);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.math.display.tex-src {
  margin: .5em 0;
  padding: .5em .75em;
  white-space: pre;
  overflow-x: auto;
}

/* ---------- 10. 按钮 ---------- */
.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: var(--row-min);
  padding: 0 4px;
  border: 0;
  border-radius: 2px;
  background: none;
  font-size: 14px;
  color: var(--accent-ink);
  text-decoration: none;
  cursor: pointer;
}
.btn-text:hover, a.btn-text {       /* 悬停只加下划线，不换浅色，保持对比度 */
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin-top: 20px;
  padding: 0 20px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { background: #3A3835; border-color: #3A3835; }

/* ---------- 11. 加载与错误卡 ---------- */
.loading {
  padding: 64px 0;
  font-family: var(--serif);
  letter-spacing: .1em;
  text-align: center;
  color: var(--ink-2);
}
.error-card {
  max-width: 640px;
  margin-top: var(--block);
  padding: 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.error-card h2, .error-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.45;
}
.error-card p, .error-text { margin-top: 8px; font-size: 15px; color: var(--ink-2); }
.error-card .error-detail {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-done);
}

/* ---------- 12. 预留组件（尚未进入 DOM，保持精简） ---------- */
/* F4 历史列表：日期 + done/total + 迷你进度条 */
.history-list { margin-top: var(--block); border-top: 1px solid var(--line); }
.history-item {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 44px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.history-item a { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.history-item .bar { flex: none; width: 96px; height: 2px; margin-top: 0; }
@media (hover: hover) { .history-item:hover { background-color: var(--hover); } }

/* 只读视图顶部条：“只读 · 返回” */
.readonly-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  margin-top: var(--block);
  padding: 8px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  color: var(--ink-2);
}
.readonly-bar a, .readonly-bar button { color: var(--accent-ink); }

/* 轻提示：底部居中，墨色底，无阴影 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  line-height: 1.5;
  transform: translateX(-50%);
}

/* ---------- 13. 平板 768–1023：两栏变窄，顶部栏两列 ---------- */
@media (min-width: 768px) {
  .masthead {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "title  sync"
      "cd     dates"
      "exam   dates"
      "sprint dates"
      "prog   prog";
    column-gap: 32px;
    align-items: end;
    padding: 40px 0 28px;
  }
  .masthead-title { grid-area: title; align-self: start; margin-bottom: 20px; }
  .masthead > .sync-status { grid-area: sync; justify-self: end; align-self: start; }
  .countdown { grid-area: cd; margin-top: 0; }
  .cd-days { font-size: 64px; }
  .exam-date { grid-area: exam; }
  .sprint { grid-area: sprint; }
  .dates {
    grid-area: dates;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
    border: 0;
  }
  .progress { grid-area: prog; margin-top: 24px; }

  /* 主体两栏：左 .task-column（时段），右 .side-column（里程碑在上、复习题在下） */
  .main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    column-gap: 24px;
    align-items: start;
  }
  .main-grid > * { min-width: 0; }
  .side-column { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 20px; }
  .side-column > :not(.history-link) { flex: 1 0 100%; min-width: 0; }
  .side-column > .milestones { order: -1; }

  /* 里程碑：右栏顶部卡片 */
  .side-column > .milestones {
    padding: 16px 20px 4px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 4px;
  }
  .side-column > .milestones .rows > li:last-child { border-bottom: 0; }
}

/* ---------- 14. 桌面 ≥1024：3fr:2fr，顶部栏横排 倒计时 | 日期 | 进度 ---------- */
@media (min-width: 1024px) {
  .masthead {
    grid-template-columns: auto minmax(0, 1fr) minmax(240px, 360px);
    grid-template-areas:
      "title  .     sync"
      "cd     dates prog"
      "exam   dates prog"
      "sprint dates prog";
    column-gap: 56px;
    padding: 56px 0 32px;
  }
  .cd-days { font-size: 72px; }
  .progress { margin-top: 0; }

  .main-grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    column-gap: 48px;
  }
  .side-column > .milestones { padding: 20px 24px 8px; }
  .sec-title { font-size: 20px; }
}

/* 桌面精确指针：行更紧凑 */
@media (min-width: 1024px) and (pointer: fine) {
  .row { padding-block: 6px; }
}

/* ---------- 15. 无障碍偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
/* 强制颜色模式：退回原生勾选框，进度条用系统色 */
@media (forced-colors: active) {
  .row input[type="checkbox"] { -webkit-appearance: auto; appearance: auto; }
  .bar { border: 1px solid CanvasText; }
  .bar-fill { background: Highlight; }
}

/* “昨天 / 历史”入口：右栏（手机为复习题前）顶部一行文字链接 */
.side-column > .history-link { order: -2; display: inline-flex; align-items: center; min-height: 44px; }
.side-column:not(:has(> .history-link + .history-link)) > .history-link,
.side-column > .history-link + .history-link { margin-bottom: 8px; }
@media (max-width: 767px) {
  .side-column { display: flex; flex-wrap: wrap; column-gap: 20px; margin-top: var(--block); }
  .side-column > :not(.history-link) { flex: 1 0 100%; min-width: 0; }
}
@media (min-width: 768px) { .countdown:has(.cd-days[hidden]) .cd-label { font-size: 52px; } }
@media (min-width: 1024px) { .countdown:has(.cd-days[hidden]) .cd-label { font-size: 60px; } }
/* 考试中 / 已考完 优先级高于整句大号 */
.countdown.is-after:has(.cd-days[hidden]) .cd-label { color: var(--ink); }
/* 入口行紧贴右栏顶部，下方里程碑不再叠加区块上边距 */
@media (min-width: 768px) {
  .side-column { margin-top: calc(var(--block) - 12px); }
  .side-column > .history-link { min-height: 32px; margin-bottom: 4px; }
  .side-column > .milestones { margin-top: 0; }
}
