/* ── Typography ───────────────────────────────────────────────────────────────
   Three self-hosted families (DESIGN.md §3): doction runs on LANs and VPNs, often
   with no route to a CDN. Only the painted faces are vendored; no italics.
   Inter is not vendored: it would come from the same origin, so `system-ui` is
   the real fallback. */
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/vendor/fonts/manrope-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/vendor/fonts/manrope-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/static/vendor/fonts/manrope-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/static/vendor/fonts/manrope-latin-ext-500-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/static/vendor/fonts/manrope-latin-600-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/static/vendor/fonts/manrope-latin-ext-600-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/vendor/fonts/instrument-serif-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/vendor/fonts/instrument-serif-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/vendor/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/vendor/fonts/jetbrains-mono-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/static/vendor/fonts/jetbrains-mono-latin-500-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/static/vendor/fonts/jetbrains-mono-latin-ext-500-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* === Light tokens ========================================================= */
/* Colours are DESIGN.md §2 in oklch. Where a value fails its contrast target,
   the hue is kept and the lightness moved; the note says so. */
:root {
  /* Surfaces: warm technical paper. */
  --background:     oklch(0.965 0.012 94);
  --surface:        oklch(0.982 0.008 92);
  --surface-raised: oklch(0.994 0.004 90);
  --surface-muted:  oklch(0.936 0.016 91);
  --surface-inset:  oklch(0.908 0.020 91);


  /* Ink: dark green, not blue. */
  --ink:         oklch(0.245 0.030 151);
  --ink-strong:  oklch(0.185 0.026 150);
  --ink-muted:   oklch(0.445 0.025 151);
  /* Corrected from 0.590, which fails 4.5:1 for text. */
  --ink-subtle:  oklch(0.501 0.020 151);
  --ink-on-green:    oklch(0.982 0.008 92);
  /* Ink on the avatar's identity colour, which does not follow the theme. */
  --ink-on-identity: oklch(0.982 0.008 92);

  /* Functional green: what you click and what you read. */
  --green:       oklch(0.365 0.055 151);
  --green-hover: oklch(0.315 0.052 151);
  --green-press: oklch(0.315 0.052 151);
  --green-soft:  oklch(0.915 0.030 151);
  /* Corrected from alpha 0.13, which fails the 3:1 a focus ring needs. */
  --green-ring:  oklch(0.365 0.055 151 / 0.60);

  /* Orange is a signal. The first decorates; the second informs, so it must pass 4.5:1. */
  --orange:       oklch(0.635 0.155 52);   /* decoration */
  --orange-ink:   oklch(0.515 0.133 52);   /* chroma 0.155 cannot reach 4.5:1 at any lightness */

  /* Lines: decorative ones may fade; control boundaries must be seen. */
  --border-subtle:  oklch(0.875 0.018 90);
  /* Corrected from 0.818, which fails 3:1 as a control boundary. */
  --border-default: oklch(0.600 0.024 90);

  /* State. Corrected from 0.590, which fails 4.5:1 for text. */
  --danger:      oklch(0.525 0.185 28);
  --danger-soft: oklch(0.911 0.046 28);
  --ok-soft:     oklch(0.981 0.030 148);

  /* Pre-mixed, not color-mix(): Safari 15.4–16.1 rejects it silently. */
  --callout-bg: oklch(0.960 0.022 63.2);
  --input-bg:   oklch(0.987 0.007 97.3);

  /* Inner sheen of the code slab (§9). */
  --code-sheen:     oklch(1 0 0 / 0.045);

  /* Scrim behind the mobile drawer, modals and the command palette. */
  --scrim: oklch(0.200 0.020 150 / 0.45);

  /* Inline code: green on faint green. */
  --code-inline-bg:     oklch(0.915 0.030 151);
  --code-inline-border: oklch(0.870 0.035 151);

  /* The code slab has its own value per theme (§2). */
  --code-bg:        oklch(0.205 0.024 151);
  --code-text:      oklch(0.930 0.018 96);
  --code-muted:     oklch(0.690 0.025 120);
  --code-green:     oklch(0.760 0.110 142);
  --code-orange:    oklch(0.780 0.130 61);

  /* Radii (§6): 4px interface, 6px code, 8px modals. xl/2xl alias the 8px cap;
     the pill is only for avatars and theme dots. */
  --radius-xs:   2px;
  --radius-sm:   4px;
  --radius-md:   6px;
  --radius-lg:   8px;
  --radius-xl:   var(--radius-lg);
  --radius-2xl:  var(--radius-lg);
  --radius-pill: 999px;

  /* Shadows (§6) are only for what floats. */
  --shadow-1: 0 1px 2px oklch(0.20 0.02 150 / 0.05);
  --shadow-2: 0 4px 14px oklch(0.20 0.02 150 / 0.07);
  --shadow-3: 0 12px 32px oklch(0.20 0.02 150 / 0.10);
  /* Four steps collapse into three: minimal, raised and modal. */
  --shadow-xs: var(--shadow-1);
  --shadow-sm: var(--shadow-1);
  --shadow-md: var(--shadow-2);
  --shadow-lg: var(--shadow-3);

  /* Spacing (§5) on a 4px base, plus a 2px optical step for gaps under 11–12px text. */
  --space-0:  2px;
  --space-1:  4px;   --space-2:  8px;   --space-3: 12px;  --space-4: 16px;
  --space-5: 20px;   --space-6: 24px;   --space-8: 32px;
  --space-12: 48px;  --space-16: 64px;  --space-20: 80px;  --space-24: 96px;

  /* Width of the custom scrollbar. */
  --scrollbar-width: 8px;
  /* Air above H2 (56px) and H3 (36px), which §5 asks for. */
  --space-7:  28px;
  --space-9:  36px;
  --space-14: 56px;

  /* === Chrome: navigation is another material ===============================
   The sidebar is dark green ink in both themes; `.sidebar` maps these onto the
   usual token names. It is darker than the canvas in both themes so it recedes. */
  /* §8: the floor is a vertical gradient; the active row has no surface of its own. */
  --nav-bg:        oklch(0.145 0.028 151);
  --nav-bg-end:    oklch(0.115 0.022 151);
  --nav-hover:     oklch(0.185 0.030 151);
  /* The panel edge is measured against the canvas, not the chrome. */
  --nav-edge:      oklch(0.330 0.030 151);

  --nav-ink:            oklch(0.928 0.014 93);
  /* Active row text: without this, --ink-strong resolves to the canvas's dark ink. */
  --nav-ink-strong:     oklch(0.975 0.007 93);
  --nav-ink-muted:      oklch(0.720 0.018 100);
  --nav-ink-subtle:     oklch(0.659 0.018 110);
  --nav-border-subtle:  oklch(0.290 0.028 151);
  --nav-border-default: oklch(0.556 0.025 150);

  --nav-green:        oklch(0.745 0.090 145);
  --nav-green-hover:  oklch(0.805 0.090 145);
  --nav-green-press:  oklch(0.805 0.090 145);
  --nav-green-soft:   oklch(0.290 0.050 149);
  --nav-green-ring:   oklch(0.745 0.090 145 / 0.55);
  --nav-ink-on-green: oklch(0.185 0.024 151);

  /* Chrome orange is only a rule on the active item, so 3:1 is enough. */
  --nav-orange:         oklch(0.635 0.155 52);
  --nav-danger:         oklch(0.700 0.150 28);
  --nav-danger-soft:    oklch(0.280 0.070 28);

  --nav-shadow-xs: 0 1px 2px oklch(0 0 0 / 0.28);
  --nav-shadow-sm: 0 1px 3px oklch(0 0 0 / 0.34), 0 1px 2px oklch(0 0 0 / 0.28);
  --nav-shadow-md: 0 4px 16px oklch(0 0 0 / 0.42);
  --nav-shadow-lg: 0 12px 32px oklch(0 0 0 / 0.55);

  /* === Back to the canvas ====================================================
   A <dialog> declared inside the sidebar inherits its palette, but showModal()
   paints it over the canvas. These aliases give the canvas palette back.
   They depend on [data-theme="dark"] coming AFTER :root in this file. */
  --canvas-background:             var(--background);
  --canvas-surface:        var(--surface);
  --canvas-surface-muted: var(--surface-muted);
  --canvas-surface-inset:  var(--surface-inset);
  --canvas-ink:           var(--ink);
  --canvas-ink-strong:    var(--ink-strong);
  --canvas-ink-muted:           var(--ink-muted);
  --canvas-ink-subtle:           var(--ink-subtle);
  --canvas-ink-on-green:   var(--ink-on-green);
  --canvas-border-subtle:         var(--border-subtle);
  --canvas-border-default:  var(--border-default);
  --canvas-green:         var(--green);
  --canvas-green-hover:   var(--green-hover);
  --canvas-green-press:   var(--green-press);
  --canvas-green-soft:    var(--green-soft);
  --canvas-green-ring:    var(--green-ring);
  --canvas-orange:         var(--orange);
  --canvas-danger:         var(--danger);
  --canvas-danger-soft:    var(--danger-soft);
  --canvas-shadow-xs:      var(--shadow-xs);
  --canvas-shadow-sm:      var(--shadow-sm);
  --canvas-shadow-md:      var(--shadow-md);
  --canvas-shadow-lg:      var(--shadow-lg);

  /* Layout (§4). */
  --sidebar-width:       280px;
  --toc-width:           220px;
  --topbar-height:       56px;
  /* On mobile the safe area makes the bar taller; what sticks under it reads this. */
  --topbar-height-mobile: calc(44px + env(safe-area-inset-top));
  --document-max-width:   760px;
  --document-gutter:      72px;
  --shell-max-width:     1720px;
  --editor-measure:      1600px;

  /* Motion (§13). */
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --duration-fast: 120ms;
  --duration-base: 180ms;
  --duration-slow: 240ms;

  /* Typography (§3). Each fallback is of the same class as its face. */
  --font-ui:      'Manrope', 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --font-mono:    'JetBrains Mono', ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  /* Role aliases: `data` is any value (slug, tag, path, date, count), `code` is code. */
  --font-data:    var(--font-mono);

  /* Scale (§3): 14px interface, 13px navigation, 16px document body, 11px floor. */
  --text-xs:   0.6875rem;  /* 11px — metadata */
  --text-sm:   0.75rem;    /* 12px */
  --text-base: 0.875rem;   /* 14px — interface */
  --text-md:   1rem;       /* 16px — document body */
  --text-lg:   1.125rem;   /* 18px */
  --text-xl:   1.375rem;   /* 22px — H2 */
  --text-2xl:  1.75rem;    /* 28px */
  --text-3xl:  2.25rem;    /* 36px — document H1 and page title */
  --text-4xl:  3.25rem;    /* 52px — landing hero only */
  /* Navigation has its own 13px step (§3). */
  --text-nav:  0.8125rem;  /* 13px */
}

