/* Color palettes. These tokens also drive the swatches in Appearance. */
:root,
.theme-sample[data-theme-sample="blue"] {
  --ink: #f6f2e7;
  --ink-muted: #ccd6ed;
  --ink-faint: #9db0da;
  --surface-panel: #20386f;
  --surface-page: #2f52a0;
  --surface-hover: #385db1;
  --surface-header: rgba(32, 56, 111, 0.96);
  --dialog-backdrop: rgb(10 25 55 / 65%);
  --surface-sidebar: rgba(31, 65, 139, 0.23);
  --surface-editor: rgba(20, 36, 76, 0.97);
  --surface-card-hover: rgba(29, 65, 145, 0.27);
  --surface-card-selected: rgba(52, 94, 182, 0.42);
  --page-wash:
    radial-gradient(circle at 78% 5%, rgba(109, 139, 210, 0.2), transparent 29rem),
    radial-gradient(circle at 8% 72%, rgba(21, 56, 132, 0.28), transparent 36rem),
    var(--surface-page);
  --surface-tint: 255 255 255;
  --focus-tint: 248 244 233;
  --focus-color: #f8f4e9;
  --highlight-fill: #f8f4e9;
  --highlight-ink: #273d74;
  --block-label-tint: #e5def7;
  --nested-label-fill: #dceade;
  --deep-label-fill: #eee2cf;
  --link-ink: var(--ink);
  --link-line: rgb(var(--focus-tint) / 0.55);
  --error-ink: var(--focus-color);
  --status-tint: 168 199 189;
  --preview-active-fill: white;
  --preview-active-ink: #20386f;
  --completed-opacity: 0.62;
  --line: rgba(220, 230, 255, 0.2);
  --line-strong: rgba(235, 240, 255, 0.42);
  --glass: rgba(24, 54, 122, 0.18);
  --card-shadow: 0 10px 35px rgba(18, 41, 98, 0.1);
  --selected-card-shadow: 0 12px 38px rgba(18, 41, 98, 0.2);
  --menu-shadow: 0 12px 32px rgba(13, 32, 82, 0.4);
  --editor-shadow: 0 22px 60px rgba(13, 32, 82, 0.38);
  --toast-shadow: 0 14px 42px rgba(9, 27, 70, 0.38);
}

:root[data-theme="paper"],
.theme-sample[data-theme-sample="paper"] {
  --ink: #25376b;
  --ink-muted: #435575;
  --ink-faint: #566580;
  --surface-panel: #fffef9;
  --surface-page: #faf9f4;
  --surface-hover: #e5ebf7;
  --surface-header: rgba(252, 251, 246, 0.97);
  --dialog-backdrop: rgb(37 55 107 / 24%);
  --surface-sidebar: #f4f2e9;
  --surface-editor: #fffef9;
  --surface-card-hover: #f3f5fa;
  --surface-card-selected: #ebf0fa;
  --page-wash: var(--surface-page);
  --surface-tint: 37 55 107;
  --focus-tint: 49 76 155;
  --focus-color: #314c9b;
  --highlight-fill: #e2e9f8;
  --highlight-ink: #25376b;
  --block-label-tint: #e9edf9;
  --nested-label-fill: #e5eee7;
  --deep-label-fill: #f3e9d9;
  --link-ink: #314c9b;
  --link-line: #5268a2;
  --card-link-ink: var(--link-ink);
  --error-ink: #8b302b;
  --status-tint: 46 110 85;
  --preview-active-fill: var(--highlight-fill);
  --preview-active-ink: var(--highlight-ink);
  --completed-opacity: 0.86;
  --line: #bfc6d6;
  --line-strong: #7c8bab;
  --glass: #fdfcf7;
  --card-shadow: none;
  --selected-card-shadow: 0 8px 24px rgba(37, 55, 107, 0.07);
  --menu-shadow: 0 12px 30px rgba(37, 55, 107, 0.16);
  --editor-shadow: 0 20px 48px rgba(37, 55, 107, 0.14);
  --toast-shadow: 0 10px 30px rgba(37, 55, 107, 0.18);
}

:root {
  --block-label-radius: 4px;
  --card-title-size: 16px;
  --card-heading-size: 15px;
  --reading-measure: 68ch;
  --reading-column: 42rem;
  --heading-follow: 4px;
  --passage-gap: 8px;
  --section-gap: 16px;
  --sidebar-width: 260px;
  --workspace-gutter: clamp(24px, 4vw, 64px);
  --topbar-font-size: 14px;
  --nav-control-height: 40px;
  --command-height: var(--nav-control-height);
  --breadcrumb-height: 24px;
  --header-height: calc(var(--command-height) + var(--heading-follow) + var(--breadcrumb-height)
    + 2 * var(--passage-gap) + 1px + var(--stacked-nav-row, 0px));
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.codex-panel, .codex-dialog {
  color: var(--ink);
  background: var(--surface-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 18px;
  overflow-wrap: anywhere;
}
.codex-panel { margin-top: 18px; }
.codex-dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.codex-dialog::backdrop { background: var(--dialog-backdrop); }
.codex-panel label, .codex-dialog label { display: block; margin: 10px 0 6px; }
.codex-panel input, .codex-panel textarea, .codex-dialog input {
  width: 100%; min-width: 0; padding: 10px; border: 1px solid var(--line-strong);
  border-radius: 6px; color: var(--ink); background: var(--glass);
}
.codex-panel textarea { resize: vertical; }
.codex-settings { margin-bottom: 16px; }
.codex-settings-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; gap: 10px; }
.codex-settings-fields > div { min-width: 0; }
.codex-panel select { width: 100%; min-width: 0; padding: 9px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); background: var(--surface-panel); }
.codex-settings button { padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--highlight-fill); color: var(--highlight-ink); }
.codex-settings button:disabled { opacity: .6; }
.codex-settings p { margin: 8px 0 0; overflow-wrap: anywhere; }
#codex-settings-error:empty, #codex-permissions-error:empty { display: none; }
@media (max-width: 480px) { .codex-settings-fields { grid-template-columns: minmax(0, 1fr); } .codex-settings-fields > button { justify-self: start; } }
.codex-panel input[type="checkbox"] { width: auto; }
.codex-panel p, .codex-dialog p { font-size: 14px; }
.codex-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.codex-buttons button, #codex-existing-find { padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--highlight-fill); color: var(--highlight-ink); }
.codex-buttons button:disabled, #codex-existing-find:disabled { opacity: .6; cursor: wait; }
.note-action-button {
  max-width: 100%; padding: .35em .8em; overflow-wrap: anywhere;
  color: var(--highlight-ink); background: var(--highlight-fill);
  border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer;
}
.note-action-button:disabled { opacity: .65; cursor: wait; }
.note-button-error { overflow-wrap: anywhere; }
.note-field {
  display: block; max-width: 32rem; font: inherit;
}
.note-field :is(input, select) {
  display: block; box-sizing: border-box; width: 100%; min-width: 0;
  margin-top: 5px; padding: 9px 10px; color: var(--ink); background: var(--surface-panel);
  border: 1px solid var(--line-strong); border-radius: 6px; font: inherit;
}

