:root {
  color-scheme: light;
  --background: #f4f0d8;
  --sidebar: #f7f2d5;
  --paper: #fffbea;
  --text: #1d1d1f;
  --muted: #686861;
  --faint: #929187;
  --line: #e5dfbd;
  --line-strong: #d6cea6;
  --hover: rgb(29 29 31 / 4%);
  --selected: rgb(29 29 31 / 7%);
  --danger: #b42318;
  --status: #0a84ff;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

[data-theme='dark'] {
  color-scheme: dark;
  --background: #151514;
  --sidebar: #1d1c19;
  --paper: #22211d;
  --text: #f5f5f7;
  --muted: #aaa9a1;
  --faint: #7e7c74;
  --line: #34322b;
  --line-strong: #454139;
  --hover: rgb(255 255 255 / 5%);
  --selected: rgb(255 255 255 / 8%);
  --danger: #ff6961;
}

* { box-sizing: border-box; }

html,
body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--background);
  color: var(--text);
  font-size: 12px;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button,
select { cursor: pointer; }

button { border: 0; }

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--status);
  outline-offset: 2px;
}

.app-root {
  display: grid;
  height: 100dvh;
  grid-template-rows: 46px minmax(0, 1fr);
}

.app-root.is-fullscreen { grid-template-rows: 0 minmax(0, 1fr); }
.app-root.is-fullscreen .app-header { visibility: hidden; }

