/* ================================================================
   Notes — one hue, two themes.

   The palette is deliberately monochromatic: a single near-neutral ramp, and the only
   "accent" is the text colour itself, used inverted. Nothing in this app is coloured to
   mean something, so nothing has to be learned — emphasis comes from contrast, weight and
   space instead, and the writing stays the loudest thing on the page.
   ================================================================ */

:root {
  color-scheme: light;

  --bg: #ffffff;
  --bg-sub: #fbfbfc;
  --surface: #f4f4f6;
  --surface-2: #ebebee;
  --surface-3: #e0e0e5;
  --line: #e7e7ea;
  --line-2: #d8d8dd;
  --line-3: #bcbcc4;

  --text: #16161a;
  --text-2: #5c5c66;
  --text-3: #9a9aa4;
  --text-4: #c2c2ca;

  --flip-bg: #16161a;
  --flip-text: #fbfbfc;

  --ring: #16161a;
  --select: rgb(22 22 26 / 0.14);

  --shadow-1: 0 1px 2px rgb(16 16 20 / 0.06), 0 1px 1px rgb(16 16 20 / 0.04);
  --shadow-2: 0 4px 12px rgb(16 16 20 / 0.08), 0 1px 3px rgb(16 16 20 / 0.06);
  --shadow-3: 0 16px 48px rgb(16 16 20 / 0.16), 0 2px 8px rgb(16 16 20 / 0.08);

  --side-w: 268px;
  --doc-w: 46rem;
  --rail: 3.25rem;
  --r-sm: 6px;
  --r: 9px;
  --r-lg: 14px;

  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
  --serif: ui-serif, Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
  --body: var(--sans);

  --tap: 180ms cubic-bezier(0.22, 0.61, 0.36, 1);
  --tick: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fbfbfc' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5 9 17l10.5-11'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;

    --bg: #131315;
    --bg-sub: #0d0d0f;
    --surface: #1c1c20;
    --surface-2: #26262b;
    --surface-3: #303036;
    --line: #232328;
    --line-2: #32323a;
    --line-3: #4a4a54;

    --text: #f2f2f4;
    --text-2: #a4a4b0;
    --text-3: #6f6f7b;
    --text-4: #4c4c56;

    --flip-bg: #f2f2f4;
    --flip-text: #131315;

    --ring: #d8d8e0;
    --select: rgb(220 220 232 / 0.18);

    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.5);
    --shadow-2: 0 4px 14px rgb(0 0 0 / 0.55), 0 1px 3px rgb(0 0 0 / 0.4);
    --shadow-3: 0 18px 56px rgb(0 0 0 / 0.7), 0 2px 10px rgb(0 0 0 / 0.5);
  --tick: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23131315' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5 9 17l10.5-11'/%3E%3C/svg%3E");
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #131315;
  --bg-sub: #0d0d0f;
  --surface: #1c1c20;
  --surface-2: #26262b;
  --surface-3: #303036;
  --line: #232328;
  --line-2: #32323a;
  --line-3: #4a4a54;

  --text: #f2f2f4;
  --text-2: #a4a4b0;
  --text-3: #6f6f7b;
  --text-4: #4c4c56;

  --flip-bg: #f2f2f4;
  --flip-text: #131315;

  --ring: #d8d8e0;
  --select: rgb(220 220 232 / 0.18);

  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.5);
  --shadow-2: 0 4px 14px rgb(0 0 0 / 0.55), 0 1px 3px rgb(0 0 0 / 0.4);
  --shadow-3: 0 18px 56px rgb(0 0 0 / 0.7), 0 2px 10px rgb(0 0 0 / 0.5);
  --tick: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23131315' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 12.5 9 17l10.5-11'/%3E%3C/svg%3E");
}

:root[data-font='serif'] { --body: var(--serif); }
:root[data-font='mono'] { --body: var(--mono); }

/* ---------------------------------------------------------------- base */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

