:root {
  --bg: #f5f3ec;
  --bg-grad: radial-gradient(900px 540px at 90% -12%, rgba(44,110,98,.10), transparent 58%), radial-gradient(720px 480px at -5% 105%, rgba(190,132,72,.09), transparent 62%);
  --panel: #fffefb;
  --panel-2: #faf8f2;
  --sidebar: rgba(238,235,225,.92);
  --border: #dedbd0;
  --border-strong: #c9c4b7;
  --text: #282a27;
  --text-soft: #75776f;
  --text-faint: #a3a397;
  --accent: #2c6e62;
  --accent-hover: #235c52;
  --accent-soft: #e1eeea;
  --accent-border: #b9d6ce;
  --danger: #b94a4c;
  --danger-hover: #9f3b3d;
  --danger-soft: #f8e8e7;
  --success: #2c8066;
  --warn: #b7792a;
  --hover: #e8e5dc;
  --shadow-soft: 0 1px 2px rgba(31,35,30,.04), 0 10px 34px rgba(31,35,30,.06);
  --shadow-pop: 0 24px 70px rgba(24,28,24,.19);
  --radius: 14px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #111513;
  --bg-grad: radial-gradient(900px 540px at 90% -12%, rgba(62,145,128,.12), transparent 58%), radial-gradient(720px 480px at -5% 105%, rgba(190,132,72,.06), transparent 62%);
  --panel: #1b201e;
  --panel-2: #202623;
  --sidebar: rgba(20,25,23,.94);
  --border: #303834;
  --border-strong: #46504b;
  --text: #edf0eb;
  --text-soft: #a0a7a1;
  --text-faint: #6e7770;
  --accent: #63b6a5;
  --accent-hover: #7bc4b5;
  --accent-soft: rgba(99,182,165,.13);
  --accent-border: rgba(99,182,165,.34);
  --danger: #ef8788;
  --danger-hover: #f39b9c;
  --danger-soft: rgba(239,135,136,.11);
  --success: #75c7a8;
  --warn: #e8b768;
  --hover: #282f2c;
  --shadow-soft: 0 1px 2px rgba(0,0,0,.3), 0 12px 34px rgba(0,0,0,.27);
  --shadow-pop: 0 24px 70px rgba(0,0,0,.5);
  color-scheme: dark;
}

html, body { min-width: 300px; }
body { letter-spacing: .005em; }
button, input, textarea { font-family: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); outline-offset: 2px; }

