/* ==========================================================================
   私密笔记 · 样式表
   设计约束：不使用任何外部字体/图片/CDN —— 严格 CSP 下,零第三方请求。
   ========================================================================== */

:root {
  --bg: #f6f6fb;
  --surface: #ffffff;
  --surface-2: #f1f1f9;
  --border: #e3e3f0;
  --text: #1b1b26;
  --muted: #6c6c81;
  --accent: #4f46e5;
  --accent-soft: #ecebff;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --warn: #b7791f;
  --warn-soft: #fdf3e2;
  --ok: #2f855a;
  --shadow: 0 1px 2px rgba(20, 20, 43, .06), 0 8px 24px rgba(20, 20, 43, .06);
  --radius: 12px;
  --radius-sm: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101017;
    --surface: #191922;
    --surface-2: #20202b;
    --border: #2c2c3a;
    --text: #e9e9f2;
    --muted: #9b9bb0;
    --accent: #8b8bf7;
    --accent-soft: #26264a;
    --danger: #f08a8a;
    --danger-soft: #3a2020;
    --warn: #e2b866;
    --warn-soft: #332915;
    --ok: #7bd6a4;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  --bg: #101017;
  --surface: #191922;
  --surface-2: #20202b;
  --border: #2c2c3a;
  --text: #e9e9f2;
  --muted: #9b9bb0;
  --accent: #8b8bf7;
  --accent-soft: #26264a;
  --danger: #f08a8a;
  --danger-soft: #3a2020;
  --warn: #e2b866;
  --warn-soft: #332915;
  --ok: #7bd6a4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

#app { min-height: 100%; display: flex; flex-direction: column; }

h1, h2, h3, h4 { line-height: 1.3; margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------- 启动态 ------------------------------- */
.boot {
  flex: 1; display: grid; place-content: center; justify-items: center; gap: 14px;
  color: var(--muted); min-height: 60vh;
}
.boot-spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ------------------------------- 通用控件 ------------------------------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--radius-sm); padding: 8px 14px;
  font: inherit; font-size: 14px; cursor: pointer; display: inline-flex;
  align-items: center; gap: 7px; transition: background .15s, border-color .15s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { color: var(--danger); border-color: var(--border); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-icon { padding: 7px 9px; }
.btn svg { width: 16px; height: 16px; flex: none; }

input, textarea, select { font: inherit; color: inherit; }
.input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--muted); opacity: .75; }

.field { display: grid; gap: 6px; }
.field > label { font-size: 13px; color: var(--muted); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.pill-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.tag {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); cursor: pointer; border: 1px solid transparent;
}
.tag[data-active="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.banner {
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px;
  display: flex; gap: 9px; align-items: flex-start; line-height: 1.5;
}
.banner-info { background: var(--surface-2); color: var(--muted); }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-danger { background: var(--danger-soft); color: var(--danger); }
.banner-ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

/* ------------------------------- 落地页 ------------------------------- */
.landing { flex: 1; display: flex; flex-direction: column; }
.landing-header {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 22px; max-width: 1060px; width: 100%; margin: 0 auto;
}
.landing-brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 650; text-decoration: none; color: inherit; }
.landing-brand img { width: 26px; height: 26px; border-radius: 7px; }
.landing-nav { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.landing-nav a { color: var(--muted); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 7px; }
.landing-nav a:hover { background: var(--surface-2); color: var(--text); }

.landing-main { flex: 1; max-width: 1060px; width: 100%; margin: 0 auto; padding: 10px 22px 60px; }
.hero { display: grid; gap: 34px; grid-template-columns: 1fr; padding: 26px 0 34px; }
@media (min-width: 900px) { .hero { grid-template-columns: 1.05fr .95fr; align-items: center; padding: 48px 0 56px; } }
.hero h1 { font-size: clamp(30px, 5vw, 46px); letter-spacing: -.03em; }
.hero-lead { color: var(--muted); font-size: 16px; margin-top: 14px; max-width: 44ch; }

.entry-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; box-shadow: var(--shadow); margin-top: 24px; max-width: 520px;
}
.entry-row { display: flex; gap: 8px; }
.entry-row .input { flex: 1; }
.entry-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.entry-help { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.entry-help strong { color: var(--warn); font-weight: 600; }

.facts { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 18px; color: var(--muted); font-size: 13.5px; }
.facts span { display: inline-flex; align-items: center; gap: 6px; }
.facts svg { width: 15px; height: 15px; color: var(--ok); }

.illustration {
  border: 1px solid var(--border); border-radius: 16px; background: var(--surface);
  padding: 22px; box-shadow: var(--shadow);
}
.illustration h3 { font-size: 15px; }
.flow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 0 10px; color: var(--muted); font-size: 13.5px; }
.flow svg { width: 16px; height: 16px; color: var(--accent); }
.diagram {
  border-radius: 12px; background: var(--surface-2); padding: 16px;
  font-family: var(--mono); font-size: 12px; color: var(--muted); line-height: 1.75;
  white-space: pre; overflow-x: auto;
}

