:root {
  --accent: #3b5bdb;
  --accent-soft: #edf1fd;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f2f3f5;
  --border: #e4e6eb;
  --text: #1a1d21;
  --text-2: #5c6370;
  --text-3: #9aa1ad;
  --danger: #d93a3a;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .05), 0 4px 16px rgba(16, 20, 30, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --read-size: 17px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #7c8ff5;
    --accent-soft: #1e2340;
    --bg: #131417;
    --surface: #1b1d21;
    --surface-2: #232529;
    --border: #2e3136;
    --text: #eceef1;
    --text-2: #a4abb6;
    --text-3: #737a85;
    --danger: #f07070;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }

.hidden { display: none !important; }

/* ---------------------------------------------------------- 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 8px;
}
.topbar-row { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 17px; font-weight: 600; letter-spacing: .3px; white-space: nowrap; }
.brand-dot { color: var(--accent); }

.search-wrap { flex: 1; position: relative; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .45; }
#search {
  width: 100%; padding: 10px 34px 10px 34px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); outline: none;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; border-radius: 50%; color: var(--text-3);
  font-size: 16px; line-height: 1;
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }

.chips {
  display: flex; gap: 7px; overflow-x: auto; padding: 9px 0 1px;
  scrollbar-width: none; margin: 0 -14px; padding-left: 14px; padding-right: 14px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 13.5px; color: var(--text-2); white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.chip .cnt { opacity: .6; font-size: 12px; margin-left: 3px; }
.tagrow { padding-top: 7px; }
.chip.tag { font-size: 12.5px; padding: 4px 10px; }
.chip.tag.on { background: var(--surface-2); border-color: var(--accent); color: var(--accent); font-weight: 500; }

/* ---------------------------------------------------------- 列表 */
main { max-width: 760px; margin: 0 auto; padding: 12px 14px 110px; }
.meta-line {
  display: flex; justify-content: space-between; align-items: center;
  padding: 2px 2px 10px; font-size: 12.5px; color: var(--text-3);
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 15px; margin-bottom: 10px;
  box-shadow: var(--shadow); transition: transform .12s ease, border-color .12s;
}
.card:active { transform: scale(.994); border-color: var(--text-3); }
.card-head { display: flex; align-items: baseline; gap: 8px; }
.card-title {
  font-size: 16px; font-weight: 600; line-height: 1.45;
  flex: 1; word-break: break-word;
}
.pin-mark { color: var(--accent); font-size: 13px; flex: none; }
.card-excerpt {
  margin-top: 6px; color: var(--text-2); font-size: 14px; line-height: 1.65;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.card-excerpt mark { background: #fdf0a8; color: inherit; border-radius: 2px; }
@media (prefers-color-scheme: dark) { .card-excerpt mark { background: #6b5d1a; } }
.card-foot {
  margin-top: 10px; display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap; font-size: 12px; color: var(--text-3);
}
.pill {
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2);
  color: var(--text-2); font-size: 12px;
}
.pill.cat { background: var(--accent-soft); color: var(--accent); }
.card-foot .sp { flex: 1; }
.empty { text-align: center; padding: 70px 20px; color: var(--text-3); }
.empty b { display: block; font-size: 15px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }

/* ---------------------------------------------------------- FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(22px + var(--safe-b));
  width: 56px; height: 56px; border-radius: 18px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; z-index: 40;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent);
}
.fab:active { transform: scale(.94); }

/* ---------------------------------------------------------- 覆盖层 */
.sheet, .reader {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg); display: flex; flex-direction: column;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.sheet-head .ttl { flex: 1; font-weight: 600; font-size: 15px; }
.btn {
  padding: 7px 15px; border-radius: 9px; font-size: 14px; font-weight: 500;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.btn.danger { background: transparent; border: 1px solid var(--border); color: var(--danger); }
.btn:disabled { opacity: .5; }

.sheet-body { flex: 1; overflow-y: auto; padding: 16px 14px calc(30px + var(--safe-b)); max-width: 760px; width: 100%; margin: 0 auto; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }
#f-title {
  width: 100%; padding: 11px 13px; font-size: 16px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); outline: none;
}
#f-content {
  width: 100%; min-height: 240px; padding: 13px; font-size: 15.5px; line-height: 1.8;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  outline: none; resize: vertical; font-family: inherit;
}
#f-title:focus, #f-content:focus, #f-cat:focus, #f-tags:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
#f-cat, #f-tags {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); outline: none;
}
.hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* ---------------------------------------------------------- 阅读页 */
.reader-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0;
}
.reader-head .sp { flex: 1; }
.reader-body {
  flex: 1; overflow-y: auto;
  padding: 20px 20px calc(60px + var(--safe-b));
  max-width: 760px; width: 100%; margin: 0 auto;
}
.reader-title { font-size: 22px; font-weight: 600; line-height: 1.45; margin: 0 0 10px; word-break: break-word; }
.reader-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; font-size: 12px; color: var(--text-3); align-items: center; }
.reader-content {
  font-size: var(--read-size); line-height: 1.85; white-space: pre-wrap;
  word-break: break-word; color: var(--text);
}
.reader-content h1, .reader-content h2, .reader-content h3 { line-height: 1.4; margin: 1.4em 0 .5em; }
.reader-content code {
  background: var(--surface-2); padding: 2px 6px; border-radius: 5px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em;
}
.reader-content .hl { color: var(--accent); font-weight: 500; }

.reader-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border); background: var(--surface);
  max-width: 760px; width: 100%; margin: 0 auto;
}
.reader-actions .btn { flex: 1; text-align: center; min-width: 72px; }

.fontctl { display: flex; gap: 4px; align-items: center; }
.fontctl button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-size: 14px;
}

/* ---------------------------------------------------------- 杂项 */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b));
  transform: translateX(-50%); z-index: 100;
  background: #1a1d21; color: #fff; padding: 10px 18px;
  border-radius: 10px; font-size: 14px; max-width: 84vw; text-align: center;
  animation: slideUp .18s ease;
}
@media (prefers-color-scheme: dark) { .toast { background: #eceef1; color: #131417; } }

.login {
  min-height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 28px;
}
.login-inner { width: 100%; max-width: 360px; }
.login h1 { font-size: 24px; margin: 0 0 8px; font-weight: 600; }
.login p { color: var(--text-2); font-size: 14px; margin: 0 0 26px; }
.login input {
  width: 100%; padding: 13px 15px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); outline: none; margin-bottom: 12px;
}
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login .btn { width: 100%; padding: 13px; font-size: 15.5px; border-radius: 11px; }
.login .err { color: var(--danger); font-size: 13.5px; margin-top: 12px; min-height: 20px; }

footer.about {
  text-align: center; color: var(--text-3); font-size: 12px;
  padding: 26px 10px 40px;
}