::selection { background: var(--select); }

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
  border-radius: 4px;
}

a { color: inherit; }

button { font: inherit; color: inherit; }

h1, h2, h3, p, dl, dd { margin: 0; }

kbd {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  padding: 2px 6px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-2);
  white-space: nowrap;
}

/* A quiet, thin scrollbar — the content is the only thing that should draw the eye. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-3) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: transparent;
  border: 3px solid transparent;
  border-radius: 10px;
  background-clip: content-box;
}
*:hover::-webkit-scrollbar-thumb { background: var(--line-3); background-clip: content-box; }

.booting { opacity: 0; }
.grow { flex: 1; }
.muted { color: var(--text-2); }

/* ---------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--tap), border-color var(--tap), color var(--tap);
}
.btn:hover { background: var(--surface); border-color: var(--line-3); }
.btn:active { background: var(--surface-2); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { min-height: 27px; padding: 0 9px; font-size: 12.5px; border-radius: var(--r-sm); }

.btn-solid {
  background: var(--flip-bg);
  border-color: var(--flip-bg);
  color: var(--flip-text);
}
.btn-solid:hover { background: var(--text); border-color: var(--text); opacity: 0.9; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--tap), color var(--tap);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { background: var(--surface-3); }

.input {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: 2px solid var(--ring); outline-offset: -1px; border-color: transparent; }

.tag {
  padding: 1px 7px;
  border: 1px solid var(--line-2);
  border-radius: 100px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.avatar {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 100px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  user-select: none;
}

/* ---------------------------------------------------------------- shell */

.shell {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  /* The row has to be told to fit, or it sizes to the tallest note and pushes the sidebar
     and the scroller straight off the bottom of the window. */
  grid-template-rows: minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
:root[data-sidebar='closed'] .shell { grid-template-columns: 0 minmax(0, 1fr); }

.scrim { display: none; }

.gate {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  height: 100dvh;
  padding: 24px;
  text-align: center;
}
.gate h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.gate p { max-width: 34ch; color: var(--text-2); }
.gate .btn { text-decoration: none; }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-sub);
  border-right: 1px solid var(--line);
}
.sidebar > * { min-width: var(--side-w); }

.side-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 6px 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text-2);
}

.side-search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 2px 10px 8px;
}
.side-search > svg {
  position: absolute;
  left: 9px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input {
  width: 100%;
  min-height: 32px;
  padding: 5px 10px 5px 30px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--text-3); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-input:focus { outline: none; border-color: var(--line-3); background: var(--bg); }

.side-actions {
  display: flex;
  gap: 6px;
  padding: 0 10px 10px;
}
.side-actions .grow { flex: 1; }

.note-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 8px 10px;
}

.list-head {
  padding: 14px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: var(--text-3);
}
.list-head:first-child { padding-top: 4px; }

.note-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 8px;
  border-radius: var(--r);
  color: var(--text-2);
  text-decoration: none;
  cursor: default;
  transition: background var(--tap), color var(--tap);
}
.note-row:hover { background: var(--surface); color: var(--text); }
.note-row.on { background: var(--surface-2); color: var(--text); }
.note-row.archived .row-title { color: var(--text-3); }

.row-icon {
  display: grid;
  place-items: center;
  width: 18px;
  flex: 0 0 auto;
  color: var(--text-3);
}
.note-row.on .row-icon { color: var(--text-2); }
.row-emoji { font-size: 15px; line-height: 1; }

.row-main { flex: 1; min-width: 0; display: grid; }
.row-title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-row.on .row-title { font-weight: 600; }
.row-snippet {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta {
  flex: 0 0 auto;
  font-size: 11.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.row-more {
  position: absolute;
  right: 4px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  opacity: 0;
  cursor: pointer;
  transition: opacity var(--tap), background var(--tap);
}
.row-more:hover { background: var(--surface-3); color: var(--text); }
@media (hover: hover) {
  .note-row:hover .row-more, .note-row:focus-within .row-more { opacity: 1; }
  .note-row:hover .row-meta { opacity: 0; }
}
@media (hover: none) {
  .row-more { opacity: 1; background: transparent; }
  .row-meta { margin-right: 22px; }
}

.list-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-3);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--tap), color var(--tap);
}
.list-toggle:hover { background: var(--surface); color: var(--text-2); }

