:root {
  --bg: #16161f;
  --bg-secondary: #101018;
  --bg-tertiary: #0c0c12;
  --surface: #1e1e2a;
  --surface-hover: #262636;
  --surface-raised: #2a2a3c;
  --border: #2e2e42;
  --border-subtle: #242436;
  --fg: #ececf1;
  --fg-muted: #9494a8;
  --fg-dim: #5c5c72;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.14);
  --topic-accent: var(--accent);
  --danger: #f87171;
  --success: #34d399;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 6px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --tab-height: 38px;
  --content-max: 720px;
  --header-height: 56px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

body.light-theme {
  --bg: #f4f5f7;
  --bg-secondary: #ebedf0;
  --bg-tertiary: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f8f9fb;
  --surface-raised: #ffffff;
  --border: #dde1e8;
  --border-subtle: #e8ebf0;
  --fg: #12141a;
  --fg-muted: #5f6577;
  --fg-dim: #9aa0ad;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.1);
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 8px 32px rgba(15, 23, 42, 0.1);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
}

/* ===== Tab bar ===== */
.tabs-wrap {
  position: relative;
  z-index: 100;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.tabs-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding-right: 8px;
}

.tabs-wrap::before,
.tabs-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20px;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.tabs-wrap::before {
  left: 0;
  background: linear-gradient(to right, var(--bg-secondary), transparent);
}

.tabs-wrap::after {
  right: 0;
  background: linear-gradient(to left, var(--bg-secondary), transparent);
}

.chrome-tabs {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  flex: 1;
  min-width: 0;
  padding: 6px 4px 0 12px;
  min-height: calc(var(--tab-height) + 6px);
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.chrome-tabs::-webkit-scrollbar { display: none; }

.chrome-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: var(--tab-height);
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  position: relative;
  flex-shrink: 0;
  scroll-snap-align: start;
}

.chrome-tab:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg);
}

body.light-theme .chrome-tab:hover {
  background: rgba(0, 0, 0, 0.04);
}

.chrome-tab.active {
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  border-color: var(--border);
  box-shadow: inset 0 2px 0 var(--topic-accent);
}

.chrome-tab.archived {
  opacity: 0.65;
}

.chrome-tab.archived.active {
  opacity: 1;
}

.chrome-tab .tab-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

body.light-theme .chrome-tab .tab-indicator {
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06);
}

.chrome-tab .tab-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chrome-tab.new-tab,
.chrome-tab.settings-tab {
  min-width: 36px;
  padding: 0 10px;
  justify-content: center;
  opacity: 0.55;
}

.chrome-tab.new-tab:hover,
.chrome-tab.settings-tab:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.06);
}

.chrome-tab.new-tab .tab-name {
  font-size: 18px;
  font-weight: 300;
  line-height: 1;
  max-width: none;
}

.topic-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  align-self: center;
  margin: 0 4px;
  flex-shrink: 0;
}

.topic-sep-label {
  align-self: center;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: 0 4px;
  flex-shrink: 0;
  user-select: none;
}

.topics-archive {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.topics-archive.is-collapsed .topics-archive-tabs {
  display: none;
}

.topics-archive-toggle {
  opacity: 0.8;
  gap: 6px;
}

.topics-archive-toggle:hover {
  opacity: 1;
}

.topics-archive-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-muted);
}

.topics-archive-chevron {
  flex-shrink: 0;
  opacity: 0.7;
  transition: transform 0.2s;
}

.topics-archive.is-collapsed .topics-archive-chevron {
  transform: rotate(-90deg);
}

.topics-archive-tabs {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.tabs-spacer,
.header-spacer {
  flex: 1;
  min-width: 8px;
}

.settings-wrap,
.header-menu {
  position: relative;
  flex-shrink: 0;
  align-self: flex-end;
  z-index: 110;
}

.settings-dropdown {
  right: 0;
  left: auto;
  z-index: 1200;
}

/* ===== Main area ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: var(--bg);
  position: relative;
  z-index: 1;
}

.main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--header-height);
  padding: 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topic-title {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: var(--surface-hover); border-color: var(--fg-dim); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn.danger { border-color: color-mix(in srgb, var(--danger) 50%, var(--border)); color: var(--danger); }
.btn.danger:hover { background: rgba(248, 113, 113, 0.1); }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-hover); }

.new-note-btn .btn-icon {
  display: none;
  font-size: 18px;
  line-height: 1;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 18px;
  border-radius: var(--radius-sm);
}

/* ===== Content ===== */
.content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 24px 32px;
}