.app { position: relative; }
.sidebar { width: 350px; min-width: 280px; box-shadow: 8px 0 35px rgba(31,35,30,.025); }
.sidebar::before { content: "PRIVATE NOTEBOOK"; display: block; padding: 22px 20px 2px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .24em; }
.sidebar-header { padding: 8px 18px 15px; }
.sidebar-header h1 { font-family: Georgia, "STSong", "SimSun", serif; font-size: 22px; letter-spacing: .08em; }
.sidebar-header h1 .logo { position: relative; width: 38px; height: 38px; border-radius: 12px; overflow: hidden; background: linear-gradient(145deg, #438577, #245e54); color: transparent; box-shadow: 0 8px 22px rgba(44,110,98,.25); }
.sidebar-header h1 .logo::before { content: "墨"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-family: "STSong", "SimSun", serif; font-size: 18px; }
.new-btn { min-height: 39px; padding: 9px 15px; border-radius: 11px; background: linear-gradient(145deg, #438577, #245e54); box-shadow: 0 8px 20px rgba(44,110,98,.2); }
.new-btn:hover { box-shadow: 0 10px 24px rgba(44,110,98,.25); }
.search-box { padding: 0 18px 13px; }
.search-box svg { left: 31px; }
.search-box input { height: 42px; padding-left: 37px; border-radius: 12px; background: color-mix(in srgb, var(--panel) 80%, transparent); }
.search-box .clear-search { right: 27px; transform: translateY(calc(-50% - 6px)); }
.tag-bar { padding: 0 18px 12px; gap: 7px; }
.tag-chip { padding: 5px 11px; border-radius: 8px; font-size: 11px; }
.tag-chip.active { box-shadow: 0 5px 14px rgba(44,110,98,.15); }
.note-list { padding: 2px 12px 16px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.note-item { margin-bottom: 7px; padding: 13px 14px 12px 17px; border-radius: 12px; }
.note-item::before { content: ""; position: absolute; top: 15px; bottom: 15px; left: 5px; width: 2px; border-radius: 3px; background: transparent; }
.note-item.active::before { background: var(--accent); }
.note-item.active { background: var(--accent-soft); border-color: var(--accent-border); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }
.note-item-title { font-size: 14px; }
.note-item-snippet { margin-top: 5px; line-height: 1.55; }
.note-item-meta { margin-top: 8px; }
.sidebar-footer { padding: 12px 16px; background: color-mix(in srgb, var(--sidebar) 88%, var(--panel)); }
.sidebar-footer .icon-btn { width: 34px; height: 34px; justify-content: center; padding: 0; border-radius: 10px; }
.sidebar-footer .icon-btn { font-size: 0; }
.sidebar-footer .icon-btn svg { width: 14px; height: 14px; }

.editor { position: relative; background: var(--panel); }
.editor::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .26; background-image: linear-gradient(to right, transparent 0, transparent calc(100% - 1px), var(--border) calc(100% - 1px)); background-size: 88px 100%; mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent); }
.editor-toolbar { position: relative; z-index: 2; min-height: 66px; padding: 11px clamp(18px, 3vw, 36px); background: color-mix(in srgb, var(--panel-2) 86%, transparent); backdrop-filter: blur(16px); }
.save-status { font-size: 11px; }
.save-status::before { content: "墨记"; margin-right: 12px; color: var(--text); font-family: Georgia, "STSong", serif; font-size: 14px; font-weight: 700; letter-spacing: .1em; }
.tool-btn { min-height: 38px; padding: 7px 11px; border-radius: 10px; font-size: 12px; }
.tool-btn svg { width: 14px; height: 14px; }
.editor-body { position: relative; z-index: 1; width: min(920px, 100%); margin: 0 auto; padding: 38px clamp(26px, 6vw, 80px) 14px; }
#titleInput { font-family: Georgia, "STSong", "SimSun", serif; font-size: clamp(28px, 3vw, 38px); font-weight: 700; line-height: 1.3; letter-spacing: -.02em; padding: 0 0 17px; }
.md-toolbar { gap: 6px; padding: 0 0 14px; border-bottom: 1px solid var(--border); }
.md-toolbar button { min-width: 30px; height: 29px; padding: 3px 8px; border-radius: 8px; background: var(--panel-2); }
.content-wrap { padding-top: 17px; }
#contentInput, #previewPane { font-family: Georgia, "Noto Serif SC", "STSong", "SimSun", serif; font-size: var(--editor-font-size, 17px); line-height: 2; letter-spacing: .02em; }
#contentInput { caret-color: var(--accent); }
#previewPane { max-width: 760px; }
.editor-footer { margin-top: 3px; padding: 11px 0 3px; border-top: 1px solid var(--border); }
.editor-footer .stat { font-size: 10px; }
.attach-panel { border-top: 1px solid var(--border); }
.editor-empty { position: relative; z-index: 1; }
.editor-empty .big { position: relative; width: 86px; height: 86px; overflow: hidden; border: 1px solid var(--accent-border); border-radius: 26px; background: var(--accent-soft); color: transparent; animation: none; }
.editor-empty .big::after { content: "墨"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--accent); font-family: "STSong", serif; font-size: 42px; }
.editor-empty p { font-family: Georgia, "STSong", serif; font-size: 16px; }

.enhance-tools { display: flex; align-items: center; gap: 5px; padding-left: 5px; border-left: 1px solid var(--border); }
.enhance-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); color: var(--text-soft); cursor: pointer; transition: .16s ease; }
.enhance-btn:hover { color: var(--accent); border-color: var(--accent-border); background: var(--accent-soft); }
.enhance-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.enhance-btn.focus-on { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-border); }
.editor-progress { position: absolute; z-index: 5; right: 0; bottom: 0; left: 0; height: 2px; overflow: hidden; background: transparent; }
.editor-progress span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--accent), #b48753); transition: width .2s ease; }
.shortcut-hint { display: flex; align-items: center; gap: 7px; margin-right: auto; color: var(--text-faint); font-size: 10px; white-space: nowrap; }
.shortcut-hint kbd { padding: 2px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--panel-2); color: var(--text-soft); font: inherit; }

body.focus-mode .sidebar { display: none; }
body.focus-mode .editor-body { width: min(880px, 100%); }
body.focus-mode .save-status::before { content: "专注书写"; color: var(--accent); }
body.focus-mode .tool-btn:not(#previewBtn) { display: none; }
body.focus-mode .editor-toolbar { padding-inline: max(24px, calc((100vw - 940px) / 2)); }

.modal-mask { background: rgba(16,20,17,.48); backdrop-filter: blur(8px); }
.modal { border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-pop); }
.toast { bottom: 26px; border-radius: 12px; backdrop-filter: blur(14px); }

#dbStatusBadge { right: 18px !important; bottom: 18px !important; padding: 7px 10px !important; border-radius: 9px !important; opacity: .8; }

@media (max-width: 900px) {
  .sidebar { width: 310px; }
  .editor-toolbar { gap: 5px; padding-inline: 12px; }
  .tool-btn { padding-inline: 9px; }
  .shortcut-hint { display: none; }
}

@media (max-width: 720px) {
  .sidebar { width: 100%; min-width: 0; }
  .sidebar::before { padding: 18px 18px 2px; }
  .sidebar-header { padding-inline: 16px; }
  .note-list { padding-inline: 10px; }
  .editor-toolbar { min-height: 60px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .editor-toolbar::-webkit-scrollbar { display: none; }
  .back-btn { flex: 0 0 auto; min-width: 48px; }
  .save-status { flex: 0 0 auto; min-width: 75px; }
  .save-status::before { display: none; }
  .tool-btn { flex: 0 0 auto; min-width: 38px; padding-inline: 9px; }
  .tool-btn > span:not(#previewBtnText):not(#pinBtnText) { display: none; }
  .enhance-tools { flex: 0 0 auto; }
  .editor-body { padding: 27px 20px 10px; }
  #titleInput { font-size: 27px; }
  #contentInput, #previewPane { font-size: var(--editor-font-size, 16px); line-height: 1.9; }
  .md-toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .editor-footer { overflow-x: auto; white-space: nowrap; }
  body.focus-mode .editor-toolbar { padding-inline: 12px; }
  #dbStatusBadge { right: 10px !important; bottom: 10px !important; }
}

@media (max-width: 420px) {
  .sidebar-footer #noteCount { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .editor-toolbar .danger { margin-left: auto; }
  .editor-body { padding-inline: 17px; }
  .modal-actions { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
