:root {
  color-scheme: light;
  --background: #f7f7f5;
  --surface: #ffffff;
  --surface-raised: #fbfbfa;
  --foreground: #252523;
  --secondary: #6f6f69;
  --tertiary: #9b9b94;
  --border: #e4e4df;
  --hover: #eeeeea;
  --selected: #e4e8f0;
  --accent: #315ea8;
  --accent-soft: #e7edf8;
  --ring: #315ea8;
  --topbar: 52px;
  --notebooks: 210px;
  --notes: 330px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --background: #181817;
  --surface: #20201f;
  --surface-raised: #252523;
  --foreground: #efefeb;
  --secondary: #b0b0a9;
  --tertiary: #85857f;
  --border: #353532;
  --hover: #2c2c29;
  --selected: #303946;
  --accent: #91afe0;
  --accent-soft: #29364b;
  --ring: #91afe0;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--background);
  color: var(--foreground);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
}
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
[hidden] { display: none !important; }
.skip-link { position: fixed; top: 6px; left: 8px; z-index: 100; padding: 8px 12px; border-radius: 7px; background: var(--surface); transform: translateY(-150%); }
.skip-link:focus { transform: translateY(0); }
.mobile-only { display: none !important; }

.topbar {
  position: relative; z-index: 40;
  height: var(--topbar); padding: 0 12px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); background: var(--surface-raised);
}
.topbar-start, .topbar-actions, .brand, .sync-label { display: flex; align-items: center; }
.topbar-start, .topbar-actions { gap: 8px; }
.brand { min-height: 40px; gap: 9px; text-decoration: none; font-weight: 650; }
.brand-mark { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 7px; color: #fff; background: #252523; font-size: 12px; font-weight: 750; }
[data-theme="dark"] .brand-mark { color: #252523; background: #efefeb; }
.sync-label { gap: 7px; color: var(--secondary); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #2e9f58; }
.icon-button { width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 8px; color: var(--secondary); background: transparent; cursor: pointer; transition: background-color 160ms ease, color 160ms ease; }
.icon-button:hover { color: var(--foreground); background: var(--hover); }
.moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

.notebook-layout { height: calc(100dvh - var(--topbar)); display: grid; grid-template-columns: var(--notebooks) var(--notes) minmax(0, 1fr); }
.notebooks-pane, .notes-pane, .reader { min-width: 0; min-height: 0; }
.notebooks-pane { padding: 12px 9px; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--background); }
.pane-heading { min-height: 36px; padding: 4px 9px 8px; display: flex; align-items: center; justify-content: space-between; color: var(--secondary); font-size: 12px; font-weight: 700; letter-spacing: .04em; }
.notebook-nav { display: grid; gap: 2px; overflow-y: auto; }
.notebook-link { width: 100%; min-height: 40px; padding: 8px 9px; display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; align-items: center; gap: 8px; border: 0; border-radius: 7px; color: var(--secondary); background: transparent; text-align: left; cursor: pointer; transition: background-color 150ms ease, color 150ms ease; }
.notebook-link:hover { color: var(--foreground); background: var(--hover); }
.notebook-link.active { color: var(--foreground); background: var(--selected); font-weight: 650; }
.notebook-link svg { width: 18px; height: 18px; }
.notebook-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notebook-link small { color: var(--tertiary); font-size: 11px; font-variant-numeric: tabular-nums; }
.notebooks-footer { margin-top: auto; padding: 14px 9px 4px; border-top: 1px solid var(--border); color: var(--tertiary); font-size: 11px; }
.notebooks-footer p { margin: 0 0 3px; }
.notebooks-footer a { color: var(--secondary); text-decoration: none; }
.notebooks-footer a:hover { color: var(--accent); }

.notes-pane { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface-raised); }
.notes-toolbar { flex: 0 0 auto; padding: 12px; border-bottom: 1px solid var(--border); }
.compact-search { height: 36px; padding: 0 10px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.compact-search:focus-within { border-color: var(--ring); box-shadow: 0 0 0 2px color-mix(in srgb, var(--ring) 14%, transparent); }
.compact-search svg { flex: 0 0 auto; width: 17px; height: 17px; color: var(--tertiary); }
.compact-search input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--foreground); background: transparent; font-size: 13px; }
.compact-search input::placeholder { color: var(--tertiary); }
kbd { padding: 1px 5px; border: 1px solid var(--border); border-radius: 4px; color: var(--tertiary); background: var(--background); font-size: 9px; white-space: nowrap; }
.list-heading { min-height: 36px; padding: 12px 2px 0; display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.list-heading h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; line-height: 1.3; letter-spacing: -.02em; }
.list-heading span { flex: 0 0 auto; color: var(--tertiary); font-size: 11px; }
.notes-list { min-height: 0; overflow-y: auto; }
.note-row { width: 100%; min-height: 104px; padding: 13px 14px; display: block; border: 0; border-bottom: 1px solid var(--border); color: inherit; background: transparent; text-align: left; text-decoration: none; cursor: pointer; transition: background-color 150ms ease; }
.note-row:hover { background: var(--hover); }
.note-row.active { background: var(--selected); }
.note-row-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--tertiary); font-size: 10px; }
.note-row-meta span:first-child { color: var(--accent); font-weight: 650; }
.note-row h2 { margin: 7px 0 4px; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 14px; line-height: 1.4; letter-spacing: -.01em; }
.note-row p { margin: 0; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; color: var(--secondary); font-size: 12px; line-height: 1.45; }
.empty-state { margin: auto; padding: 24px; display: grid; justify-items: center; gap: 8px; color: var(--secondary); text-align: center; }
.empty-state svg { color: var(--tertiary); }
.empty-state button { min-height: 38px; border: 0; color: var(--accent); background: transparent; cursor: pointer; }