/* Keep the old dialog's proportions inside the normal, editable page shell. */
.publishing-page .collection {
  box-sizing: border-box; width: min(520px, 100%); margin: 18px auto;
  padding: 18px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-panel); color: var(--ink);
}
.publishing-page #page-context { padding: 0; margin: 20px 0; border: 0; }
.publishing-page #page-title { font: 700 24px/1.2 var(--sans); }
.publishing-page #block-grid { display: block; padding-inline: 0; }
.publishing-page #block-grid > .page-text-line { font: 14px/1.5 var(--sans); margin: 8px 0; padding: 0; }
.publishing-page [data-pcloud-slot] { min-width: 0; }
.publishing-page [data-control] label, .publishing-page label[data-control] { display: block; }
.publishing-page [data-control] label, .publishing-page .note-field, .publishing-page summary { font-size: 16px; }
.publishing-page [data-control] :is(input, select) {
  display: block; width: 100%; min-width: 0; margin-top: 5px; padding: 9px 10px;
  background: var(--glass); border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); font: inherit;
}
.publishing-page [data-control] select { background: var(--surface-panel); }
.publishing-page .note-field input { background: var(--glass); }
.publishing-page #pcloud-error:empty { display: none; }
.publishing-page [data-control] p { margin: 6px 0; }
.publishing-page #block-grid > .page-text-line[data-text-kind="button"] {
  display: inline-block; width: auto; margin: 14px 9px 0 0;
}
.publishing-page .note-action-button { padding: 8px 14px; font-size: 16px; }
.publishing-page #block-grid > .pcloud-field-row {
  margin: 0 2px; padding: 4px 12px; border-inline: 2px groove var(--line-strong);
}
.publishing-page #block-grid > .pcloud-legend {
  padding-top: 0; border-top: 2px groove var(--line-strong); margin-top: 18px;
}
.publishing-page .pcloud-legend > :is(h2,h3,h4) {
  display: table; margin-top: -.75em; padding: 0 4px; background: var(--surface-panel);
  font: 400 16px/1.5 var(--sans);
}
.publishing-page #block-grid > .pcloud-field-end { border-bottom: 2px groove var(--line-strong); padding-bottom: 18px; }
.publishing-page #block-grid.pcloud-unavailable > :is(.pcloud-field-row, .pcloud-connect-row) { display: none; }
.codex-request { margin: 12px 0; border: 1px solid var(--line-strong); padding: 12px; border-radius: 6px; }
.codex-request pre { overflow: auto; max-height: 240px; white-space: pre-wrap; overflow-wrap: anywhere; }
#codex-create-error, #pcloud-error { color: var(--error-ink); }
.codex-dialog select { width: 100%; min-width: 0; padding: 9px; color: var(--ink); background: var(--surface-panel); border: 1px solid var(--line-strong); border-radius: 6px; }
#codex-existing-find { margin-top: 8px; padding: 6px 10px; }
#codex-existing-help { overflow-wrap: anywhere; }
.codex-live-reply { margin: 14px 0; padding: 16px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--glass); }
.codex-live-reply .card-content { margin-top: 12px; }
.codex-update { border-left: 2px solid var(--line-strong); margin: 8px 0; padding: 6px 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.codex-update.is-streaming { color: var(--ink-muted); }
.cloud-import-choice { display: flex !important; align-items: flex-start; gap: 8px; padding: 8px 0; overflow-wrap: anywhere; }
.cloud-import-choice input { width: auto !important; margin-top: 4px; }

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--surface-page);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--page-wash);
  font-family: var(--sans);
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: grid;
  grid-template: var(--header-height) 1fr / var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

@media (max-width: 650px) {
  :root {
    --stacked-nav-row: calc(var(--nav-control-height) + var(--passage-gap));
    --workspace-gutter: 16px;
  }
}


.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) auto;
  align-items: start;
  min-height: var(--header-height);
  padding-block: var(--passage-gap);
  padding-inline-end: var(--workspace-gutter);
  background: var(--surface-header);
  border-bottom: 1px solid rgb(var(--surface-tint) / 0.05);
  backdrop-filter: blur(18px);
  font-size: var(--topbar-font-size);
}


.topbar-navigation {
  display: flex;
  padding-inline-start: var(--section-gap);
  gap: var(--passage-gap);
  align-items: center;
}

.topbar-navigation svg {
  display: block;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-message {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-self: center;
  min-height: var(--nav-control-height);
  margin-inline-start: 24px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}


.status-dot {
  width: 6px;
  height: 6px;
  background: rgb(var(--status-tint));
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgb(var(--status-tint) / 0.08);
}

.block-sidebar {
  position: sticky;
  top: var(--header-height);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
  padding: 24px var(--section-gap);
  overflow: hidden;
  background: var(--surface-sidebar);
  border-right: 1px solid var(--line);
}

.block-navigation {
  display: grid;
  align-content: start;
  gap: var(--heading-follow);
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* A new section starts a fresh group after the previous section's block links. */
@media (min-width: 651px) {
  .block-navigation-button + .document-outline-button { margin-block-start: var(--passage-gap); }
}

:is(.block-navigation-button, .document-outline-button) {
  width: 100%;
  min-height: 32px;
  padding: 6px 11px;
  overflow: hidden;
  color: var(--ink-muted);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 13px;
  line-height: 1.4;
}

/* Hover is a cue for where the pointer is, separate from the current row. */
:is(.block-navigation-button, .document-outline-button):hover {
  color: var(--ink);
  text-decoration: underline;
}

:is(.block-navigation-button, .document-outline-button)[aria-current="location"] {
  color: var(--ink);
  background: rgb(var(--surface-tint) / 0.08);
  border-color: var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--ink-faint);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.17em;
  text-transform: uppercase;
}

.workspace {
  position: relative;
  min-width: 0;
  padding: 0 var(--workspace-gutter) 28px;
}

.recycle-bin-action {
  padding: 6px 10px;
  color: var(--highlight-ink);
  background: var(--highlight-fill);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
}
.recycle-bin-action:disabled { opacity: 0.6; }


.document-workspace {
  min-width: 0;
  height: auto;
  overflow: visible;
}


.document-content-editor {
  display: block;
  width: 100%;
  min-height: 200px;
  padding: 0;
  overflow: hidden;
  resize: none;
  color: var(--ink);
  caret-color: var(--focus-color);
  background: transparent;
  border: 0;
  outline: 0;
  font: 15px/1.5 var(--sans);
  tab-size: 2;
}

.document-content-editor:focus-visible {
  outline: 0;
  box-shadow: inset 3px 0 0 rgb(var(--focus-tint) / 0.42);
}

.document-content-editor::placeholder {
  color: var(--ink-faint);
  opacity: 0.72;
}

.document-view-controls button,
#block-full-edit-button {
  padding: 5px 9px;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  font: inherit;
  cursor: pointer;
}