.empty {
  display: grid;
  justify-items: start;
  gap: 10px;
  padding: 20px 8px;
  color: var(--text-3);
  font-size: 13px;
}

.side-foot {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.who {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 4px 6px 4px 4px;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--tap);
}
.who:hover { background: var(--surface); }
.who-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who > svg:last-child { color: var(--text-3); }

/* ---------------------------------------------------------------- main */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 46px;
  flex: 0 0 auto;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid transparent;
  background: var(--bg);
  transition: border-color var(--tap);
}
.topbar.scrolled { border-bottom-color: var(--line); }

.show-side { display: none; }
:root[data-sidebar='closed'] .show-side { display: inline-flex; }

.crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.crumb-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background var(--tap);
}
.crumb-icon:hover { background: var(--surface-2); color: var(--text-2); }
.crumb-title {
  font-size: 13.5px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  padding: 0 8px;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  transition: color var(--tap), opacity var(--tap);
}
.status-saved { opacity: 0.55; }
.status-error { color: var(--text); font-weight: 550; opacity: 1; }

.doc-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-padding-block: 90px;
}

/* ---------------------------------------------------------------- document */

.doc {
  max-width: calc(var(--doc-w) + var(--rail) * 2);
  margin: 0 auto;
  padding: 28px var(--rail) 0;
  font-family: var(--body);
}
.doc.is-archived { opacity: 0.82; }

.doc-head { margin-bottom: 20px; }

.doc-title {
  position: relative;
  font-family: var(--body);
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.16;
  letter-spacing: -0.021em;
  text-wrap: balance;
  outline: none;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 10px;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--text-3);
}
.meta-item { display: inline-flex; align-items: center; gap: 5px; }

.doc-tail { min-height: 34vh; cursor: text; }

.read-only .blk-body, .read-only .doc-title { caret-color: transparent; }

/* ---------------------------------------------------------------- the document */

.doc-body { position: relative; }

.prose { outline: none; }
.prose > * { margin: 0; position: relative; }
.prose > * + * { margin-top: 0.14em; }

.prose p { line-height: 1.65; }

.prose h1, .prose h2, .prose h3 {
  font-weight: 660;
  letter-spacing: -0.014em;
  line-height: 1.28;
}
.prose > h1 { font-size: 1.62em; margin-top: 1.5em; }
.prose > h2 { font-size: 1.3em; margin-top: 1.25em; }
.prose > h3 { font-size: 1.08em; margin-top: 1em; }
.prose > :first-child { margin-top: 0; }

.prose a {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  cursor: pointer;
}
.prose a:hover { text-decoration-color: var(--text-3); }

.prose code {
  padding: 0.12em 0.34em;
  border-radius: 4px;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.87em;
  font-variant-ligatures: none;
}

/* lists */
.prose ul, .prose ol { padding-left: 1.4em; margin: 0; }
.prose li { line-height: 1.65; }
.prose li > p { margin: 0; }
.prose li > ul, .prose li > ol, .prose li > ul[data-type='taskList'] { margin-top: 0.14em; }
.prose ul { list-style: disc; }
.prose ul ul { list-style: circle; }
.prose ul ul ul { list-style: square; }
.prose ol { list-style: decimal; }
.prose ol ol { list-style: lower-alpha; }
.prose li::marker { color: var(--text-3); font-size: 0.9em; }

