:root {
  --paper: #f6f0e4;
  --paper-deep: #eee3d2;
  --surface: #fffaf1;
  --ink: #29251f;
  --muted: #80776b;
  --line: #ded3c3;
  --terra: #a9583f;
  --terra-dark: #7d3e2e;
  --sage: #71856d;
  --danger: #a33d35;
  --shadow: 0 18px 55px rgba(68, 52, 34, .12);
  --field-bg: rgba(255,255,255,.5);
  --sidebar-bg: #e9ddcc;
  --pane-bg: rgba(255,250,241,.62);
  --active-bg: rgba(255,250,241,.7);
  --tab-bg: rgba(255,250,241,.97);
  --focus-ring: rgba(169,88,63,.1);
  --accent-shadow: rgba(169,88,63,.24);
  --soft-shadow: rgba(50,40,30,.1);
  --item-line: rgba(222,211,195,.75);
}
html[data-theme="clean"] {
  --paper: #f5f7fb;
  --paper-deep: #e8edf7;
  --surface: #ffffff;
  --ink: #202532;
  --muted: #6e7687;
  --line: #dce2ec;
  --terra: #596fc6;
  --terra-dark: #40549e;
  --sage: #57816b;
  --shadow: 0 18px 55px rgba(39, 54, 90, .10);
  --field-bg: rgba(255,255,255,.72);
  --sidebar-bg: #e8edf7;
  --pane-bg: rgba(255,255,255,.68);
  --active-bg: rgba(255,255,255,.86);
  --tab-bg: rgba(245,247,251,.97);
  --focus-ring: rgba(89,111,198,.13);
  --accent-shadow: rgba(89,111,198,.24);
  --soft-shadow: rgba(39,54,90,.11);
  --item-line: rgba(220,226,236,.85);
}
html[data-theme="studio"] {
  color-scheme: dark;
  --paper: #171a20;
  --paper-deep: #20252d;
  --surface: #1c2027;
  --ink: #edf0f4;
  --muted: #9da6b2;
  --line: #323944;
  --terra: #5eb6aa;
  --terra-dark: #85d0c6;
  --sage: #7ea88d;
  --danger: #e27d75;
  --shadow: 0 18px 55px rgba(0, 0, 0, .28);
  --field-bg: rgba(255,255,255,.035);
  --sidebar-bg: #20252d;
  --pane-bg: rgba(28,32,39,.76);
  --active-bg: rgba(255,255,255,.07);
  --tab-bg: rgba(23,26,32,.97);
  --focus-ring: rgba(94,182,170,.16);
  --accent-shadow: rgba(94,182,170,.25);
  --soft-shadow: rgba(0,0,0,.24);
  --item-line: rgba(50,57,68,.9);
}
html[data-theme="studio"] input,
html[data-theme="studio"] textarea,
html[data-theme="studio"] select {
  background: rgba(255,255,255,.035);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }
body { font-family: "Noto Serif SC", "Songti SC", "Microsoft YaHei", serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 5px; color: var(--terra); font: 700 11px/1.2 system-ui; letter-spacing: .17em; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; }
.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; }
.login-mark { position: absolute; top: 28px; left: 32px; font-weight: 800; letter-spacing: .18em; }
.login-card { width: min(520px, 100%); padding: 44px 48px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.login-card h1 { font-size: 34px; line-height: 1.35; margin: 10px 0; }
.login-intro { margin: 0 0 24px; color: var(--muted); font: 14px/1.75 system-ui; }
.login-card form { display: grid; gap: 14px; }
.privacy-note { margin-top: 22px; padding: 15px 16px; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--paper) 58%, var(--surface)); font: 12px/1.65 system-ui; }
.privacy-note strong { color: var(--terra-dark); }
.privacy-note p { margin: 5px 0 0; color: var(--muted); }
label { display: grid; gap: 7px; color: var(--muted); font: 600 13px/1.3 system-ui; }
input, textarea, select { color: var(--ink); background: var(--field-bg); border: 1px solid var(--line); border-radius: 8px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--terra); box-shadow: 0 0 0 3px var(--focus-ring); }
label input { padding: 12px 13px; }
.primary, .secondary { border-radius: 8px; padding: 11px 18px; font: 700 14px system-ui; }
.primary { border: 1px solid var(--terra); color: white; background: var(--terra); }
.secondary { border: 1px solid var(--line); background: transparent; color: var(--ink); }
.login-card .primary { width: 100%; margin-top: 4px; }
.primary:disabled { cursor: wait; opacity: .7; }
.danger-outline { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 210px 310px minmax(420px, 1fr);
  overflow: hidden;
  transition: grid-template-columns .22s ease;
}
.app.sidebar-collapsed { grid-template-columns: 54px 310px minmax(420px, 1fr); }
.app.notes-collapsed { grid-template-columns: 210px 54px minmax(420px, 1fr); }
.app.sidebar-collapsed.notes-collapsed { grid-template-columns: 54px 54px minmax(420px, 1fr); }
.sidebar { min-width: 0; background: var(--sidebar-bg); border-right: 1px solid var(--line); padding: 28px 18px 22px; display: flex; flex-direction: column; overflow: hidden; }
.brand { display: flex; justify-content: space-between; padding: 0 12px 30px; font-size: 21px; font-weight: 800; letter-spacing: .2em; }
.brand > span, .categories, .side-footer, .pane-header > div:not(.pane-actions), .search-wrap, .note-list, #addNoteTop, #refreshNotes {
  transition: opacity .14s ease;
}
.collapse-button {
  position: relative;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  color: var(--muted);
}
.collapse-button::before {
  content: "‹";
  display: block;
  font: 22px/24px system-ui;
  transform: translateY(-1px);
}
.collapse-button:hover { color: var(--terra-dark); border-color: var(--terra); }
.sidebar-collapsed #toggleSidebar::before,
.notes-collapsed #toggleNotesPane::before { content: "›"; }
.sidebar-collapsed .sidebar { padding-left: 12px; padding-right: 12px; }
.sidebar-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar-collapsed .brand > span,
.sidebar-collapsed .categories,
.sidebar-collapsed .side-footer { display: none; }
.categories { display: grid; gap: 4px; }
.categories button { border: 0; border-radius: 7px; padding: 10px 12px; text-align: left; color: var(--muted); background: transparent; }
.categories button.active { color: var(--terra-dark); background: var(--active-bg); font-weight: 700; }
.side-footer { margin-top: auto; padding: 12px; color: var(--muted); font: 12px system-ui; }
.settings-entry {
  width: 100%;
  margin-bottom: 12px;
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font: 12px system-ui;
}
.settings-entry:hover { color: var(--terra-dark); }
.settings-entry > span:first-child { font-size: 15px; }
.sync-status { white-space: nowrap; }
.dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--sage); }
.notes-pane { min-width: 0; background: var(--pane-bg); border-right: 1px solid var(--line); overflow: hidden; }
.pane-header, .settings-header { min-height: 96px; padding: 25px 24px 14px; display: flex; align-items: center; justify-content: space-between; }
.settings-header-actions { display: flex; align-items: center; gap: 8px; }
.settings-header-actions .secondary { padding: 8px 13px; font-size: 12px; }
.pane-actions { display: flex; align-items: center; gap: 4px; }
.refresh-button { font-size: 19px; }
.refresh-button.refreshing { animation: refresh-spin .75s linear infinite; }
.refresh-button:disabled { cursor: wait; opacity: .55; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
.notes-collapsed .notes-pane .pane-header { padding: 25px 12px 14px; justify-content: center; }
.notes-collapsed .notes-pane .pane-header > div:not(.pane-actions),
.notes-collapsed .notes-pane .search-wrap,
.notes-collapsed .notes-pane .note-list,
.notes-collapsed #addNoteTop,
.notes-collapsed #refreshNotes { display: none; }
.header-save-button { min-width: 68px; padding: 9px 16px; border: 1px solid var(--terra); border-radius: 8px; background: var(--terra); color: white; font: 700 13px system-ui; }
.header-save-button:active { background: var(--terra-dark); }
h2 { margin: 0; font-size: 21px; }
.icon { width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; font-size: 21px; color: var(--ink); }
.icon:hover { background: var(--paper-deep); }
.search-wrap { padding: 0 18px 15px; }
.search-wrap input { width: 100%; padding: 10px 12px; }
.note-list { height: calc(100vh - 151px); overflow: auto; }
.note-item { width: 100%; padding: 16px 22px; border: 0; border-top: 1px solid var(--item-line); background: transparent; color: var(--ink); text-align: left; }
.note-item.active { background: var(--surface); box-shadow: inset 3px 0 var(--terra); }
.note-item h3 { margin: 0 0 7px; font-size: 16px; }
.note-item p { margin: 0 0 8px; height: 38px; overflow: hidden; color: var(--muted); font: 13px/1.5 system-ui; }
.note-meta { display: flex; justify-content: space-between; color: var(--muted); font: 11px system-ui; }
.editor-pane { background: var(--surface); overflow: hidden; }
.editor-header { height: 66px; flex: 0 0 66px; padding: 14px 28px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.note-search { width: min(290px, 42%); height: 34px; display: grid; grid-template-columns: minmax(70px, 1fr) auto 30px 30px; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--field-bg); overflow: hidden; }
.note-search input { min-width: 0; height: 100%; padding: 0 9px; border: 0; border-radius: 0; background: transparent; box-shadow: none; font: 12px system-ui; }
.note-search span { min-width: 38px; color: var(--muted); text-align: center; font: 10px system-ui; }
.note-search button { width: 30px; height: 100%; padding: 0; border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--muted); }
.note-search button:active { color: var(--terra); background: var(--paper-deep); }
.segmented { padding: 3px; background: var(--paper); border-radius: 8px; }
.segmented button { border: 0; border-radius: 6px; padding: 7px 12px; background: transparent; color: var(--muted); font: 12px system-ui; }
.segmented button.active { background: var(--surface); color: var(--terra-dark); box-shadow: 0 1px 4px var(--soft-shadow); }
.text-btn { border: 0; padding: 8px; color: var(--terra); background: transparent; }
.text-btn.danger { color: var(--danger); }
.editor-body { max-width: 780px; height: calc(100vh - 66px); margin: auto; padding: 34px 54px 22px; display: flex; flex-direction: column; }
.meta-row { display: flex; align-items: center; justify-content: space-between; color: var(--sage); font: 12px system-ui; }
.meta-row select { border: 0; background: transparent; color: var(--terra); padding: 5px; }
.save-note-button { border: 1px solid var(--line); border-radius: 8px; padding: 7px 13px; background: transparent; color: var(--muted); font: 700 12px system-ui; }
.save-note-button.dirty { border-color: var(--terra); background: var(--terra); color: white; box-shadow: 0 6px 16px var(--accent-shadow); }
.save-note-button:disabled { cursor: default; opacity: .52; box-shadow: none; }
.save-note-button.saving { cursor: wait; opacity: .8; }
.title-input { width: 100%; padding: 18px 0 13px; border: 0; border-radius: 0; background: transparent; font-size: 32px; font-weight: 700; }
.title-input:focus, #noteContent:focus { box-shadow: none; }
#noteContent { flex: 1; resize: none; width: 100%; padding: 12px 0; border: 0; border-radius: 0; background: transparent; font: 16px/1.95 "Noto Serif SC","Microsoft YaHei",serif; }
.inline-preview { flex: 1; overflow: auto; padding: 12px 0 30px; font: 16px/1.9 "Noto Serif SC","Microsoft YaHei",serif; }
.inline-preview.html-lines { white-space: pre-wrap; overflow-wrap: anywhere; }
.search-preview { flex: 1; min-height: 0; overflow: auto; scroll-padding-block: 32px; margin: 0; padding: 12px 4px 30px 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 16px/1.95 "Noto Serif SC","Microsoft YaHei",serif; }
.search-preview mark { padding: 1px 0; border-radius: 2px; background: color-mix(in srgb, var(--terra) 28%, var(--surface)); color: var(--ink); }
.search-preview mark.current { position: relative; z-index: 1; background: var(--terra); color: white; box-shadow: 0 0 0 3px color-mix(in srgb, var(--terra) 24%, transparent); }
.inline-preview img { max-width: 100%; height: auto; }
.inline-preview h1,.inline-preview h2,.inline-preview h3 { line-height: 1.35; }
.inline-preview blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--terra); color: var(--muted); }
.inline-preview code { padding: 2px 5px; border-radius: 4px; background: var(--paper-deep); }
.format-bar { position: relative; min-height: 48px; display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); color: var(--muted); font: 11px system-ui; }
.format-primary-tools { display: flex; align-items: center; gap: 2px; min-width: 0; }
.format-bar button, .image-button { border: 0; border-radius: 6px; padding: 7px 9px; background: transparent; color: var(--ink); font-weight: 700; }
.format-bar button:hover, .image-button:hover { color: var(--terra-dark); background: var(--paper-deep); }
.image-button { display: block; cursor: pointer; white-space: nowrap; }
.image-button input { display: none; }
.html-tools-menu { position: relative; margin-left: auto; }
.html-tools-menu summary { list-style: none; min-width: 92px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--field-bg); cursor: pointer; font-weight: 700; text-align: center; user-select: none; }
.html-tools-menu summary::-webkit-details-marker { display: none; }
.html-tools-menu summary::after { content: "⌄"; margin-left: 7px; font-size: 10px; }
.html-tools-menu[open] summary { color: var(--terra-dark); border-color: var(--terra); background: var(--paper-deep); }
.html-tools-menu[open] summary::after { content: "⌃"; }
.html-tools-popover { position: absolute; right: 0; bottom: calc(100% + 9px); z-index: 8; width: 246px; padding: 9px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); }
.html-tools-popover button { padding: 9px 10px; color: var(--muted); background: var(--field-bg); font-size: 11px; font-weight: 650; text-align: left; white-space: nowrap; }
.html-tools-popover button:hover { color: var(--terra-dark); background: var(--paper-deep); }
.html-tools-popover small { grid-column: 1 / -1; padding: 5px 4px 1px; color: var(--muted); line-height: 1.4; }
.settings-pane { background: var(--surface); grid-column: 3; overflow: hidden; }
.settings-scroll { height: calc(100vh - 96px); overflow: auto; padding: 0 8vw 100px; }
.settings-section { padding: 24px 0; border-top: 1px solid var(--line); display: grid; gap: 14px; }
.settings-section h3 { margin: 0; }
.settings-section small { color: var(--muted); font-weight: 400; }
.theme-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.theme-picker button { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--ink); text-align: left; }
.theme-picker button.active { border-color: var(--terra); box-shadow: 0 0 0 2px color-mix(in srgb, var(--terra) 18%, transparent); }
.theme-picker strong { font-size: 13px; }
.theme-picker small { font-size: 11px; }
.theme-preview { display: block; height: 52px; border-radius: 6px; border: 1px solid rgba(90,80,70,.15); position: relative; overflow: hidden; }
.theme-preview::before { content: ""; position: absolute; left: 9px; right: 9px; top: 12px; height: 4px; border-radius: 2px; background: currentColor; box-shadow: 0 10px 0 currentColor, 0 20px 0 currentColor; opacity: .55; }
.theme-clean { background: #fff; color: #596fc6; }
.theme-studio { background: #1c2027; color: #5eb6aa; }
.theme-paper { background: #fffaf1; color: #a9583f; }
.two-col, .button-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.two-col > label { min-width: 0; width: 100%; }
.two-col > label > input,
.two-col > label > .password-field { width: 100%; }
.password-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; }
.password-field input { width: 100%; min-width: 0; border-radius: 8px 0 0 8px; }
.password-field button { min-width: 58px; border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; background: var(--paper); color: var(--terra); font: 600 12px system-ui; }
.sync-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--paper) 62%, var(--surface)); }
.sync-card > div { display: grid; gap: 5px; }
.sync-card small, .settings-hint { color: var(--muted); font: 12px/1.55 system-ui; }
.settings-hint { margin: 0; }
.local-app .side-footer { display: none; }
.local-app #webLoginSettings { display: none; }
.category-row { display: flex; gap: 8px; margin-bottom: 8px; }
.category-row input { padding: 10px; }
.category-row button { border: 0; background: transparent; color: var(--danger); }
.bottom-tabs { display: none; }
.markdown-preview { font: 16px/1.9 "Noto Serif SC","Microsoft YaHei",serif; }
.markdown-preview h1,.markdown-preview h2,.markdown-preview h3 { line-height: 1.35; }
.markdown-preview blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--terra); color: var(--muted); }
.markdown-preview code { padding: 2px 5px; border-radius: 4px; background: var(--paper-deep); }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 8px 0; }
#toast { position: fixed; left: 50%; bottom: 26px; translate: -50% 20px; padding: 10px 18px; border-radius: 8px; background: var(--ink); color: white; opacity: 0; transition: .2s; pointer-events: none; font: 13px system-ui; z-index: 20; }
#toast.show { opacity: 1; translate: -50% 0; }
.icp-footer {
  position: fixed;
  left: 50%;
  bottom: 10px;
  z-index: 12;
  translate: -50% 0;
  padding: 4px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--muted);
  font: 12px/1.3 system-ui;
}
.icp-footer a {
  color: inherit;
  text-decoration: none;
}
.icp-footer a:hover {
  color: var(--terra-dark);
  text-decoration: underline;
}
.mobile-only { display: none; }
.desktop-only { display: inline-grid; place-items: center; }
@media (max-width: 800px) {
  .app { display: block; height: 100dvh; padding-bottom: 65px; }
  .mobile-only { display: inline-grid; place-items: center; }
  .desktop-only { display: none; }
  .sidebar { position: fixed; inset: 0 22% 65px 0; z-index: 10; translate: -105% 0; transition: .22s; box-shadow: var(--shadow); }
  .sidebar.open { translate: 0; }
  .notes-pane { height: 100%; border: 0; }
  .note-list { height: calc(100dvh - 216px); }
  .editor-pane, .settings-pane { position: fixed; inset: 0 0 65px; z-index: 6; }
  .editor-header { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .segmented { display: flex; flex-shrink: 0; }
  .segmented button { padding-left: 5px; padding-right: 5px; font-size: 10px; }
  .note-search { flex: 1; width: auto; min-width: 118px; grid-template-columns: minmax(44px, 1fr) auto 28px 28px; }
  .note-search button { width: 28px; }
  .note-search span { min-width: 31px; font-size: 9px; }
  .editor-actions { display: none; }
  .editor-body { padding: 24px 22px 62px; height: calc(100dvh - 66px); }
  .title-input { font-size: 27px; }
  .settings-scroll { padding: 0 24px 80px; height: calc(100dvh - 96px); }
  .settings-header { padding-right: 20px; }
  .theme-picker { gap: 8px; }
  .theme-picker button { padding: 7px; }
  .bottom-tabs { position: fixed; inset: auto 0 0; height: 65px; z-index: 15; display: grid; grid-template-columns: repeat(3,1fr); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: var(--tab-bg); }
  .bottom-tabs button { border: 0; background: transparent; color: var(--muted); font: 11px system-ui; }
  .bottom-tabs span { display: block; margin-bottom: 3px; font-size: 19px; }
  .bottom-tabs button.active { color: var(--terra); }
  .bottom-tabs .note-tab span { width: 40px; height: 40px; margin: -19px auto 1px; display: grid; place-items: center; border-radius: 50%; background: var(--terra); color: white; box-shadow: 0 5px 15px var(--accent-shadow); font: 700 24px/1 Georgia, serif; transform: rotate(-8deg); }
  .format-bar .paste-hint { display: none; }
  .login-card { padding: 35px 27px; }
}
@media (display-mode: standalone), (max-width: 800px) {
  body { overscroll-behavior: none; }
}