.document-view-controls {
  display: flex;
  flex: 0 0 56px;
  width: 56px;
  height: var(--nav-control-height);
  padding: 3px;
  gap: 2px;
  color: var(--ink-muted);
  cursor: pointer;
  background: var(--surface-panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.document-view-controls > span {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
}

.header-command {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--heading-follow);
  min-width: 0;
  max-inline-size: var(--reading-column);
  margin-inline-start: var(--workspace-gutter);
}
.header-command .page-command-fields { flex: 0 0 auto; min-width: 0; }
.header-path {
  display: flex;
  align-items: end;
  gap: var(--passage-gap);
}

.notification-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  height: var(--breadcrumb-height);
  padding-inline: var(--passage-gap);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: var(--glass);
}

@media (min-width: 651px) {
  /* Share the breadcrumb row while sitting under the navigation controls. */
  .notification-toggle {
    position: absolute;
    inset-inline-start: calc(var(--section-gap) - var(--sidebar-width) - var(--workspace-gutter));
    inset-block-end: 0;
  }
}

.notification-toggle:hover,
.notification-toggle[aria-expanded="true"] { background: var(--surface-hover); }

.notification-dot {
  visibility: hidden;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--focus-color);
}

.notification-toggle[data-unread] .notification-dot { visibility: visible; }

.page-breadcrumbs {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: var(--heading-follow);
  min-height: var(--breadcrumb-height);
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: thin;
}
.page-breadcrumbs a {
  display: inline-flex;
  align-items: center;
  min-height: var(--breadcrumb-height);
  color: var(--ink-muted);
  text-decoration: none;
}
.page-breadcrumbs a:hover { text-decoration: underline; }
.page-breadcrumbs a:focus-visible { outline-offset: -2px; }
.page-breadcrumbs a[aria-current="page"] { color: var(--ink); }
.breadcrumb-separator {
  flex: 0 0 auto;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  color: var(--ink-muted);
  background: transparent;
  line-height: 20px;
}
.breadcrumb-separator:hover,
.breadcrumb-separator[aria-expanded="true"] {
  color: var(--ink);
  background: rgb(var(--surface-tint) / 0.1);
}

.document-view-controls[aria-pressed="false"] #page-preview-mode,
.document-view-controls[aria-pressed="true"] .document-edit-label {
  color: var(--highlight-ink);
  background: var(--highlight-fill);
}


.document-preview-list {
  margin: 0;
  padding-left: 1.35em;
}

.document-preview-list li {
  margin: 0;
  padding-left: 0.15em;
}

.document-preview-list li::marker {
  color: var(--ink-muted);
}

.document-preview-spacer {
  height: 1lh;
}

.document-preview-spacer + h2,
.document-preview-spacer + h3,
.document-preview-spacer + h4 {
  margin-top: 0;
}

.markdown-link {
  color: var(--link-ink);
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
  text-decoration-skip-ink: auto;
}

.markdown-link:hover {
  text-decoration-color: currentColor;
}

.card-content :is(strong, b),
.page-text-line :is(strong, b),
.block-line-preview strong { color: var(--ink); font-weight: 700; }

.card-content code,
.page-text-line code,
.block-line-preview code {
  padding: 0.08em 0.3em;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}

.markdown-code {
  max-width: 100%;
  margin: 8px 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  tab-size: 2;
}

.markdown-code > code {
  padding: 0;
  border: 0;
  font-size: inherit;
  overflow-wrap: normal;
}

.markdown-file-reference { border-bottom: 1px dotted var(--line-strong); }
.markdown-file-reference code { font-size: 0.8em; color: var(--ink-faint); }

.markdown-table-scroll, .markdown-diagram {
  max-width: 100%;
  min-width: 0;
  margin: 10px 0;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.markdown-table {
  width: 100%;
  min-width: 540px;
  border-collapse: collapse;
  font-size: 0.9em;
  line-height: 1.5;
}

.markdown-table th, .markdown-table td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  vertical-align: top;
}

.markdown-table th { color: var(--ink); font-weight: 700; }
.markdown-align-left { text-align: left; }
.markdown-align-center { text-align: center; }
.markdown-align-right { text-align: right; }

.markdown-diagram svg {
  display: block;
  width: 100%;
  min-width: 640px;
  max-height: 500px;
  color: var(--ink-muted);
  font-family: var(--sans);
  font-size: 14px;
}

.markdown-diagram :is(path, rect, ellipse) { fill: none; stroke: currentColor; stroke-width: 1.4; }
.markdown-diagram .markdown-node { fill: var(--surface-page); }
.markdown-diagram text { fill: var(--ink); stroke: none; }
.markdown-diagram .markdown-edge-label { font-size: 11px; }

.card-content .markdown-link {
  color: var(--card-link-ink, inherit);
}

.title-page-link {
  display: inline-block;
  margin-left: 5px;
  color: var(--ink-muted);
  font-family: var(--sans);
  font-size: 0.85em;
  text-decoration: none;
}

.title-page-link:hover { color: var(--ink); text-decoration: underline; }

.block-tab-with-links {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.block-tab-link-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.block-tab-with-links .markdown-link { color: inherit; }
.block-tab-with-links .title-page-link { margin: 0; color: inherit; }
.block-tab-select {
  flex: 0 0 auto;
  padding: 0 3px;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 3px;
  font: inherit;
}

.collection,
.app-footer {
  max-inline-size: var(--reading-column);
}

.collection {
  padding: 18px 0 26px;
}

.page-context {
  display: flex;
  gap: 18px;
  align-items: center;
  padding-block: 8px 0;
  margin-bottom: var(--section-gap);
}

/* Home has no visible document title. */
.page-context:has(> .page-context-heading[hidden]) { display: none; }

:root[data-theme="paper"] .page-context {
  border-bottom: 1px solid var(--line);
  padding-block-end: 16px;
}

:root[data-theme="paper"] .page-context-heading h2 {
  font-size: clamp(26px, 3vw, 32px);
}

.page-context-heading {
  flex: 1;
  min-width: 0;
  font-size: 15px;
}

.page-context-heading h2 {
  margin: 0;
  text-wrap: balance;
  font-family: var(--sans);
  font-size: 1.5em;
  font-weight: 400;
  line-height: 1.25;
}

#page-title[data-heading-depth]:not([data-heading-depth="0"]) { font-weight: 700; }

.title-edit-row {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.title-edit-row > :is(h1, h2) {
  min-width: 0;
  overflow-wrap: anywhere;
}


.title-edit-button {
  display: inline-grid;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  padding: 0;
  place-items: center;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 19px;
  line-height: 1;
}

.title-edit-button:hover,
.title-edit-button[aria-pressed="true"] {
  color: var(--ink);
  background: rgb(var(--surface-tint) / 0.08);
  border-color: var(--line);
}

.back-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) 24px repeat(2, minmax(0, 1fr));
  height: var(--nav-control-height);
  flex: 1;
  min-inline-size: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.back-controls button {
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background: var(--glass);
  border: 0;
}
.back-controls button + button { border-inline-start: 1px solid var(--line); }
.back-controls button:first-child { border-radius: 7px 0 0 7px; }
.back-controls button:last-child { border-radius: 0 7px 7px 0; }
.back-controls button:disabled { opacity: 0.4; cursor: default; }
#settings-button[aria-expanded="true"] { background: var(--highlight-fill); color: var(--highlight-ink); }

:is(.back-history-menu, .notifications-menu, .settings-menu) {
  position: fixed;
  z-index: 65;
  width: min(320px, calc(100vw - 24px));
  max-height: min(60vh, 420px);
  padding: 5px;
  overflow-y: auto;
  color: var(--ink);
  background: var(--surface-panel);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--menu-shadow);
  font-size: var(--topbar-font-size);
}