/* to-dos */
.prose ul[data-type='taskList'] { list-style: none; padding-left: 0; }
.prose ul[data-type='taskList'] ul[data-type='taskList'] { padding-left: 1.55em; }
.prose ul[data-type='taskList'] > li {
  display: flex;
  align-items: flex-start;
  gap: 0.55em;
}
.prose ul[data-type='taskList'] > li > label {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  height: 1.65em;
  user-select: none;
}
.prose ul[data-type='taskList'] > li > div { flex: 1; min-width: 0; }
.prose ul[data-type='taskList'] > li input[type='checkbox'] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid var(--line-3);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  transition: background var(--tap), border-color var(--tap);
}
.prose ul[data-type='taskList'] > li input[type='checkbox']:hover {
  border-color: var(--text-3);
  background: var(--surface-2);
}
.prose ul[data-type='taskList'] > li input[type='checkbox']:checked {
  background: var(--flip-bg) var(--tick) center / 11px no-repeat;
  border-color: var(--flip-bg);
}
.prose ul[data-type='taskList'] > li[data-checked='true'] > div {
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: var(--text-4);
}

/* quote, callout, code */
.prose blockquote {
  margin: 0.5em 0;
  padding-left: 0.95em;
  border-left: 2.5px solid var(--line-3);
  color: var(--text-2);
  font-style: italic;
}
.prose blockquote p + p { margin-top: 0.4em; }

.prose [data-type='callout'] {
  margin: 0.7em 0;
  padding: 0.7em 0.9em;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
}

.prose pre {
  margin: 0.7em 0;
  padding: 0.8em 1em;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  font-family: var(--mono);
  font-size: 0.85em;
  line-height: 1.6;
  white-space: pre-wrap;
  tab-size: 2;
  font-variant-ligatures: none;
  overflow-x: auto;
}
.prose pre code { padding: 0; background: none; font-size: inherit; }

.prose hr {
  height: 1px;
  margin: 0.9em 0;
  border: 0;
  background: var(--line-2);
}

/* images */
.prose .figure { margin: 0.6em 0; }
.prose .figure img {
  display: block;
  width: 100%;
  border-radius: var(--r);
  border: 1px solid var(--line);
  cursor: zoom-in;
}
.prose .figure.size-small { max-width: 220px; }
.prose .figure.size-medium { max-width: 420px; }
.prose .figure.size-large { max-width: 100%; }
.prose .figure.size-full {
  max-width: none;
  width: calc(100% + var(--rail) * 2);
  margin-left: calc(var(--rail) * -1);
}
.prose .figure.size-full img { border-radius: 0; border-left: 0; border-right: 0; }
.prose .caption {
  margin-top: 6px;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--text-3);
  outline: none;
}

/* what ProseMirror puts on a selected node */
.prose .ProseMirror-selectednode {
  outline: 2px solid var(--line-3);
  outline-offset: 3px;
  border-radius: 4px;
}

.read-only .prose { caret-color: transparent; }
.read-only .prose ul[data-type='taskList'] > li input { pointer-events: none; }

/* the handle in the margin */
.blk-rail {
  position: absolute;
  right: 100%;
  top: 0;
  display: flex;
  align-items: center;
  height: 1.7em;
  padding-right: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tap);
}
.blk-rail.on { opacity: 1; pointer-events: auto; }
.rail-btn {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-4);
  cursor: pointer;
  transition: background var(--tap), color var(--tap);
}
.rail-btn:hover { background: var(--surface-2); color: var(--text-2); }
.rail-btn[draggable='true'] { cursor: grab; }
.rail-btn[draggable='true']:active { cursor: grabbing; }
.read-only .blk-rail { display: none; }
@media (hover: none) { .blk-rail { display: none; } }

.ProseMirror-gapcursor:after { border-top-color: var(--text-2); }

/* ---------------------------------------------------------------- layers */

#layers { position: relative; z-index: 60; }

.layer {
  position: fixed;
  z-index: 70;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--bg);
  box-shadow: var(--shadow-3);
  animation: pop 140ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.layer.leaving { opacity: 0; transform: scale(0.98); transition: opacity 110ms, transform 110ms; }

