/* ══════════════════════════════════════════════════════════════
   灵感 · 私人笔记
   视觉基线完全对齐 Memos：stone 灰、白卡、12px 圆角、无边框按钮、
   大量留白。注意这一页刻意不套主站的磨砂玻璃 + 金色，二者并存是
   用户明确要求的「界面照搬 Memos」。
   ══════════════════════════════════════════════════════════════ */

:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #f0efed;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text: #1c1917;
  --text-2: #78716c;
  --text-3: #a8a29e;
  --accent: #2c2c2a;
  --accent-text: #ffffff;
  --link: #3b82f6;
  --tag-bg: #eff6ff;
  --danger: #dc2626;
  --radius: 12px;
  --side: 288px;
}

html[data-theme="dark"] {
  --bg: #191919;
  --surface: #232322;
  --surface-2: #2c2c2a;
  --border: #343331;
  --border-strong: #444240;
  --text: #e7e5e4;
  --text-2: #a8a29e;
  --text-3: #78716c;
  --accent: #f5f5f4;
  --accent-text: #191919;
  --link: #60a5fa;
  --tag-bg: #1e3a5f;
  --danger: #f87171;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #191919;
    --surface: #232322;
    --surface-2: #2c2c2a;
    --border: #343331;
    --border-strong: #444240;
    --text: #e7e5e4;
    --text-2: #a8a29e;
    --text-3: #78716c;
    --accent: #f5f5f4;
    --accent-text: #191919;
    --link: #60a5fa;
    --tag-bg: #1e3a5f;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }

/* ⚠ 关键：作者样式里的 display（如 .auth / .modal 的 grid）会覆盖 [hidden] 自带的
   display:none，导致「隐藏」失效——弹层会一直盖在页面上。必须显式兜住。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

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

button, input, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 3px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ───────────── 首设 / 登录 ───────────── */

.auth {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 90;
}

.auth-card {
  width: 100%;
  max-width: 344px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 28px 26px;
  text-align: center;
}

.auth-logo {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border-radius: 11px;
  background: var(--accent);
  display: grid;
  place-items: center;
}
.auth-logo span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
}

.auth-title { font-size: 17px; font-weight: 500; margin: 16px 0 6px; }
.auth-sub { font-size: 12.5px; color: var(--text-3); margin: 0 0 20px; }

.auth-form { display: flex; flex-direction: column; gap: 10px; }

.field input {
  width: 100%;
  height: 40px;
  padding: 0 13px;
  font-size: 13.5px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.field input::placeholder { color: var(--text-3); }
.field input:focus {
  border-color: var(--border-strong);
  background: var(--surface);
}

.strength {
  display: flex;
  gap: 4px;
  height: 3px;
  margin: 2px 0 0;
}
.strength i {
  flex: 1;
  background: var(--border);
  border-radius: 2px;
  transition: background .2s;
}
.strength[data-lv="1"] i:nth-child(1) { background: #ef4444; }
.strength[data-lv="2"] i:nth-child(-n+2) { background: #f59e0b; }
.strength[data-lv="3"] i { background: #22c55e; }

.auth-msg {
  min-height: 17px;
  margin: 0;
  font-size: 12px;
  color: var(--danger);
  line-height: 1.4;
}

.auth-btn {
  height: 40px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: opacity .15s;
}
.auth-btn:hover { opacity: .88; }
.auth-btn:disabled { opacity: .5; cursor: default; }

.auth-foot { font-size: 11.5px; color: var(--text-3); margin: 16px 0 0; }

/* ───────────── 主框架 ───────────── */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ───────────── 侧栏 ───────────── */

.side {
  width: var(--side);
  flex: 0 0 var(--side);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px 12px;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  margin-bottom: 14px;
}
.logo { display: flex; align-items: center; gap: 9px; }
.logo-mark {
  width: 24px; height: 24px;
  border-radius: 7px;
  background: var(--accent);
  position: relative;
}
.logo-mark::after {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--surface);
}
.logo-text { font-size: 16px; font-weight: 500; letter-spacing: .2px; }
.side .side-close { display: none; }

.search {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 10px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 9px;
  transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--border-strong); background: var(--surface); }
.search svg { width: 15px; height: 15px; color: var(--text-3); flex: 0 0 auto; }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  outline: none;
  background: none;
  font-size: 13px;
  padding: 0 8px;
}
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear { display: grid; place-items: center; width: 18px; height: 18px; color: var(--text-3); }
.search-clear svg { width: 12px; height: 12px; stroke-width: 2; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text-2);
  text-align: left;
  transition: background .13s, color .13s;
}
.nav-item svg { width: 16px; height: 16px; flex: 0 0 auto; }
.nav-item span { flex: 1; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.on { background: var(--surface-2); color: var(--text); font-weight: 500; }
.nav-n { font-style: normal; font-size: 11.5px; color: var(--text-3); }

.tags {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin-top: 18px;
  padding: 0 2px;
}
.tags-title {
  font-size: 11.5px;
  color: var(--text-3);
  padding: 0 8px 6px;
  letter-spacing: .3px;
}
.tags-list { display: flex; flex-direction: column; gap: 1px; }
.tag-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--text-2);
  text-align: left;
  transition: background .13s, color .13s;
}
.tag-item:hover { background: var(--surface-2); color: var(--text); }
.tag-item.on { background: var(--surface-2); color: var(--link); }
.tag-item em { font-style: normal; font-size: 11px; color: var(--text-3); margin-left: auto; }
.tags-empty { font-size: 12px; color: var(--text-3); padding: 4px 10px; }

