/* Yestion layout and editor. Loaded after tokens.css, native.css and components.css (byte-identical copies of
   packages/ui): buttons (.btn-*), fields (.input), cards, badges, segmented, sheets (.overlay/.sheet), skeleton
   come from components.css. Shell and rules: design/PLATFORM_UI.md. Values only from tokens.css. */
@font-face { font-family: 'Geist Variable'; src: url('fonts/Geist-Variable.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Geist'; src: url('fonts/Geist-Variable.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }
@font-face { font-family: 'Geist Mono'; src: url('fonts/GeistMono-Variable.woff2') format('woff2'); font-weight: 100 900; font-display: swap; }

/* Editor-local shorthands, all derived from the tokens (dark comes from tokens.css) */
:root {
  --fg: var(--color-ink);
  --muted: var(--color-mid-gray);
  --faint: color-mix(in srgb, var(--color-ink) 36%, var(--color-paper));
  --border: var(--color-hairline);
  --hover: color-mix(in srgb, var(--color-ink) 5%, transparent);
  --active: color-mix(in srgb, var(--color-ink) 9%, transparent);
  --accent-soft: color-mix(in srgb, var(--color-ink) 7%, transparent);
  --selection: color-mix(in srgb, var(--color-ink) 15%, transparent);
  --mark: color-mix(in srgb, var(--color-ink) 12%, transparent);
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

html, body { height: 100%; }
body { font-family: 'Geist Variable', var(--font-geist), var(--emoji); }
::selection { background: var(--selection); }

/* ================================================================ app shell (PLATFORM_UI.md §2) */
body.app-body { display: flex; flex-direction: column; overflow: hidden; }
#app { flex: 1; min-height: 0; display: flex; }
#scrim { display: none; }

/* sidebar: #fafafa, no border, full height */
#sidebar { width: 248px; flex: none; background: var(--surface-sidebar); display: flex; flex-direction: column; padding: var(--spacing-16) var(--spacing-12) var(--spacing-12); gap: var(--spacing-8); transition: margin-left .2s ease; user-select: none; }
body.sb-collapsed #sidebar { margin-left: -248px; }
.sb-head { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-8); padding: 4px 0 4px 4px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sb-close { opacity: 0; }
#sidebar:hover .sb-close, .sb-close:focus-visible { opacity: 1; }
.sb-action .btn { width: 100%; }
.sb-nav { display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 0 var(--spacing-12); border: 0; background: none; border-radius: var(--radius-buttons); color: var(--color-ink-soft); font: inherit; font-weight: var(--font-weight-medium); text-align: left; text-decoration: none; cursor: pointer; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--hover); color: var(--color-ink); }
.ni-icon { width: 18px; flex: none; display: grid; place-items: center; color: var(--color-ink-soft); }
.kbd { margin-left: auto; font-size: var(--text-caption); color: var(--muted); }
.sb-scroll { flex: 1; min-height: 0; overflow-y: auto; margin: 0 calc(-1 * var(--spacing-12)); padding: 0 var(--spacing-12); scrollbar-width: thin; }
.sb-section + .sb-section { margin-top: var(--spacing-12); }
.sb-label { font-size: var(--text-caption); font-weight: 500; letter-spacing: var(--tracking-caption); text-transform: uppercase; color: var(--muted); padding: 8px var(--spacing-12) 4px; }
.sb-foot { display: grid; gap: 2px; padding-top: var(--spacing-8); border-top: 1px solid var(--border); }
.theme-switch { justify-self: start; margin: 0 0 6px var(--spacing-8); }

/* page tree: active = paper + card shadow, like a nav link */
.tree-item { display: flex; align-items: center; gap: 2px; min-height: 36px; padding: 0 4px 0 calc(6px + var(--depth) * 14px); border-radius: var(--radius-buttons); cursor: pointer; position: relative; color: var(--color-ink); font-size: var(--text-body); }
.tree-item:hover { background: var(--hover); }
.tree-item.active { background: var(--color-paper); font-weight: 500; box-shadow: var(--shadow-card); }
.tree-item.drop-inside { background: var(--active); }
.tree-item.drop-before { box-shadow: inset 0 2px 0 var(--fg); }
.tree-item.drop-after { box-shadow: inset 0 -2px 0 var(--fg); }
.twisty { position: relative; width: 24px; height: 24px; border: 0; background: none; border-radius: var(--radius-nested); cursor: pointer; padding: 0; flex: none; color: var(--color-ink-soft); }
.twisty:hover { background: var(--active); }
.tw-arrow, .tw-icon { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--emoji); font-size: 15px; }
.tw-arrow { opacity: 0; transition: transform .15s; color: var(--muted); }
.twisty.open .tw-arrow { transform: rotate(90deg); }
.tree-item:hover .tw-arrow { opacity: 1; }
.tree-item:hover .tw-icon { opacity: 0; }
.ti-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 4px; color: inherit; text-decoration: none; }
.ti-actions { display: none; gap: 1px; }
.tree-item:hover .ti-actions { display: flex; }
.tree-empty { font-size: 13px; color: var(--muted); padding: 4px 8px 4px calc(36px + var(--depth) * 14px); }

/* content: canvas, padding 24, the page as a card (max width of the platform) */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; margin: var(--spacing-24) auto; width: calc(100% - 2 * var(--spacing-24)); max-width: var(--page-max-width);
  background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius-cards); box-shadow: var(--shadow-card); overflow: hidden; }
