:root {
  /* Brand — pieuvre orange + complémentaire océan */
  --brand: #ff6201;
  --brand-deep: #d44f00;
  --brand-soft: #fff0e6;
  --action: #10557f;
  --action-2: #1a6f9c;
  --action-soft: #e3ecf2;
  --action-ink: #f4f8fb;

  --bg: #f3ebe3;
  --paper: #fbf7f1;
  --ink: #1c1915;
  --muted: #6f675d;
  --line: #e4d9cb;
  /* Alias historiques (pine/moss/copper) → tokens marque */
  --pine: var(--action);
  --pine-2: var(--action-2);
  --moss: var(--action-soft);
  --copper: var(--brand);
  --danger: #8d2e2e;
  --vault-open: #17864a;
  --shadow: 0 18px 50px rgba(48, 32, 18, 0.08);
  --sans: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", "Book Antiqua", Georgia, serif;
  /* Wordmark produit (Plus Jakarta Sans) — échantillonné sur charte */
  --brand-font: "Plus Jakarta Sans", var(--sans);
  --wordmark-pulpo: #ff5800;
  --wordmark-note: #4a4a4a;
  --radius-pill: 999px;
  --radius-card: 28px;
  --radius-panel: 16px;
  --radius-control: 12px;
  --radius-chip: 10px;
  --top: 62px;
  color-scheme: light;
}