.content:has(.editor) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 20px;
  min-height: 0;
}

.content-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: var(--content-max);
  margin-inline: auto;
}

.note-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 10px 16px 22px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: var(--shadow-sm);
  -webkit-tap-highlight-color: transparent;
}

.note-card-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.note-card-menu {
  position: relative;
  flex-shrink: 0;
  margin-top: -4px;
  margin-right: -2px;
}

.note-menu-btn {
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 18px;
  opacity: 0.55;
}

.note-card:hover .note-menu-btn,
.note-card-menu:focus-within .note-menu-btn {
  opacity: 1;
}

.note-card-dropdown {
  right: 0;
  left: auto;
  z-index: 50;
}

.note-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--topic-accent);
  opacity: 0.85;
}

.note-card:hover {
  border-color: color-mix(in srgb, var(--topic-accent) 35%, var(--border));
  background: var(--surface-hover);
  box-shadow: var(--shadow-sm), 0 0 0 1px color-mix(in srgb, var(--topic-accent) 12%, transparent);
}

.note-card-body:active {
  transform: scale(0.995);
}

.note-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.note-card h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.note-card time {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  letter-spacing: 0.02em;
}

.note-card .body-preview {
  margin-top: 8px;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.55;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.note-card .body-preview :is(ul, ol) { margin: 4px 0 4px 1.1em; padding-left: 0.4em; }
.note-card .body-preview .note-checklist { margin: 4px 0 4px 0; padding: 0; list-style: none; }
.note-card .body-preview li { margin: 2px 0; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 72px 24px;
  max-width: 360px;
  margin: 0 auto;
}

.empty-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 16px;
  opacity: 0.7;
}

.empty-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
}

.empty-hint {
  margin: 0;
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.5;
}

.notes-all-archived-hint {
  margin: 0 0 16px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--fg-muted);
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  max-width: var(--content-max);
  margin-inline: auto;
}

.notes-archive {
  margin-top: 28px;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
}

.notes-archive-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 4px;
  margin-bottom: 10px;
  border: none;
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.notes-archive-header:hover {
  color: var(--fg);
}

.notes-archive-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg-muted);
}

.notes-archive-chevron {
  margin-left: auto;
  transition: transform 0.2s;
}

.notes-archive.is-collapsed .notes-archive-chevron {
  transform: rotate(-90deg);
}

.notes-archive.is-collapsed .note-list-archived {
  display: none;
}

.note-list-archived {
  gap: 8px;
}

.note-card.is-archived {
  opacity: 0.82;
  background: var(--bg-tertiary);
}

.note-card.is-archived::before {
  background: var(--fg-dim);
  opacity: 0.5;
}

.note-card.is-archived:hover {
  opacity: 1;
}