.app-header {
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.header-leading,
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-brand {
  padding: 4px 6px;
  background: transparent;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.icon-button,
.small-icon-button,
.format-toolbar button {
  display: inline-grid;
  place-items: center;
  padding: 0;
  background: transparent;
}

.icon-button { width: 30px; height: 30px; color: var(--muted); }
.small-icon-button { width: 26px; height: 26px; color: var(--muted); }
.small-icon-button svg { width: 14px; height: 14px; }
.icon-button:hover,
.small-icon-button:hover,
.format-toolbar button:hover { color: var(--text); }

#mobile-menu { display: none; }

.app-shell {
  position: relative;
  display: grid;
  min-height: 0;
  grid-template-columns: 210px minmax(0, 1fr);
}

.app-shell.is-fullscreen { grid-template-columns: 0 minmax(0, 1fr); }
.app-shell.is-fullscreen .sidebar { visibility: hidden; }

.sidebar-scrim { display: none; }

.sidebar {
  z-index: 4;
  display: flex;
  min-width: 0;
  height: 100%;
  flex-direction: column;
  padding: 10px 10px 8px;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.sidebar-header { display: none; }

.primary-button {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-strong);
  background: transparent;
  font-size: 12px;
  font-weight: 500;
}

.primary-button:hover { background: var(--hover); }
.primary-button svg { width: 15px; height: 15px; }
.primary-button kbd { margin-left: auto; }
.primary-button.compact { display: inline-flex; padding-inline: 14px; }

kbd {
  color: var(--faint);
  font-family: inherit;
  font-size: 10px;
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 8px 0 7px;
  border-bottom: 1px solid var(--line);
}

.view-tabs button {
  padding: 6px 0 5px;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.view-tabs button.is-active {
  border-bottom-color: var(--text);
  color: var(--text);
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  color: var(--muted);
}

.search-box svg {
  position: absolute;
  left: 3px;
  width: 13px;
  height: 13px;
}

.search-box input {
  width: 100%;
  min-height: 32px;
  padding: 5px 4px 5px 24px;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 400;
}

.search-box input::placeholder { color: var(--faint); }
.search-box kbd { display: none; }

.section-label-row {
  display: flex;
  min-height: 20px;
  align-items: center;
  justify-content: space-between;
  padding-inline: 3px;
}

.section-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.note-total {
  color: var(--faint);
  font-size: 11px;
  font-weight: 500;
}

.note-list {
  min-height: 100px;
  margin: 3px -4px 7px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.note-card {
  width: 100%;
  padding: 8px 9px;
  background: transparent;
  text-align: left;
}

.note-card:hover { background: var(--hover); }
.note-card.is-selected { background: var(--selected); }

.note-card-header {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.note-card-title {
  overflow: hidden;
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favorite-mark { color: var(--text); font-size: 12px; }

.note-card-preview {
  display: -webkit-box;
  overflow: hidden;
  margin: 4px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.note-card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 500;
}

.note-card-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
}

.collections-section {
  margin-top: auto;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

.folder-list { margin-top: 2px; }

.folder-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 7px;
  padding: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
}

.folder-button:hover,
.folder-button.is-active { background: var(--hover); color: var(--text); }
.folder-button svg { width: 14px; height: 14px; }
.folder-button span:nth-child(2) { flex: 1; }
.folder-count { color: var(--faint); font-size: 11px; }

.local-note {
  margin: 8px 0 0;
  color: var(--faint);
  font-size: 11px;
  font-weight: 500;
  text-align: center;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--status);
}

.workspace {
  position: relative;
  min-width: 0;
  height: 100%;
  grid-column: 2;
  overflow: hidden;
  background: var(--paper);
}

.editor-view {
  display: grid;
  height: 100%;
  grid-template-rows: 40px 40px minmax(0, 1fr) 32px;
}

.editor-topbar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

.document-heading {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 8px;
}

.note-title-input {
  min-width: 60px;
  height: 30px;
  flex: 1;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -.01em;
}

.note-title-input::placeholder { color: var(--faint); }

.document-folder {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.document-actions {
  display: flex;
  align-items: center;
}

.save-status {
  margin-right: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.save-status.is-saving .status-dot { animation: pulse 1s infinite; }

@keyframes pulse { 50% { opacity: .3; } }

.menu-wrap { position: relative; }

.action-menu {
  position: absolute;
  z-index: 20;
  top: 34px;
  right: 0;
  width: 190px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper);
  box-shadow: 0 16px 40px rgb(0 0 0 / 14%);
}

.action-menu button {
  display: block;
  width: 100%;
  padding: 8px;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
}

.action-menu button:hover { background: var(--hover); }
.danger-item { color: var(--danger); }

.format-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.style-select-label select {
  width: 108px;
  height: 28px;
  padding: 0 5px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
}

.format-toolbar button {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.format-toolbar button.is-active {
  color: var(--text);
  box-shadow: inset 0 -1px var(--text);
}

.format-toolbar button svg { width: 15px; height: 15px; }

.toolbar-divider {
  width: 1px;
  height: 17px;
  margin-inline: 3px;
  flex: 0 0 auto;
  background: var(--line);
}

.document {
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 16px 18px 60px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.rich-editor {
  min-height: calc(100% - 10px);
  outline: 0;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.65;
}

.rich-editor:empty::before {
  color: var(--faint);
  content: attr(data-placeholder);
  pointer-events: none;
}

.rich-editor p { margin: 0 0 1.15em; }
.rich-editor h1,
.rich-editor h2,
.rich-editor h3 { font-weight: 700; letter-spacing: -.02em; }
.rich-editor h1 { margin: 1em 0 .45em; font-size: 2em; line-height: 1.15; }
.rich-editor h2 { margin: 1.2em 0 .5em; font-size: 1.5em; line-height: 1.2; }
.rich-editor h3 { margin: 1.2em 0 .5em; font-size: 1.2em; line-height: 1.3; }
.rich-editor ul,
.rich-editor ol { padding-left: 1.5em; }
.rich-editor blockquote {
  margin: 1.5em 0;
  padding-left: 1em;
  border-left: 2px solid var(--text);
  color: var(--muted);
}
.rich-editor a { color: inherit; text-underline-offset: 3px; }

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
}

.folder-picker {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
}

.folder-picker svg { width: 13px; height: 13px; }
.folder-picker select {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.counts {
  display: flex;
  gap: 14px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 500;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 24px;
  background: var(--paper);
  text-align: center;
}

.empty-illustration {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  margin-bottom: 16px;
  color: var(--muted);
}

.empty-illustration svg { width: 42px; height: 42px; }
.empty-state h2 { margin: 0 0 6px; font-size: 20px; font-weight: 600; }
.empty-state p {
  max-width: 320px;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 6px;
  pointer-events: none;
}

.toast {
  padding: 9px 12px;
  border-radius: 3px;
  background: var(--text);
  color: var(--paper);
  font-size: 12px;
  animation: toast-in .18s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
}

@media (max-width: 540px) {
  #mobile-menu { display: inline-grid; }

  .app-shell,
  .app-shell.is-fullscreen { display: block; }

  .workspace,
  .app-shell.is-fullscreen .workspace { grid-column: auto; }

  .sidebar {
    position: fixed;
    z-index: 40;
    inset: 46px auto 0 0;
    width: min(280px, calc(100vw - 24px));
    height: auto;
    padding: 12px;
    box-shadow: 16px 0 40px rgb(0 0 0 / 14%);
    transform: translateX(-105%);
    transition: transform .2s ease;
  }

  .app-shell.is-sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-scrim {
    position: fixed;
    z-index: 35;
    inset: 46px 0 0;
    display: block;
    background: rgb(0 0 0 / 16%);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  .app-shell.is-sidebar-open .sidebar-scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-close { display: inline-grid; }
  .document-folder,
  .save-status { display: none; }
  .document { padding-inline: 14px; }
  .counts span:first-child { display: none; }
}

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