/* Sombre : préférence système (auto) ou choix forcé data-theme="dark" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #ff7a2e;
    --brand-deep: #ff6201;
    --brand-soft: #3a2418;
    --action: #5aaee2;
    --action-2: #9fd0ee;
    --action-soft: #1a2f3a;
    --action-ink: #0b1c26;

    --bg: #161411;
    --paper: #211e1a;
    --ink: #f4efe7;
    --muted: #b3a89b;
    --line: #3a342c;
    --pine: var(--action);
    --pine-2: var(--action-2);
    --moss: var(--action-soft);
    --copper: var(--brand);
    --danger: #ffb4b4;
    --vault-open: #3dce7a;
    --wordmark-pulpo: #ff7a2e;
    --wordmark-note: #d4cdc2;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --brand: #ff7a2e;
  --brand-deep: #ff6201;
  --brand-soft: #3a2418;
  --action: #5aaee2;
  --action-2: #9fd0ee;
  --action-soft: #1a2f3a;
  --action-ink: #0b1c26;

  --bg: #161411;
  --paper: #211e1a;
  --ink: #f4efe7;
  --muted: #b3a89b;
  --line: #3a342c;
  --pine: var(--action);
  --pine-2: var(--action-2);
  --moss: var(--action-soft);
  --copper: var(--brand);
  --danger: #ffb4b4;
  --vault-open: #3dce7a;
  --wordmark-pulpo: #ff7a2e;
  --wordmark-note: #d4cdc2;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
body {
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: -0.011em;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 50%),
    radial-gradient(900px 420px at 90% 0%, color-mix(in srgb, var(--action) 8%, transparent), transparent 55%),
    var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
[hidden] { display: none !important; }

.mark {
  display: block;
  width: 64px;
  height: auto;
  flex-shrink: 0;
}
.mark.tiny {
  width: 22px;
  height: auto;
}

#gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
}
.gate-card {
  width: min(400px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 32px 28px 24px;
  box-shadow: var(--shadow);
}
.gate-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.gate-brand .mark { width: 48px; }
.gate-brand-name,
.brand-name {
  font-family: var(--brand-font);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  white-space: nowrap;
}
.gate-brand-name { font-size: 26px; }
.brand-pulpo { color: var(--wordmark-pulpo); }
.brand-note { color: var(--wordmark-note); }
.gate-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 0 0 14px;
}
.dialog-lede {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 0 0 14px;
}
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.password-field { position: relative; display: block; width: 100%; }
.password-field input { padding-right: 44px; }
.password-field input::-ms-reveal,
.password-field input::-ms-clear { display: none; }
.password-reveal {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.password-reveal svg { width: 18px; height: 18px; display: block; pointer-events: none; }
.password-reveal.is-revealing { color: var(--ink); }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 82%, var(--bg));
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--pine); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pine) 25%, transparent); }
.primary, .secondary, .ghost, .danger, .icon-button {
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  padding: 10px 16px;
}
.primary { background: var(--action); color: var(--action-ink); }
.primary:hover { background: var(--action-2); }
.secondary { background: var(--action-soft); color: var(--ink); border-color: var(--line); }
.ghost { background: transparent; border-color: var(--line); }
.danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
#new-note.primary { background: var(--action); color: var(--action-ink); }
#new-note.primary:hover { background: var(--action-2); }
.wide { width: 100%; }
.tight { padding: 8px 12px; }
.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  display: none;
  place-content: center;
  place-items: center;
  align-content: center;
  gap: 2px;
  background: transparent;
  border-color: var(--line);
}
.icon-button span {
  display: block;
  width: 15px;
  height: 2px;
  background: currentColor;
  margin: 0;
  border-radius: 1px;
}
.form-error { color: var(--danger); font-size: 13px; min-height: 1.2em; }
.form-message { color: var(--ink); font-size: 13px; line-height: 1.45; margin: 0 0 10px; }
#login-form .primary,
#forgot-form .primary,
#reset-form .primary,
#forgot-open,
#forgot-back,
#reset-back { width: 100%; margin-top: 6px; }
#forgot-open { margin-top: 10px; }

.topbar {
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-mark { position: relative; display: flex; flex: none; }
.brand-name { font-size: 17px; }
.presence {
  position: absolute;
  right: -4px;
  bottom: -2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #1f9a52;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--paper) 88%, transparent);
}
.presence.is-offline { background: #b7ab9d; }
.presence-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.search { flex: 1 1 auto; min-width: 0; }
.search input { border-radius: 999px; background: var(--paper); min-width: 0; }
.header-icon, .avatar-badge {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
}
.header-icon {
  border: 0;
  background: transparent;
  color: var(--brand);
}
.header-icon.is-open { color: var(--vault-open); }
.header-icon:hover, .avatar-badge:hover { background: var(--moss); }
.header-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.avatar-badge {
  border: 0;
  background: var(--action);
  color: var(--action-ink);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  line-height: 1;
}
.avatar-badge:hover { background: var(--action-2); color: var(--action-ink); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .presence { background: #3dce7a; }
  :root:not([data-theme="light"]) .presence.is-offline { background: #7d746a; }
}
:root[data-theme="dark"] .presence { background: #3dce7a; }
:root[data-theme="dark"] .presence.is-offline { background: #7d746a; }
.menu {
  position: absolute;
  top: 54px;
  right: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  min-width: 220px;
  padding: 6px;
  z-index: 8;
}
.menu button { text-align: left; background: transparent; border: 0; border-radius: 10px; padding: 10px 12px; }
.menu .menu-label {
  margin: 6px 12px 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.menu button.is-checked { background: var(--moss); font-weight: 520; }
.menu hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 6px 8px;
}
.menu button:hover { background: var(--moss); }

.workspace {
  height: calc(100dvh - var(--top));
  display: grid;
  grid-template-columns: 272px 332px minmax(0, 1fr);
}
#sidebar, #list-pane, #editor-pane {
  min-height: 0;
  min-width: 0;
}
#sidebar {
  border-right: 1px solid var(--line);
  padding: 16px 12px 28px;
  overflow: auto;
  background: color-mix(in srgb, var(--paper) 55%, transparent);
}
.side-nav { display: grid; gap: 4px; margin: 14px 0; }
.nav-item, .tree button, .tag-chip {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 430;
  letter-spacing: -0.006em;
}
.nav-item.is-active, .tree button.is-active, .tag-chip.is-active { background: var(--moss); }
.nav-item.is-active { font-weight: 520; }
.nav-item em { font-style: normal; font-weight: 430; color: var(--muted); margin-left: 6px; }
.side-head, .side-label { display: flex; align-items: center; justify-content: space-between; margin: 8px 4px; }
.side-head h2, .side-label { font-size: 11px; font-weight: 500; letter-spacing: 0.13em; text-transform: uppercase; color: var(--muted); }
.side-actions { display: flex; gap: 4px; }
.side-actions button { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); }
.tree-row { display: flex; align-items: center; }
.tree-row > button { flex: 1; min-width: 0; width: auto; padding-left: 4px; }
.tree .tree-caret,
.tree .tree-caret-spacer {
  flex: 0 0 20px;
  width: 20px;
  height: 28px;
}
.tree .tree-caret {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}
.tree .tree-caret:hover,
.tree .tree-caret:focus-visible {
  background: color-mix(in srgb, var(--moss) 80%, transparent);
  color: var(--ink);
}
.tree .tree-caret svg {
  width: 11px;
  height: 11px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 140ms ease;
}
.tree .tree-caret.is-open svg { transform: rotate(90deg); }
.tree-row:has(> button.is-active) {
  background: var(--moss);
  border-radius: 10px;
}
.tree-row:has(> button.is-active) > button.is-active { background: transparent; }
.tree-row:has(> button.is-active) .tree-caret { color: var(--ink); }
.tree-row:has(> button.is-drop) {
  border-radius: 10px;
  background: color-mix(in srgb, var(--action) 16%, var(--paper));
  box-shadow: inset 0 0 0 2px var(--action);
}
.tree-row:has(> button.is-drop) > button.is-drop {
  background: transparent;
  box-shadow: none;
}
.tree button { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; line-height: 1.35; }
.tree button .tree-label { font-size: 14px; font-weight: 460; color: var(--ink); letter-spacing: -0.008em; }
.tree button.is-active .tree-label { font-weight: 540; }
.tree button .tree-count { color: var(--muted); font-size: 11px; font-weight: 450; font-variant-numeric: tabular-nums; }
.tree button.is-drop {
  background: color-mix(in srgb, var(--action) 16%, var(--paper));
  box-shadow: inset 0 0 0 2px var(--action);
}
body.note-dragging #folder-tree {
  border-radius: 12px;
  outline: 1px dashed color-mix(in srgb, var(--action) 55%, var(--line));
  outline-offset: 4px;
}
body.note-dragging, body.note-dragging * { cursor: grabbing !important; }
.note-drag-ghost {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 0;
  pointer-events: none;
  max-width: 280px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip { width: auto; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font-size: 13px; }
.tag-chip small { color: var(--muted); margin-left: 4px; }

#list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; background: color-mix(in srgb, var(--bg) 35%, var(--paper)); }
.pane-head { padding: 18px 18px 8px; }
.pane-head h1 { font-family: var(--serif); font-size: 28px; font-weight: 500; letter-spacing: -0.02em; }
.pane-head p { color: var(--muted); font-size: 13px; margin-top: 4px; }
.note-list { overflow: auto; padding: 8px; }
.note-card {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 16px;
  padding: 12px 12px 12px 14px;
  display: grid;
  gap: 4px;
  position: relative;
}
.note-card.is-active { background: var(--paper); border-color: var(--line); box-shadow: var(--shadow); }
.note-card strong { font-size: 14.5px; font-weight: 530; letter-spacing: -0.012em; }
.note-card p { color: var(--muted); font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.note-card .when { font-size: 12px; color: var(--copper); }
.locks { font-size: 12px; }

#editor-pane { overflow: auto; background: var(--paper); }
#editor-empty { min-height: 100%; display: grid; place-items: center; align-content: center; gap: 14px; color: var(--muted); }
#editor-main {
  max-width: 820px;
  margin: 0 auto;
  padding: 18px 28px 80px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.editor-scroll { display: contents; }
.editor-nav { grid-row: 1; }
#conflict-bar { grid-row: 2; }
.title-row { grid-row: 3; }
.note-sub { grid-row: 4; }
.editor-controls { grid-row: 5; }
#editor { grid-row: 6; }
#attachment-list { grid-row: 7; }
#editor.is-readonly .ProseMirror,
#editor.is-readonly .plain-editor { caret-color: transparent; }
.note-title[readonly] { cursor: default; }
.editor-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.title-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 10px 14px;
  min-width: 0;
}
.title-row .note-title { flex: 1 1 auto; width: auto; min-width: 0; }
.title-row .caret-field { flex: 0 1 auto; max-width: min(46%, 12rem); }
.note-title {
  font-family: var(--serif);
  font-size: 40px;
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -0.025em;
  border: 0;
  background: transparent;
  padding: 2px 0 0;
  border-radius: 0;
}
.note-title:focus { box-shadow: none; }
@media (min-width: 981px) {
  .note-title.is-movable:not(:focus) { cursor: grab; }
}
.note-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 0;
  min-width: 0;
  margin: 2px 0 4px;
  padding-right: 30px;
  position: relative;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.note-sub > * + *::before {
  content: "·";
  margin: 0 6px;
  color: var(--muted);
}
.note-menu-wrap {
  position: absolute;
  top: 0;
  right: 0;
  height: 22px;
  display: flex;
  align-items: center;
}
.note-sub > .note-menu-wrap::before { content: none; margin: 0; }
.note-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.note-more svg { width: 16px; height: 16px; display: block; fill: currentColor; }
.note-more:hover,
.note-more[aria-expanded="true"] { background: var(--moss); color: var(--ink); }
.menu.note-menu {
  top: auto;
  right: auto;
  z-index: 12;
  min-width: 220px;
}
.note-menu .menu-label {
  margin: 6px 12px 2px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.note-menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 8px; }
.note-menu button.is-current { background: var(--moss); }
.note-menu button.is-danger { color: var(--danger); }
.note-menu button:disabled { opacity: 0.45; cursor: default; }
.note-menu button:disabled:hover { background: transparent; }
.note-trash-ghost {
  position: fixed;
  z-index: 45;
  pointer-events: none;
  margin: 0;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform-origin: center center;
  transition: transform 0.52s cubic-bezier(.4, .05, .65, 1), opacity 0.18s ease 0.36s;
}
.note-trash-ghost p {
  margin: 6px 0 0;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: -0.011em;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trash-catch {
  position: fixed;
  z-index: 44;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--ink);
  pointer-events: none;
}
.trash-catch svg { width: 22px; height: 22px; display: block; }
.nav-item.is-gulp,
.trash-catch.is-gulp { animation: trash-gulp 0.42s ease; }
@keyframes trash-gulp {
  0% { transform: scale(1); }
  45% { transform: scale(1.12); background: var(--moss); }
  100% { transform: scale(1); }
}
label.caret-field {
  display: inline-flex;
  align-items: center;
  position: relative;
  max-width: 100%;
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}
label.caret-field select {
  width: auto;
  max-width: 100%;
  min-width: 0;
  field-sizing: content;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: 1px 14px 1px 1px;
  color: inherit;
  font: inherit;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
  text-overflow: ellipsis;
}
label.caret-field select:hover { color: var(--ink); }
label.caret-field select:focus {
  outline: none;
  border-color: transparent;
  box-shadow: none;
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
label.caret-field select:disabled { cursor: default; opacity: 0.8; }
label.caret-field::after {
  content: "";
  position: absolute;
  right: 3px;
  top: 50%;
  width: 0;
  height: 0;
  margin-top: -1px;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 4px solid currentColor;
  pointer-events: none;
}
label.caret-field:has(select:disabled)::after { display: none; }
label.caret-field:has(select:disabled) select { padding-right: 1px; }
.editor-foot, .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tag-inline { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; min-width: 0; }
#tag-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border: 0; border-radius: 999px; background: var(--moss); padding: 1px 7px; font-size: 12px; line-height: 1.45; color: var(--ink); }
.chip.is-lock { background: color-mix(in srgb, var(--copper) 18%, var(--paper)); }
.tag-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}
.tag-add svg { width: 14px; height: 14px; display: block; }
.tag-add:hover { background: var(--moss); color: var(--ink); }
#tag-input {
  width: 7.2rem;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  line-height: 1.45;
  background: transparent;
}
#tag-input:focus { box-shadow: none; }
.editor-controls {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
}
.editor-bar { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }
#format-toggle { display: none; }
#format-toggle.is-active { background: var(--moss); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1; min-width: 0; background: transparent; padding: 0; border: 0; margin: 0; }
.toolbar button { border: 1px solid var(--line); background: transparent; border-radius: 9px; min-width: 34px; height: 34px; padding: 0 8px; }
.toolbar button:hover { background: var(--moss); }
.toolbar-sep { width: 1px; height: 20px; align-self: center; margin: 0 2px; background: color-mix(in srgb, var(--muted) 65%, transparent); flex: none; }
.toolbar button.history-btn {
  border: 0;
  background: transparent;
  min-width: 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--muted);
  border-radius: 8px;
}
.toolbar button svg { width: 16px; height: 16px; display: block; margin: 0 auto; }
.toolbar button.history-btn:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--ink); }
.encrypt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  height: 34px;
  padding: 0 12px;
  border: 1.5px solid var(--brand);
  border-radius: 9px;
  background: color-mix(in srgb, var(--brand) 16%, var(--paper));
  color: var(--brand-deep);
  font-weight: 650;
}
.encrypt-btn svg { width: 15px; height: 15px; display: block; }
.encrypt-btn:hover { background: color-mix(in srgb, var(--brand) 28%, var(--paper)); }
.encrypt-btn:disabled { opacity: 0.4; cursor: default; }
#save-state { color: var(--muted); font-size: 12px; white-space: nowrap; }
#editor .ProseMirror, .plain-editor {
  min-height: 48vh;
  outline: none;
  font-family: var(--serif);
  font-size: 18.5px;
  font-weight: 400;
  line-height: 1.68;
  letter-spacing: 0.004em;
}
#editor .ProseMirror p, .plain-editor p { margin: 0 0 0.8em; }
#editor .ProseMirror h1, #editor .ProseMirror h2, #editor .ProseMirror h3 { font-weight: 550; letter-spacing: -0.015em; line-height: 1.25; }
#editor .ProseMirror strong, #editor .ProseMirror b,
.plain-editor strong, .plain-editor b { font-weight: 650; }
#editor .ProseMirror img, .plain-editor img { max-width: 100%; height: auto; border-radius: 12px; }
#editor .ProseMirror blockquote { border-left: 3px solid var(--copper); margin-left: 0; padding-left: 14px; color: var(--muted); }
#editor .ProseMirror pre { background: var(--bg); border-radius: 12px; padding: 12px; overflow: auto; }
#editor .ProseMirror a { color: var(--pine-2); }
#editor .ProseMirror table,
.plain-editor table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.3em 0 1em;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
}
#editor .ProseMirror th,
#editor .ProseMirror td,
.plain-editor th,
.plain-editor td {
  border: 1px solid var(--line);
  padding: 0.4em 0.7em;
  vertical-align: top;
}
#editor .ProseMirror th,
.plain-editor th {
  font-weight: 650;
  background: color-mix(in srgb, var(--muted) 14%, var(--paper));
}
#editor .ProseMirror td > p:last-child,
#editor .ProseMirror th > p:last-child { margin-bottom: 0; }
.ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: var(--muted);
  pointer-events: none;
}
.attachment, .missing-media { font-family: var(--sans); font-size: 14px; }
#attachment-list { display: grid; gap: 6px; margin-top: 18px; }
#attachment-list a, #attachment-list button { font-size: 14px; }
.editor-foot { margin-top: 28px; }
.banner { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; background: var(--moss); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.banner.warn { background: color-mix(in srgb, var(--copper) 16%, var(--paper)); }
.enc-block {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px dashed var(--brand);
  border-radius: 10px;
  padding: 4px 6px 4px 10px;
  margin: 6px 0;
  background: color-mix(in srgb, var(--brand) 7%, var(--paper));
  font-family: var(--sans);
  cursor: pointer;
}
.enc-block.is-open {
  align-items: flex-start;
  border-style: solid;
  border-color: var(--vault-open);
  background: color-mix(in srgb, var(--vault-open) 8%, var(--paper));
  cursor: text;
}
.enc-block.is-legacy { cursor: default; }
.enc-body {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: 0.14em;
  text-transform: none;
  color: var(--ink);
}
.enc-actions {
  display: flex;
  flex: none;
  gap: 2px;
  margin-left: auto;
}
.enc-block.is-open .enc-actions { margin-top: 1px; }
.enc-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--brand-deep);
  cursor: pointer;
}
.enc-action svg { width: 16px; height: 16px; display: block; }
.enc-action:hover { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.enc-action.enc-hide { color: var(--muted); }
.enc-action:disabled { opacity: 0.35; cursor: default; }
.enc-block.is-open .enc-body,
.enc-block.is-legacy .enc-body,
.enc-block.is-pending .enc-body { letter-spacing: 0; }
#editor .enc-block .enc-body p { margin: 0 0 0.35em; }
#editor .enc-block .enc-body p:last-child { margin-bottom: 0; }
#vault-hint { color: var(--ink); margin-bottom: 12px; }
.vault-rules {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--paper) 82%, var(--bg));
}
.vault-rules div {
  display: grid;
  grid-template-columns: 4.6rem 1fr;
  gap: 8px;
  align-items: baseline;
}
.vault-rules dt {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink);
}
.vault-rules dd {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}
#back-button { display: none; }

dialog {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  width: min(440px, calc(100vw - 24px));
  box-shadow: var(--shadow);
  padding: 22px;
}
dialog::backdrop { background: rgba(28, 25, 21, 0.45); }
dialog h2 { font-family: var(--serif); font-size: 30px; font-weight: 500; letter-spacing: -0.02em; margin-bottom: 8px; }
dialog p { color: var(--muted); line-height: 1.45; margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
#toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 30;
  max-width: min(520px, calc(100vw - 24px));
}

@media (max-width: 980px) {
  .brand-name {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .topbar { gap: 8px; }
  .search { min-width: 7.5rem; }
  .workspace { grid-template-columns: 1fr; }
  .icon-button { display: grid; }
  #sidebar {
    position: fixed;
    z-index: 20;
    top: var(--top);
    bottom: 0;
    left: 0;
    width: min(86vw, 340px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    background: var(--paper);
    box-shadow: var(--shadow);
  }
  body.nav-open #sidebar { transform: none; }
  #scrim { position: fixed; inset: var(--top) 0 0 0; background: rgba(0, 0, 0, 0.35); z-index: 15; }
  body.nav-open #scrim { display: block !important; }
  #editor-pane { display: none; }
  body.reading #list-pane { display: none; }
  body.reading #editor-pane {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: calc(100dvh - var(--top));
  }
  body.reading #editor-empty:not([hidden]) { flex: 1; }
  body.reading #editor-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    max-width: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
  body.reading .editor-scroll {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 8px 16px 12px;
  }
  #back-button { display: inline-flex; }
  body.reading #editor { display: flex; flex-direction: column; flex: 1 0 auto; }
  body.reading #editor .ProseMirror,
  body.reading .plain-editor { flex: 1; min-height: max(16rem, calc(100dvh - var(--top) - 150px)); }
  body.reading .editor-controls {
    position: static;
    flex: none;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin: 0;
    padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
    border-bottom: 0;
    border-top: 1px solid var(--line);
    background: var(--paper);
  }
  body.reading .editor-bar { margin-left: 0; justify-content: space-between; }
  body.reading .encrypt-btn { justify-content: center; }
  body.reading #format-toggle { display: inline-flex; }
  body.reading #format-bar { display: none; }
  body.reading #format-bar.is-open {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    order: -1;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  body.reading #format-bar.is-open button { flex: 0 0 auto; }
  .note-title { font-size: 32px; }
  .topbar { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
}

@media (prefers-reduced-motion: reduce) {
  #sidebar { transition: none; }
  .note-trash-ghost { transition: none; }
  .nav-item.is-gulp,
  .trash-catch.is-gulp { animation: none; }
}
