:root {
  --bg: #f7f4ee;
  --panel: #fffdf9;
  --text: #24211c;
  --muted: #7a7266;
  --line: #e4ddd0;
  --accent: #a0561c;
  --accent-soft: #f3e3d3;
  --danger: #b3261e;
  --sel: #efe6d8;
  --shadow: 0 6px 24px rgba(40, 30, 10, .15);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --panel: #23201c;
    --text: #ece6dc;
    --muted: #9a917f;
    --line: #38332c;
    --accent: #e09a5c;
    --accent-soft: #3a2b1d;
    --danger: #f08b82;
    --sel: #302b24;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* login */
.login { max-width: 320px; margin: 18vh auto 0; padding: 0 16px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 8px; font-weight: 600; }
.login input { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.login button { padding: 12px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }

/* folders sidebar (a slide-out drawer on phones) */
.sidebar { width: 230px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg); overflow-y: auto; padding: 10px 6px calc(10px + env(safe-area-inset-bottom)); }
.folders { list-style: none; margin: 0; padding: 0; }
.folders li { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.folders li:hover { background: var(--sel); }
.folders li.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folders li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.folders li .n { font-size: 13px; color: var(--muted); font-weight: 400; }
.folders li.sep { height: 1px; padding: 0; margin: 6px 10px; background: var(--line); cursor: default; }
.folders li .ico { width: 1.1em; text-align: center; color: var(--muted); flex: none; }
.new-folder { margin: 8px 4px 0; text-align: left; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 29; }

/* layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.list-pane { width: 360px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); position: relative; min-height: 0; }
.editor-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }

.list-head { display: flex; gap: 6px; padding: 10px; align-items: center; }
#search { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.icon-btn { width: 38px; height: 38px; flex: none; border: 0; border-radius: 8px; background: transparent; font-size: 22px; line-height: 1; }
.icon-btn:hover, .text-btn:hover { background: var(--sel); }
.text-btn { border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; color: var(--accent); }
.text-btn.on { background: var(--accent-soft); }
.danger { color: var(--danger); }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 42px; z-index: 10; min-width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 6px; }
.menu button:hover { background: var(--sel); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

.chips { display: flex; gap: 6px; padding: 0 10px 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 11px; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip small { opacity: .7; margin-left: 4px; }

.count { padding: 0 14px 4px; font-size: 13px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.list li { padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:hover { background: var(--sel); }
.list li.active { background: var(--accent-soft); }
.list .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .t.untitled { color: var(--muted); font-weight: 400; font-style: italic; }
.list .s { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.list .m { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list .pin { color: var(--accent); margin-right: 4px; }
.list .more { text-align: center; color: var(--accent); }

.fab { position: absolute; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 16px; border: 0; background: var(--accent); color: #fff; font-size: 30px; box-shadow: var(--shadow); }

/* editor */
.empty { margin: auto; color: var(--muted); padding: 16px; }
.editor { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.editor-head { display: flex; align-items: center; gap: 2px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.spacer { flex: 1; }
.status { font-size: 13px; color: var(--muted); padding-left: 6px; }
.conflict { background: var(--accent-soft); padding: 8px 14px; font-size: 14px; }
.title { border: 0; background: transparent; font-size: 22px; font-weight: 600; padding: 14px 18px 2px; outline: none; }
.meta-row { display: flex; align-items: center; gap: 8px; padding: 2px 18px 10px; border-bottom: 1px solid var(--line); }
.folder-select { flex: none; max-width: 45%; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); font-size: 14px; color: var(--muted); padding: 3px 6px; }
.tags { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 14px; color: var(--muted); padding: 0; outline: none; }
.body { flex: 1; min-height: 0; border: 0; background: transparent; resize: none; padding: 14px 18px 80px; outline: none; line-height: 1.6; }
.preview { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 18px 80px; line-height: 1.6; overflow-wrap: anywhere; }
.preview img { max-width: 100%; }
.preview pre { background: var(--sel); padding: 10px; border-radius: 6px; overflow-x: auto; }
.preview code { background: var(--sel); padding: 1px 4px; border-radius: 4px; font-size: .92em; }
.preview pre code { background: none; padding: 0; }
.preview blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.preview a { color: var(--accent); }
.preview ul, .preview ol { padding-left: 22px; }
.preview li.task { list-style: none; margin-left: -22px; }
.preview li.task input { margin-right: 8px; }
.preview .i1 { margin-left: 1.5em; } .preview .i2 { margin-left: 3em; } .preview .i3 { margin-left: 4.5em; }
.preview li.task.i1 { margin-left: calc(1.5em - 22px); } .preview li.task.i2 { margin-left: calc(3em - 22px); } .preview li.task.i3 { margin-left: calc(4.5em - 22px); }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 20; max-width: calc(100vw - 32px); }

.mobile-only { display: none; }

@media (max-width: 799px) {
  .desktop-only { display: none; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 30; width: min(300px, 82vw); transform: translateX(-100%); transition: transform .2s ease; padding-top: calc(10px + env(safe-area-inset-top)); }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .folders li { padding: 10px 12px; }
  .meta-row { padding: 2px 14px 8px; }
  .mobile-only { display: inline-block; }
  .list-pane { width: 100%; border-right: 0; }
  .editor-pane { display: none; }
  .app.editing .list-pane { display: none; }
  .app.editing .editor-pane { display: flex; }
  .title { padding: 10px 14px 2px; }
  .body { padding: 12px 14px 80px; font-size: 17px; }
  .preview { padding: 4px 14px 80px; }
}