.side-foot {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 8px;
}

/* ───────────── 主区 ───────────── */

.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 24px 90px;
  scroll-behavior: smooth;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  height: 58px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.page-title { font-size: 16px; font-weight: 500; margin: 0; flex: 1; }
.count { font-size: 12px; color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--text-2);
  transition: background .13s, color .13s;
  flex: 0 0 auto;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.only-mobile { display: none; }

/* 输入卡 */

.composer,
.timeline,
.empty {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 10px;
  transition: border-color .15s;
}
.composer:focus-within { border-color: var(--border-strong); }

.composer textarea {
  display: block;
  width: 100%;
  min-height: 26px;
  max-height: 42vh;
  padding: 0;
  border: none;
  outline: none;
  background: none;
  resize: none;
  font-size: 14px;
  line-height: 1.65;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--text-3); }

.preview {
  font-size: 14px;
  line-height: 1.7;
  padding: 2px 0;
  min-height: 26px;
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.composer-tools { display: flex; align-items: center; gap: 2px; }
.tool {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  color: var(--text-3);
  transition: background .13s, color .13s;
}
.tool svg { width: 16px; height: 16px; }
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.on { background: var(--surface-2); color: var(--link); }
.draft-state { font-size: 11.5px; color: var(--text-3); margin-left: 6px; }

.composer-actions { display: flex; align-items: center; gap: 8px; }

.save-btn {
  height: 32px;
  padding: 0 16px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 500;
  transition: opacity .15s;
}
.save-btn:hover { opacity: .88; }
.save-btn:disabled { opacity: .45; cursor: default; }

.ghost-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  font-size: 13px;
  color: var(--text-2);
}
.ghost-btn:hover { background: var(--surface-2); }

/* 时间线 */

.timeline { margin-top: 18px; }

.day {
  font-size: 11.5px;
  color: var(--text-3);
  padding: 0 2px;
  margin: 20px 0 8px;
  letter-spacing: .3px;
}
.timeline .day:first-child { margin-top: 0; }

.memo {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px 12px;
  margin-bottom: 9px;
  transition: border-color .15s;
}
.memo:hover { border-color: var(--border-strong); }
.memo.pinned { border-left: 2px solid var(--accent); }

.memo-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 7px;
}
.avatar {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 500;
}
.memo-name { font-size: 13px; font-weight: 500; }
.memo-time { font-size: 11.5px; color: var(--text-3); }
.memo-act {
  display: flex;
  align-items: center;
  gap: 1px;
  margin-left: auto;
  opacity: 0;
  transition: opacity .15s;
}
.memo:hover .memo-act,
.memo:focus-within .memo-act,
.memo-act.show { opacity: 1; }
.memo-act .icon-btn { width: 26px; height: 26px; }
.memo-act .icon-btn svg { width: 14px; height: 14px; }
.memo-act .icon-btn.danger:hover { color: var(--danger); }

.memo-body { font-size: 14px; line-height: 1.72; word-wrap: break-word; overflow-wrap: anywhere; }
.memo-edit { display: none; }
.memo.editing .memo-body { display: none; }
.memo.editing .memo-edit { display: block; }
.memo-edit textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.7;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 9px;
  outline: none;
  resize: vertical;
}
.memo-edit .row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* Markdown 排版 */