@keyframes pop {
  from { opacity: 0; transform: scale(0.97) translateY(-3px); }
  to { opacity: 1; transform: none; }
}

.menu {
  min-width: 210px;
  max-width: 300px;
  padding: 5px;
  font-family: var(--sans);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background var(--tap);
}
.menu-item:hover:not(:disabled) { background: var(--surface-2); }
.menu-item:disabled { opacity: 0.4; cursor: not-allowed; }
.menu-item > svg { flex: 0 0 auto; color: var(--text-3); }
.menu-item.on > svg:last-child { color: var(--text); }
.menu-item.danger { color: var(--text); }
.menu-item.danger:hover { background: var(--flip-bg); color: var(--flip-text); }
.menu-item.danger:hover > svg { color: var(--flip-text); }
.menu-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-hint { color: var(--text-3); font-size: 11.5px; letter-spacing: 0.02em; }
.menu-gap { width: 16px; flex: 0 0 auto; }
.menu-rule { height: 1px; margin: 5px 4px; background: var(--line); }
.menu-heading {
  padding: 8px 8px 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.has-sub > svg:last-child { color: var(--text-4); }

.popover { padding: 8px; font-family: var(--sans); }
.popover.wide { width: min(420px, calc(100vw - 24px)); }

.link-form { display: flex; gap: 6px; width: min(340px, calc(100vw - 32px)); }
.link-form .input { min-height: 28px; font-size: 13px; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  width: 280px;
}
.emoji {
  display: grid;
  place-items: center;
  height: 32px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 17px;
  cursor: pointer;
  transition: background var(--tap);
}
.emoji:hover { background: var(--surface-2); }
.emoji-none { color: var(--text-3); }

.slash-list {
  width: 244px;
  max-height: 306px;
  overflow-y: auto;
  font-family: var(--sans);
}
.slash-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.slash-item.on { background: var(--surface-2); }
.slash-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text-2);
}

/* the selection toolbar */
.toolbar {
  position: fixed;
  z-index: 75;
  display: flex;
  gap: 1px;
  padding: 3px;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  background: var(--bg);
  box-shadow: var(--shadow-3);
  opacity: 0;
  pointer-events: none;
  transform: translateY(3px);
  transition: opacity 120ms, transform 120ms;
}
.toolbar.on { opacity: 1; pointer-events: auto; transform: none; }
.fmt-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--tap), color var(--tap);
}
.fmt-btn:hover { background: var(--surface-2); color: var(--text); }
.fmt-btn.on { background: var(--flip-bg); color: var(--flip-text); }

/* ---------------------------------------------------------------- dialogs */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(10 10 12 / 0.4);
  backdrop-filter: blur(2px);
  animation: fade 140ms ease;
}
.backdrop.leaving { opacity: 0; transition: opacity 140ms; }
@keyframes fade { from { opacity: 0; } }

.dialog {
  display: grid;
  gap: 12px;
  width: min(400px, 100%);
  padding: 20px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--bg);
  box-shadow: var(--shadow-3);
  animation: rise 160ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(6px) scale(0.99); } }
.dialog-title { font-size: 15.5px; font-weight: 620; letter-spacing: -0.008em; }
.dialog-body { color: var(--text-2); font-size: 13.5px; line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }

.lightbox { cursor: zoom-out; background: rgb(10 10 12 / 0.82); }
.lightbox img { max-width: 100%; max-height: 92dvh; border-radius: var(--r); box-shadow: var(--shadow-3); }
.lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 100px;
  background: rgb(255 255 255 / 0.12);
  color: #fff;
  cursor: pointer;
}
.lightbox-close:hover { background: rgb(255 255 255 / 0.2); }

/* the info sheet */
.sheet {
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  max-height: min(82dvh, 760px);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--bg);
  box-shadow: var(--shadow-3);
  animation: rise 180ms cubic-bezier(0.22, 0.61, 0.36, 1);
  overflow: hidden;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 20px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { font-size: 15px; font-weight: 650; }