/* === Dark tokens ========================================================== */
/* Warm charcoal (§2), corrected the same way as the light theme. */
[data-theme="dark"] {
  /* A third of §2's chroma: at 0.018–0.023 the whole app read as tinted green. */
  --background:     oklch(0.170 0.006 150);
  --surface:        oklch(0.205 0.007 150);
  --surface-raised: oklch(0.238 0.008 150);
  --surface-muted:  oklch(0.238 0.008 150);
  --surface-inset:  oklch(0.265 0.008 150);


  --ink:         oklch(0.925 0.016 93);
  --ink-strong:  oklch(0.975 0.007 93);
  --ink-muted:   oklch(0.720 0.018 100);
  /* Corrected from 0.550, which fails 4.5:1. */
  --ink-subtle:  oklch(0.639 0.018 110);
  --ink-on-green:    oklch(0.170 0.018 150);
  --ink-on-identity: oklch(0.982 0.008 92);

  --green:       oklch(0.745 0.090 145);
  --green-hover: oklch(0.805 0.090 145);
  --green-press: oklch(0.805 0.090 145);
  --green-soft:  oklch(0.290 0.050 149);
  /* Corrected as in light: alpha 0.13 fails 3:1 in both themes. */
  --green-ring:  oklch(0.745 0.090 145 / 0.53);

  --orange:       oklch(0.735 0.135 57);
  /* On charcoal the orange passes as text, so one value covers both roles. */
  --orange-ink:   oklch(0.735 0.135 57);

  --border-subtle:  oklch(0.285 0.020 150);
  /* Corrected from 0.345, which fails 3:1 as a control boundary. */
  --border-default: oklch(0.538 0.025 150);

  --danger:      oklch(0.700 0.150 28);
  --danger-soft: oklch(0.280 0.070 28);
  --ok-soft:     oklch(0.270 0.050 148);

  /* Pre-mixed as in light, composed over this theme's surface. */
  --callout-bg: oklch(0.248 0.030 72.5);
  --input-bg:   oklch(0.222 0.021 150.5);

  --scrim: oklch(0.100 0.010 150 / 0.62);

  --code-inline-bg:     oklch(0.290 0.050 149);
  --code-inline-border: oklch(0.345 0.045 149);

  /* Against this canvas the slab barely separates, so §9's border carries the edge. */
  --code-bg:        oklch(0.115 0.014 150);
  --code-text:      oklch(0.925 0.016 93);
  --code-muted:     oklch(0.620 0.025 113);
  --code-green:     oklch(0.760 0.110 142);
  --code-orange:    oklch(0.790 0.130 61);

  --shadow-xs: 0 1px 2px oklch(0 0 0 / 0.22);
  --shadow-sm: 0 1px 3px oklch(0 0 0 / 0.28), 0 1px 2px oklch(0 0 0 / 0.22);
  --shadow-md: 0 4px 16px oklch(0 0 0 / 0.35);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.5);

  /* The chrome has no dark variant: it is the same ink in both themes (§8).
     Its floor cannot be lightened: the avatar's inline colour is a control
     boundary that would drop below 3:1. */
}

/* === Theme transition on key surfaces ==================================== */
body, .sidebar, .content-body, .auth-card,
.btn, .new-btn, .search-field, .editor-textarea, .preview,
.avatar-menu, .user-block {
  transition:
    background-color var(--duration-base) var(--ease-standard),
    border-color     var(--duration-base) var(--ease-standard),
    color            var(--duration-base) var(--ease-standard);
}

/* === Reset ================================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* DESIGN.md §7: the canvas is a flat tone, as on doction.site. Depth comes from
   the chrome/canvas contrast, not from anything painted over the paper. */
body {
  background-color: var(--background);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-optical-sizing: auto;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}
a { color: inherit; }

::selection { background: var(--green-soft); color: var(--green-press); }

/* === Shared pieces ======================================================== */
/* Seven small pieces that compose; none grows variants for a single screen. */

/* 1. Card: a surface resting on the page. A line, not a shadow. */
.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card-title {
  font-family: var(--font-ui);
  font-size: var(--text-lg);
  font-weight: 600;
  margin: 0 0 var(--space-1);
  color: var(--ink);
}

.card-desc {
  margin: 0 0 var(--space-4);
  color: var(--ink-subtle);
  font-size: var(--text-base);
}

/* 2. Eyebrow: the small label heading a group. */
.eyebrow {
  margin: 0 0 var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-subtle);
}

/* A label tied to a control: same label, less air below. */
.field-label {
  display: block;
  margin-bottom: var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-subtle);
}

/* 3. Rows / Row: the container owns separation; the card's border closes the last row. */
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Actions wrap under the name on narrow screens instead of squeezing it. */
.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  min-height: 44px;
}

.rows--divided > * + * { border-top: 1px solid var(--border-subtle); }

.row-name {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-0);
  color: var(--ink);
  /* An email or URL has no spaces to break at. */
  overflow-wrap: anywhere;
}

.row-title {
  color: var(--ink);
  font-weight: 500;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.row-name a {
  color: var(--ink);
  text-decoration: none;
}
.row-name a:hover { color: var(--green); }

.row-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* 4. Meta: data face with tabular figures, so a column of numbers reads as one. */
.meta {
  margin: 0;
  color: var(--ink-subtle);
  font-family: var(--font-data);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.meta--strong { color: var(--ink); }

/* 5. Field: one text input style. */
.field {
  width: 100%;
  min-height: 36px;
  padding: var(--space-2) var(--space-3);
  background: var(--input-bg);
  color: var(--ink);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
}
.field::placeholder { color: var(--ink-subtle); }
.field:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-ring);
}

/* The bare field: editor textarea, title, palette input. */
.field--bare {
  min-height: 0;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
}
.field--bare:focus { box-shadow: none; }


/* === Layout =============================================================== */
/* §4's width cap applies to the reading column, not the shell: the sidebar stays on the edge. */
.layout {
  display: grid;
  grid-template-columns: auto 1fr;
  min-height: 100vh; min-height: 100dvh;
}