.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 .55em; }
.md h1, .md h2, .md h3, .md h4 {
  font-weight: 500;
  line-height: 1.4;
  margin: .9em 0 .35em;
}
.md h1 { font-size: 19px; }
.md h2 { font-size: 16.5px; }
.md h3 { font-size: 15px; }
.md h4 { font-size: 14px; }
.md ul, .md ol { margin: .25em 0 .6em; padding-left: 1.35em; }
.md li { margin: .18em 0; }
.md li::marker { color: var(--text-3); }
.md input[type="checkbox"] {
  width: 14px; height: 14px;
  margin-right: 6px;
  accent-color: var(--accent);
}
.md blockquote {
  margin: .5em 0;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-2);
}
.md code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .89em;
  background: var(--surface-2);
  padding: 1.5px 5px;
  border-radius: 5px;
}
.md pre {
  margin: .6em 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 9px;
  overflow-x: auto;
}
.md pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.6; }
.md a { color: var(--link); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  width: auto;
  height: auto;
  margin: .55em auto;
  border-radius: 9px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.md table { border-collapse: collapse; width: 100%; margin: .5em 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-2); font-weight: 500; }

.tag {
  display: inline-block;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--tag-bg);
  color: var(--link);
  font-size: .93em;
  text-decoration: none;
  cursor: pointer;
}
.tag:hover { text-decoration: none; filter: brightness(.96); }

/* 空态 */

.empty {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}
.empty strong { display: block; font-size: 14px; color: var(--text-2); font-weight: 500; margin-bottom: 6px; }

/* ───────────── 设置弹层 ───────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 20, 19, .42);
  backdrop-filter: blur(3px);
}
.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px 22px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.modal-head h2 { font-size: 15px; font-weight: 500; margin: 0; }
.modal-sec { padding-top: 16px; }
.modal-sec + .modal-sec { border-top: 1px solid var(--border); margin-top: 16px; }
.modal-sec-title { font-size: 12px; color: var(--text-3); margin-bottom: 10px; }
.modal-sec .field { margin-bottom: 8px; }
.modal-sec .save-btn { width: 100%; height: 36px; border-radius: 18px; }
.modal-msg { min-height: 16px; margin: 2px 0 8px; font-size: 12px; color: var(--danger); }
.modal-hint { font-size: 11.5px; color: var(--text-3); margin: 10px 0 0; line-height: 1.6; }

.seg {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 9px;
  gap: 2px;
}
.seg button {
  height: 28px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--text-2);
  transition: background .13s, color .13s;
}
.seg button.on { background: var(--surface); color: var(--text); font-weight: 500; }

/* ───────────── 灯箱 / 提示 ───────────── */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  background: rgba(10, 10, 10, .9);
  cursor: zoom-out;
  padding: 20px;
}
.lightbox img {
  max-width: 94vw;
  max-height: 92vh;
  border-radius: 6px;
  object-fit: contain;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 120;
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12.5px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
  max-width: 80vw;
  text-align: center;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 20, 19, .38);
}

/* ───────────── 响应式 ───────────── */

@media (max-width: 860px) {
  .side {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .16);
  }
  .side.open { transform: none; }
  .side .side-close { display: grid; }
  .only-mobile { display: grid; }
  .main { padding: 0 14px calc(64px + env(safe-area-inset-bottom, 0px)); }
  .topbar { height: 52px; }
  .composer { padding: 10px 12px 8px; }
  .memo { padding: 12px 13px 11px; }
  .memo-act { opacity: 1; }
}

@media (max-width: 420px) {
  .auth-card { padding: 28px 20px 22px; }
  .page-title { font-size: 15px; }
  .composer textarea { font-size: 15px; }
  .memo-body { font-size: 14.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ── 页内对话框（替代原生 confirm/prompt） ────────────────── */
.ask-mask {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: rgba(28, 25, 23, .32);
}
html[data-theme="dark"] .ask-mask { background: rgba(0, 0, 0, .55); }
.ask-card {
  width: min(92vw, 372px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(28, 25, 23, .18);
  padding: 18px 18px 14px;
}
.ask-title { margin: 0 0 6px; font-size: 15px; font-weight: 600; color: var(--text); }
.ask-text { margin: 0; font-size: 13px; line-height: 1.7; color: var(--text-2); white-space: pre-line; }
.ask-input {
  width: 100%; margin-top: 10px; padding: 8px 10px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; outline: none;
}
.ask-input:focus { border-color: var(--text-2); }
.ask-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.ask-btns button {
  padding: 6px 14px; font-size: 13px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--text-2);
}
.ask-btns button:hover { background: var(--surface-2); }
.ask-btns .ask-ok { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.ask-btns .ask-ok:hover { background: var(--accent); filter: brightness(1.08); }
.ask-btns .ask-ok.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ask-btns .ask-ok.danger:hover { background: var(--danger); filter: brightness(.94); }