.note-archive-label {
  display: inline-block;
  margin-bottom: 6px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

/* ===== Editor ===== */
.editor {
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.editor-header {
  padding: 16px 18px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.editor-header input {
  flex: 1;
  border: none;
  font-size: 20px;
  font-weight: 650;
  font-family: inherit;
  letter-spacing: -0.02em;
  outline: none;
  background: transparent;
  color: var(--fg);
  padding: 10px 0 14px;
  min-width: 0;
}

.editor-header input::placeholder { color: var(--fg-dim); }

.editor-header .btn.ghost {
  flex-shrink: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.editor-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.editor-toolbar button:hover { background: var(--surface-hover); color: var(--fg); }
.editor-toolbar button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.editor-toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex-shrink: 0; }

.toolbar-color-wrap {
  position: relative;
  flex-shrink: 0;
}

.toolbar-color-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 32px;
  height: 32px;
  padding: 2px 6px 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.toolbar-color-btn:hover { background: var(--surface-hover); color: var(--fg); }

.toolbar-color-bar {
  display: block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: var(--fg);
}

.color-picker-menu {
  display: none;
  position: fixed;
  z-index: 3000;
  box-sizing: border-box;
  width: 212px;
  padding: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.color-picker-menu.show { display: block; }

.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(6, 32px);
  gap: 4px;
  justify-content: center;
}

.color-swatch {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.color-swatch:active { transform: scale(0.95); }

@media (min-width: 769px) {
  .color-picker-menu {
    width: 164px;
  }

  .color-picker-grid {
    grid-template-columns: repeat(6, 22px);
  }

  .color-swatch {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
  }

  .color-swatch:hover { transform: scale(1.08); }
}

.editor-body .note-text-color,
.editor-body font {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  font-size: inherit;
  font-weight: inherit;
  font-style: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  vertical-align: baseline;
}

.editor-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px;
  outline: none;
  line-height: 1.7;
  font-size: 15px;
  color: var(--fg);
}

.editor-body:empty::before {
  content: "Начните писать...";
  color: var(--fg-dim);
  pointer-events: none;
}

.editor-body ul,
.editor-body ol {
  margin: 6px 0 6px 1.1em;
  padding-left: 0.4em;
}
.editor-body li { margin: 2px 0; }
.editor-body blockquote {
  margin: 10px 0;
  padding: 4px 0 4px 16px;
  border-left: 3px solid var(--topic-accent);
  color: var(--fg-muted);
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-tertiary);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

.editor-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 8px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.editor-back-btn .back-icon {
  flex-shrink: 0;
  opacity: 0.75;
  transition: transform 0.15s;
}

.editor-back-btn:hover {
  color: var(--fg);
  background: var(--surface-hover);
}

.editor-back-btn:hover .back-icon {
  opacity: 1;
  transform: translateX(-2px);
}

.editor-back-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.editor-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  border: none;
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: not-allowed;
  opacity: 0.55;
  transition: background 0.2s, color 0.2s, opacity 0.2s, box-shadow 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.editor-save-btn .save-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fg-dim);
  flex-shrink: 0;
  transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
}

.editor-save-btn.is-ready {
  opacity: 1;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  box-shadow: 0 2px 12px color-mix(in srgb, var(--accent) 40%, transparent);
}

.editor-save-btn.is-ready .save-indicator {
  background: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, #fff 25%, transparent);
  animation: save-pulse 1.8s ease-in-out infinite;
}

.editor-save-btn.is-ready:hover {
  box-shadow: 0 4px 16px color-mix(in srgb, var(--accent) 50%, transparent);
  transform: translateY(-1px);
}

.editor-save-btn.is-ready:active {
  transform: translateY(0);
}

.editor-save-btn.is-saving {
  opacity: 0.7;
  pointer-events: none;
}

.editor-save-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@keyframes save-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.85; }
}

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.actions form { margin: 0; }

/* ===== Dropdown menus ===== */
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  z-index: 1000;
  padding: 6px;
  right: 0;
  left: auto;
}

.dropdown-menu.show { display: block; }

.dropdown-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.dropdown-menu button:hover { background: var(--surface-hover); }
.dropdown-menu button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.dropdown-menu button.danger { color: var(--danger); }
.dropdown-menu button.danger:hover { background: rgba(248, 113, 113, 0.1); }

.dropdown-menu .sep {
  height: 1px;
  background: var(--border);
  margin: 6px 8px;
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 380px;
  max-width: 100%;
  box-shadow: var(--shadow);
}

.modal h3 {
  margin: 0 0 20px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.modal label {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
}

.modal input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  margin-top: 6px;
  outline: none;
  background: var(--bg-tertiary);
  color: var(--fg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.modal input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.modal input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  cursor: pointer;
  margin-top: 6px;
  background: var(--bg-tertiary);
}

.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; }

.modal label {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
}

.modal label input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  margin-top: 6px;
  outline: none;
  background: var(--bg-tertiary);
  color: var(--fg);
  box-sizing: border-box;
}

.modal label input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.modal-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
}

.modal-error[hidden] { display: none; }

/* ===== Checkbox ===== */
.note-checklist {
  list-style: none;
  margin: 8px 0 8px 0;
  padding: 0;
}

