:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e6e8ec;
  --border-soft: #eef0f3;
  --text: #17181a;
  --text-2: #6b7280;
  --text-3: #a1a7b3;
  --primary: #4f46e5;
  --primary-h: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --radius: 12px;
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

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

[hidden] { display: none !important; }

html, body { height: 100%; }

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

button { font-family: inherit; }

/* ---------- 顶栏 ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.35);
}

.search {
  position: relative;
  flex: 1;
  max-width: 340px;
  margin-left: 8px;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f6f7f9;
  padding: 0 14px 0 35px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: background .15s, border-color .15s, box-shadow .15s;
}

.search input::placeholder { color: var(--text-3); }

.search input:focus {
  background: #fff;
  border-color: #c7d2fe;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .08s, box-shadow .15s;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.3);
  flex: none;
}

.btn-primary:hover { background: var(--primary-h); }
.btn-primary:active { transform: scale(0.97); }

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

/* ---------- 布局 ---------- */

.layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: 320px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 10px 0 24px;
}

.note-list { display: flex; flex-direction: column; }

.note-item {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  margin: 2px 10px;
  padding: 11px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}

.note-item:hover { background: #f6f7f9; }

.note-item.active { background: var(--primary-soft); }
.note-item.active .note-title { color: var(--primary); }

.note-thumb {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border-soft);
  background: #fff;
}

.note-info { min-width: 0; flex: 1; }

.note-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.45;
}

.note-preview {
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  line-height: 1.5;
}

.note-date {
  font-size: 11.5px;
  color: var(--text-3);
  margin-top: 4px;
}

.empty-list {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}

.empty-list .hint {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-3);
}

/* ---------- 编辑区 ---------- */

.editor {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  scroll-behavior: smooth;
}

.editor-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  gap: 8px;
}

.editor-empty-icon { color: #c9cdd6; margin-bottom: 6px; }

.editor-empty h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-2);
}

.editor-empty p { font-size: 13px; }

.editor-main { min-height: 100%; }

.editor-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 36px 32px 140px;
  position: relative;
}

.editor-head { margin-bottom: 18px; }

.title-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  padding: 4px 0;
}

.title-input::placeholder { color: #c9cdd6; }

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  min-height: 18px;
}

.meta, .save-state {
  font-size: 12px;
  color: var(--text-3);
}

.toolbar .save-state {
  flex: none;
  min-width: 52px;
  margin-left: 8px;
  padding-right: 6px;
  text-align: right;
  white-space: nowrap;
}

.save-state.saving { color: #d97706; }
.save-state.editing { color: #d97706; }
.save-state.saved { color: #16a34a; }

/* ---------- 工具条 ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
  position: sticky;
  top: 16px;
  z-index: 10;
  margin-bottom: 22px;
}

.tool-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 7px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.tool-btn:hover { background: var(--primary-soft); color: var(--primary); }
.tool-btn:active { background: #e0e7ff; }

.tool-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: inset 0 0 0 1px #c7d2fe;
}

.tool-btn.wide { padding: 0 10px; font-size: 13px; }

.tool-btn.danger:hover { background: #fef2f2; color: var(--danger); }

.tool-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 5px;
  flex: none;
}

/* ---------- 正文（图文混排） ---------- */

.content {
  outline: none;
  font-size: 15.5px;
  line-height: 1.8;
  color: var(--text);
  min-height: 420px;
  word-break: break-word;
}

.content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-3);
  pointer-events: none;
}

.content p { margin: 0 0 10px; }

.content h2 {
  font-size: 22px;
  font-weight: 700;
  margin: 26px 0 10px;
  letter-spacing: -0.01em;
}

.content h3 {
  font-size: 17.5px;
  font-weight: 600;
  margin: 20px 0 8px;
}

.content blockquote {
  border-left: 3px solid #c7d2fe;
  background: #f8f9ff;
  color: var(--text-2);
  padding: 10px 16px;
  border-radius: 0 10px 10px 0;
  margin: 14px 0;
}

.content ul, .content ol { padding-left: 24px; margin: 10px 0; }
.content li { margin: 4px 0; }

.content img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 14px 0;
  box-shadow: 0 2px 10px rgba(16, 24, 40, 0.08);
  border: 1px solid var(--border-soft);
}

.content img.uploading {
  opacity: 0.35;
  filter: blur(1px);
}

/* 文件卡片（非图片文件，灰色边框） */

.content .file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-left: 3px solid #c7d2fe;
  background: #f8f9ff;
  border-radius: 0 10px 10px 0;
  padding: 11px 14px;
  margin: 14px 0;
}

.file-ext {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 10px;
  background: #eef0f4;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-2);
  letter-spacing: 0.02em;
}

.file-info { min-width: 0; flex: 1; }

.file-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.file-dl {
  flex: none;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
  padding: 5px 13px;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}

.file-dl:hover { background: var(--primary-soft); }

.file-del {
  flex: none;
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  color: var(--danger);
  padding: 5px 13px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}

.file-del:hover { background: #fef2f2; }

/* 引用块右上角复制按钮 */

.bq-copy {
  position: absolute;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-2);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  box-shadow: 0 1px 5px rgba(16, 24, 40, 0.1);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s, color 0.12s, border-color 0.12s;
}