/* === Sidebar ============================================================== */
/* The chrome changes material by redefining the token NAMES its rules already
   read. var() resolves at the matched element, so everything inside re-themes
   with no rule of its own. --green-press is the active tree item's text. */
.sidebar {
  --background:             var(--nav-bg);
  --surface:        var(--nav-bg);
  --surface-muted: var(--nav-bg);
  --surface-inset:  var(--nav-hover);

  --ink: var(--nav-ink);
  --ink-strong: var(--nav-ink-strong);
  --ink-muted: var(--nav-ink-muted);
  --ink-subtle: var(--nav-ink-subtle);
  --ink-on-green: var(--nav-ink-on-green);

  --border-subtle:        var(--nav-border-subtle);
  --border-default: var(--nav-border-default);

  --green:       var(--nav-green);
  --green-hover: var(--nav-green-hover);
  --green-press: var(--nav-green-press);
  --green-soft:  var(--nav-green-soft);
  --green-ring:  var(--nav-green-ring);

  --orange: var(--nav-orange);

  --danger:      var(--nav-danger);
  --danger-soft: var(--nav-danger-soft);

  --shadow-xs: var(--nav-shadow-xs);
  --shadow-sm: var(--nav-shadow-sm);
  --shadow-md: var(--nav-shadow-md);
  --shadow-lg: var(--nav-shadow-lg);

  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--nav-bg) 0%, var(--nav-bg-end) 100%);
  border-right: 1px solid var(--nav-edge);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh; height: 100dvh;
  overflow: hidden;
  transition: width var(--duration-slow) var(--ease-standard), opacity var(--duration-slow) var(--ease-standard);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-4);
  flex-shrink: 0;
}

/* === Sidebar toggle buttons =============================================== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--ink-subtle);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.icon-btn:hover { background: var(--surface-inset); color: var(--ink); }

.sidebar-toggle {
  font: inherit;
  line-height: 1;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--ink-subtle);
  border-radius: var(--radius-sm);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.sidebar-toggle:hover { background: var(--surface-inset); color: var(--ink); }
.sidebar-toggle .lucide { display: block; }

/* The top bar's toggle does this at every width; the floating one would duplicate it. */
.sidebar-toggle--show { display: none !important; }

/* === Collapsed state ====================================================== */
.sidebar-collapsed .sidebar {
  width: 0;
  opacity: 0;
  pointer-events: none;
}
.sidebar-collapsed .content { padding-left: var(--space-12); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  touch-action: none;
  transition: opacity var(--duration-base) var(--ease-standard);
  z-index: 40;
}

/* === Brand ================================================================ */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: var(--text-xl);
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink);
}

.brand-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  /* The brand mark is green on every surface (DESIGN.md §8). */
  color: var(--nav-green);
}

/* === Workspaces (dropdown) ================================================ */
.workspace-wrap {
  padding: 0 var(--space-3) var(--space-3);
  flex-shrink: 0;
}

.ws-select { position: relative; }

.ws-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 500;
  min-height: 40px;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.ws-trigger:hover { background: var(--surface-inset); border-color: var(--border-default); }
.ws-trigger-label {
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ws-trigger-icon { flex-shrink: 0; color: var(--ink-subtle); }

.ws-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 90;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);
}
.ws-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ws-menu-list {
  display: flex;
  flex-direction: column;
  max-height: 280px;
  overflow-y: auto;
  padding: var(--space-1);
}

/* Full <button> reset: each option is a button and would paint natively. */
.ws-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  color: var(--ink-muted);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.ws-option-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ws-option-check { flex-shrink: 0; opacity: 0; color: var(--green); }
.ws-option:hover { background: var(--surface-inset); color: var(--ink); }
.ws-option.active { color: var(--green-press); font-weight: 500; }
.ws-option.active .ws-option-check { opacity: 1; }

.ws-menu-divider { height: 1px; background: var(--border-subtle); margin: var(--space-1) 0; }

.ws-menu-new {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  background: none;
  border: none;
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  text-align: left;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.ws-menu-new:hover { background: var(--surface-inset); color: var(--green); }

.workspace-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-1);
  padding: 0 var(--space-2) var(--space-2);
}


.workspace-add {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  padding: 0 var(--space-2);
  cursor: pointer;
  height: 30px;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.workspace-add:hover { background: var(--surface-inset); color: var(--ink); }

/* === Search =============================================================== */
.search-wrap {
  padding: 0 var(--space-3) var(--space-3);
  flex-shrink: 0;
}

.search-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0 var(--space-3);
  height: 40px;
  transition: box-shadow var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.search-field:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-ring);
}
.search-field .lucide { color: var(--ink-subtle); flex-shrink: 0; }
.search-field input {
  border: none;
  outline: none;
  background: none;
  width: 100%;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  color: var(--ink);
}
.search-field input::placeholder { color: var(--ink-subtle); }
/* The clear button: without this it paints as a native button. */
.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--ink-subtle);
  cursor: pointer;
  padding: var(--space-0);
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.search-clear:hover { background: var(--surface-inset); color: var(--ink); }


/* The sidebar's label needs the side margin its siblings get from their containers. */
.sidebar > .eyebrow {
  padding: var(--space-2) var(--space-4) var(--space-1);
  flex-shrink: 0;
}

/* === Search results ======================================================= */
#search-results .results { margin-top: var(--space-2); }
/* A result snippet and a mention are the same: quoted text with the match marked. */
.snippet {
  margin: var(--space-1) 0 0;
  font-size: var(--text-sm);
  color: var(--ink-subtle);
  line-height: 1.45;
}
.snippet mark {
  background: var(--green-soft);
  color: var(--green-press);
  padding: 0 var(--space-0);
  border-radius: var(--radius-xs);
}
.no-results { font-size: var(--text-base); margin-top: var(--space-2); color: var(--ink-subtle); }

/* ── Scrollbar ────────────────────────────────────────────────────────────────
   One definition for the tree, the workspace menu and the TOC, so it re-themes
   inside the sidebar. `scrollbar-*` is the standard; `::-webkit-*` the fallback. */
.page-list,
.ws-menu-list,
.has-toc .toc {
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}
.page-list::-webkit-scrollbar,
.ws-menu-list::-webkit-scrollbar,
.has-toc .toc::-webkit-scrollbar {
  width: var(--scrollbar-width);
}
.page-list::-webkit-scrollbar-track,
.ws-menu-list::-webkit-scrollbar-track,
.has-toc .toc::-webkit-scrollbar-track {
  background: transparent;
}
.page-list::-webkit-scrollbar-thumb,
.ws-menu-list::-webkit-scrollbar-thumb,
.has-toc .toc::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-lg);
  /* A transparent border keeps the thumb thinner than the track. */
  border: 2px solid transparent;
  background-clip: content-box;
}
.page-list::-webkit-scrollbar-thumb:hover,
.ws-menu-list::-webkit-scrollbar-thumb:hover,
.has-toc .toc::-webkit-scrollbar-thumb:hover {
  background: var(--ink-subtle);
  background-clip: content-box;
}

/* === Nav / page list ====================================================== */
.page-list {
  flex: 1;
  /* Without this a flex item won't shrink below its content, and the head and foot scroll away. */
  min-height: 0;
  overflow-y: auto;
  /* The 44px touch area of each row's ⋯ overhangs the edge; it must not scroll sideways. */
  overflow-x: hidden;
  padding: 0 var(--space-2) var(--space-3);
}
.page-list ul,
.page-list [role='tree'] { list-style: none; margin: 0; padding: 0; }
.page-list li { margin: 0; }
.page-list a {
  display: block;
  text-decoration: none;
  font-size: var(--text-nav);
  color: var(--ink-muted);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.page-list a:hover { background: var(--surface-inset); color: var(--ink); }
/* §8: a 2px green rule and no surface, as on doction.site; weight and ink carry the rest. */
.page-list a.active {
  color: var(--ink-strong);
  font-weight: 500;
  box-shadow: inset 2px 0 0 var(--green);
}
/* Indent comes from the tree's aria-level: 14px per level. */
.page-list [aria-level='2'] { padding-left: calc(var(--space-3) + 14px); }
.page-list [aria-level='3'] { padding-left: calc(var(--space-3) + 28px); }
.page-list [aria-level='4'] { padding-left: calc(var(--space-3) + 42px); }
.muted { color: var(--ink-subtle); }

/* The twisty keeps its slot on leaf rows so titles of a level line up. */
.page-row-twisty {
  flex: none;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  cursor: pointer;
}
.page-row-twisty:disabled {
  cursor: default;
  visibility: hidden;
}
.page-row-twisty:hover { color: var(--ink); background: var(--surface-inset); }
.page-row-twisty .lucide,
.page-row-twisty svg {
  transition: transform var(--duration-fast) var(--ease-standard);
}
.page-row-twisty.open svg { transform: rotate(90deg); }

/* === Sidebar footer ======================================================= */
.sidebar-foot {
  padding: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-1);
}