body.sb-collapsed #main, body.share #main { margin-left: auto; }
.page-skeleton { padding: 72px 50px; display: grid; gap: 14px; max-width: 820px; width: 100%; margin: 0 auto; }
.page-skeleton .skeleton { border-radius: var(--radius-nested); }
.sk-title { height: 40px; width: 55%; margin-bottom: 12px; }
.sk-line { height: 16px; }
.sk-line.short { width: 70%; }

/* ================================================================ icons and small controls */
.ic { display: block; flex: none; }
.mi-icon .ic { margin: 0 auto; }
.btn-text .ic, .placeholder .ic, .file-link .ic { display: inline-block; vertical-align: -3px; }
.icon-btn { width: 34px; height: 34px; border: 0; background: none; border-radius: var(--radius-buttons); display: inline-grid; place-items: center; cursor: pointer; color: var(--color-ink-soft); padding: 0; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn.sm { width: 24px; height: 24px; border-radius: var(--radius-nested); }
.star.on { color: var(--fg); }
.star.on .ic { fill: currentColor; }
.btn-text { display: inline-flex; align-items: center; gap: 6px; height: 30px; border: 0; background: none; border-radius: var(--radius-buttons); padding: 0 var(--spacing-12); cursor: pointer; color: var(--muted); font-size: var(--text-body); font-weight: 500; white-space: nowrap; }
.btn-text:hover { background: var(--hover); color: var(--fg); }
.spacer { flex: 1; }

/* ================================================================ page topbar (inside the card) */
.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: var(--spacing-8); padding: 0 var(--spacing-16); font-size: var(--text-body); }
.sb-toggle { display: none; }
body.sb-collapsed .sb-toggle { display: inline-grid; }
.crumbs { flex: 1 1 auto; display: flex; align-items: center; min-width: 0; overflow: hidden; }
.crumb { display: flex; align-items: center; gap: 6px; border: 0; background: none; padding: 4px 8px; border-radius: var(--radius-buttons); cursor: pointer; min-width: 0; white-space: nowrap; color: var(--muted); text-decoration: none; font: inherit; }
.crumb > span:first-child { font-family: var(--emoji); }
.crumb:last-child { color: var(--fg); }
.crumb:hover { background: var(--hover); color: var(--fg); }
.crumb-t { overflow: hidden; text-overflow: ellipsis; max-width: 200px; font-family: 'Geist Variable', var(--font-geist); }
.crumb-sep, .crumb.muted { color: var(--faint); padding: 0 2px; }
.status { color: var(--muted); font-size: 13px; padding: 0 6px; white-space: nowrap; }