.note-checklist .note-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0;
  padding: 0;
}

.note-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0;
}

.note-checkbox input[type="checkbox"],
.note-checklist input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== Auth ===== */
body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.auth-logo img {
  border-radius: 14px;
}

.auth-logo h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  padding: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  color: var(--fg-muted);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}

.auth-tab:hover { color: var(--fg); }

.auth-tab.active {
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.auth-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
}

.auth-form label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
}

.auth-form input {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 14px;
  background: var(--bg-tertiary);
  color: var(--fg);
  box-sizing: border-box;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-submit {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font-size: 15px;
}

.settings-user-label {
  padding: 10px 12px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: none;
  letter-spacing: 0;
}

.settings-logout-form {
  margin: 0;
}

.settings-logout-form button {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}

.settings-logout-form button:hover {
  background: var(--surface-hover);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-dim); }

/* ===== Desktop enhancements ===== */
@media (min-width: 1024px) {
  .content {
    padding: 28px 32px 40px;
  }

  .main-header {
    padding: 0 32px;
  }

  .chrome-tabs {
    padding-inline: 20px;
  }

  .editor {
    min-height: min(600px, calc(100dvh - var(--header-height) - 140px));
  }
}

/* ===== Tablet & mobile ===== */
@media (max-width: 768px) {
  :root {
    --header-height: 52px;
    --tab-height: 36px;
  }

  .chrome-tabs {
    padding: 4px 8px 0;
    gap: 2px;
  }

  .chrome-tab {
    padding: 0 12px;
    height: var(--tab-height);
    font-size: 12px;
    border-radius: 8px 8px 0 0;
  }

  .chrome-tab .tab-name { max-width: 88px; }
  .chrome-tab.new-tab,
  .chrome-tab.settings-tab { min-width: 34px; padding: 0 8px; }

  .main-header {
    padding: 0 14px;
    gap: 8px;
  }

  .header-left { gap: 10px; }

  .topic-title { font-size: 15px; }

  .new-note-btn {
    padding: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
  }

  .new-note-btn .btn-label { display: none; }
  .new-note-btn .btn-icon { display: block; }

  .content {
    padding: 14px 16px 24px;
  }

  .note-card {
    padding: 14px 8px 14px 20px;
  }

  .note-menu-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
  }

  .note-card h3 { font-size: 14px; }
  .note-card time { font-size: 10px; }
  .note-card .body-preview {
    font-size: 13px;
    -webkit-line-clamp: 2;
  }

  .editor {
    flex: 1;
    min-height: 0;
    border-radius: var(--radius);
  }

  .editor-header { padding: 12px 14px 0; }
  .editor-header input { font-size: 18px; padding-bottom: 12px; }

  .editor-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 6px 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  .editor-toolbar::-webkit-scrollbar { display: none; }

  .editor-toolbar button {
    min-width: 40px;
    height: 40px;
    flex-shrink: 0;
  }

  .toolbar-color-btn {
    min-width: 40px;
    height: 40px;
  }

  .editor-body {
    min-height: 0;
    padding: 14px 16px;
    font-size: 16px;
  }

  .editor-footer {
    padding: 10px 14px;
    gap: 12px;
    position: sticky;
    bottom: 0;
  }

  .editor-back-btn {
    min-height: 44px;
    padding: 8px 10px 8px 6px;
  }

  .editor-save-btn {
    min-height: 44px;
    padding: 10px 18px;
  }

  .editor-footer .btn { padding: 8px 14px; font-size: 13px; }

  .modal-overlay { padding: 16px; }
  .modal { padding: 20px; }

  .dropdown-menu { min-width: 180px; }

  .empty { padding: 48px 20px; }
  .empty-icon { font-size: 36px; }

  .chrome-tab,
  .btn:not(.new-note-btn),
  .editor-toolbar button,
  .dropdown-menu button {
    min-height: 44px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 480px) {
  .chrome-tab { padding: 0 10px; font-size: 11px; }
  .chrome-tab .tab-name { max-width: 68px; }
  .topic-title { font-size: 14px; }
  .topic-sep-label { display: none; }
}

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

  .editor-save-btn.is-ready .save-indicator {
    animation: none;
  }
}