/* The avatar menu opens upward in the sidebar footer. */
.sidebar-user .avatar-menu {
  top: auto;
  bottom: calc(100% + 6px);
}

.new-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 0 var(--space-4);
  height: 34px;
  width: 100%;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.new-btn:hover { background: var(--surface-inset); color: var(--ink); }
.new-btn .lucide { color: var(--ink-subtle); }

/* === Auth links in sidebar ================================================ */
.auth-links {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: 0 var(--space-3);
}

/* === Theme toggle ========================================================= */
.theme-toggle,
.lang-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--ink-subtle);
  cursor: pointer;
  padding: 0;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.theme-toggle:hover,
.lang-toggle:hover { background: var(--surface-inset); color: var(--ink); border-color: var(--border-default); }
.theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun  { display: flex; }

/* === Avatar =============================================================== */
.avatar-wrap { position: relative; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: var(--green);
  color: var(--ink-on-identity);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0;
  user-select: none;
  flex-shrink: 0;
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-xs);
  transition: opacity var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
}
.avatar:hover { opacity: 0.85; box-shadow: var(--shadow-sm); }

.avatar-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 100;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);
}
.avatar-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.avatar-menu-name {
  padding: var(--space-3) var(--space-4) 0;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar-menu-name + .avatar-menu-email { padding-top: var(--space-0); }
.avatar-menu-email {
  padding: var(--space-3) var(--space-4) var(--space-2);
  font-size: var(--text-sm);
  color: var(--ink-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar-menu-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-1) 0;
}
.avatar-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
  text-decoration: none;
  font: inherit;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  background: none;
  border: none;
  color: var(--ink-muted);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.avatar-menu-item:hover { background: var(--surface-inset); color: var(--green); }
.avatar-menu-item--danger,
.avatar-menu-item--danger:hover { color: var(--danger); }

/* === Content area ========================================================= */
.content {
  display: flex;
  flex-direction: column;
  transition: padding-left var(--duration-base) var(--ease-standard);
}

.content-body {
  flex: 1;
  /* §4: content starts 72px from the side. */
  padding: var(--space-16) var(--document-gutter) var(--space-20);
  /* The shell is capped here, not on .layout, so the sidebar stays on the edge. */
  max-width: var(--shell-max-width);
  display: flex;
  /* Content starts at a fixed 72px; centring it would tie the margin to the window width. */
  justify-content: flex-start;
}

/* sticky, not fixed: it stays in the flow, so content needs no top padding. */
/* Top bar (§4), at every width. */
.app-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--topbar-height);
  padding: 0 var(--document-gutter);
  background: var(--background);
  border-bottom: 1px solid var(--border-subtle);
}

/* Direct child only: the reader's ⋯ button shares the class inside .app-bar-actions. The bar's toggle only opens, so it hides while the sidebar is open. */
html:not(.sidebar-collapsed) .app-bar > .sidebar-toggle { display: none; }
.app-bar-title {
  font-family: var(--font-ui);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-bar-actions { position: relative; flex: none; }
/* On desktop a page's title shows in the bar only once its own H1 has scrolled
   under it, as doction.site's header does. `visibility` keeps the row's layout. */
@media (min-width: 821px) {
  .app-bar--reader:not(.app-bar--titled) .app-bar-title { visibility: hidden; }
}

.page, .placeholder { width: 100%; max-width: var(--document-max-width); min-width: 0; }
.editor { width: 100%; max-width: var(--editor-measure); }

/* === Page wrapper + optional TOC column =================================== */
.page-wrap {
  width: 100%;
  max-width: var(--document-max-width);
  align-self: flex-start;
}

.page-wrap.has-toc {
  max-width: calc(var(--document-max-width) + var(--toc-width) + var(--space-24));
  display: grid;
  grid-template-columns: 1fr var(--toc-width);
  /* §4 asks for 64px as a minimum; at that distance the TOC read as part of the line. */
  gap: var(--space-24);
  align-items: start;
}

/* === Table of contents ==================================================== */
.toc { display: none; }

.has-toc .toc {
  display: block;
  position: sticky;
  top: var(--space-12);
  max-height: calc(100vh - 80px); max-height: calc(100dvh - 80px);
  overflow-y: auto;
}


#toc-nav {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* The TOC is secondary: tertiary ink, and a decorative line at rest. */
.toc-item {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--ink-subtle);
  text-decoration: none;
  line-height: 1.5;
  padding: var(--space-0) var(--space-3);
  border-left: 1px solid var(--border-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.toc-item:hover { color: var(--ink); }
/* One carrier for the active state: the rule. The text only steps up to primary ink. */
.toc-item.active { color: var(--ink); border-left-color: var(--green); border-left-width: 2px; }
.toc-h1 { font-weight: 500; }
.toc-h2 { padding-left: var(--space-4); }
.toc-h3 { padding-left: var(--space-6); font-size: var(--text-sm); }

@media (max-width: 1120px) {
  /* Between 820 and 1120px the bar stayed full width with no TOC, narrowing content for nothing. */
  :root { --sidebar-width: 220px; }

  .page-wrap.has-toc {
    max-width: var(--document-max-width);
    grid-template-columns: 1fr;
  }
  .toc { display: none !important; }
}

/* === Page view ============================================================ */
/* Document header (§9). */
.page-header {
  padding-bottom: var(--space-6);
  margin-bottom: var(--space-8);
  border-bottom: 1px solid var(--border-subtle);
}
/* A page's path is data, not prose: data face, so it doesn't compete with the title. */
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-data);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
  margin-bottom: var(--space-4);
}
.breadcrumbs a {
  color: var(--ink-muted);
  text-decoration: none;
}
.breadcrumbs a:hover { color: var(--green); }
/* The separator is aria-hidden, so it owes no contrast. */
.breadcrumbs .crumb-sep { color: var(--ink-subtle); }
.breadcrumbs .crumb-current { color: var(--ink-subtle); font-weight: 500; }
.page-header h1 {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  text-wrap: balance;
  margin: 0 0 var(--space-4);
  color: var(--ink);
}
/* Edit, New subpage and History stay visible; Delete lives in the ⋯ menu beside them. */
.page-header-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.page-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}
.page-actions form { margin: 0; }
.page-actions-more { position: relative; display: inline-flex; }
.meta {
  color: var(--ink-subtle);
  font-size: var(--text-sm);
  margin: var(--space-2) 0 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-variant-numeric: tabular-nums;
}

/* Scoped: .meta has many uses and only the header's gets this treatment. */
.page-header .meta {
  margin: 0;
  font-family: var(--font-data);
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  gap: var(--space-3);
}

.meta a {
  color: var(--ink-muted);
}

.meta a:hover {
  color: var(--green);
}

.subpages {
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-subtle);
}

.subpages-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}


/* A card that is also a link, in a grid: only padding and hover differ from .card. */
.subpage-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.subpage-card:hover {
  background: var(--surface-inset);
  border-color: var(--border-default);
}

.subpages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-3);
}


.subpage-icon {
  color: var(--ink-subtle);
  flex-shrink: 0;
  margin-top: var(--space-0);
}




/* === Relations (backlinks / related) ===================================== */
.relations {
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-6);
}


/* === Diff ================================================================= */
.diff {
  margin-top: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-base);
  line-height: 1.5;
  background: var(--surface);
}
.diff-line {
  display: block;
  white-space: pre;
  padding: 0 var(--space-3);
  min-height: 1.5em;
  color: var(--ink-muted);
}
.diff-add { background: var(--ok-soft); color: var(--ink); }
.diff-del { background: var(--danger-soft); color: var(--ink); }
.diff-hunk { color: var(--green); background: var(--surface-inset); }
.diff-meta { color: var(--ink-subtle); }





