:root {
  --bg: #FBFAF7;
  --surface: #FFFFFF;
  --surface-soft: #F4F1EA;
  --surface-hover: #EEEAE0;
  --border: #EBE7DD;
  --border-strong: #DDD7C8;
  --text: #1D1B1A;
  --text-dim: #6E6C68;
  --text-placeholder: #B5B2AC;
  --accent: #7C3AED;
  --accent-hover: #6D28D9;
  --accent-soft: #F1ECFE;
  --danger: #DC2626;
  --radius-pill: 999px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(17, 17, 17, 0.04);
  --shadow-lg: 0 20px 48px rgba(17, 17, 17, 0.10);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

button { font-family: inherit; }

/* ─── Topbar ─── */

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 16px 28px;
  background: transparent;
  position: relative;
  z-index: 10;
}

.brand {
  grid-column: 1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-pill);
  border: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s;
}

.brand:hover { background: var(--surface-soft); }

.brand-icon {
  display: block;
}

.brand-text {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  font-family: inherit;
}

.search-group {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-wrap {
  width: 480px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 42px;
  padding: 0 18px 0 42px;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  outline: none;
  background: var(--surface-soft);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.search-input::placeholder { color: var(--text-placeholder); }
.search-input:hover { background: var(--surface-hover); }
.search-input:focus {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: 0 2px 10px rgba(17, 17, 17, 0.05);
}

/* ─── Dropdown ─── */

.note-list {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  list-style: none;
  padding: 6px;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 20;
}

.note-list[hidden] { display: none; }

.note-list li {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin: 2px 0;
  transition: background 0.1s;
}

.note-list li:hover { background: var(--surface-soft); }
.note-list li.active { background: var(--accent-soft); }

.note-list .empty-hint {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  cursor: default;
  font-size: 13px;
}

.note-title {
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* ─── New-note icon button ─── */

.btn-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-icon:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.btn-icon:active {
  background: var(--surface-hover);
}

/* ─── Editor area ─── */

.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
  gap: 10px;
}

.empty.hidden { display: none; }

.empty-title {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
}

.empty-sub {
  color: var(--text-dim);
  font-size: 14px;
}

.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 32px 20px;
  gap: 8px;
  overflow: hidden;
}

.editor-pane.hidden { display: none; }

/* ─── Toolbar (minimal, borderless) ─── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 4px;
  background: transparent;
  flex-wrap: wrap;
  align-self: flex-start;
  opacity: 0.55;
  transition: opacity 0.15s;
}

.editor-pane:focus-within .toolbar,
.toolbar:hover { opacity: 1; }

.tb-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  transition: background 0.1s, color 0.1s;
}

.tb-btn .u { text-decoration: underline; }
.tb-btn:hover { background: var(--surface-soft); color: var(--text); }
.tb-btn:active { background: var(--border); }
.tb-btn.active { background: var(--accent-soft); color: var(--accent); }

.tb-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.tb-spacer { flex: 1; min-width: 8px; }

.menu-wrap {
  position: relative;
}

.menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  list-style: none;
  padding: 6px;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 30;
}

.menu-list[hidden] { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
  transition: background 0.1s;
}

.menu-item:hover { background: var(--surface-soft); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover { background: #FEF2F2; }
.menu-item svg { flex-shrink: 0; }

/* ─── Content editor (borderless, paper-like) ─── */

.content-input {
  flex: 1;
  min-height: 0;
  padding: 8px 4px 16px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  line-height: 1.75;
  overflow-y: auto;
  word-break: break-word;
  color: var(--text);
}

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

.content-input h1 {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 24px 0 10px;
}
.content-input h2 {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.35;
  margin: 20px 0 8px;
}
.content-input h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 16px 0 6px;
}

.content-input h1:first-child,
.content-input h2:first-child,
.content-input h3:first-child,
.content-input p:first-child,
.content-input div:first-child { margin-top: 0; }

.content-input p,
.content-input div { margin: 8px 0; }

.content-input blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 14px;
  color: var(--text-dim);
  margin: 12px 0;
  font-style: italic;
}

.content-input ul,
.content-input ol {
  padding-left: 28px;
  margin: 10px 0;
}

.content-input li { margin: 4px 0; }

.content-input pre {
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  overflow-x: auto;
  margin: 12px 0;
  color: var(--text);
}

.content-input a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.content-input ::selection { background: var(--accent-soft); }

/* ─── Footer ─── */

.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 0;
}

.status {
  font-size: 12.5px;
  color: var(--text-dim);
}

.menu-wrap.hidden { display: none; }

/* ─── Small screens ─── */

@media (max-width: 640px) {
  .topbar {
    grid-template-columns: auto 1fr;
    padding: 12px 14px;
    gap: 10px;
  }
  .brand-text { display: none; }
  .search-group { grid-column: 2; }
  .search-wrap { width: auto; flex: 1; min-width: 0; }
  .editor-pane { padding: 8px 20px 16px; }
  .content-input { font-size: 15px; }
  .content-input h1 { font-size: 24px; }
  .content-input h2 { font-size: 19px; }
}
