:root {
  --bg: #ffffff;
  --sidebar-bg: #f7f7f8;
  --sidebar-border: #e6e6ea;
  --hover: #ececf0;
  --selected: #d9d9e0;
  --text: #1c1c1e;
  --text-2: #8a8a8e;
  --text-3: #b0b0b5;
  --accent: #ffd60a;
  --accent-soft: #fff6cc;
  --line: #ececf0;
  --danger: #ff3b30;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 任何带 hidden 属性的元素都必须隐藏（避免被 display:flex 等覆盖） */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 10px;
}
.sidebar-head h1 {
  font-size: 22px;
  font-weight: 700;
  flex: 1;
  letter-spacing: .2px;
}
.icon-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.new-btn { color: #c79a00; font-weight: 700; }
.menu-btn { display: none; }

.search {
  margin: 4px 14px 10px;
  position: relative;
}
.search-ico {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 13px; opacity: .55;
}
.search input {
  width: 100%;
  border: none;
  background: #e9e9ee;
  border-radius: 9px;
  padding: 8px 10px 8px 30px;
  font-size: 14px;
  color: var(--text);
  outline: none;
}
.search input::placeholder { color: var(--text-3); }

.note-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.note-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background .12s;
}
.note-item:hover { background: var(--hover); }
.note-item.active { background: var(--selected); }
.note-item .ni-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .ni-snippet {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .ni-title mark,
.note-item .ni-snippet mark {
  background: #ffe58f;
  color: #5a4d00;
  border-radius: 3px;
  padding: 0 2px;
}
.note-item .ni-date {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 3px;
}

.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--sidebar-border); }
.mode-btn {
  width: 100%;
  border: none;
  background: var(--accent);
  color: #1c1c1e;
  font-weight: 600;
  font-size: 14px;
  padding: 11px;
  border-radius: 11px;
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.mode-btn:hover { filter: brightness(.96); }
.mode-btn.editing { background: #ececf0; color: var(--text-2); }
.tips-entry {
  width: 100%;
  margin-top: 8px;
  border: 1px solid var(--sidebar-border);
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  font-size: 13px;
  padding: 9px;
  border-radius: 11px;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-family: var(--font);
}
.tips-entry:hover { background: var(--hover); color: var(--text); }

/* ---------- 主编辑区 ---------- */
.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tool {
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 13px;
  color: #444;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s;
}
.tool:hover { background: var(--hover); }
.tool.danger { color: var(--danger); margin-left: auto; }
.sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.version-mark {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  opacity: 0.7;
  user-select: text;
  padding: 0 4px;
}

.save-status {
  font-size: 12px;
  color: var(--text-3);
  margin-left: 6px;
  min-width: 48px;
}

.note-head {
  padding: 22px 56px 6px;
}
.title-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  font-family: var(--font);
}
.title-input::placeholder { color: var(--text-3); }
.meta {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}

.content-wrap { flex: 1; position: relative; overflow-y: auto; }
.content {
  padding: 8px 56px 80px;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  outline: none;
  min-height: 100%;
}
.content[contenteditable="true"] {
  cursor: text;
  outline: 2px solid #b8c5d6;
  outline-offset: 8px;
  border-radius: 10px;
  background: #f9fafb;
  transition: outline-color .15s, background .15s;
}
.content[contenteditable="true"]:focus {
  outline-color: #9aa8b8;
  background: #ffffff;
}

/* 富文本内容样式 */
.content h2 { font-size: 21px; font-weight: 700; margin: 14px 0 6px; }
.content h3 { font-size: 18px; font-weight: 700; margin: 12px 0 5px; }
.content p { margin: 6px 0; }
.content ul, .content ol { margin: 6px 0 6px 24px; }
.content blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  margin: 10px 0;
  padding: 8px 14px;
  border-radius: 0 8px 8px 0;
  color: #5a4d00;
}
.content img.note-img {
  max-height: 130px;
  max-width: 100%;
  width: auto;
  border-radius: 10px;
  margin: 8px 0;
  display: inline-block;
  box-shadow: var(--shadow);
  cursor: zoom-in;
  transition: filter .15s;
}
.content img.note-img:hover { filter: brightness(.96); }
.content a { color: #0a84ff; }

/* ---------- 图片灯箱 ---------- */
.overlay.lightbox {
  background: rgba(0,0,0,.86);
  cursor: zoom-out;
  padding: 40px;
}
.overlay.lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  cursor: default;
}

.empty {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  text-align: center;
  gap: 10px;
}
.empty.show { display: flex; }
.empty-emoji { font-size: 46px; }
.empty-new {
  margin-top: 8px;
  border: none;
  background: var(--accent);
  color: #1c1c1e;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 11px;
  cursor: pointer;
  font-family: var(--font);
}
.empty-new:hover { filter: brightness(.96); }

/* ---------- 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.32);
  display: grid; place-items: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }
.modal {
  background: #fff;
  width: 320px;
  max-width: 88vw;
  border-radius: 16px;
  padding: 22px 20px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal h3 { font-size: 18px; margin-bottom: 6px; }
.modal p { font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.modal input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  font-family: var(--font);
}
.modal input:focus { border-color: var(--accent); }
.tips-modal { width: 360px; }
.tips-list {
  list-style: none;
  margin: 10px 0 4px;
  max-height: 60vh;
  overflow-y: auto;
}
.tips-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.tips-list li:last-child { border-bottom: none; }
.tips-list .key {
  display: inline-block;
  min-width: 96px;
  font-size: 12px;
  font-weight: 600;
  color: #1c1c1e;
  background: var(--hover);
  border-radius: 6px;
  padding: 3px 8px;
  text-align: center;
  flex-shrink: 0;
}
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 11px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
}
.btn.ghost { background: #f0f0f3; color: var(--text); }
.btn.primary { background: var(--accent); color: #1c1c1e; }
.btn.primary:hover { filter: brightness(.96); }

/* ---------- 移动端顶栏 / 遮罩（默认隐藏） ---------- */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    left: 0;
    height: 100%;
    width: 84%;
    max-width: 360px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.18);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  /* 侧栏打开时的半透明遮罩：点击空白处关闭 */
  .app.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.30);
    z-index: 25;
  }
  .menu-btn { display: none; }
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }
  .mobile-topbar .mt-title {
    flex: 1;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
  }
  .note-head, .content { padding-left: 18px; padding-right: 18px; }
  .note-head { padding-top: 14px; }
  .new-btn { margin-left: auto; }
}