.section { margin-top: 52px; }
.section-head h2 { font-size: 22px; }
.section-head p { color: var(--muted); margin-top: 6px; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-top: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.card h3 { font-size: 15px; margin-bottom: 6px; }
.card p { color: var(--muted); font-size: 13.5px; }
.card h4 { font-size: 14px; margin-bottom: 4px; }
.card-icon { width: 20px; height: 20px; color: var(--accent); margin-bottom: 10px; }

.recent { margin-top: 18px; display: grid; gap: 8px; max-width: 520px; }
.recent-title { font-size: 13px; color: var(--muted); }
.recent-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; font: inherit; color: inherit;
}
.recent-item:hover { border-color: var(--accent); }
.recent-item .grow { display: grid; }
.recent-item .name { font-weight: 550; }
.recent-item .meta { font-size: 12px; color: var(--muted); }

details.faq { border-top: 1px solid var(--border); padding: 14px 0; }
details.faq summary { cursor: pointer; font-weight: 550; list-style: none; display: flex; align-items: center; gap: 8px; }
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::before { content: "＋"; color: var(--muted); font-weight: 400; }
details.faq[open] summary::before { content: "－"; }
details.faq p { color: var(--muted); font-size: 13.5px; margin-top: 8px; padding-left: 20px; }

.footer { border-top: 1px solid var(--border); margin-top: 56px; padding-top: 18px; color: var(--muted); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 8px 20px; }

/* ------------------------------- 解锁界面 ------------------------------- */
.unlock-wrap { flex: 1; display: grid; place-items: center; padding: 24px; }
.unlock {
  width: 100%; max-width: 430px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; box-shadow: var(--shadow); display: grid; gap: 16px;
}
.unlock-head { display: grid; gap: 4px; }
.unlock-head h1 { font-size: 20px; }
.unlock-actions { display: flex; gap: 8px; align-items: center; }
.progress { height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 30%; background: var(--accent); border-radius: 999px; animation: slide 1.1s ease-in-out infinite alternate; }
@keyframes slide { from { margin-left: 0; } to { margin-left: 70%; } }

