:root {
  color-scheme: light dark;
  --bg: #faf9f6;
  --panel: #f3f1ec;
  --ink: #24221f;
  --muted: #8b867d;
  --line: #e7e3da;
  --hover: #ebe8e1;
  --accent: #b1532c;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", ui-serif, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  --side: 300px;
  --kb: 0px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --panel: #1d1c19;
    --ink: #e8e4db;
    --muted: #8f8b82;
    --line: #2b2925;
    --hover: #272521;
    --accent: #dc8d66;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.75 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.grow { flex: 1; }
[hidden] { display: none !important; }

.icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: inline-grid; place-items: center; color: var(--muted);
}
.icon:hover { background: var(--hover); color: var(--ink); }

/* ── 正文 ── */
main { min-height: 100dvh; display: flex; flex-direction: column; }
#top {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 2px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.pill { font-size: 14px; padding: 5px 14px; margin-right: 6px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill:hover { background: var(--hover); color: var(--ink); }

#page { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 12px 22px 120px; cursor: text; }
#title { font: 600 34px/1.2 var(--serif); letter-spacing: 0.02em; margin: 8px 0 4px; cursor: default; }
#sub { font-size: 14px; margin: 0 0 26px; cursor: default; }

#blocks textarea {
  display: block; width: 100%; min-height: 1.75em;
  field-sizing: content; resize: none; overflow: hidden;
  border: 0; outline: 0; padding: 0; margin: 0; background: none;
  color: inherit; font: inherit; caret-color: var(--accent);
}
#blocks textarea::placeholder { color: var(--muted); opacity: 0.7; }
#blocks textarea:only-child { min-height: 40vh; }