.reader { overflow-y: auto; background: var(--surface); }
.reader-empty { height: 100%; display: grid; align-content: center; justify-items: center; gap: 10px; color: var(--tertiary); }
.reader-empty svg { width: 30px; height: 30px; }
.reader-empty p { margin: 0; font-size: 12px; }
#article-view { width: min(100% - 64px, 760px); margin: 0 auto; padding: 44px 0 96px; }
.article-header { padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.article-header h1 { margin: 10px 0 12px; font-size: clamp(25px, 3vw, 36px); line-height: 1.25; letter-spacing: -.035em; }
.article-meta, .category-tag { color: var(--tertiary); font-size: 11px; }
.category-tag { color: var(--accent); font-weight: 700; }
.article-body { padding-top: 24px; color: var(--foreground); font-size: 16px; line-height: 1.8; }
.article-body .lead { margin-top: 0; color: var(--secondary); font-size: 17px; }
.article-body h2 { margin: 36px 0 10px; font-size: 20px; line-height: 1.4; letter-spacing: -.02em; }
.article-body p, .article-body ul { max-width: 68ch; }
.article-body li { margin: 5px 0; }
.callout { margin: 24px 0; padding: 14px 16px; border-left: 3px solid var(--accent); border-radius: 0 7px 7px 0; background: var(--accent-soft); }
.callout p { margin: 3px 0 0; }
.back-link { min-height: 40px; align-items: center; gap: 5px; margin-bottom: 16px; color: var(--secondary); text-decoration: none; }
.back-link svg { width: 18px; height: 18px; }
.notebooks-scrim { display: none; }

@media (max-width: 980px) {
  :root { --notebooks: 190px; --notes: 300px; }
  #article-view { width: min(100% - 40px, 700px); padding-top: 32px; }
}

@media (max-width: 760px) {
  .mobile-only { display: flex !important; }
  body { overflow: hidden; }
  .sync-label { display: none; }
  .notebook-layout { display: block; }
  .notebooks-pane { position: fixed; z-index: 60; inset: var(--topbar) auto 0 0; width: min(82vw, 280px); transform: translateX(-102%); box-shadow: 14px 0 34px rgba(0, 0, 0, .16); transition: transform 200ms ease; }
  .notebooks-open .notebooks-pane { transform: translateX(0); }
  .notebooks-scrim { position: fixed; z-index: 50; inset: var(--topbar) 0 0; background: rgba(0, 0, 0, .35); }
  .notebooks-open .notebooks-scrim { display: block; }
  .notes-pane, .reader { position: absolute; inset: var(--topbar) 0 0; border-right: 0; }
  .notes-pane { display: flex; }
  .reader { display: none; }
  .note-open .notes-pane { display: none; }
  .note-open .reader { display: block; }
  .note-row { min-height: 98px; padding-inline: 16px; }
  #article-view { width: min(100% - 32px, 680px); padding: 16px 0 64px; }
  .back-link { display: inline-flex; }
  .article-header h1 { font-size: 26px; }
  .article-body { font-size: 16px; }
}

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