.history-sub {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.history-sep { color: var(--ink-subtle); }


/* === Buttons ============================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  padding: 0 var(--space-3);
  height: 32px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
  transition:
    background    var(--duration-fast) var(--ease-standard),
    border-color  var(--duration-fast) var(--ease-standard),
    color         var(--duration-fast) var(--ease-standard),
    transform     var(--duration-fast) var(--ease-standard);
}
.btn:hover { background: var(--surface-inset); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: var(--ink-on-green);
}
.btn-primary:hover { background: var(--green-hover); border-color: var(--green-hover); }
.btn-primary:active { background: var(--green-press); border-color: var(--green-press); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-muted);
  padding: 0 var(--space-3);
}
.btn-ghost:hover { background: var(--surface-inset); color: var(--ink); }

.btn-danger {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }

.btn-sm {
  height: 26px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

/* === Prose (reading view) ================================================= */
.prose {
  /* Body in the interface face; the serif is only for headings, where it says "document". */
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: 1.78;
  color: var(--ink);
}
.prose h1, .prose h2, .prose h3 {
  font-family: var(--font-display);
  letter-spacing: -0.005em;
  line-height: 1.2;
  text-wrap: balance;
  color: var(--ink);
}
/* Document rhythm (§5). Sizes come from the heading block further down. */
.prose h1 { margin: var(--space-16) 0 var(--space-4); }
.prose h2 { margin: var(--space-14) 0 var(--space-4); }
.prose h3 { margin: var(--space-9) 0 var(--space-3); }
/* The header above already closes with a rule and its own margin. */
.prose > :first-child { margin-top: 0; }
.prose p  { margin: 0 0 var(--space-4); text-wrap: pretty; }
.prose a  { color: var(--green); text-underline-offset: 2px; text-decoration-thickness: 1px; }
.prose a:hover { color: var(--green-hover); }

/* A wikilink to a page that doesn't exist yet is something to write, not an error: dim and dashed, not danger. */
.prose a.wikilink--missing {
  color: var(--ink-subtle);
  text-decoration-style: dashed;
}
.prose a.wikilink--missing:hover { color: var(--ink-muted); }
.prose ul, .prose ol { padding-left: var(--space-6); }
.prose li { margin: var(--space-1) 0; }
/* Relative on purpose: inline code sits one step below whatever text surrounds it. */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-inline-bg);
  border: 1px solid var(--code-inline-border);
  border-radius: var(--radius-xs);
  padding: 0.1em 0.35em;
}
/* Colour lives here, not on .hljs: prose.js only highlights fences that declare a language. */
.prose pre {
  position: relative;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--nav-edge);
  border-radius: var(--radius-md);
  box-shadow: inset 0 1px 0 var(--code-sheen);
  padding: var(--space-5) var(--space-6);
  overflow-x: auto;
  /* The slab is dark in both themes; without this the native scrollbar is light. */
  color-scheme: dark;
}
.prose pre code { background: none; border: none; padding: 0; font-size: var(--text-base); line-height: 1.6; }

/* Mermaid: prose.js replaces the block with <div class="mermaid"> and renders it. */
.prose .mermaid {
  margin: var(--space-4) 0;
  text-align: center;
  overflow-x: auto;
}

/* highlight.js theme, measured against --code-bg; the same in both themes like the slab. */
.hljs { color: var(--code-text); background: transparent; }
.hljs-comment, .hljs-quote { color: var(--code-muted); }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section { color: var(--code-text); }
.hljs-string, .hljs-attr, .hljs-meta .hljs-string { color: var(--code-green); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--code-orange); }
.hljs-title, .hljs-name, .hljs-type, .hljs-built_in, .hljs-title.class_ { color: var(--code-text); }
.hljs-variable, .hljs-template-variable, .hljs-attribute { color: var(--code-text); }
.hljs-meta, .hljs-tag { color: var(--code-muted); }
.hljs-deletion { color: var(--code-orange); }
.hljs-addition { color: var(--code-green); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 600; }
.hljs-link { color: var(--code-green); }

/* Copy button, shown on hover. */
.code-copy {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--surface);
  color: var(--ink-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
  transition:
    opacity var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard),
    background var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard);
}
.prose pre:hover .code-copy,
.code-copy:focus-visible { opacity: 1; }
.code-copy:hover { color: var(--ink); background: var(--surface-inset); }
.code-copy.copied { color: var(--green); border-color: var(--green); opacity: 1; }

/* Heading anchors (#). */
.prose h1, .prose h2, .prose h3 { position: relative; }
.heading-anchor {
  position: absolute;
  left: -1.1em;
  top: 0;
  opacity: 0;
  padding-right: 0.3em;
  color: var(--ink-subtle);
  font-weight: 400;
  text-decoration: none;
  transition: opacity var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}
.prose h1:hover .heading-anchor,
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.heading-anchor:focus { opacity: 1; }
.heading-anchor:hover { color: var(--green); }
/* Quotes as technical notes: no italics (whole italic paragraphs read worse), an orange rule in the margin. */
.prose blockquote {
  margin: var(--space-7) 0;
  padding: var(--space-4) var(--space-5);
  border-left: 2px solid var(--orange);
  background: var(--callout-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink);
}
.prose table {
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  width: 100%;
  margin: var(--space-4) 0;
  /* Opaque canvas colour, not --surface: --surface turned tables into panels. */
  background: var(--background);
}
.prose th, .prose td { border: 1px solid var(--border-subtle); padding: var(--space-2) var(--space-3); text-align: left; font-variant-numeric: tabular-nums; }
.prose th { background: var(--surface-muted); font-weight: 600; }
.prose img { max-width: 100%; border-radius: var(--radius-md); }
.prose hr { border: none; border-top: 1px solid var(--border-subtle); margin: var(--space-8) 0; }
.prose del { color: var(--ink-subtle); }
mark, .prose mark { background: var(--green-soft); color: var(--green-press); border-radius: var(--radius-xs); padding: 0 var(--space-0); }

/* === Editor =============================================================== */
.editor-bar {
  display: flex;
  gap: var(--space-4);
  align-items: center;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
/* A page's title is written in the serif it is read in. */
.title-input {
  flex: 1;
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 400;
  letter-spacing: -0.01em;
}
.editor-actions { display: flex; gap: var(--space-2); }
.editor-preview-toggle { display: none; }

.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  min-height: 78vh;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
}

/* Writing markdown is reading data: mono face on the inset paper. */
.editor-textarea {
  resize: none;
  font-family: var(--font-mono);
  line-height: 1.65;
  padding: var(--space-4) var(--space-6) var(--space-12);
  border-right: 1px solid var(--border-subtle);
  background: var(--surface-muted);
  min-height: 78vh;
  tab-size: 2;
}
.editor-textarea:focus { outline: none; }

.preview {
  background: var(--surface);
  padding: var(--space-4) var(--space-6) var(--space-12);
  overflow-y: auto;
}
.preview-empty {
  color: var(--ink-subtle);
  font-family: var(--font-ui);
  font-style: italic;
  font-size: var(--text-base);
}

/* Editor pane labels */
.pane-label {
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-subtle);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-muted);
}

/* === Placeholder / empty state =========================================== */
.placeholder {
  text-align: center;
  margin-top: var(--space-16);
  color: var(--ink-subtle);
}
.placeholder h1 {
  font-family: var(--font-ui);
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--ink-muted);
  margin: 0 0 var(--space-2);
}
.placeholder .btn { margin-top: var(--space-4); }
/* Error state (500): the danger accent sets it apart from the neutral placeholder. */
.placeholder--error { margin-top: var(--space-12); }
.placeholder--error h1 { color: var(--danger); }

/* === Auth ================================================================= */
.auth {
  min-height: 70vh;
  display: grid;
  place-items: center;
  width: 100%;
}

.auth-card {
  width: min(420px, 92vw);
  padding: var(--space-8);
}

.auth-card h1 {
  margin: 0 0 var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

/* Scoped above `.auth-card h1` so the wordmark keeps its own treatment. */
.auth-card .auth-brand {
  font-family: var(--font-ui);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--green);
  margin: 0 0 var(--space-3);
}



.auth-submit {
  width: 100%;
  margin-top: var(--space-6);
  min-height: 44px;
  font-size: var(--text-md);
}

.auth-lang { margin-top: var(--space-4); }

.auth-switch { margin-top: var(--space-4); font-size: var(--text-base); color: var(--ink-muted); }
.auth-switch a { color: var(--green); }