.settings-menu { width: min(200px, calc(100vw - 24px)); }

:is(.back-history-item, .notification-item, .settings-menu button) {
  display: block;
  width: 100%;
  padding: 9px 11px;
  color: inherit;
  text-align: left;
  overflow-wrap: anywhere;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
}

.back-history-item[aria-current="page"] { color: var(--ink-muted); background: var(--glass); opacity: 1; cursor: default; }

:is(.back-history-item, .notification-item.is-seen, .settings-menu button):enabled:is(:hover, :focus-visible) {
  background: var(--glass);
  border-color: var(--line);
}

.notification-item { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notification-item[data-unread] { background: var(--highlight-fill); color: var(--highlight-ink); }
.notification-item.is-seen, #notification-empty { color: var(--ink-muted); }
#notification-empty { cursor: default; }

.page-text-line,
.inline-text-line {
  grid-column: 1 / -1;
  min-width: 0;
  min-height: 1.5em;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  position: relative;
}

.inline-text-line.is-card-text { font-size: 13px; }

.text-line-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -14px;
  width: 12px;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: grab;
}

.text-line-handle::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: transparent;
}

:is(.page-text-line, .inline-text-line):hover > .text-line-handle::before,
.text-line-handle:focus-visible::before { background: var(--ink); }
.text-line-handle:active { cursor: grabbing; }
:is(.page-text-line, .inline-text-line).is-dragging { opacity: 0.45; }
:is(.page-text-line, .inline-text-line, .block-card, .embedded-block).is-drop-before { box-shadow: 0 -2px 0 var(--focus-color); }
:is(.page-text-line, .inline-text-line, .block-card, .embedded-block).is-drop-after { box-shadow: 0 2px 0 var(--focus-color); }

:is(.page-text-line, .inline-text-line) :is(h2, h3, h4, p, ul) { margin: 0; }
:is(.page-text-line, .inline-text-line) ul { padding-left: 1.3em; }

/* Long equations scroll inside their line instead of widening the page. */
.math-display,
.math-source {
  display: block;
  max-width: 100%;
  margin: 0.2em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.math-display math {
  display: block;
  width: max-content;
  margin-inline: auto;
  color: inherit;
  font-size: 1em;
}

.math-inline {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  vertical-align: -0.12em;
}

.math-inline math {
  color: inherit;
  font-size: 1em;
  white-space: nowrap;
}

.math-source {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.page-command-line {
  display: block;
  margin-bottom: 22px;
}

.page-line-area {
  position: relative;
}

.page-command-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.is-quick-edit .page-command-fields {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--heading-follow);
}

.page-command-fields > label { min-width: 0; }

.header-command .page-command-line {
  margin: 0;
}

.header-command .page-command-primary {
  position: relative;
  min-width: 0;
  min-height: var(--command-height);
}

.block-line-popup {
  --quick-edit-gap: calc(var(--editor-overhang, 0px) + 6px);
  position: absolute;
  z-index: 15;
  /* The command area is vertically centered in the desktop toolbar. */
  top: calc((100% + var(--topbar-height, var(--header-height))) / 2 + var(--quick-edit-gap));
  inset-inline: 0;
  display: flex;
  flex-direction: column;
  min-height: min(60vh, 480px);
  max-height: min(760px, calc(100dvh - var(--topbar-height, var(--header-height)) - var(--quick-edit-gap) - 8px));
  overflow: hidden;
  color: var(--ink);
  background: var(--surface-editor);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--editor-shadow);
  backdrop-filter: blur(10px);
}

.block-tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
}

.block-tab-button,
.block-tab-add,
.block-tab-remove-block {
  flex: 0 0 auto;
  max-width: 190px;
  min-height: 27px;
  padding: 4px;
  overflow: hidden;
  color: var(--ink-muted);
  text-overflow: ellipsis;
  text-decoration: none;
  white-space: nowrap;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 11px;
}

.block-tab-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  position: relative;
  isolation: isolate;
}

/* Keep the tab surface close to the text within the full click area. */
.block-tab-button::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset-inline: 0;
  top: 50%;
  height: 1.1em;
  transform: translateY(-50%);
  background: var(--tab-tint, transparent);
  background-clip: padding-box;
  border: 1px solid var(--block-border-color, var(--line));
  border-radius: var(--block-label-radius);
  transition: border-color 160ms ease;
  pointer-events: none;
}

.block-tab-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.block-tab-button:hover,
.block-tab-add:hover,
.block-tab-remove-block:hover {
  color: var(--ink);
}

.block-tab-button[aria-pressed="true"],
.block-tab-button.is-active {
  --tab-tint: var(--block-label-tint);
  color: var(--highlight-ink);
}

.block-tab-add { font-size: 17px; line-height: 1; }
.block-tab-remove-block { display: none; text-decoration: underline; }
.block-card.is-selected > .card-title-row .block-tab-remove-block { display: inline-block; }
.quick-edit-tabs { flex: 0 0 auto; margin: 0 12px 6px; }
.page-tabs { flex: 1; min-width: 0; }

/* Start where the compact input was and let the field grow over the page. */
.expanded-quick-edit {
  position: absolute;
  z-index: 16;
  inset: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-panel);
}

.expanded-quick-edit:focus-within {
  outline: 2px solid var(--focus-color);
  outline-offset: -2px;
}

#expanded-quick-edit-input {
  display: block;
  width: 100%;
  min-height: 3.5em;
  max-height: min(42vh, 380px);
  padding: 8px calc(var(--passage-gap) - 1px) 2px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--focus-color);
  line-height: 1.5;
}

#expanded-quick-edit-status {
  display: block;
  padding: 2px calc(var(--passage-gap) - 1px) 4px;
  color: var(--ink-muted);
}

.header-command:has(.expanded-quick-edit:not([hidden])) #block-navigation-help,
.header-command:has(.expanded-quick-edit[hidden]) .is-quick-navigation .block-line-insert { display: none; }
.is-quick-navigation #block-line-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-command .block-line-popup.is-quick-navigation {
  min-height: 0;
}

.block-line-popup-heading {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px 6px;
}

.block-line-popup-heading strong { font-weight: 500; }

.block-line-popup-heading [role="status"] { color: var(--ink-muted); }