/* ================================================================ page */
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; position: relative; }
.cover { height: 30vh; min-height: 140px; max-height: 280px; background-size: cover; background-position: center; position: relative; box-shadow: inset 0 -1px 0 var(--border); } /* hairline: a dark cover stays visible in dark mode */
.cover-actions { position: absolute; right: max(16px, calc(50% - 360px)); bottom: 12px; display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.cover:hover .cover-actions { opacity: 1; }
.cover-btn { background: var(--color-paper); box-shadow: var(--shadow-card); } /* readable on any cover, light or dark */
.cover-btn:hover { background: var(--color-canvas); }
.page { max-width: 820px; margin: 0 auto; padding: 48px 50px 30vh; font-size: var(--text-body-lg); line-height: var(--leading-body-lg); }
.page.full { max-width: none; padding-left: 96px; padding-right: 96px; }
.page.has-cover { padding-top: 24px; }
.page-controls { display: flex; gap: 2px; height: 30px; margin: 0 0 6px -12px; opacity: 0; transition: opacity .15s; }
.page:hover .page-controls { opacity: 1; }
.page-controls:empty { display: none; }
.page-icon { font-family: var(--emoji); font-size: 64px; line-height: 1.1; border: 0; background: none; padding: 4px; margin: 0 0 4px -4px; border-radius: var(--radius-buttons); cursor: pointer; display: block; }
.page-icon:hover:not([disabled]) { background: var(--hover); }
.page.has-cover .page-icon { margin-top: -60px; position: relative; }
/* page title = platform page title: heading 30/600, -0.75px */
.title { margin: 0 0 var(--spacing-16); outline: none; word-break: break-word; white-space: pre-wrap; } /* size: components.css .content-title */
.title:empty::before { content: attr(data-ph); color: var(--faint); }
.click-below { height: 30vh; cursor: text; }

/* message card (not found, empty, error) */
.msg-body { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.msg-card, .not-found { margin: var(--spacing-16); max-width: 420px; display: grid; gap: var(--spacing-8); }
.msg-card h1, .not-found h1 { margin: 0; }
.msg-card p, .not-found p { margin: 0; }
.not-found .btn { justify-self: start; margin-top: var(--spacing-8); }
#main > .not-found { align-self: center; margin: auto var(--spacing-16); box-shadow: none; }

/* ================================================================ blocks */
.editor { position: relative; }
.block { position: relative; padding-left: calc(var(--indent, 0) * 26px); }
.block.hidden { display: none; }
.block.dragging { opacity: .4; }
.gutter { position: absolute; top: 3px; left: calc(var(--indent, 0) * 26px - 52px); display: flex; opacity: 0; transition: opacity .1s; }
.block:hover > .gutter { opacity: 1; }
.gutter button { width: 24px; height: 24px; border: 0; background: none; color: var(--faint); border-radius: var(--radius-nested); cursor: pointer; padding: 0; display: grid; place-items: center; }
.gutter button:hover { background: var(--hover); color: var(--muted); }
.gutter .g-drag { cursor: grab; }
.body { display: flex; align-items: flex-start; padding: 3px 2px; border-radius: var(--radius-small); min-height: 30px; }
.body:focus { outline: none; background: var(--accent-soft); }
.content { flex: 1; min-width: 0; outline: none; white-space: pre-wrap; word-break: break-word; min-height: 1.5em; }
.content:empty::before { content: attr(data-ph); color: var(--faint); pointer-events: none; }
.type-p .content:empty:not(:focus)::before { content: none; }
.editor.readonly .content:empty::before { content: none; }
.content a { color: inherit; text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 2px; cursor: pointer; }
.content a:hover { text-decoration-color: currentColor; }
.content code { font-family: var(--mono); font-size: 85%; background: var(--surface-canvas); border: 1px solid var(--border); padding: .1em .4em; border-radius: var(--radius-small); }
.content mark { background: var(--mark); color: inherit; border-radius: 4px; padding: 0 2px; }

/* block headings sit under the page title (30): 24 / 18 / 16 */
.type-h1 { margin-top: 1.4em; }
.type-h2 { margin-top: 1.1em; }
.type-h3 { margin-top: .8em; }
/* heading blocks: sizes from components.css (.content h1 30 / h2 24 / h3 18) */
.body.content > h1, .body.content > h2, .body.content > h3 { margin: 0; }
.editor > .block:first-child { margin-top: 0; }

.marker { flex: none; min-width: 26px; height: 24px; display: grid; place-items: center; user-select: none; }
.type-bullet .marker { font-size: 1.3em; line-height: 1; }
.marker.num { padding-right: 4px; justify-items: end; min-width: 26px; }
.check { width: 16px; height: 16px; margin: 0; cursor: pointer; accent-color: var(--fg); }
.checked .content { text-decoration: line-through; color: var(--muted); }
.twist { border: 0; background: none; cursor: pointer; padding: 0; color: var(--fg); border-radius: var(--radius-nested); transition: transform .15s; }
.twist:hover { background: var(--hover); }
.twist.open { transform: rotate(90deg); }
.type-quote .body { border-left: 3px solid currentColor; border-radius: 0; padding-left: 14px; margin: 4px 0; }
.type-callout .body { background: var(--surface-canvas); border: 1px solid var(--border); padding: 16px 18px 16px 14px; border-radius: var(--radius-buttons); margin: 4px 0; }
.callout-icon { font-family: var(--emoji); border: 0; background: none; cursor: pointer; font-size: 20px; line-height: 1; height: 26px; margin-right: 6px; border-radius: var(--radius-small); }
.callout-icon:hover:not([disabled]) { background: var(--hover); }
.type-code .body { background: var(--surface-canvas); border: 1px solid var(--border); border-radius: var(--radius-nested); padding: 32px 20px 20px; margin: 4px 0; position: relative; }
.type-code .content { font: 14px/1.6 var(--mono); white-space: pre; overflow-x: auto; tab-size: 2; }
.copy-btn { position: absolute; top: 8px; right: 10px; border: 1px solid var(--border); background: var(--surface-card); color: var(--muted); border-radius: var(--radius-buttons); font-size: var(--text-caption); font-weight: 500; padding: 2px 10px; cursor: pointer; opacity: 0; }
.type-code:hover .copy-btn { opacity: 1; }
.type-divider .body { padding: 12px 2px; cursor: default; }
hr { border: 0; border-top: 1px solid var(--border); width: 100%; margin: 0; }
.type-image .body { padding: 6px 2px; }
.type-image img { max-width: 100%; border-radius: var(--radius-nested); display: block; }
.placeholder { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; background: var(--surface-canvas); padding: 12px 14px; border-radius: var(--radius-nested); color: var(--muted); font-size: var(--text-body); }
.file-link { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; padding: 4px 8px; border-radius: var(--radius-nested); width: 100%; }
.file-link:hover { background: var(--hover); }
.fl-name { font-weight: 500; }
.fl-size { color: var(--muted); font-size: 13px; }
.page-link { display: flex; align-items: center; gap: 8px; width: 100%; padding: 0 4px; cursor: pointer; border-radius: var(--radius-small); font-weight: 500; color: inherit; text-decoration: none; }
.page-link:hover { background: var(--hover); }
.pl-icon { font-family: var(--emoji); display: inline-grid; place-items: center; }
.pl-title { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.page-link.gone { color: var(--faint); }
.pl-note { font-weight: 400; font-size: 13px; }
.drop-line { position: fixed; height: 3px; background: var(--fg); opacity: .5; border-radius: 2px; pointer-events: none; z-index: 30; }

/* ================================================================ popovers (components.css .popover > .menu-item, .menu-sep) */
#layer { position: fixed; inset: 0; pointer-events: none; z-index: 100; }
#layer > * { pointer-events: auto; }
.popup, .slash, .toolbar { position: fixed; z-index: 110; }
.popup { max-height: 70vh; overflow-y: auto; }
.menu { min-width: 220px; font-size: var(--text-body); }
.mi-icon { width: 18px; flex: none; display: grid; place-items: center; }
.mi-label { flex: 1; }
.mi-hint { color: var(--muted); font-size: var(--text-caption); }
.menu-heading { font-size: var(--text-caption); letter-spacing: var(--tracking-caption); text-transform: uppercase; color: var(--muted); padding: 6px 10px 4px; font-weight: 500; }

.slash { width: 300px; max-height: 340px; overflow-y: auto; }
.slash-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; border-radius: var(--radius-small); padding: 4px 8px; cursor: pointer; text-align: left; color: var(--color-ink); }
.slash-item.sel, .slash-item:hover { background: var(--color-canvas); }
.sl-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border: 1px solid var(--border); border-radius: var(--radius-nested); background: var(--surface-card); }
.sl-icon .ic { width: 18px; height: 18px; }
.sl-text { display: flex; flex-direction: column; min-width: 0; }
.sl-label { font-size: var(--text-body); font-weight: 500; }
.sl-desc { font-size: var(--text-caption); color: var(--muted); }

.toolbar { display: flex; gap: 2px; min-width: 0; }
.tb-btn { border: 0; background: none; width: 32px; height: 32px; border-radius: var(--radius-small); cursor: pointer; padding: 0; display: grid; place-items: center; color: var(--color-ink); }
.tb-btn:hover { background: var(--color-canvas); }

.emoji-picker { width: 340px; padding: 6px; }
.emoji-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.emoji-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; }
.emoji-grid button { font-family: var(--emoji); border: 0; background: none; font-size: 20px; height: 32px; border-radius: var(--radius-nested); cursor: pointer; padding: 0; }
.emoji-grid button:hover { background: var(--hover); }
.emoji-input { margin-top: 8px; }