.auth-error {
  background: var(--danger-soft);
  color: var(--danger);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  margin-top: var(--space-3);
  font-size: var(--text-base);
}

/* === No-sidebar pages (login, register) =================================== */
.no-sidebar .sidebar,
.no-sidebar .sidebar-overlay,
.no-sidebar .layout { grid-template-columns: 1fr; }

/* === Responsive =========================================================== */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh; height: 100dvh;
    width: 85vw;
    max-width: 320px;
    transform: translateX(0);
    opacity: 1;
    z-index: 60;
    padding-left: env(safe-area-inset-left);
    transition: transform var(--duration-slow) var(--ease-standard), opacity var(--duration-slow) var(--ease-standard);
  }
  .sidebar-collapsed .sidebar {
    display: block;
    width: 85vw;
    max-width: 320px;
    transform: translateX(-110%);
    opacity: 0;
  }
  /* Without this the bar shifted when the drawer opened and closed. */
  .sidebar-collapsed .content { padding-left: 0; }

  .content-body {
    padding: var(--space-6) max(var(--space-4), env(safe-area-inset-right))
      calc(var(--space-12) + env(safe-area-inset-bottom)) max(var(--space-4), env(safe-area-inset-left));
  }
  .prose table { display: block; overflow-x: auto; }

  .app-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: var(--topbar-height-mobile);
    padding: env(safe-area-inset-top) max(var(--space-3), env(safe-area-inset-right)) 0
      max(var(--space-3), env(safe-area-inset-left));
    background: var(--surface);
    border-bottom: 1px solid var(--border-subtle);
  }

  .sidebar-overlay { opacity: 0; }
  html:not(.sidebar-collapsed) .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  /* Save must be reachable from the end of a long document. */
  .editor-bar {
    position: sticky;
    top: var(--topbar-height);
    z-index: 20;
    background: var(--background);
    margin-bottom: 0;
    padding-top: var(--space-3);
  }
  .title-input { min-width: 0; }

  .editor-split { grid-template-columns: 1fr; }
  .editor-textarea { min-height: 40vh; }

  /* The split stacks on mobile, so preview is toggled with a button instead. */
  .editor-preview-toggle { display: inline-flex; }
  .editor-split > .preview { display: none; }
  .editor-split--preview > .editor-textarea { display: none; }
  .editor-split--preview > .preview { display: block; }
}

/* === Keyboard shortcuts modal ============================================= */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-standard);
  z-index: 200;
}
.shortcuts-overlay.open { opacity: 1; pointer-events: auto; }
.shortcuts-modal {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  transform: translateY(8px) scale(0.98);
  transition: transform var(--duration-fast) var(--ease-standard);
}
.shortcuts-overlay.open .shortcuts-modal { transform: translateY(0) scale(1); }
.shortcuts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.shortcuts-title { font-weight: 600; color: var(--ink); }
.shortcuts-close {
  background: none;
  border: none;
  color: var(--ink-subtle);
  font-size: var(--text-xl);
  line-height: 1;
  cursor: pointer;
  padding: 0 var(--space-1);
}
.shortcuts-close:hover { color: var(--ink); }
.shortcuts-list { list-style: none; margin: 0; padding: var(--space-3) var(--space-6) var(--space-6); }
.shortcuts-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
  color: var(--ink-muted);
  font-size: var(--text-base);
}
kbd {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--surface-muted);
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  padding: var(--space-0) var(--space-2);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* === Settings page ======================================================= */
.settings { width: 100%; max-width: 720px; }
.settings-h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-6);
  color: var(--ink);
}
.settings-form { display: flex; flex-direction: column; gap: var(--space-2); }
.settings-actions { margin-top: var(--space-4); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.profile-row { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-2); }
.profile-fields { flex: 1; min-width: 0; }
.profile-preview {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: var(--radius-pill);
  background: var(--green);
  color: var(--ink-on-identity);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: var(--text-xl);
  font-weight: 700;
  user-select: none;
}

.color-swatches { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-1); }
.swatch { position: relative; cursor: pointer; line-height: 0; }
.swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatch-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--border-subtle) inset;
  transition: transform var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.swatch-dot--auto {
  background: var(--surface-muted);
  color: var(--ink-muted);
  font-size: var(--text-sm);
  font-weight: 700;
  font-family: var(--font-ui);
}
.swatch:hover .swatch-dot { transform: scale(1.08); }
.swatch.selected .swatch-dot { border-color: var(--ink); }
.swatch input:focus-visible + .swatch-dot { box-shadow: 0 0 0 3px var(--green-ring); }

.ws-rename { display: flex; gap: var(--space-2); flex: 1; min-width: 220px; margin: 0; }
.ws-delete { margin: 0; }

/* Each workspace is a collapsible <details> row, so many of them stay manageable. */
.ws-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.ws-item { border-bottom: 1px solid var(--border-subtle); }
.ws-summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  cursor: pointer;
  list-style: none;
}
.ws-summary::-webkit-details-marker { display: none; }
.ws-summary-name { flex: 1; font-weight: 500; color: var(--ink); }
.ws-summary:hover .ws-summary-name { color: var(--green); }
.ws-summary-count { font-size: var(--text-sm); color: var(--ink-subtle); }
.ws-chevron { color: var(--ink-subtle); transition: transform var(--duration-fast) var(--ease-standard); }
.ws-item[open] .ws-chevron { transform: rotate(180deg); }
.ws-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: 0 0 var(--space-4) var(--space-3);
}
.ws-members { padding-left: var(--space-3); border-left: 2px solid var(--border-subtle); }
.member-role {
  font-size: var(--text-sm);
  color: var(--ink-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-0) var(--space-2);
}
.member-add { display: flex; gap: var(--space-2); margin: 0; }

/* Theme and language controls: sidebar footer, and login/register via .auth-lang. */
.sidebar-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
/* === Accessibility and polish ============================================== */

/* Skip link, visible only on keyboard focus. */
.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 300;
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  transform: translateY(-150%);
  transition: transform var(--duration-fast) var(--ease-standard);
}
.skip-link:focus { transform: translateY(0); outline: none; }

/* Toasts, stacked bottom right. */
.toasts {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 400;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 320px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--ink-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-base);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--duration-base) var(--ease-standard), transform var(--duration-base) var(--ease-standard);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast--ok { border-left-color: var(--green); }
.toast--error { border-left-color: var(--danger); }

/* Confirm dialog (replaces native confirm()). */
/* Declared inside the sidebar but painted over the canvas by showModal(): custom
   properties inherit through the DOM, not the top layer, so the canvas palette is
   redeclared here. Only the dialog; anchored menus stay dark. */
.sidebar .confirm-dialog {
  --background:             var(--canvas-background);
  --surface:        var(--canvas-surface);
  --surface-muted: var(--canvas-surface-muted);
  --surface-inset:  var(--canvas-surface-inset);
  --ink: var(--canvas-ink);
  --ink-strong: var(--canvas-ink-strong);
  --ink-muted: var(--canvas-ink-muted);
  --ink-subtle: var(--canvas-ink-subtle);
  --ink-on-green: var(--canvas-ink-on-green);
  --border-subtle:        var(--canvas-border-subtle);
  --border-default: var(--canvas-border-default);
  --green:       var(--canvas-green);
  --green-hover: var(--canvas-green-hover);
  --green-press: var(--canvas-green-press);
  --green-soft:  var(--canvas-green-soft);
  --green-ring:  var(--canvas-green-ring);
  --orange: var(--canvas-orange);
  --danger:      var(--canvas-danger);
  --danger-soft: var(--canvas-danger-soft);
  --shadow-xs: var(--canvas-shadow-xs);
  --shadow-sm: var(--canvas-shadow-sm);
  --shadow-md: var(--canvas-shadow-md);
  --shadow-lg: var(--canvas-shadow-lg);
}

.confirm-dialog {
  width: 100%;
  max-width: 380px;
  padding: var(--space-6);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
}
.confirm-dialog::backdrop { background: var(--scrim); }
.confirm-dialog-msg { margin: 0 0 var(--space-4); color: var(--ink); }
.confirm-dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* Row actions menu. It lives in the <dialog> because .page-list clips overflow. */
.row-menu { display: flex; flex-direction: column; gap: var(--space-0); }
.row-menu .avatar-menu-item { border-radius: var(--radius-sm); }