.block-line-list {
  min-height: 0;
  overflow-y: auto;
  padding: 6px 0;
}

.block-line-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 20px;
  gap: 10px;
  min-height: 28px;
  align-items: start;
  padding: 3px 18px;
  cursor: pointer;
}

.block-line-insert {
  width: 20px;
  height: 20px;
  padding: 0;
  color: var(--ink-muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
  opacity: 0;
  cursor: pointer;
}

.block-line-row:hover .block-line-insert,
.block-line-row:focus-within .block-line-insert,
.block-line-insert:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .block-line-insert { opacity: 1; }
}

.block-line-row:first-child {
  padding-top: 8px;
  padding-bottom: 7px;
}

.block-line-row:hover {
  background: rgb(var(--surface-tint) / 0.05);
}

.is-selected-text,
.block-line-row[aria-current="true"] {
  outline: none;
  background: rgb(var(--focus-tint) / 0.11);
  box-shadow: inset 3px 0 0 var(--focus-color);
}

.block-line-number {
  padding-top: 2px;
  color: var(--ink-faint);
  font-size: 10px;
  text-align: right;
}

.block-line-preview {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.35;
}

.block-line-title,
.block-line-block-heading {
  font-size: var(--card-title-size);
  line-height: 1.5;
}

.block-line-block {
  --block-border-color: var(--line);
  display: flex;
  gap: 8px;
  min-width: 0;
  margin-block-start: 10px;
  padding: 0 6px 7px;
  color: var(--ink);
  border: 1px solid var(--block-border-color);
  border-radius: 7px;
}

.block-line-block-main { min-width: 0; flex: 1; }

/* The title straddles the frame and long titles stay in the row's flow. */
.block-line-block-heading { margin: -.75em 0 5px -6px; }

.block-line-block-content {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.35;
}

.block-line-child-reference {
  padding-left: 7px;
  border-left: 1px solid var(--line-strong);
  font-size: calc(var(--card-heading-size) - 0.5px);
}
.block-line-child-missing { color: var(--ink-faint); font-size: 12px; }

.block-line-preview :is(h2, h3, h4, p, ul) {
  margin: 0;
}

.block-line-preview h2 { font-size: 1.2em; }
.block-line-preview h3 { font-size: 1.1em; }
.block-line-preview h4 { font-size: 1em; }
.block-line-preview ul { padding-left: 1.3em; }

.block-line-blank {
  display: block;
  min-height: 1em;
}

.block-line-empty,
.block-line-help {
  color: var(--ink-muted);
  font-size: 11px;
}

.block-line-help {
  margin: 0;
  padding: 11px 18px;
}

