:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #1d1b18;
  --muted: #7a7366;
  --guide: #d9d2c3;
  --line: #e4ddcf;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --warn: #9a4b16;
  --ok: #2f5d50;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a17;
    --paper: #24221e;
    --ink: #efe9dc;
    --muted: #a39c8d;
    --guide: #4a463d;
    --line: #38352f;
    --accent: #6fa595;
    --accent-ink: #111;
    --warn: #e0a36f;
    --ok: #8cc4b3;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button {
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.link { color: var(--accent); text-decoration: none; padding: 10px 4px; }

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 6px; }
.tab { border-radius: 999px; padding: 8px 18px; }
.tab.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.stats { color: var(--muted); font-variant-numeric: tabular-nums; flex: 1; min-width: 12em; }
.bar-right { display: flex; align-items: center; gap: 16px; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); user-select: none; }

/* ---------- 采集页 ---------- */
body.collect { display: flex; flex-direction: column; overflow: hidden; overscroll-behavior: none; }
body.collect, body.collect * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 12px 16px 4px; min-height: 0; }
.prompt-row { display: flex; align-items: baseline; gap: 16px; min-height: 64px; }
.prompt { font-size: 44px; line-height: 1.2; letter-spacing: 0.04em; }
.prompt.sentence { font-size: 26px; }
.prompt-meta { color: var(--muted); font-size: 14px; }
.paper { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 8px 0; }
canvas#pad { background: var(--paper); border-radius: 6px; touch-action: none; box-shadow: 0 1px 0 var(--line), 0 0 0 1px var(--line); }
.status { min-height: 24px; color: var(--muted); font-size: 14px; }
.status[data-kind="warn"] { color: var(--warn); }
.status[data-kind="ok"] { color: var(--ok); }
.tools {
  display: flex;
  gap: 10px;
  justify-content: center;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}
.tools .primary { min-width: 9em; }

/* ---------- 登录浮层 ---------- */
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 85%, transparent); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.overlay[hidden] { display: none; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.card h1 { margin: 0; font-size: 22px; }
.card input { width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); -webkit-user-select: text; user-select: text; }
.token-row[hidden] { display: none; }
.login-msg { margin: 0; color: var(--warn); font-size: 14px; min-height: 1.4em; }

/* ---------- 回看页 ---------- */
body.review main { padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.sample { margin: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.sample.line { grid-column: span 2; }
.thumb { display: block; width: 100%; height: auto; aspect-ratio: 1; fill: var(--ink); stroke: var(--ink); stroke-linecap: round; stroke-linejoin: round; }
.thumb path { fill: none; }
.sample.line .thumb { aspect-ratio: auto; }
.sample figcaption { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px; border-top: 1px solid var(--line); font-size: 14px; }
.sample figcaption button { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.sample.status-discarded .thumb, .sample.status-redo .thumb { opacity: 0.25; }
.more { display: block; margin: 20px auto; }
.more[hidden] { display: none; }

@media (max-width: 600px) {
  .prompt { font-size: 36px; }
  .tools button { flex: 1 1 40%; }
}