/* Command palette (⌘K). */
.palette {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh var(--space-4) var(--space-4);
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-standard);
  z-index: 250;
}
.palette.open { opacity: 1; pointer-events: auto; }
.palette-box {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(8px) scale(0.98);
  transition: transform var(--duration-fast) var(--ease-standard);
}
.palette.open .palette-box { transform: translateY(0) scale(1); }
.palette-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  background: transparent;
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-md);
  color: var(--ink);
}
.palette-input:focus { outline: none; }
.palette-list { list-style: none; margin: 0; padding: var(--space-2); max-height: 50vh; overflow-y: auto; }
.palette-item {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--ink-muted);
  text-decoration: none;
  font-size: var(--text-base);
}
.palette-item.active,
.palette-item:hover { background: var(--green-soft); color: var(--ink); }
.palette-empty { padding: var(--space-3); color: var(--ink-subtle); font-size: var(--text-base); }

/* API tokens in settings. */
.secret-reveal {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--green-soft);
  border: 1px solid var(--green);
  border-radius: var(--radius-md);
}
.secret-note { margin: 0 0 var(--space-2); font-size: var(--text-base); color: var(--ink-muted); }
.secret-row { display: flex; align-items: center; gap: var(--space-2); }
.secret-value {
  flex: 1;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  word-break: break-all;
  color: var(--ink);
}
.row-name { display: flex; flex-direction: column; gap: var(--space-0); min-width: 0; }
.add-form { display: flex; gap: var(--space-2); }

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

/* ── Capture, inbox and per-page actions ───────────────────────────────────── */

/* The capture modal reuses .palette with a textarea. */
.capture-input {
  resize: vertical;
  min-height: 7rem;
  font-family: inherit;
  line-height: 1.5;
}
.capture-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
}

/* Each tree row hosts a ⋯ menu, shown on hover or keyboard focus. */
.page-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.page-row > a {
  flex: 1;
  min-width: 0;
}
.page-row-actions {
  position: relative;
  flex: none;
}
.page-row-actions-btn {
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--ink-subtle);
  padding: var(--space-0);
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
}
.page-row-actions-btn:hover {
  color: var(--ink);
  background: var(--surface-inset);
}

.inbox-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  color: var(--ink-muted);
  font-size: var(--text-base);
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.inbox-link:hover {
  background: var(--surface-inset);
  color: var(--ink);
}

/* ── Touch and iPhone ─────────────────────────────────────────────────────────── */

/* Safari zooms into inputs under 16px and never zooms back. */
@media (pointer: coarse) {
  input,
  textarea,
  select {
    font-size: var(--text-md);
  }
}

/* Removes Safari's default grey tap flash. */
html {
  -webkit-tap-highlight-color: transparent;
}

/* Scrolling past the end of the sidebar or a modal must not scroll the page behind. */
.sidebar,
.page-list,
.palette-box {
  overscroll-behavior: contain;
}

/* Installed as a PWA there is no browser chrome, so the footer would sit under the home indicator. */
@supports (padding: max(0px)) {
  .sidebar-foot {
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  }
  .sidebar-head {
    padding-top: max(var(--space-3), env(safe-area-inset-top));
  }
}

/* Hover-only affordances don't exist on touch: the ⋯ menu must always be visible there. */
@media (hover: hover) {
  .page-row-actions-btn {
    opacity: 0;
  }
  .page-row:hover .page-row-actions-btn,
  .page-row-actions-btn:focus-visible {
    opacity: 1;
  }
}
@media (hover: none) {
  .page-row-actions-btn {
    opacity: 1;
  }
}

/* ── Settings sections ────────────────────────────────────────────────────────
   The cut is 1120px, not the shell's 820px: in between, a second column would
   leave content narrower than its own chrome. */
.settings-layout { display: grid; gap: var(--space-6); }
.settings-panel { min-width: 0; }

.settings-select { position: relative; margin-bottom: var(--space-2); }
.settings-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: 500;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
}
.settings-select-trigger:hover { background: var(--surface-inset); border-color: var(--border-default); }
.settings-select-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.settings-select-icon { flex-shrink: 0; color: var(--ink-subtle); }

.settings-select-menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: var(--space-1);
  display: none;
}
.settings-select-menu.open { display: block; }
.settings-select-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-xs);
  color: var(--ink-muted);
  font-size: var(--text-base);
  text-decoration: none;
}
.settings-select-option-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.settings-select-option-check { flex-shrink: 0; opacity: 0; color: var(--green); }
.settings-select-option:hover { background: var(--surface-inset); color: var(--ink); }
.settings-select-option.active { color: var(--green-press); font-weight: 500; }
.settings-select-option.active .settings-select-option-check { opacity: 1; }

.settings-nav { display: none; flex-direction: column; gap: var(--space-0); }
.settings-nav-item {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-xs);
  border-left: 2px solid transparent;
  color: var(--ink-muted);
  font-size: var(--text-base);
  text-decoration: none;
}
.settings-nav-item:hover { background: var(--surface-inset); color: var(--ink); }
/* The active state does not rest on colour alone: it also carries the rule and the weight. */
.settings-nav-item--active {
  background: var(--surface-inset);
  border-left-color: var(--green);
  color: var(--green-press);
  font-weight: 500;
}



@media (min-width: 1121px) {
  .settings { max-width: 960px; }
  .settings-layout { grid-template-columns: 180px minmax(0, 1fr); align-items: start; }
  .settings-nav { display: flex; position: sticky; top: var(--space-4); }
  .settings-select { display: none; }
}

/* 44px touch targets (Apple HIG) without changing the look: a pseudo-element extends the area. */
@media (pointer: coarse) {
  .page-row-actions-btn,
  .sidebar-toggle,
  .theme-toggle,
  .lang-toggle,
  .search-clear,
  .btn {
    position: relative;
  }
  /* The twisty gets the row's height and its ~24px gutter, not a 44px square that would eat the title. */
  .page-row-twisty {
    width: 24px;
    height: 44px;
  }
  .page-row-actions-btn::after,
  .sidebar-toggle::after,
  .theme-toggle::after,
  .lang-toggle::after,
  .search-clear::after,
  .btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
  }
  .ws-option,
  .avatar-menu-item,
  .settings-select-option,
  .settings-nav-item {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .settings-select-trigger { min-height: 44px; }
  /* Not flex: it would turn the text into an anonymous item and lose the ellipsis. */
  .page-list a {
    padding-block: var(--space-3);
    min-height: 44px;
  }
}

/* ── Motion ────────────────────────────────────────────────────────────────────
   Content rises in and controls respond to presses. The reduced-motion block
   above overrides all of it. */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Content entering on navigation. */
.prose,
.placeholder,
.settings {
  animation: rise var(--duration-base) var(--ease-standard) both;
}

/* Lists stagger 30ms per row, capped at the sixth. */
.results .row {
  animation: rise var(--duration-base) var(--ease-standard) both;
}
.results .row:nth-child(1) { animation-delay: 0ms; }
.results .row:nth-child(2) { animation-delay: 30ms; }
.results .row:nth-child(3) { animation-delay: 60ms; }
.results .row:nth-child(4) { animation-delay: 90ms; }
.results .row:nth-child(5) { animation-delay: 120ms; }
.results .row:nth-child(n + 6) { animation-delay: 150ms; }

/* Press feedback: on touch it is the only confirmation of a tap. */
.btn,
.new-btn,
.inbox-link,
.sidebar-toggle,
.theme-toggle,
.lang-toggle,
.avatar,
.ws-trigger,
.page-row-actions-btn {
  transition:
    background var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard),
    transform var(--duration-fast) var(--ease-standard);
}
.btn:active,
.new-btn:active,
.inbox-link:active,
.sidebar-toggle:active,
.theme-toggle:active,
.lang-toggle:active,
.avatar:active,
.ws-trigger:active,
.page-row-actions-btn:active {
  transform: scale(0.96);
}

/* Controls get the accent ring; links get an outline, which follows each fragment of a wrapped link. */
:where(button, input, textarea, select, summary, [tabindex]):focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--green-ring);
}
:where(a):focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  transition: outline-color var(--duration-fast) var(--ease-standard);
}

/* ── View states, connection and deliveries ─────────────────────────────────── */

/* An error outside the shell has no sidebar, so it centres as a full page. */
.placeholder--standalone {
  /* Outside the shell there is no reading column: the page is full width and its content is centred. */
  max-width: none;
  margin-top: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
}

