:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #ece9e3;
  --ink: #23221f;
  --ink-2: #5d5a54;
  --ink-3: #8a867e;
  --line: #dedad2;
  --accent: #3f5f57;
  --accent-ink: #ffffff;
  --accent-soft: #e2ebe7;
  --warn: #9a5b12;
  --warn-soft: #f6ead9;
  --danger: #a33a2f;
  --danger-soft: #f6e1de;
  --ok: #3d6b3f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 28, 24, .06), 0 2px 10px rgba(30, 28, 24, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716;
    --surface: #1f2120;
    --surface-2: #2a2c2b;
    --ink: #ecebe7;
    --ink-2: #b4b1aa;
    --ink-3: #85827b;
    --line: #333634;
    --accent: #8fb5aa;
    --accent-ink: #11201c;
    --accent-soft: #23332f;
    --warn: #e0a95e;
    --warn-soft: #362a1a;
    --danger: #ec8a7e;
    --danger-soft: #3a2220;
    --ok: #8fc391;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.3; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 17px; margin: 0; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .back { border: 0; background: none; padding: 4px 8px 4px 0; font-size: 22px; line-height: 1; color: var(--accent); cursor: pointer; }
.top .sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 24px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; text-decoration: none; color: var(--ink-3); font-size: 12px;
}
.tabs a svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--accent); }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 14px 16px; margin: 0 0 14px;
}
.card h2 { font-size: 16px; margin: 0 0 8px; display: flex; align-items: baseline; gap: 8px; }
.card h2 .meta { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--ink-3); }
.section-title { font-size: 13px; color: var(--ink-3); margin: 20px 4px 8px; letter-spacing: .04em; }
.muted { color: var(--ink-3); font-size: 13px; }
.small { font-size: 13px; }
.empty { text-align: center; color: var(--ink-3); padding: 30px 0; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: 12px; color: var(--ink-3); }
.stat.warn b { color: var(--warn); }
.stat.danger b { color: var(--danger); }

.prose { font-size: 15px; overflow-wrap: anywhere; }
.prose p { margin: .5em 0; }
.prose ol, .prose ul { padding-left: 1.3em; margin: .4em 0; }
.prose li { margin: .3em 0; }
.prose h1 { font-size: 21px; margin: .2em 0 .6em; }
.prose h2 { font-size: 18px; margin: 1.4em 0 .5em; padding-top: .6em; border-top: 1px solid var(--line); }
.prose h3 { font-size: 16px; margin: 1.2em 0 .4em; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.prose pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; }
.prose blockquote { margin: .6em 0; padding: .2em .9em; border-left: 3px solid var(--line); color: var(--ink-2); }
.prose img { max-width: 100%; border-radius: 8px; }
.prose .tbl { overflow-x: auto; margin: .6em 0; -webkit-overflow-scrolling: touch; }
.prose table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.prose th, .prose td { border: 1px solid var(--line); padding: 5px 7px; vertical-align: top; text-align: left; }
.prose th { background: var(--surface-2); white-space: nowrap; }
.prose td { min-width: 5em; }
.prose a.missing { color: var(--ink-3); text-decoration: line-through dotted; }
.clamp { max-height: 15em; overflow: hidden; position: relative; }
.clamp::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3em; background: linear-gradient(transparent, var(--surface)); }
.more { border: 0; background: none; color: var(--accent); padding: 6px 0 0; font-size: 14px; cursor: pointer; }

.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; line-height: 1.7; }
.pill.due { background: var(--accent-soft); color: var(--accent); }
.pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.over { background: var(--danger-soft); color: var(--danger); }
.pill.ok { background: var(--accent-soft); color: var(--ok); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 13px; font-size: 14px; white-space: nowrap; cursor: pointer; color: var(--ink-2); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 52px; }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { overflow-wrap: anywhere; }
.row .meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row .ic { width: 34px; height: 34px; border-radius: 9px; flex: none; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); font-size: 11px; font-weight: 600; }
.row .ic.dir { background: var(--accent-soft); color: var(--accent); }
.row .ic svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.row .chev { color: var(--ink-3); flex: none; }
.row.todo { align-items: flex-start; cursor: pointer; }
.row.todo.done .name { color: var(--ink-3); text-decoration: line-through; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--ink-3); flex: none; margin-top: 1px; background: none; padding: 0; cursor: pointer; display: grid; place-items: center; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on::after { content: ""; width: 6px; height: 11px; border: solid var(--accent-ink); border-width: 0 2.5px 2.5px 0; transform: translateY(-1px) rotate(45deg); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; margin-bottom: 14px; }
.grid a { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); display: block; }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid span { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10.5px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.55)); padding: 10px 5px 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px; font-size: 16px; }
.crumbs { font-size: 13px; color: var(--ink-3); margin: 0 2px 10px; overflow-wrap: anywhere; }
.crumbs a { color: var(--ink-2); text-decoration: none; }

.btn { border: 0; border-radius: 11px; padding: 11px 16px; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; font-size: 15px; }
.btn.ghost { background: var(--surface-2); color: var(--ink); font-weight: 500; }
.btn.danger { background: var(--danger-soft); color: var(--danger); font-weight: 500; }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.fab { position: fixed; right: 18px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 7; width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1; box-shadow: 0 4px 14px rgba(0,0,0,.2); cursor: pointer; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; }
.field textarea { min-height: 84px; resize: vertical; }
.actions { display: flex; gap: 10px; margin-top: 4px; }
.actions .btn { flex: 1; }

dialog.sheet {
  border: 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); margin: auto auto 0; width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; background: var(--bg); color: var(--ink); max-height: 90vh;
}
dialog.sheet::backdrop { background: rgba(0,0,0,.4); }
dialog.sheet h3 { margin: 0 0 14px; font-size: 17px; }

.viewer { text-align: center; }
.viewer img { max-width: 100%; border-radius: 6px; background: var(--surface-2); }
.viewer .nav { display: flex; justify-content: space-between; gap: 10px; margin: 12px 0; }
.textdoc { white-space: pre-wrap; font-size: 14.5px; overflow-wrap: anywhere; }
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px 14px; text-align: center; background: var(--surface); margin-bottom: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
.hidden { display: none !important; }

/* 登录页 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: 100%; max-width: 340px; text-align: center; }
.login h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
.login p { color: var(--ink-3); margin: 0 0 22px; font-size: 14px; }
.login input { width: 100%; text-align: center; font-size: 24px; letter-spacing: .35em; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px; }
.login .err { color: var(--danger); min-height: 1.5em; font-size: 14px; }