.bq-copy.show { opacity: 1; pointer-events: auto; }
.bq-copy:hover { color: var(--primary); border-color: #c7d2fe; background: var(--primary-soft); }

/* 图片 / 文件卡片右上角删除按钮 */

.media-del {
  position: absolute;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-2);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  box-shadow: 0 1px 5px rgba(16, 24, 40, 0.1);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s, color 0.12s, border-color 0.12s, background 0.12s;
}

.media-del.show { opacity: 1; pointer-events: auto; }
.media-del:hover { color: var(--danger); border-color: #fecaca; background: #fef2f2; }

/* ---------- 其他 ---------- */

.icon-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:hover { background: #eceef2; }

.back-btn { display: none; margin-bottom: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(10px);
  background: #1f2937;
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 滚动条 ---------- */

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb {
  background: #d8dbe1;
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: #c3c8d0; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 启动遮罩（数据就绪前隐藏主体，防止加载中闪屏） ---------- */

.layout,
.user-area,
.auth-gate {
  transition: opacity 0.18s ease;
}

body.booting .layout,
body.booting .user-area,
body.booting .auth-gate {
  opacity: 0;
  pointer-events: none;
}

/* ---------- 未登录引导 ---------- */

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

.gate-card {
  text-align: center;
  max-width: 340px;
}

.gate-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 22px;
  background: linear-gradient(135deg, #eef2ff, #ede9fe);
  display: grid;
  place-items: center;
  color: var(--primary);
}

.gate-card h2 {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 8px;
}

.gate-card p {
  font-size: 13.5px;
  color: var(--text-2);
  line-height: 1.7;
  margin-bottom: 20px;
}

.save-state.error { color: var(--danger); }

/* ---------- 用户区（右上角） ---------- */

.user-area { position: relative; flex: none; margin-left: auto; }

.btn-ghost {
  height: 38px;
  padding: 0 15px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.btn-ghost:hover {
  border-color: #c7d2fe;
  color: var(--primary);
  background: var(--primary-soft);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px 0 6px;
  border-radius: 19px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.user-chip:hover { border-color: #c7d2fe; background: var(--primary-soft); }

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 700;
}

.user-menu {
  position: absolute;
  right: 0;
  top: 46px;
  min-width: 170px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 32px rgba(16, 24, 40, 0.14);
  padding: 6px;
  z-index: 150;
}

.user-menu-name {
  font-size: 12px;
  color: var(--text-3);
  padding: 6px 10px 7px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-2);
  cursor: pointer;
}

.user-menu-item:hover { background: #fef2f2; color: var(--danger); }

/* ---------- 图片放大查看（灯箱） ---------- */

.img-viewer {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(13, 15, 20, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  animation: viewer-in 0.16s ease;
}

@keyframes viewer-in {
  from { opacity: 0; }
}

.img-viewer > img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.5);
  cursor: default;
  animation: viewer-img-in 0.2s ease;
}

@keyframes viewer-img-in {
  from { opacity: 0; transform: scale(0.965); }
}

.img-viewer-actions {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 301;
}

.img-viewer-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background 0.15s;
}

.img-viewer-btn:hover { background: rgba(255, 255, 255, 0.26); }
.img-viewer-del:hover { background: rgba(220, 38, 38, 0.78); }

@media (max-width: 800px) {
  .img-viewer { padding: 14px; }
  .img-viewer-actions { top: 10px; right: 10px; }
}

/* ---------- 登录 / 注册弹窗 ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(17, 20, 26, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  position: relative;
  width: 380px;
  max-width: 100%;
  background: #fff;
  border-radius: 18px;
  padding: 26px 26px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: modal-in 0.18s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 20px;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
}

.modal-close:hover { background: #f2f3f6; color: var(--text); }

.tabs {
  display: flex;
  gap: 4px;
  background: #f2f3f6;
  border-radius: 10px;
  padding: 4px;
  margin: 16px 0 18px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: 8px;
  padding: 8px 0;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.tab.active {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.1);
}

.field {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 14px;
}

.field input {
  display: block;
  width: 100%;
  margin-top: 7px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fafbfc;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.field input::placeholder { color: var(--text-3); }

.field input:focus {
  border-color: #c7d2fe;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-msg {
  font-size: 12.5px;
  min-height: 18px;
  margin: -2px 0 8px;
}

.form-msg.err { color: var(--danger); }
.form-msg.ok { color: #16a34a; }

.btn-primary.block {
  width: 100%;
  justify-content: center;
  height: 42px;
  font-size: 14px;
}

.switch-line {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
  margin-top: 14px;
}

.link {
  border: none;
  background: none;
  padding: 0;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.link:hover { text-decoration: underline; }

/* ---------- 响应式 ---------- */

@media (max-width: 800px) {
  .search { max-width: none; }
  .sidebar { width: 100%; border-right: none; }
  .editor { display: none; }
  body.editing .sidebar { display: none; }
  body.editing .editor { display: block; }
  .back-btn { display: inline-flex; }
  .editor-inner { padding: 20px 18px 120px; }
  .title-input { font-size: 25px; }
  .brand { display: none; }
  .user-chip { padding: 0 6px; }
  .user-chip #userName, .user-chip svg { display: none; }
  .toolbar .save-state { min-width: 0; font-size: 11px; margin-left: 4px; padding-right: 2px; }
  .toolbar [data-val="h2"], .toolbar [data-val="h3"] { display: none; }
  .toolbar .tool-sep:nth-of-type(2) { display: none; }
  .toolbar .btn-label { display: none; }
}

@media (max-width: 520px) {
  .btn-primary span-label { display: none; }
}