/* Editor notice (recoverable draft, server down): it sits above the text without covering it. */
.editor-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin: 0 var(--space-4) var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: var(--text-base);
  color: var(--ink-muted);
}
.editor-notice--warn {
  border-color: var(--green);
  color: var(--ink);
}
.editor-notice-actions {
  display: flex;
  gap: var(--space-2);
  flex: none;
}

/* API and MCP status: renders nothing while everything works. */
/* Bottom left: toasts already live bottom right. */
.conn {
  position: fixed;
  left: var(--space-4);
  bottom: var(--space-4);
  z-index: 400;
}
@media (max-width: 820px) {
  /* On mobile the sidebar is a drawer whose footer reaches the bottom. */
  .conn {
    left: auto;
    right: var(--space-4);
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  }
}
.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0) var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  color: var(--ink-muted);
  font-size: var(--text-sm);
  cursor: pointer;
}
.conn-badge--down {
  border-color: var(--danger);
  color: var(--danger);
}
.conn-detail {
  position: absolute;
  left: 0;
  bottom: calc(100% + var(--space-1));
  z-index: 20;
  min-width: 200px;
  padding: var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: var(--text-base);
}
.conn-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-0) 0;
  color: var(--ink-muted);
}

.hook-health--bad {
  color: var(--danger);
}
.delivery-list {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--border-subtle);
}
.delivery-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.delivery {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-0) 0;
  font-size: var(--text-base);
  color: var(--ink-subtle);
}
.delivery-event {
  color: var(--ink-muted);
  font-family: var(--font-mono);
}
.delivery--failed .delivery-status {
  color: var(--danger);
}
.delivery-error {
  flex-basis: 100%;
  color: var(--ink-subtle);
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

/* ── Full markdown ────────────────────────────────────────────────────────────── */

/* Column alignment: the sanitizer drops inline style, so markdown.js maps it to a class. */
.prose .align-left { text-align: left; }
.prose .align-center { text-align: center; }
.prose .align-right { text-align: right; }

/* Task lists: no bullet, checkbox on the first line, no extra indent. */
.prose li.task-list-item { list-style: none; margin-left: -1.25em; }
.prose li.task-list-item input[type='checkbox'] {
  margin-right: var(--space-2);
  vertical-align: middle;
  accent-color: var(--green);
}

/* Formulas: KaTeX brings its own CSS; a wide formula scrolls instead of widening the column. */
.prose .math--block {
  display: block;
  margin: var(--space-4) 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ── Loading skeletons ─────────────────────────────────────────────────────────
   Shaped like what arrives, with real sizes, so nothing moves when it does. */
.skeleton-bar {
  display: block;
  height: 0.9em;
  border-radius: var(--radius-xs);
  background: var(--surface-inset);
  animation: skeleton-pulse 1.4s var(--ease-standard) infinite;
}
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-bar { animation: none; }
}

/* Sidebar tree: same row height and 14px indent as the real tree. */
.skeleton-tree { padding: 0 var(--space-2); }
.skeleton-row {
  display: flex;
  align-items: center;
  min-height: 30px;
  padding: var(--space-2) var(--space-3);
}
.skeleton-row[data-level='1'] { padding-left: calc(var(--space-3) + 14px); }
.skeleton-row[data-level='2'] { padding-left: calc(var(--space-3) + 28px); }
.skeleton-row .skeleton-bar { width: 70%; }
.skeleton-row:nth-child(2n) .skeleton-bar { width: 55%; }
.skeleton-row:nth-child(3n) .skeleton-bar { width: 82%; }

/* Document body, at the reading column's width. */
.skeleton-doc {
  width: 100%;
  max-width: var(--document-max-width);
  margin-top: var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.skeleton-bar--title {
  height: 1.8em;
  width: 55%;
  margin-bottom: var(--space-4);
}
.skeleton-bar--short { width: 62%; }

.skeleton-list {
  width: 100%;
  max-width: var(--document-max-width);
  margin-top: var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.skeleton-list .skeleton-bar { height: 1.4em; }

/* No results: the message and a way out. */
.no-results {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

/* ── Data vs prose ─────────────────────────────────────────────────────────────
   A machine value (slug, tag, section path, date, count, version, status) is set
   in the data face; a sentence never is. */
.member-role,
.delivery-event,
.delivery-when,
.delivery-status,
.delivery-error,
.hook-health,
.conn-row span:last-child,
.page-meta,

/* A snippet's heading path is a data coordinate, not prose. */
.snippet mark {
  font-family: inherit;
}

/* PAT tokens and webhook secrets get the data size so they don't compete with text. */
.secret-value {
  font-family: var(--font-data);
}

/* ── Serif headings ──────────────────────────────────────────────────────────── */
/* §3: serif only for the page title and document H1; at 22 and 16px its x-height is too small. */
.page-header h1,
.prose h1,
.settings-h1,
.placeholder h1 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.015em;
}

.page-header h1  { font-size: var(--text-3xl); line-height: 1.15; }
.settings-h1     { font-size: var(--text-3xl); line-height: 1.1; }
.placeholder h1  { font-size: var(--text-3xl); line-height: 1.1; }
.prose h1        { font-size: var(--text-3xl); line-height: 1.15; }

/* Section headings: interface face, weight 600, §3 sizes. */
.prose h2, .prose h3 {
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: -0.005em;
}
.prose h2 { font-size: var(--text-xl); line-height: 1.3; }
.prose h3 { font-size: var(--text-md); line-height: 1.45; }

/* === Graph view =========================================================== */
/* Every colour comes from theme variables, so dark mode is the usual cascade. */

.graph-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 100%;
  height: 100%;
  min-height: 0;
}

.graph-header { flex-shrink: 0; }

.graph-facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
  margin: var(--space-4) 0 0;
}
.graph-fact { display: flex; align-items: baseline; gap: var(--space-2); }
.graph-fact-value {
  margin: 0;
  font-family: var(--font-data);
  font-size: var(--text-lg);
  color: var(--ink);
}
.graph-fact-label {
  margin: 0;
  font-size: var(--text-base);
  color: var(--ink-muted);
}
.graph-fact--alert .graph-fact-value { color: var(--danger); }

.graph-note {
  margin: var(--space-3) 0 0;
  font-size: var(--text-base);
  color: var(--ink-muted);
}

/* §12 adapted: .graph-node is a <g> around a circle and a text, so fill and stroke go on those. Orphan and broken states are doction's own. */
.graph-canvas {
  flex: 1;
  min-height: 320px;
  width: 100%;
  /* §12: soft tonal depth from the centre, no strong grid. */
  background: radial-gradient(
    circle at 52% 42%,
    var(--surface-muted) 0%,
    var(--background) 62%
  );
  touch-action: none;      /* dragging is ours, not the browser's */
  cursor: grab;
}
.graph-canvas:active { cursor: grabbing; }
/* §12: relations as cartographic lines. */
.graph-edge {
  stroke: var(--border-default);
  stroke-width: 1;
  stroke-opacity: 0.38;
}
/* A broken link is a finding here: this view is about the whole graph's health. */
.graph-edge--broken {
  stroke: var(--danger);
  stroke-dasharray: 3 3;
  stroke-opacity: 0.75;
}

.graph-node { cursor: pointer; }
/* §12: no glow. A resting node is an outlined surface. */
.graph-node circle {
  fill: var(--surface-raised);
  stroke: var(--green);
  stroke-width: 1.25;
  transition: fill var(--duration-fast) var(--ease-standard),
              stroke var(--duration-fast) var(--ease-standard);
}
.graph-node text {
  /* §12: labels are page names, so interface face. */
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  fill: var(--ink-muted);
  pointer-events: none;
  user-select: none;
  /* Centred under the node: the layout's collision check can only measure symmetric boxes. */
  text-anchor: middle;
}
/* Orphan: no links either way. Not an error, so dimmed rather than alarming. */
.graph-node--orphan circle { fill: var(--border-default); }
.graph-node--broken { cursor: default; }
.graph-node--broken circle {
  fill: none;
  stroke: var(--danger);
  stroke-dasharray: 2 2;
}
.graph-node--broken text { fill: var(--danger); }
/* The hovered node: green fill; the state is carried by fill and label ink. */
.graph-node.is-hover circle {
  fill: var(--green);
  stroke: var(--green-hover);
  stroke-width: 1.5;
}
.graph-node.is-hover text { fill: var(--ink); }

@media (max-width: 820px) {
  .graph-facts { gap: var(--space-4); }
  .graph-canvas { min-height: 260px; }
}