#blocks figure { position: relative; margin: 10px 0; width: fit-content; max-width: 100%; cursor: default; }
#blocks img, #blocks video { display: block; max-width: 100%; max-height: 72vh; border-radius: 10px; background: var(--panel); }
#blocks img { cursor: zoom-in; min-width: 80px; min-height: 60px; }
#blocks figure.missing { width: auto; padding: 14px 16px; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 14px; }
#blocks figure.missing p { margin: 0; padding-right: 30px; }
#blocks .rm {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; background: rgb(0 0 0 / 0.45);
}
#blocks .rm svg { width: 15px; height: 15px; }
@media (hover: hover) { #blocks .rm { opacity: 0; transition: opacity 0.15s; } #blocks figure:hover .rm, #blocks .rm:focus-visible { opacity: 1; } }

#bar {
  position: sticky; bottom: var(--kb); z-index: 2;
  display: flex; align-items: center; gap: 4px;
  width: 100%; max-width: 720px; margin: 0 auto;
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tool { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 11px; border-radius: 10px; font-size: 14px; color: var(--muted); }
.tool:hover { background: var(--hover); color: var(--ink); }
.status { font-size: 13px; color: var(--muted); padding: 8px 10px; border-radius: 10px; display: inline-flex; align-items: center; gap: 7px; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; }
.status[data-state="ok"]::before, .status[data-state=""]::before { background: #5a9a6a; opacity: 1; }
.status[data-state="login"], .status[data-state="error"] { color: var(--accent); }
.status:hover { background: var(--hover); }

/* ── 侧栏 ── */
#side {
  position: fixed; inset: 0 auto 0 0; width: var(--side); z-index: 5;
  display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line);
  font-size: 15px;
}
.side-head { display: flex; align-items: center; gap: 4px; padding: calc(12px + env(safe-area-inset-top)) 12px 8px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 11px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.search svg { width: 16px; height: 16px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none; }
.search:focus-within { border-color: var(--muted); }
#side .scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 12px 12px; }

.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; font-weight: 600; }
.cal-head .icon { width: 34px; height: 34px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.cal-grid i { font-style: normal; font-size: 12px; color: var(--muted); padding: 2px 0 4px; }
.cal-grid button { position: relative; aspect-ratio: 1; border-radius: 50%; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-grid button.has { color: var(--ink); font-weight: 600; }
.cal-grid button.has::after { content: ""; position: absolute; left: 50%; bottom: 14%; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--accent); }
.cal-grid button:hover { background: var(--hover); }
.cal-grid button.today { box-shadow: inset 0 0 0 1px var(--muted); }
.cal-grid button.cur { background: var(--ink); color: var(--bg); box-shadow: none; }
.cal-grid button.cur::after { background: var(--bg); }

#list { list-style: none; margin: 0; padding: 0; }
#list .month { font-size: 12px; color: var(--muted); padding: 16px 8px 4px; letter-spacing: 0.04em; }
#list .empty { color: var(--muted); padding: 28px 8px; font-size: 14px; }
#list li { content-visibility: auto; contain-intrinsic-size: auto 64px; }
#list button { display: flex; gap: 12px; width: 100%; text-align: left; padding: 9px 8px; border-radius: 10px; }
#list button:hover { background: var(--hover); }
#list button.cur { background: var(--hover); }
#list .day { width: 34px; flex: none; text-align: center; line-height: 1.2; padding-top: 2px; }
#list .day b { display: block; font: 600 20px/1.1 var(--serif); }
#list .day i { font-style: normal; font-size: 11px; color: var(--muted); }
#list .ex { flex: 1; min-width: 0; font-size: 14px; line-height: 1.55; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#list .clip { width: 13px; height: 13px; margin-left: 5px; vertical-align: -1px; }
mark { background: color-mix(in srgb, var(--accent) 24%, transparent); color: var(--ink); border-radius: 3px; }

.side-foot { display: flex; align-items: center; gap: 10px; padding: 13px 20px calc(13px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; text-align: left; }
.side-foot:hover { color: var(--ink); }
.side-foot .muted { margin-left: auto; font-size: 12px; }
.side-foot svg { width: 18px; height: 18px; }
#closeSide { display: none; }

@media (min-width: 900px) {
  main { margin-left: var(--side); }
  #openSide { display: none; }
  #page { padding: 28px 40px 140px; }
  #title { font-size: 40px; }
  #top { padding-right: 20px; }
}
@media (max-width: 899.98px) {
  #side { width: 100%; border-right: 0; background: var(--bg); transform: translateY(8px); opacity: 0; visibility: hidden; transition: transform 0.18s ease, opacity 0.18s ease, visibility 0s 0.18s; }
  body.browsing #side { transform: none; opacity: 1; visibility: visible; transition-delay: 0s; }
  body.browsing { overflow: hidden; }
  #closeSide { display: inline-grid; }
  .tool span { display: none; }
  .tool { width: 44px; justify-content: center; padding: 0; }
  #side .scroll { padding: 0 16px 16px; }
  .cal-grid button { font-size: 15px; aspect-ratio: auto; width: 42px; height: 42px; margin: 1px auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ── 设置、看图、提示 ── */
dialog { border: 0; padding: 0; color: var(--ink); background: none; max-width: none; max-height: none; }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
#settings { width: min(460px, 100vw - 24px); margin: auto; }
.sheet { background: var(--bg); border-radius: 16px; padding: 6px 22px 22px; max-height: calc(100dvh - 40px); overflow-y: auto; }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; margin-right: -10px; }
.sheet h2 { font: 600 22px var(--serif); margin: 0; }
.sheet section { padding: 16px 0 4px; border-top: 1px solid var(--line); margin-top: 14px; }
.sheet h3 { font-size: 15px; margin: 0 0 6px; }
.sheet p { font-size: 14px; line-height: 1.7; margin: 0 0 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.btn { height: 40px; padding: 0 18px; border-radius: 10px; font-size: 15px; background: var(--ink); color: var(--bg); }
.btn.ghost { background: none; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--hover); }
.btn:disabled { opacity: 0.5; }

#viewer { width: 100vw; height: 100dvh; background: rgb(0 0 0 / 0.9); cursor: zoom-out; }
#viewer[open] { display: grid; place-items: center; }
#viewer img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }

#toast {
  position: fixed; left: 50%; bottom: calc(72px + var(--kb) + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9;
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  background: var(--ink); color: var(--bg); box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
}
#toast button { color: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; flex: none; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