.sheet-tabs { display: flex; gap: 2px; flex: 1; }
.sheet-tab {
  padding: 5px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--tap), color var(--tap);
}
.sheet-tab:hover { background: var(--surface); color: var(--text-2); }
.sheet-tab.on { background: var(--surface-2); color: var(--text); }
.sheet-content { overflow-y: auto; padding: 20px 24px 28px; }

.info-body { display: grid; gap: 12px; font-size: 13.5px; line-height: 1.62; color: var(--text-2); max-width: 62ch; }
.info-body .lede { font-size: 15px; color: var(--text); font-weight: 500; }
.info-body h3 {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
}
.info-body code { font-family: var(--mono); font-size: 0.9em; }
.info-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0; }

.code-sample {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}

.api-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.api-table td { padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.api-table td:first-child { white-space: nowrap; width: 1%; }
.api-table code { font-size: 11.5px; color: var(--text); }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: baseline; }
.keys dt { justify-self: start; }

.token-list { display: grid; gap: 6px; }
.token-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.token-main { flex: 1; min-width: 0; display: grid; }
.token-name { font-size: 13px; font-weight: 550; color: var(--text); }
.token-meta { font-size: 11.5px; color: var(--text-3); }

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 90;
  display: grid;
  gap: 8px;
  justify-items: center;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 9px 14px;
  border-radius: 100px;
  background: var(--flip-bg);
  color: var(--flip-text);
  font-family: var(--sans);
  font-size: 13px;
  box-shadow: var(--shadow-3);
  pointer-events: auto;
  animation: toast-in 220ms cubic-bezier(0.22, 0.61, 0.36, 1);
}
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 180ms, transform 180ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.toast-action {
  padding: 2px 8px;
  border: 1px solid currentColor;
  border-radius: 100px;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
  opacity: 0.85;
}
.toast-action:hover { opacity: 1; }

/* ---------------------------------------------------------------- narrow */

@media (max-width: 860px) {
  :root { --rail: 1.25rem; }

  .shell { grid-template-columns: minmax(0, 1fr); }
  :root[data-sidebar='closed'] .shell { grid-template-columns: minmax(0, 1fr); }

  /* The sidebar becomes a sheet over the note rather than a column beside it — there is no
     bottom bar and no second navigation, only these two surfaces. */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(84vw, 320px);
    border-right: 1px solid var(--line-2);
    box-shadow: var(--shadow-3);
    transform: translateX(-102%);
    transition: transform 240ms cubic-bezier(0.22, 0.61, 0.36, 1);
    padding-top: env(safe-area-inset-top);
  }
  .sidebar > * { min-width: 0; }
  :root[data-sidebar='open'] .sidebar { transform: none; }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: block;
    background: rgb(10 10 12 / 0.36);
    opacity: 0;
    pointer-events: none;
    transition: opacity 240ms;
  }
  :root[data-sidebar='open'] .scrim { opacity: 1; pointer-events: auto; }

  .show-side, :root[data-sidebar='closed'] .show-side { display: inline-flex; }
  .topbar { padding-top: env(safe-area-inset-top); height: calc(46px + env(safe-area-inset-top)); }
  .doc { padding-top: 18px; }
  .doc-title { font-size: 1.7rem; }
  .figure.size-full { width: 100%; margin-left: 0; }
  .figure.size-full img { border-radius: var(--r); border-left-width: 1px; border-right-width: 1px; }
  .sheet { max-height: 88dvh; }
  .sheet-head { padding-left: 16px; flex-wrap: wrap; }
  .sheet-content { padding: 16px; }
}

@media (max-width: 480px) {
  .sheet-head h2 { display: none; }
  .keys { grid-template-columns: 1fr; gap: 2px 0; }
  .keys dd { margin-bottom: 8px; }
}

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