.cover-pop { width: 340px; padding: 6px; }
.cover-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cover-grid button { height: 44px; border: 1px solid var(--border); border-radius: var(--radius-nested); cursor: pointer; }
.cover-grid button:hover { outline: 2px solid var(--fg); outline-offset: 1px; }
.cover-row { display: flex; gap: 6px; margin-top: 10px; }

.share-pop { width: 340px; padding: var(--spacing-12); font-size: var(--text-body); }
.switch-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; cursor: pointer; }
.switch-row small { color: var(--muted); }
.switch { appearance: none; width: 36px; height: 20px; border-radius: var(--radius-badges); background: var(--active); position: relative; cursor: pointer; flex: none; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--color-paper); transition: transform .15s; box-shadow: var(--shadow-card); }
.switch:checked { background: var(--color-ink); }
.switch:checked::after { transform: translateX(16px); background: var(--color-surface-alt); }
.share-link { display: flex; gap: 6px; margin-top: 12px; }
.share-link .input { flex: 1; min-width: 0; }

/* ================================================================ sheets (components.css .overlay/.sheet) */
#layer > .overlay { z-index: 105; }
#layer > .dialog-overlay { z-index: 115; }
.dialog { width: min(100%, 420px); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--spacing-8); }
.search-modal { gap: 0; padding: 0; }
.search-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); color: var(--muted); }
.search-input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 17px; padding: 2px 0; color: var(--fg); }
.search-results { overflow-y: auto; padding: 8px; }
.search-item { display: flex; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 8px 12px; border-radius: var(--radius-buttons); cursor: pointer; align-items: flex-start; }
.search-item.sel { background: var(--hover); }
.si-icon { flex: none; width: 22px; display: grid; place-items: center; font-family: var(--emoji); }
.si-main { display: flex; flex-direction: column; min-width: 0; }
.si-title { font-size: var(--text-body); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-crumbs { color: var(--muted); font-weight: 400; }
.si-snippet { font-size: var(--text-caption); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-list { display: grid; gap: 2px; }
.trash-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-buttons); font-size: var(--text-body); }
.trash-row:hover { background: var(--hover); }
.tr-icon { font-family: var(--emoji); display: grid; place-items: center; }
.tr-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty, .loading { color: var(--muted); padding: var(--spacing-16); font-size: var(--text-body); }

.toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px);
  background: var(--color-ink-soft); color: var(--color-surface-alt); padding: 8px 16px; border-radius: var(--radius-badges); font-size: var(--text-body); font-weight: 500; box-shadow: var(--shadow-popover); transition: opacity .3s; z-index: 120; }
.toast.out { opacity: 0; }
.toast-action { border: 0; background: none; color: inherit; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; padding: 0; white-space: nowrap; }

/* ================================================================ published page (read-only), login */
body.share #sidebar, body.share #appbar, body.share .tabbar, .tabbar:empty { display: none !important; }
.login-body { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: var(--spacing-16); }
.login-card { width: min(360px, 100%); display: grid; gap: var(--spacing-16); }
.login-card p, .login-card h1 { margin: 0; } /* same card as the portal's login */

/* ================================================================ native.css adjustments for the editor */
.content:focus-visible, .title:focus-visible, .body:focus-visible { outline: none; }
@media (pointer: coarse) {
  /* native.css allows text selection only on contenteditable="true"; titles and code use plaintext-only */
  [contenteditable] { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
  /* …and forces 16px on contenteditable (no iOS zoom): keep the heading sizes of the blocks */
  .body.content > h1.content { font-size: var(--text-heading) !important; }
  .body.content > h2.content { font-size: var(--text-heading-sm) !important; }
  .body.content > h3.content { font-size: var(--text-subheading) !important; }
  .type-p .content { font-size: var(--text-body-lg) !important; }
  .title { font-size: var(--text-heading-lg) !important; }
  .type-code .content { font-size: 16px !important; }
}

/* ================================================================ touch screens: no hover */
@media (hover: none) {
  .tw-arrow, .cover-actions, .copy-btn, .sb-close, .page-controls { opacity: 1; }
  .tree-item:hover .tw-icon { opacity: 1; }
  .tree-item .tw-arrow { opacity: 0; }
  .tree-item.has-children .tw-arrow { opacity: 1; }
  .tree-item.has-children .tw-icon { opacity: 0; }
  .ti-actions { display: flex; }
  .ti-actions .icon-btn.sm { width: 36px; height: 36px; }
  .tree-item, .nav-item { min-height: 44px; }
  /* block menu on the right of the block being edited (the left gutter has no room on a phone) */
  .block { padding-right: 32px; }
  .gutter { display: flex; left: auto; right: 0; opacity: 0; }
  .gutter .g-add { display: none; }
  .gutter .g-drag { width: 28px; height: 28px; color: var(--muted); }
  .block:focus-within > .gutter { opacity: 1; }
  .mi-hint, .kbd { display: none; } /* keyboard shortcuts mean nothing on a touch screen */
}

/* ================================================================ phone layout (< 768px, PLATFORM_UI.md §2b)
   No sidebar: .appbar on top and .tabbar at the bottom (components.css), one full screen at a time. */
@media (max-width: 767px) {
  #sidebar, #scrim, .sb-toggle { display: none !important; }
  #appbar .app-mark { margin-left: 6px; }
  #appbar .presence { flex: none; }
  /* a page fills the screen; its title and menu live in the app bar */
  body.has-tabbar #main { margin: 0; width: 100%; max-width: none; border: 0; border-radius: 0; box-shadow: none; }
  body.has-tabbar #main .topbar { display: none; }
  body.share #main { margin: var(--spacing-16); width: calc(100% - 2 * var(--spacing-16)); }
  .topbar { height: 48px; padding: 0 var(--spacing-8) 0 var(--spacing-12); }
  .page, .page.full { padding: 20px 16px 40vh; }
  .page-skeleton { padding: 24px 16px; }
  .gutter { display: none; }
  .page-controls { opacity: 1; }
  .crumb-t { max-width: 110px; }
  .block { padding-left: calc(var(--indent, 0) * 18px); }
  /* list screens */
  #main.phone-list { background: var(--surface-canvas); overflow: hidden; }
  .phone-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .phone-search { padding: var(--spacing-12) var(--spacing-16); }
  .list { display: grid; }
  .list-row { width: 100%; border-left: 0; border-right: 0; border-top: 0; font: inherit; text-align: left; cursor: pointer; }
  .row-icon { width: 24px; flex: none; display: grid; place-items: center; font-family: var(--emoji); font-size: 18px; color: var(--color-ink-soft); }
  .row-text { flex: 1; min-width: 0; display: grid; }
  .row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
  .row-sub { font-size: var(--text-caption); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .row-more { margin-right: -8px; }
  .open-row { color: var(--color-ink-soft); }
  .more-row { justify-content: space-between; min-height: 56px; }
  .theme-row .row-title { flex: 1; }
  .more-row.destructive, .more-row.destructive .row-icon { color: var(--color-ember); }
  .more-row .row-icon + .row-title { flex: 1; }
  .empty-state { display: grid; justify-items: start; gap: var(--spacing-12); padding: var(--spacing-24) var(--spacing-16); }
  .empty-state p { margin: 0; }
  /* menus, pickers: bottom sheets with big rows; slash menu and formatting bar right above the keyboard */
  .phone-sheet .menu { min-width: 0; }
  .phone-sheet .menu-item { height: 48px; font-size: var(--text-body-lg); }
  .phone-sheet .emoji-picker, .phone-sheet .cover-pop { width: auto; }
  .slash, .toolbar { left: 0 !important; right: 0; top: auto !important; bottom: calc(var(--kb, 0px) + 0px); width: auto; max-height: 40vh; border-radius: var(--radius-nested) var(--radius-nested) 0 0; }
  body.has-tabbar .slash, body.has-tabbar .toolbar { bottom: max(var(--kb, 0px), calc(60px + env(safe-area-inset-bottom))); }
  .toolbar { justify-content: space-around; padding: 6px; }
  .tb-btn { width: 44px; height: 44px; }
}
@media (max-width: 767px) and (hover: none) { .gutter { display: flex; } }
@media (max-width: 600px) {
  .status-long { display: none; }
  /* the page title wins: the save status stays for screen readers only, parent crumbs shrink to their icon */
  #status:not(.warn) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  #status.warn { flex: none; } /* a failed save stays visible: « Hors ligne » */
  .crumb:not(:last-child) .crumb-t { display: none; }
  .crumb:last-child { flex: 1 1 auto; }
  .crumb:last-child .crumb-t { max-width: none; }
  .publish-btn .ic { display: none; }
}

/* ================================================================ sharing with people (same layout as the portal's share links), presence */
.share-sheet { display: grid; gap: var(--spacing-16); }
.share-sheet h3 { margin: 0; }
.share-help { margin: 0; }
.links, .publish { display: grid; gap: var(--spacing-12); }
.publish { padding-top: var(--spacing-16); border-top: 1px solid var(--border); }
.link-form { display: grid; grid-template-columns: 1fr auto; gap: var(--spacing-8); align-items: end; }
.link-form .field:first-child { grid-column: 1 / -1; }
.link-form .btn { grid-column: 1 / -1; justify-self: end; }
.fresh { display: grid; gap: var(--spacing-8); padding: var(--spacing-12); border: 1px solid var(--color-ink); border-radius: var(--radius-nested); }
.fresh p { margin: 0; }
.fresh-actions { display: flex; align-items: center; gap: var(--spacing-8); flex-wrap: wrap; }
.link-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--spacing-8); }
.link-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-8); padding: var(--spacing-8) 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.link-list li.expired .link-label { color: var(--muted); text-decoration: line-through; }
.link-text { display: grid; min-width: 0; flex: 1 1 180px; }
.link-label { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.link-actions .segmented > button { height: 26px; padding: 0 10px; font-size: 12px; }
.switch-row { display: flex; gap: var(--spacing-12); align-items: center; justify-content: space-between; cursor: pointer; }
.presence { display: flex; align-items: center; }
.presence:empty { display: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; margin-left: -6px; background: var(--color-ink-soft); color: var(--color-surface-alt); border: 2px solid var(--surface-card); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.avatar:first-child { margin-left: 0; }
.avatar.more { background: var(--color-canvas); color: var(--color-ink); }

/* ================================================================ table block */
.type-table .body { display: block; padding: 6px 2px; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-nested); }
.tbl { border-collapse: collapse; width: 100%; min-width: max-content; font-size: var(--text-body); line-height: var(--leading-body); }
.tbl-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 8px 10px; min-width: 96px; max-width: 360px; vertical-align: top; text-align: left; white-space: pre-wrap; word-break: break-word; outline: none; }
.tbl tr > .tbl-cell:last-child { border-right: 0; }
.tbl tr:last-child > .tbl-cell { border-bottom: 0; }
.tbl th.tbl-cell { background: var(--surface-canvas); font-weight: 600; }
.tbl-cell:focus { box-shadow: inset 0 0 0 1px var(--color-ink); background: var(--color-paper); }
.editor:not(.readonly) .tbl-cell:empty::before { content: '\200b'; } /* keeps an empty cell clickable at full height */
.tbl-tools { display: flex; gap: 4px; margin-top: 4px; opacity: 0; transition: opacity .15s; }
.type-table:hover .tbl-tools, .type-table:focus-within .tbl-tools { opacity: 1; }
@media (hover: none) { .tbl-tools { opacity: 1; } }
