:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e2230;
  --border: #2a2f3f;
  --text: #e6e8ef;
  --muted: #8b90a3;
  --accent: #4f8cff;
  --accent-hover: #3d76e8;
  --danger: #e5534b;
  --danger-hover: #cc4038;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Views ---------- */
.view { min-height: 100vh; }

/* ---------- Login ---------- */
.login-card {
  max-width: 380px;
  margin: 18vh auto 0;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card form { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.error-text { color: var(--danger); margin-top: 12px; min-height: 1.2em; }

/* ---------- Inputs / buttons ---------- */
input[type="password"],
input[type="search"],
.title-input,
.content-input,
.modal-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--accent); }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { background: #262c3d; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(229,83,75,.12); border-color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-block { width: 100%; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 17px; margin: 0; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: calc(100vh - 60px);
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 220px; }
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.search { flex-shrink: 0; }
.note-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.note-list li { cursor: pointer; }
.note-item {
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  transition: background .12s;
  word-break: break-word;
}
.note-item:hover { background: var(--panel-2); }
.note-item.active { background: var(--panel-2); border-color: var(--accent); }
.note-item .note-title { font-size: 14px; font-weight: 600; }
.note-item .note-date { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.note-count { font-size: 12px; text-align: center; }

/* ---------- Editor ---------- */
.editor-area { display: flex; flex-direction: column; padding: 18px 24px; overflow: hidden; }
.empty-state { margin: auto; text-align: center; }

.editor-header { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.title-input { max-width: 460px; font-size: 17px; font-weight: 600; }
.editor-meta { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.editor-body { display: flex; flex: 1; gap: 16px; min-height: 0; }
.content-input {
  flex: 1;
  min-width: 0;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  height: 100%;
  background: var(--panel);
}
.preview {
  flex: 1;
  min-width: 0;
  max-height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
}
/* markdown-it output */
.preview h1, .preview h2, .preview h3 { margin-top: 0; }
.preview h1 { border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.preview pre {
  background: #0b0d12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}
.preview code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.preview :not(pre) > code { background: rgba(79,140,255,.12); padding: 2px 5px; border-radius: 4px; color: #9fbfff; }
.preview blockquote { border-left: 3px solid var(--accent); margin-left: 0; padding-left: 14px; color: var(--muted); }
.preview a { color: var(--accent); }
.preview img { max-width: 100%; border-radius: 6px; }
.preview table { border-collapse: collapse; }
.preview th, .preview td { border: 1px solid var(--border); padding: 6px 10px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-input { margin-top: 8px; }