/* ------------------------------- 笔记主界面 ------------------------------- */
.nb { flex: 1; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.nb-top {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.nb-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; min-width: 0; }
.nb-title img { width: 22px; height: 22px; border-radius: 6px; }
.nb-top .search { flex: 1 1 200px; max-width: 380px; }
.nb-body { flex: 1; display: grid; grid-template-columns: 300px 1fr; min-height: 0; }

.nb-side {
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.side-head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.side-list { overflow-y: auto; padding: 8px; display: grid; gap: 6px; align-content: start; }
.side-empty { padding: 28px 18px; color: var(--muted); text-align: center; font-size: 13.5px; }

.note-item {
  display: grid; gap: 3px; text-align: left; width: 100%; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  padding: 9px 10px; font: inherit; color: inherit;
}
.note-item:hover { background: var(--surface-2); }
.note-item[data-active="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.note-item .row1 { display: flex; align-items: baseline; gap: 8px; }
.note-item .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.note-item .time { font-size: 11.5px; color: var(--muted); flex: none; }
.note-item .snippet { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.note-item .tag { font-size: 11px; padding: 1px 7px; cursor: pointer; }

.nb-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.editor { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.editor-head { padding: 16px 20px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--border); }
.editor-title {
  border: none; background: transparent; font-size: 22px; font-weight: 650;
  padding: 0; outline: none; width: 100%;
}
.editor-title::placeholder { color: var(--muted); opacity: .6; }
.editor-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.editor-tags { border: none; background: transparent; outline: none; font-size: 13px; color: var(--muted); flex: 1; min-width: 130px; }
.editor-tags::placeholder { color: var(--muted); opacity: .7; }
.editor-toolbar { display: flex; gap: 6px; align-items: center; }
.editor-panes { flex: 1; display: grid; grid-template-columns: 1fr; min-height: 0; }
.editor-panes[data-view="split"] { grid-template-columns: 1fr 1fr; }
.editor-body {
  border: none; outline: none; resize: none; width: 100%; height: 100%;
  padding: 18px 20px; background: transparent; font-family: var(--mono);
  font-size: 14px; line-height: 1.75; min-height: 0;
}
.preview {
  overflow-y: auto; padding: 18px 22px; border-left: 1px solid var(--border);
  background: var(--surface); min-height: 0;
}
.preview h1 { font-size: 24px; margin: 18px 0 10px; }
.preview h2 { font-size: 20px; margin: 18px 0 8px; }
.preview h3 { font-size: 17px; margin: 16px 0 6px; }
.preview h4, .preview h5, .preview h6 { font-size: 15px; margin: 14px 0 6px; }
.preview p { margin: 10px 0; }
.preview ul, .preview ol { margin: 10px 0; padding-left: 22px; }
.preview li { margin: 4px 0; }
.preview blockquote { margin: 12px 0; padding: 4px 0 4px 14px; border-left: 3px solid var(--border); color: var(--muted); }
.preview pre { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; overflow-x: auto; margin: 12px 0; }
.preview pre code { background: none; padding: 0; font-size: 13px; }
.preview hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.preview table { border-collapse: collapse; margin: 12px 0; width: 100%; font-size: 14px; }
.preview th, .preview td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.preview img { max-width: 100%; border-radius: 8px; }
.preview .task { list-style: none; margin-left: -18px; }
.preview .task input { margin-right: 7px; }

.statusbar {
  border-top: 1px solid var(--border); padding: 7px 14px; display: flex;
  align-items: center; gap: 12px; font-size: 12.5px; color: var(--muted);
  background: var(--surface); flex-wrap: wrap;
}
.statusbar .grow { min-width: 10px; }
.empty-main { flex: 1; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); text-align: center; padding: 30px; }

.nb-back { display: none; }

@media (max-width: 860px) {
  .nb-body { grid-template-columns: 1fr; }
  .nb-side {
    position: fixed; inset: 0 auto 0 0; width: min(88vw, 340px); z-index: 30;
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .nb[data-drawer="open"] .nb-side { transform: translateX(0); }
  .nb[data-drawer="open"]::after {
    content: ""; position: fixed; inset: 0; background: rgba(6, 6, 14, .45); z-index: 25;
  }
  .nb-back { display: inline-flex; }
  .editor-panes[data-view="split"] { grid-template-columns: 1fr; }
  .preview { border-left: none; border-top: 1px solid var(--border); }
}

/* ------------------------------- 对话框 ------------------------------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(8, 8, 18, .5); z-index: 40;
  display: grid; place-items: center; padding: 18px; overflow-y: auto;
}
.dialog {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; width: 100%; max-width: 480px; box-shadow: var(--shadow);
  display: grid; gap: 16px; margin: auto;
}
.dialog h2 { font-size: 18px; }
.dialog-rows { display: grid; gap: 14px; }
.dialog-row { display: grid; gap: 6px; }
.dialog-row .label { font-size: 13px; color: var(--muted); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.secret {
  font-family: var(--mono); font-size: 13px; background: var(--surface-2);
  padding: 10px 12px; border-radius: 8px; overflow-wrap: anywhere; user-select: all;
}

/* ------------------------------- 提示条 ------------------------------- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(94vw, 520px); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; box-shadow: var(--shadow); font-size: 13.5px;
  display: flex; gap: 9px; align-items: center;
}
.toast-danger { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); color: var(--danger); }
.toast-ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
/* ------------------------------- 小工具类 -------------------------------
   严格 CSP（style-src 'self'，无 'unsafe-inline'）下，元素的 style="" 内联属性会被拦掉，
   因此所有零星样式都必须落成类名，这里集中定义。 */
.entry-row-spaced { margin-top: 10px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.dialog-actions-left { justify-content: flex-start; }
.inline-warn { margin: 12px 20px 0; }