.page-command-line input {
  width: 100%;
  min-height: var(--command-height);
  padding: 8px calc(var(--passage-gap) - 1px);
  color: var(--ink);
  caret-color: var(--focus-color);
  background: rgb(var(--surface-tint) / 0.08);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.page-command-line input::placeholder {
  color: var(--ink-muted);
}

/* Selection shows source without a caret until editing starts. */
#page-command-input.is-selection-preview { caret-color: transparent; }
#page-command-input.is-selection-preview::placeholder { color: transparent; }

.page-command-line input:focus {
  background: rgb(var(--surface-tint) / 0.13);
  border-color: var(--focus-color);
}

.page-command-line input:focus-visible { outline-offset: -2px; }

kbd {
  min-width: 21px;
  padding: 2px 6px;
  color: var(--ink-faint);
  background: rgb(var(--surface-tint) / 0.07);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 10px;
  text-align: center;
}

.block-grid,
.inline-page-rows {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

/* Frame titles need clearance. Prose follows the source's line breaks. */
:is(.block-grid, .inline-page-rows) > :not(:first-child) { margin-block-start: 14px; }
.paper-abstract-content > [data-text-kind] + .block-card,
.paper-abstract-content > .block-card + [data-text-kind] { margin-block-start: 14px; }
.block-card + .block-card,
.embedded-block + .embedded-block { margin-block-start: 20px; }
/* A title rises above its frame. Leave a full break after the last line of prose. */
[data-text-kind="text"] + :is(.block-card, .embedded-block),
.paper-abstract-content > [data-text-kind="text"] + .block-card {
  margin-block-start: 24px;
}

[data-text-kind] + [data-text-kind] { margin-block-start: 0; }
[data-text-kind] + :is([data-text-kind="bullet"], [data-text-kind="code"], [data-text-kind="table"], [data-text-kind="math"]),
:is([data-text-kind="bullet"], [data-text-kind="code"], [data-text-kind="table"], [data-text-kind="math"]) + [data-text-kind] {
  margin-block-start: var(--passage-gap);
}
[data-text-kind] + [data-text-kind="heading"] { margin-block-start: var(--section-gap); }
.markdown-rule { max-inline-size: var(--reading-measure); margin: 0; border: 0; border-top: 1px solid var(--line); }
[data-text-kind="rule"] { min-height: 0; }
[data-text-kind] + [data-text-kind="rule"],
[data-text-kind="rule"] + [data-text-kind] { margin-block-start: var(--passage-gap); }
[data-text-kind="heading"] + [data-text-kind] { margin-block-start: var(--heading-follow); }
/* Give controls room while keeping them close to the heading that introduces them. */
[data-text-kind] + :is([data-text-kind="field"], [data-text-kind="button"]),
:is([data-text-kind="field"], [data-text-kind="button"]) + [data-text-kind] {
  margin-block-start: var(--section-gap);
}
[data-text-kind="heading"] + :is([data-text-kind="field"], [data-text-kind="button"]) {
  margin-block-start: var(--passage-gap);
}
[data-text-kind="blank"] + [data-text-kind],
[data-text-kind] + [data-text-kind="blank"] { margin-block-start: 0; }

[data-text-kind] > :is(p, ul, .markdown-todo) {
  max-inline-size: var(--reading-measure);
}
[data-text-kind] > :is(h2, h3, h4, .card-preview-heading) {
  line-height: 1.25;
  min-height: 0;
  text-wrap: balance;
  max-inline-size: 50ch;
}
[data-text-kind] > :is(.markdown-code, .markdown-diagram, .markdown-table-scroll, .math-display) {
  margin-block: 0;
}

/* Keep a leading nested label clear of the clipping edge of a shrunk card. */
.inline-page-rows:not(.embedded-block .inline-page-rows):has(> .embedded-block:first-child) {
  padding-top: 14px;
}

.block-card,
.embedded-block {
  --block-body-inset: 6px;
  --block-border-color: var(--line);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 6px;
  min-height: 40px;
  padding: 0 var(--block-body-inset) 10px;
  overflow: hidden;
  background: var(--glass);
  border: 1px solid var(--block-border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.block-card {
  min-width: 0;
  overflow: visible;
  contain: style;
}

.block-card:hover {
  --block-border-color: var(--line-strong);
  background: var(--surface-card-hover);
}

.block-card.is-selected {
  --block-border-color: var(--focus-color);
  background: var(--surface-card-selected);
  box-shadow: 0 0 0 2px rgb(var(--focus-tint) / 0.24),
    var(--selected-card-shadow);
}

.block-card:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 3px;
}

.block-card.is-selected:focus-visible {
  outline: none;
}

.block-card.is-complete {
  opacity: var(--completed-opacity);
}

.block-card.is-complete.is-selected {
  opacity: 0.9;
}

.block-card.is-complete .card-title-button {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.block-card.is-complete .block-tab-button.is-active,
.block-card.is-complete .block-tab-button[aria-pressed="true"] {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.card-delete-button {
  position: absolute;
  z-index: 2;
  right: -12px;
  bottom: -12px;
  display: grid;
  width: 24px;
  height: 24px;
  padding: 0;
  place-items: center;
  color: var(--ink-muted);
  background: var(--surface-panel);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms ease, color 140ms ease, background 140ms ease;
}

.block-card.is-selected > .card-delete-button {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.card-delete-button:hover,
.card-delete-button:focus-visible {
  color: var(--ink);
  background: var(--surface-page);
}

.card-title-row {
  margin: 0;
  color: var(--ink-muted);
  font-family: var(--sans);
  font-size: var(--card-title-size);
  font-weight: 400;
  letter-spacing: normal;
  line-height: 1.5;
}

.card-title-row.is-tabbed {
  display: flex;
  gap: 6px;
  align-items: center;
}

.card-title-row.is-tabbed .block-tabs { min-width: 0; }
.card-title-row.is-tabbed .block-tab-button { font-size: 13px; }
.page-tabs .block-tab-button { font-size: 15px; }

.card-title-button {
  display: inline;
  padding: 0;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  font: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  text-decoration: none;
}

a.card-title-button:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.card-title-external-link {
  color: var(--ink-muted);
  white-space: nowrap;
  text-decoration: none;
}

.card-title-external-link:hover {
  color: var(--ink);
}

.card-title-arrow {
  color: var(--ink-muted);
  font-family: var(--sans);
  font-size: 0.68em;
}

.markdown-todo {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
  font-weight: inherit;
}

.markdown-todo input {
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--focus-color);
  cursor: pointer;
}

.markdown-todo > .markdown-todo-text {
  min-width: 0;
  overflow-wrap: anywhere;
  color: inherit;
  text-decoration: none;
}

.markdown-todo.is-checked > .markdown-todo-text {
  text-decoration: line-through;
  opacity: 0.7;
}

.card-content {
  --inline-heading-size: var(--card-heading-size);
  --inline-row-inset: 8px;
  display: block;
  flex: 1 1 auto;
  max-height: none;
  margin: 0;
  overflow: visible;
  color: var(--ink-muted);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: unset;
}

.card-content:empty {
  display: none;
}

/* A paper's abstract must expand fully instead of being clipped as a card excerpt. */
.card-content:has(.paper-abstract),
.block-line-block-content:has(.paper-abstract) {
  display: block;
  max-height: none;
  overflow: visible;
  -webkit-line-clamp: unset;
}

.block-card.is-shrunk > .card-content {
  display: -webkit-box;
  max-height: 9em;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
}

.block-size-button {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 4px;
  color: var(--ink-faint);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 10px;
}

.block-size-button:hover { color: var(--ink); border-color: var(--line-strong); }

.paper-abstract { margin-top: 5px; min-width: 0; }
.paper-abstract > summary { cursor: pointer; color: var(--ink-muted); }
.paper-abstract-content { padding: 6px 0 3px 16px; overflow-wrap: anywhere; }
.paper-abstract-content > p { margin: 0 0 6px; }

.block-title-list {
  margin: 0;
  padding-left: 1.3em;
  text-align: left;
}

.card-preview-line,
.card-preview-heading,
.card-preview-empty {
  display: block;
  min-height: 1.5em;
}

.embedded-block,
.block-line-child-reference {
  --block-label-tint: var(--nested-label-fill);
}

.embedded-block {
  /* Place the title between the parent's headings and the headings in this block. */
  --embedded-title-size: calc(var(--inline-heading-size) - 0.5px);
  min-width: 0;
  min-height: 0;
  margin: 0;
  gap: 6px;
  padding: 0;
  background: transparent;
  border: 0;
  border-left: 1px solid transparent;
  border-radius: 0;
  box-shadow: none;
  font-size: 16px;
  line-height: normal;
  overflow-wrap: anywhere;
}

.embedded-block .embedded-block { --block-label-tint: var(--deep-label-fill); }

.embedded-block-title {
  display: block;
  padding-right: 0;
  font-family: var(--sans);
  font-size: var(--embedded-title-size);
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink-muted);
  text-decoration: none;
}

/* Only the first nested level gets a full outline. */
.embedded-block:not(.embedded-block .embedded-block) {
  padding: 0 var(--block-body-inset) 10px;
  border: 1px solid var(--block-border-color);
  border-radius: var(--radius-md);
}

/* Keep the first line centered on the frame while wrapped text stays in flow. */
:is(.block-card > .card-title-row,
  .embedded-block:not(.embedded-block .embedded-block) > :is(.embedded-block-title, .block-tabs, .attachment-heading)) {
  margin: -.75em calc(-1 * var(--block-body-inset)) 0;
  padding: 0 14px 0 0;
  overflow-wrap: anywhere;
}

.embedded-block-title { cursor: text; }

.block-title-label {
  display: inline;
  font-weight: 400;
  padding-inline: 3px;
  color: var(--highlight-ink);
  background: var(--block-label-tint);
  background-clip: padding-box;
  border: 1px solid var(--block-border-color, var(--line));
  border-radius: var(--block-label-radius);
  transition: border-color 160ms ease;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.block-title-label :is(.markdown-link, .title-page-link, strong) {
  color: inherit;
  text-decoration-color: currentColor;
}

.block-title-label:has(> :is(.block-title-list, .markdown-todo, .math-display)) {
  display: inline-flex;
  align-items: baseline;
  max-width: 100%;
  vertical-align: top;
}

:is(.block-card > .card-title-row.is-tabbed,
  .embedded-block:not(.embedded-block .embedded-block) > :is(.block-tabs, .attachment-heading.is-tabbed)) {
  margin-top: -14px;
}

/* Resume the top edge after the tabs so it never crosses a transparent label. */
:is(.block-card:has(> .card-title-row.is-tabbed),
  .embedded-block:not(.embedded-block .embedded-block):has(> :is(.block-tabs, .attachment-heading.is-tabbed))) {
  border-top-color: transparent;
}

:is(.block-card:has(> .card-title-row.is-tabbed),
  .embedded-block:not(.embedded-block .embedded-block):has(> :is(.block-tabs, .attachment-heading.is-tabbed)))::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
  inset-block-start: -1px;
  inset-inline-end: -1px;
  width: var(--radius-md);
  height: var(--radius-md);
  border: 1px solid transparent;
  border-top-color: var(--block-border-color);
  border-start-end-radius: var(--radius-md);
  transition: border-top-color 160ms ease;
  pointer-events: none;
}

.embedded-block:not(.embedded-block .embedded-block) > .block-tabs {
  align-self: stretch;
  max-width: none;
}

:is(.block-card > .card-title-row.is-tabbed,
  .embedded-block:not(.embedded-block .embedded-block) > :is(.block-tabs, .attachment-heading.is-tabbed)) {
  padding-inline-end: calc(var(--radius-md) - 1px);
}

:is(.block-card > .card-title-row.is-tabbed,
  .embedded-block:not(.embedded-block .embedded-block) > :is(.block-tabs, .attachment-heading.is-tabbed))::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: var(--block-border-color);
  transition: background-color 160ms ease;
  pointer-events: none;
}

a.embedded-block-title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.embedded-block-content {
  --inline-heading-size: 14px;
  min-width: 0;
  color: var(--ink-muted);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
}

.embedded-block-missing {
  display: block;
  color: var(--ink-faint);
  font-style: italic;
}

.card-preview-heading {
  color: var(--ink);
  font-weight: 650;
}

.card-preview-heading.depth-1 {
  font-size: 14px;
}

.card-preview-heading.depth-2 {
  font-size: 13px;
}

.card-preview-heading.depth-3 {
  color: var(--ink-muted);
  font-size: 12px;
}

/* Tabs use the size of the title they replace. */
:is(.block-card > .card-title-row > .block-tabs,
  .embedded-block > .block-tabs,
  .embedded-block > .attachment-heading > .block-tabs) > .block-tab-button {
  font-size: var(--embedded-title-size, inherit);
  line-height: 1.25;
  padding-block: 2px;
}

.inline-text-line .card-preview-heading {
  color: var(--ink);
  font-size: var(--inline-heading-size);
}

.card-preview-list {
  margin: 0;
  padding-left: 1.25em;
}

.card-preview-list li {
  min-height: 1.5em;
  padding-left: 0.1em;
}

.card-preview-list li::marker {
  color: var(--ink-faint);
}


.card-footer {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  color: var(--ink-faint);
  border-top: 1px solid var(--line);
  font-size: 10px;
}

.topic-label {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  padding-top: 18px;
  color: var(--ink-faint);
  border-top: 1px solid var(--line);
  font-size: 10px;
}

.toast {
  position: fixed;
  z-index: 50;
  right: 24px;
  bottom: 24px;
  max-width: min(340px, calc(100vw - 48px));
  padding: 12px 16px;
  color: var(--highlight-ink);
  background: var(--highlight-fill);
  border-radius: 10px;
  box-shadow: var(--toast-shadow);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Leave the full reading width available to the command field. */
@media (max-width: 1240px) {
  .topbar-message { display: none; }
}

@media (max-width: 900px) {
  :root { --sidebar-width: 220px; }
}

@media (max-width: 650px) {
  .app-shell {
    display: block;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--passage-gap);
    min-height: 64px;
    padding-inline: var(--workspace-gutter);
  }

  .topbar-navigation { padding-inline-start: 0; }
  .back-controls {
    flex: 0 0 auto;
    grid-template-columns: repeat(2, 36px) 24px repeat(2, 36px);
  }

  .header-command {
    grid-column: 1 / -1;
    margin-inline: 0;
  }

  .header-command .block-line-popup {
    position: fixed;
    top: calc(var(--topbar-height, var(--header-height)) + var(--quick-edit-gap));
    inset-inline: 16px;
  }

  .is-quick-edit .page-command-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }



  .block-sidebar {
    position: sticky;
    z-index: 9;
    top: var(--topbar-height, var(--header-height));
    display: block;
    height: 54px;
    padding: 8px 16px;
    overflow: hidden;
    background: var(--surface-page);
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .block-navigation {
    display: flex;
    gap: var(--heading-follow);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .block-navigation::-webkit-scrollbar {
    display: none;
  }

  :is(.block-navigation-button, .document-outline-button) {
    flex: 0 0 auto;
    width: auto;
    max-width: 190px;
    min-height: 40px;
    padding: 0 11px;
    font-size: 12px;
  }

  .workspace {
    padding: 0 var(--workspace-gutter) 24px;
  }

  .collection {
    padding-top: 18px;
  }

  .page-context {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .page-context-heading {
    flex-basis: calc(100% - 100px);
  }

  .block-line-popup {
    min-height: min(65vh, 520px);
  }

  .block-grid {
    grid-template-columns: 1fr;
  }

  .app-footer {
    gap: 8px;
    align-items: flex-start;
    flex-direction: column;
  }

}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* One page shell in both modes: only the body changes from rendered rows to raw source. */
.block-sidebar {
  overflow-y: auto;
}

.block-navigation { flex: 0 0 auto; }



.page-edit-status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  color: var(--ink-muted);
  font-size: 11px;
}

.block-card, .embedded-block, .page-text-line {
  scroll-margin-top: calc(var(--topbar-height, var(--header-height)) + var(--section-gap));
}

@media (max-width: 650px) {
  .block-sidebar { height: auto; min-height: 54px; }
  .page-context-heading { flex-basis: 0; }
  .workspace { padding-left: 16px; }
  .page-breadcrumbs a:not([data-breadcrumb-home], [aria-current="page"]) {
    display: block;
    min-inline-size: 4ch;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: var(--breadcrumb-height);
  }
}

.block-card[draggable="true"] { cursor: grab; }
.block-card.is-dragging { opacity: 0.45; }
.is-drop-target {
  outline: 2px dashed var(--focus-color) !important;
  outline-offset: 4px;
  background-color: rgb(var(--focus-tint) / 0.1);
}

.embedded-block { position: relative; overflow: visible; }
:is(.block-card, .embedded-block) > .block-size-button {
  top: 0;
  bottom: 0;
  left: -6.5px;
  right: auto;
  width: 12px;
  height: auto;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

/* Center both the invisible hit area and hover stroke on the 1px left border. */
:is(.block-card, .embedded-block) > .block-size-button::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 50%;
  transform: translateX(-50%);
  width: 1px;
  background: transparent;
  transition: background 140ms ease;
}

:is(.block-card, .embedded-block) > .block-size-button:hover::before,
:is(.block-card, .embedded-block) > .block-size-button:focus-visible::before {
  width: 3px;
  background: var(--ink);
}

:is(.block-card, .embedded-block) > .block-size-button > svg { display: none; }

.block-card > .block-size-button {
  top: 12px;
  bottom: 12px;
}

.embedded-block:not(.embedded-block .embedded-block) > .block-size-button {
  top: 10px;
  bottom: 10px;
  z-index: 1;
}

/* Align child labels with text after the move-handle gutter and the 1px child border. */
.inline-text-line { padding-inline-start: var(--inline-row-inset); }
.inline-page-rows > .embedded-block { margin-inline-start: calc(var(--inline-row-inset) - 1px); }
/* Keep the text handle inside its gutter, clear of the block size control. */
.inline-text-line > .text-line-handle { left: 0; width: var(--inline-row-inset); }

.embedded-block.is-shrunk > .embedded-block-content {
  display: -webkit-box;
  max-height: 9em;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
}

.quick-block-open {
  align-self: flex-start;
  margin-block-start: 6px;
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}
.quick-block-open:hover { color: var(--ink); border-color: var(--line-strong); }

.embedded-block[draggable="true"],
.block-navigation-button[draggable="true"] { cursor: grab; }
.embedded-block.is-dragging,
.block-navigation-button.is-dragging { opacity: 0.45; }
/* Draw a straight insertion marker independently of the rounded button. */
.block-navigation-button { position: relative; }
.block-navigation-button:is(.is-drop-before, .is-drop-after)::after {
  content: "";
  position: absolute;
  inset-inline: 8px;
  height: 2px;
  background: var(--highlight-fill);
  pointer-events: none;
}
.block-navigation-button.is-drop-before::after { top: 0; }
.block-navigation-button.is-drop-after::after { bottom: 0; }

@media (max-width: 650px) {
  .block-navigation-button:is(.is-drop-before, .is-drop-after)::after {
    inset: 6px auto;
    width: 2px;
    height: auto;
  }
  .block-navigation-button.is-drop-before::after { left: 0; right: auto; }
  .block-navigation-button.is-drop-after::after { right: 0; left: auto; }
}

.workspace-page-button {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: var(--passage-gap);
  width: 100%;
  min-height: 40px;
  margin: 0 0 var(--passage-gap);
  padding: 7px 11px;
  color: var(--ink);
  background: rgb(var(--surface-tint) / 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: 650 14px/1.4 var(--sans);
  text-align: left;
  cursor: pointer;
}
#workspace-page-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-page-button:hover,
.workspace-page-button[aria-expanded="true"] { background: rgb(var(--surface-tint) / 0.1); }

#workspace-page-menu { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.workspace-menu-panel {
  position: fixed;
  width: min(248px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 5px;
  color: var(--ink);
  background: var(--surface-panel);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  box-shadow: 0 12px 32px rgba(10, 25, 60, 0.4);
  pointer-events: auto;
}
.workspace-menu-item,
.workspace-menu-back {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 3px 6px 3px 10px;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  font: 12px/1.5 var(--sans);
  text-align: left;
  cursor: pointer;
}
.workspace-menu-item:hover,
.workspace-menu-item:focus-visible,
.workspace-menu-item[aria-expanded="true"],
.workspace-menu-back:hover,
.workspace-menu-back:focus-visible {
  outline: 0;
  color: var(--focus-color);
  background: rgb(var(--focus-tint) / 0.12);
  border-color: var(--line);
}
.workspace-menu-item[aria-current="page"] .workspace-menu-name { font-weight: 700; }
.workspace-menu-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-menu-arrow { display: grid; place-items: center; flex: 0 0 28px; height: 28px; font-size: 20px; }
.workspace-menu-back { color: var(--ink-muted); border-bottom-color: var(--line); margin-bottom: 4px; }
@media (max-width: 650px) {
  .workspace-page-button { margin-block-end: var(--heading-follow); }
  .block-card, .embedded-block, .page-text-line {
    scroll-margin-top: calc(var(--topbar-height, var(--header-height)) + var(--sidebar-strip-height, 101px) + var(--section-gap));
  }
}

.workspace-menu-tools { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }

.workspace-menu-search {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 4px 4px 8px;
  margin-bottom: 4px;
  background: var(--surface-panel);
  border-bottom: 1px solid var(--line);
}
.workspace-menu-search input {
  display: block;
  width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  color: var(--ink);
  background: rgb(var(--surface-tint) / 0.06);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font: 12px/1.5 var(--sans);
}
.workspace-menu-search input::placeholder { color: var(--ink-faint); }
.workspace-menu-search-status { display: block; padding-top: 7px; color: var(--ink-muted); font-size: 11px; }
.workspace-menu-name > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-menu-page-path { color: var(--ink-faint); font-size: 10px; font-weight: 400; }

/* Prose supports native selection even inside a movable card. */
:is(.block-card, .embedded-block) :is(.page-text-line, .inline-text-line) { cursor: text; }

:is(.card-title-button, .embedded-block-title, .block-tab-button) {
  -webkit-user-select: text;
  user-select: text;
}

/* Blank space after a title belongs to its selectable text line. */
.card-title-row { cursor: text; }
.attachment-heading,
.attachment-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.attachment-heading > :is(.card-title-button, .embedded-block-title, .block-line-block-title, .block-tabs) {
  min-width: 0;
  overflow-wrap: anywhere;
}

.title-edit-row:has(#page-attachment-actions:not([hidden])) > .page-tabs { flex: 0 1 auto; }

.attachment-actions {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--ink);
  cursor: default;
}

.attachment-actions > :is(a, button) {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  color: inherit;
  background: var(--surface-panel);
  border: 0;
  border-radius: 5px;
  font-size: 16px;
  line-height: 1;
  text-decoration: none;
}

.attachment-actions > :is(a, button):hover { background: var(--surface-hover); }
.attachment-actions > button:disabled { opacity: .5; }
.attachment-actions > .attachment-open-preview[aria-pressed="true"] {
  color: var(--preview-active-ink);
  background: var(--preview-active-fill);
}

.attachment-eye {
  display: grid;
  place-items: center;
  width: 12px;
  height: 12px;
  border: 1px solid currentColor;
  border-radius: 75% 0;
  transform: rotate(45deg);
}

.attachment-eye::after {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.attachment-actions [role="status"] {
  max-width: min(30vw, 140px);
  font-size: 11px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.attachment-actions [role="status"]:empty { display: none; }

.attachment-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.attachment-toolbar button {
  padding: 5px 9px;
  color: var(--ink);
  background: var(--surface-panel);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.attachment-preview { min-width: 0; }
.page-context-heading > .attachment-preview { margin-top: 12px; }

.attachment-preview :is(img, canvas) {
  display: block;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
}

.attachment-preview img { max-height: 75dvh; object-fit: contain; }
.attachment-preview canvas { margin-top: 8px; background: white; }

.theme-options {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
}

.theme-options .theme-option {
  display: grid;
  grid-template-columns: auto 48px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 60px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  cursor: pointer;
}

.theme-option:has(input:checked) {
  background: var(--surface-card-selected);
  border-color: var(--focus-color);
}

.theme-option input { width: auto; margin: 0; padding: 0; accent-color: var(--focus-color); }
.theme-option small { display: block; margin-top: 2px; color: var(--ink-muted); }

.theme-sample {
  display: grid;
  align-content: center;
  gap: 4px;
  height: 32px;
  padding: 0 7px;
  background: var(--surface-page);
  border: 1px solid var(--line);
  border-radius: 4px;
}

.theme-sample::before,
.theme-sample::after { content: ""; border-radius: 2px; }
.theme-sample::before { width: 75%; height: 4px; background: var(--ink); }
.theme-sample::after { width: 56%; height: 2px; background: var(--link-line); }
