:root {
  --bg: #faf8f3;
  --surface: #ffffff;
  --sidebar: #f3efe4;
  --text: #2b2a26;
  --muted: #8a8577;
  --border: #e4ddcb;
  --accent: #e0a800;
  --accent-text: #2b2200;
  --active: #ffeeb3;
  --danger: #c0392b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1c19;
    --surface: #23221e;
    --sidebar: #191815;
    --text: #ebe7dc;
    --muted: #9a9484;
    --border: #35332c;
    --accent: #f2b705;
    --accent-text: #241c00;
    --active: #3a3220;
    --danger: #ff7b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  margin: 0;
}
.brand::before { content: "✎ "; color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error { color: var(--danger); margin: 0; }
.spacer { flex: 1; }

.btn {
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 6px 10px; }

.link {
  font: inherit;
  font-size: 0.85rem;
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

input, textarea { font: inherit; color: inherit; }

/* ---------- Login ---------- */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; }
.login-card input {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.login-card .btn { padding: 10px; }

/* ---------- App ---------- */

.app {
  display: flex;
  height: 100%;
}

.sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px 10px;
}
#refresh-btn { font-size: 1.05rem; line-height: 1; }
#refresh-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.search {
  margin: 0 16px 10px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.note-list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  overflow-y: auto;
  flex: 1;
}
.note-item {
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
}
.note-item:hover { background: color-mix(in srgb, var(--active) 50%, transparent); }
.note-item.active { background: var(--active); }
.note-item-head { display: flex; gap: 8px; align-items: baseline; }
.note-item-title {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-item-date { font-size: 0.78rem; color: var(--muted); flex-shrink: 0; }
.note-item-snippet {
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 1.3em;
}
.sidebar-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.sidebar-foot .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.editor {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.editor-empty {
  margin: auto;
  padding: 16px;
}
.editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 32px;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.share-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  font-size: 0.85rem;
  flex-wrap: wrap;
}
.share-bar input {
  flex: 1;
  min-width: 160px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.title {
  border: 0;
  outline: none;
  background: transparent;
  font-size: 1.6rem;
  font-weight: 700;
  padding: 18px 0 6px;
}
.content {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 1rem;
  line-height: 1.65;
  padding: 6px 0 32px;
  tab-size: 4;
}

.mobile-only { display: none; }

@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: 0; }
  .editor { display: none; }
  body.show-editor .sidebar { display: none; }
  body.show-editor .editor { display: flex; }
  .editor-body { padding: 0 16px; }
  .mobile-only { display: inline-block; }
  .toolbar .btn { padding: 6px 9px; }
}
