/* ============================================================
   scratch.txt — Notion-style workspace
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --bg:            #ffffff;
  --bg-sidebar:    #f7f7f5;
  --bg-raised:     #ffffff;
  --bg-sunken:     #f1f1ef;
  --text:          #37352f;
  --text-muted:    #787774;
  --text-faint:    #b6b5b2;
  --border:        #e9e9e7;
  --border-strong: #dcdcd9;
  --hover:         rgba(55, 53, 47, 0.06);
  --hover-strong:  rgba(55, 53, 47, 0.10);
  --active:        rgba(55, 53, 47, 0.13);
  --sel:           rgba(35, 131, 226, 0.18);
  --accent:        #2383e2;
  --danger:        #eb5757;
  --shadow-sm:     0 1px 2px rgba(15, 15, 15, 0.06), 0 2px 6px rgba(15, 15, 15, 0.05);
  --shadow-md:     0 0 0 1px rgba(15, 15, 15, 0.05), 0 3px 6px rgba(15, 15, 15, 0.08), 0 9px 24px rgba(15, 15, 15, 0.10);

  --font-ui: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif,
             "Apple Color Emoji", "Segoe UI Emoji";
  --font-serif: Lyon-Text, Georgia, ui-serif, serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --font-editor: var(--font-ui);

  --sidebar-w: 260px;
  --page-w: 720px;
  --gutter: 54px;
  --radius: 4px;
  --tap: 40px;
  --kb-inset: 0px;   /* on-screen keyboard height, set from JS */

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:            #191919;
  --bg-sidebar:    #202020;
  --bg-raised:     #252525;
  --bg-sunken:     #2a2a2a;
  --text:          #d4d4d4;
  --text-muted:    #9b9b9b;
  --text-faint:    #6b6b6b;
  --border:        #2f2f2f;
  --border-strong: #3d3d3d;
  --hover:         rgba(255, 255, 255, 0.055);
  --hover-strong:  rgba(255, 255, 255, 0.09);
  --active:        rgba(255, 255, 255, 0.13);
  --sel:           rgba(35, 131, 226, 0.28);
  --accent:        #2383e2;
  --danger:        #ff6369;
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md:     0 0 0 1px rgba(255, 255, 255, 0.07), 0 5px 20px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* Text colour palette (Notion-ish) */
:root {
  --c-default: inherit;
  --c-gray:   #787774;  --c-brown: #9f6b53;  --c-orange: #d9730d;
  --c-yellow: #cb912f;  --c-green: #448361;  --c-blue:   #337ea9;
  --c-purple: #9065b0;  --c-pink:  #c14c8a;  --c-red:    #d44c47;
  --h-gray:   #f1f1ef;  --h-brown: #f4eeee;  --h-orange: #fbecdd;
  --h-yellow: #fbf3db;  --h-green: #edf3ec;  --h-blue:   #e7f3f8;
  --h-purple: #f6f3f9;  --h-pink:  #faf1f5;  --h-red:    #fdebec;
}
html[data-theme="dark"] {
  --c-gray:   #9b9b9b;  --c-brown: #ba856f;  --c-orange: #c77d48;
  --c-yellow: #ca9849;  --c-green: #529e72;  --c-blue:   #5e87c9;
  --c-purple: #9d68d3;  --c-pink:  #d15796;  --c-red:    #ff7369;
  --h-gray:   #2f2f2f;  --h-brown: #4a3228;  --h-orange: #5c3b23;
  --h-yellow: #56452f;  --h-green: #243d30;  --h-blue:   #143a4e;
  --h-purple: #3c2d49;  --h-pink:  #4e2c3c;  --h-red:    #522e2a;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
::selection { background: var(--sel); }
.hidden { display: none !important; }
/* Class rules that set `display` would otherwise beat the UA [hidden] rule. */
[hidden] { display: none !important; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Shell ---------- */
#app { display: flex; height: 100dvh; overflow: hidden; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: margin-left .22s cubic-bezier(.3, 0, .2, 1);
  padding-left: env(safe-area-inset-left);
}
#app.sb-collapsed #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.sb-top {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 8px 6px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
}
/* Workspace switcher */
.ws-switch {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 6px; border-radius: var(--radius);
  color: var(--text); transition: background .12s;
}
.ws-switch:hover { background: var(--hover); }
.ws-icon { font-size: 15px; line-height: 1; flex: 0 0 auto; }
.ws-name {
  flex: 1; min-width: 0; text-align: left;
  font-weight: 600; font-size: 14px; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ws-caret { flex: 0 0 auto; color: var(--text-muted); }

/* Workspace rows inside the switcher menu */
.ws-row-icon {
  width: 22px; height: 22px; flex: 0 0 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; background: var(--bg-sunken); font-size: 13px;
}
.ws-row-meta { font-size: 11.5px; color: var(--text-faint); margin-left: auto; padding-left: 10px; }

.icon-btn {
  width: 28px; height: 28px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius); color: var(--text-muted);
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { background: var(--hover-strong); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }

/* Search */
.sb-search { position: relative; margin: 4px 8px 8px; }
.sb-search-icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.sb-search input {
  width: 100%; height: 30px; padding: 0 26px 0 28px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--hover); outline: none; font-size: 14px;
}
.sb-search input::placeholder { color: var(--text-muted); }
.sb-search input:focus { background: var(--bg); border-color: var(--accent); box-shadow: 0 0 0 2px rgba(35,131,226,.18); }
.sb-search input::-webkit-search-cancel-button { display: none; }
.sb-search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; border-radius: 3px; color: var(--text-muted); }
.sb-search-clear:hover { background: var(--hover-strong); color: var(--text); }

/* Tree */
#tree { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 8px 12px; min-height: 0; -webkit-overflow-scrolling: touch; }

.row {
  display: flex; align-items: center; gap: 2px;
  height: 28px; border-radius: var(--radius);
  color: var(--text-muted); cursor: pointer;
  user-select: none; -webkit-user-select: none;
  position: relative; padding-right: 2px;
}
.row:hover { background: var(--hover); }
.row.is-active { background: var(--active); color: var(--text); font-weight: 500; }
.row.is-cut { opacity: .45; }

.row-twist {
  width: 20px; height: 20px; flex: 0 0 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px; color: var(--text-faint);
}
.row-twist svg { transition: transform .15s ease; }
.row.is-open > .row-twist svg { transform: rotate(90deg); }
.row-twist:hover { background: var(--hover-strong); color: var(--text); }
.row-twist.is-leaf { visibility: hidden; }

.row-icon { width: 20px; flex: 0 0 20px; text-align: center; font-size: 14px; line-height: 1; }
.row-name {
  flex: 1; min-width: 0; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-name mark { background: rgba(255, 212, 0, .45); color: inherit; border-radius: 2px; padding: 0 1px; }
html[data-theme="dark"] .row-name mark { background: rgba(255, 212, 0, .28); }

.row-acts { display: flex; gap: 1px; opacity: 0; transition: opacity .1s; }
.row:hover .row-acts, .row:focus-within .row-acts { opacity: 1; }
.row-act {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  border-radius: 3px; color: var(--text-muted);
}
.row-act:hover { background: var(--hover-strong); color: var(--text); }

.row-hint { font-size: 11px; color: var(--text-faint); padding: 0 4px; }

/* Drag & drop */
.row.drag-source { opacity: .4; }
.row.drop-into { background: rgba(35,131,226,.16); box-shadow: inset 0 0 0 1.5px var(--accent); }
.row.drop-before::before,
.row.drop-after::after {
  content: ''; position: absolute; left: 4px; right: 4px; height: 2px;
  background: var(--accent); border-radius: 2px;
}
.row.drop-before::before { top: -1px; }
.row.drop-after::after { bottom: -1px; }

.tree-empty { padding: 14px 10px; font-size: 13px; color: var(--text-faint); line-height: 1.5; }
.tree-section { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); padding: 12px 6px 4px; }
#tree.root-drop { background: rgba(35,131,226,.06); border-radius: 6px; }

/* Sidebar bottom */
.sb-bottom {
  display: flex; align-items: center; gap: 4px;
  padding: 8px; border-top: 1px solid var(--border);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.sb-action {
  flex: 1; display: flex; align-items: center; gap: 7px;
  height: 30px; padding: 0 8px; border-radius: var(--radius);
  color: var(--text-muted); font-size: 14px; font-weight: 500;
}
.sb-action:hover { background: var(--hover); color: var(--text); }

/* Scrim (mobile drawer) */
#scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(15, 15, 15, .4);
  opacity: 0; transition: opacity .22s;
  -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px);
}
#scrim.show { opacity: 1; }

/* ---------- Main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

#topbar {
  height: 45px; flex: 0 0 45px;
  display: flex; align-items: center; gap: 4px;
  padding: 0 10px 0 8px;
  padding-top: env(safe-area-inset-top);
  height: calc(45px + env(safe-area-inset-top));
  flex-basis: calc(45px + env(safe-area-inset-top));
  border-bottom: 1px solid transparent;
  transition: border-color .15s;
  background: var(--bg);
  position: relative; z-index: 20;
}
#topbar.scrolled { border-bottom-color: var(--border); }
.topbar-menu { display: none; }
#app.sb-collapsed .topbar-menu { display: inline-flex; }

#crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; overflow: hidden; }
.crumb {
  font-size: 14px; color: var(--text-muted); padding: 3px 6px; border-radius: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px;
  display: inline-flex; align-items: center; gap: 5px;
}
.crumb:hover { background: var(--hover); color: var(--text); }
.crumb.is-last { color: var(--text); font-weight: 500; }
.crumb-sep { color: var(--text-faint); font-size: 13px; flex: 0 0 auto; }

.topbar-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.save-state { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.save-state.is-saving { color: var(--text-muted); }

/* Scroll region */
#scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; scroll-padding-bottom: 120px; }

/* Empty state */
.empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  color: var(--text-muted); text-align: center; padding: 24px;
}
.empty-mark { font-size: 40px; opacity: .8; }
.empty h2 { margin: 4px 0 0; font-size: 17px; color: var(--text); font-weight: 600; }
.empty p { margin: 0 0 14px; font-size: 14px; }

/* ---------- Page ---------- */
#page { padding-bottom: 30vh; }
.page-head { max-width: var(--page-w); margin: 0 auto; padding: 40px var(--gutter) 0; }
#app.wide .page-head, #app.wide .blocks, #app.wide .click-catcher { max-width: none; }

.page-head-tools { height: 26px; margin-bottom: 4px; opacity: 0; transition: opacity .12s; }
.page-head:hover .page-head-tools, .page-head-tools:focus-within { opacity: 1; }
.page-head-tools.always { opacity: 1; }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 8px; border-radius: 3px;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
}
.ghost-btn:hover { background: var(--hover); color: var(--text); }
.ghost-btn-sm { height: 24px; font-size: 12px; }

.page-title-row { display: flex; align-items: flex-start; gap: 10px; }
.page-icon { font-size: 46px; line-height: 1.1; border-radius: 6px; padding: 0 4px; flex: 0 0 auto; }
.page-icon:hover { background: var(--hover); }

.page-title {
  flex: 1; min-width: 0; margin: 0;
  font-size: 38px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em;
  outline: none; word-break: break-word;
}
.page-title:empty::before,
.page-title[data-empty="1"]::before {
  content: attr(data-placeholder); color: var(--text-faint); pointer-events: none;
}

/* ---------- Blocks ---------- */
.blocks { max-width: var(--page-w); margin: 6px auto 0; padding: 0 var(--gutter); }
.click-catcher { max-width: var(--page-w); margin: 0 auto; padding: 0 var(--gutter); min-height: 30vh; cursor: text; }

.block { position: relative; display: flex; align-items: flex-start; }
.block[data-indent="1"] { margin-left: 26px; }
.block[data-indent="2"] { margin-left: 52px; }
.block[data-indent="3"] { margin-left: 78px; }
.block[data-indent="4"] { margin-left: 104px; }
.block[data-indent="5"] { margin-left: 130px; }
.block.is-hidden { display: none; }

/* Gutter controls */
.blk-gutter {
  position: absolute; left: -46px; top: 0;
  display: flex; align-items: center; gap: 1px; height: 28px;
  opacity: 0; transition: opacity .1s;
}
.block:hover > .blk-gutter, .block.menu-open > .blk-gutter { opacity: 1; }
.blk-gutter button {
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  border-radius: 3px; color: var(--text-faint);
}
.blk-gutter button:hover { background: var(--hover); color: var(--text-muted); }
.blk-handle { cursor: grab; touch-action: none; }
.blk-handle:active { cursor: grabbing; }

.block.drag-source { opacity: .35; }
.block.drop-before::before,
.block.drop-after::after {
  content: ''; position: absolute; left: 0; right: 0; height: 2px;
  background: var(--accent); border-radius: 2px; z-index: 5;
}
.block.drop-before::before { top: -1px; }
.block.drop-after::after { bottom: -1px; }

/* Block body */
.blk-body { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 2px; }
.blk-lead { flex: 0 0 auto; user-select: none; -webkit-user-select: none; }

.blk-content {
  flex: 1; min-width: 0; outline: none;
  padding: 3px 2px; word-break: break-word; white-space: pre-wrap;
  font-family: var(--font-editor);
  caret-color: var(--text);
}
.blk-content:empty::before,
.blk-content[data-empty="1"]::before {
  content: attr(data-placeholder); color: var(--text-faint); pointer-events: none; position: absolute;
}
.block:not(.is-focused) .blk-content[data-placeholder-focus="1"][data-empty="1"]::before { content: ''; }

/* Inline marks */
.blk-content code, .page-title code {
  font-family: var(--font-mono); font-size: .87em;
  background: var(--h-red); color: var(--c-red);
  padding: .15em .35em; border-radius: 3px;
}
.blk-content a { color: inherit; text-decoration: underline; text-decoration-color: var(--text-faint); text-underline-offset: 2px; cursor: pointer; }
.blk-content a:hover { text-decoration-color: var(--text-muted); }

/* Block types */
.block[data-type="h1"] .blk-content { font-size: 30px; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; padding-top: 26px; padding-bottom: 1px; }
.block[data-type="h2"] .blk-content { font-size: 24px; font-weight: 600; line-height: 1.3; padding-top: 20px; padding-bottom: 1px; }
.block[data-type="h3"] .blk-content { font-size: 19px; font-weight: 600; line-height: 1.3; padding-top: 15px; padding-bottom: 1px; }
.block[data-type="h1"] > .blk-gutter { height: 44px; align-items: flex-end; padding-bottom: 4px; }
.block[data-type="h2"] > .blk-gutter { height: 38px; align-items: flex-end; padding-bottom: 3px; }
.block[data-type="h3"] > .blk-gutter { height: 32px; align-items: flex-end; padding-bottom: 2px; }

.block[data-type="quote"] .blk-body { border-left: 3px solid currentColor; padding-left: 12px; margin: 4px 0; }
.block[data-type="quote"] .blk-content { font-size: 15px; }

/* Lists */
.blk-bullet, .blk-number {
  width: 22px; height: 27px; display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: var(--text); flex: 0 0 22px;
}
.blk-bullet::before { content: '•'; font-size: 18px; line-height: 1; }
.block[data-indent="1"] .blk-bullet::before,
.block[data-indent="4"] .blk-bullet::before { content: '◦'; }
.block[data-indent="2"] .blk-bullet::before,
.block[data-indent="5"] .blk-bullet::before { content: '▪'; font-size: 12px; }
.blk-number { font-size: 14.5px; font-variant-numeric: tabular-nums; }

/* Todo */
.blk-check {
  width: 22px; height: 27px; flex: 0 0 22px;
  display: flex; align-items: center; justify-content: center;
}
.blk-check input {
  appearance: none; -webkit-appearance: none; margin: 0;
  width: 16px; height: 16px; border: 1.4px solid var(--text-faint);
  border-radius: 3px; cursor: pointer; position: relative;
  transition: background .12s, border-color .12s;
}
.blk-check input:checked { background: var(--accent); border-color: var(--accent); }
.blk-check input:checked::after {
  content: ''; position: absolute; left: 4.5px; top: 1.5px;
  width: 4px; height: 8px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}
.block.is-done .blk-content { color: var(--text-faint); text-decoration: line-through; }

/* Toggle */
.blk-twist {
  width: 22px; height: 27px; flex: 0 0 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px; color: var(--text-muted); cursor: pointer;
}
.blk-twist:hover { background: var(--hover); }
.blk-twist svg { transition: transform .15s ease; }
.block.is-open > .blk-body > .blk-lead > .blk-twist svg { transform: rotate(90deg); }

/* Callout */
.block[data-type="callout"] .blk-body {
  background: var(--h-gray); border-radius: 4px;
  padding: 14px 14px 14px 12px; margin: 4px 0; gap: 8px; align-items: flex-start;
}
.blk-callout-icon { font-size: 17px; line-height: 1.5; cursor: pointer; border-radius: 3px; padding: 0 2px; }
.blk-callout-icon:hover { background: var(--hover-strong); }

/* Code */
.block[data-type="code"] .blk-body {
  background: var(--bg-sunken); border-radius: 4px; margin: 4px 0;
  padding: 30px 14px 14px; position: relative; display: block;
}
.block[data-type="code"] .blk-content {
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.55;
  tab-size: 2; white-space: pre-wrap; padding: 0;
}
.blk-code-bar {
  position: absolute; top: 5px; left: 8px; right: 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}
.blk-lang {
  font-size: 11.5px; color: var(--text-muted); background: transparent;
  border: 0; outline: none; cursor: pointer; border-radius: 3px; padding: 2px 4px;
  font-family: var(--font-ui);
}
.blk-lang:hover { background: var(--hover); }
.blk-code-actions { display: flex; align-items: center; gap: 4px; min-width: 0; }
.blk-copy { font-size: 11.5px; color: var(--text-muted); padding: 2px 6px; border-radius: 3px; opacity: 0; transition: opacity .12s; }
.block[data-type="code"]:hover .blk-copy { opacity: 1; }
.blk-copy:hover { background: var(--hover); color: var(--text); }

/* Only shown while the code block has the caret — Enter stays inside it,
   so the way out needs saying. */
.blk-hint {
  font-size: 11px; color: var(--text-faint); white-space: nowrap;
  opacity: 0; transition: opacity .12s; pointer-events: none;
}
.block[data-type="code"].is-focused .blk-hint { opacity: 1; }
@media (max-width: 820px) { .blk-hint { display: none; } }

/* Divider */
.block[data-type="divider"] .blk-body { padding: 10px 0; }
.blk-hr { width: 100%; height: 1px; background: var(--border-strong); border: 0; margin: 0; }

/* Image */
.block[data-type="image"] .blk-body { flex-direction: column; align-items: stretch; padding: 4px 0; }
.blk-img-wrap { position: relative; display: inline-block; max-width: 100%; border-radius: 4px; overflow: hidden; }
.blk-img-wrap img { display: block; max-width: 100%; height: auto; border-radius: 4px; }
.block.is-selected .blk-img-wrap img { box-shadow: 0 0 0 2px var(--accent); }
.blk-img-empty {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; background: var(--bg-sunken); border-radius: 4px;
  color: var(--text-muted); font-size: 14px; cursor: pointer;
}
.blk-img-empty:hover { background: var(--hover); }
.blk-caption { font-size: 12.5px; color: var(--text-muted); padding: 6px 2px 0; outline: none; }
.blk-caption:empty::before { content: 'Write a caption…'; color: var(--text-faint); }

/* Table */
.block[data-type="table"] .blk-body { display: block; padding: 6px 0; overflow-x: auto; }
.blk-table { border-collapse: collapse; min-width: 100%; font-size: 14px; }
.blk-table td, .blk-table th { border: 1px solid var(--border-strong); padding: 7px 9px; min-width: 100px; vertical-align: top; outline: none; }
.blk-table th { background: var(--bg-sunken); font-weight: 600; text-align: left; }
.blk-table td:focus, .blk-table th:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.blk-table-tools { display: flex; gap: 6px; padding-top: 6px; opacity: 0; transition: opacity .12s; }
.block[data-type="table"]:hover .blk-table-tools { opacity: 1; }
.blk-table-tools button { font-size: 12px; color: var(--text-muted); padding: 3px 7px; border-radius: 3px; background: var(--hover); }
.blk-table-tools button:hover { background: var(--hover-strong); color: var(--text); }

/* Colours */
[data-color="gray"]   { color: var(--c-gray); }
[data-color="brown"]  { color: var(--c-brown); }
[data-color="orange"] { color: var(--c-orange); }
[data-color="yellow"] { color: var(--c-yellow); }
[data-color="green"]  { color: var(--c-green); }
[data-color="blue"]   { color: var(--c-blue); }
[data-color="purple"] { color: var(--c-purple); }
[data-color="pink"]   { color: var(--c-pink); }
[data-color="red"]    { color: var(--c-red); }
[data-bg="gray"]   .blk-body, .blk-content [data-bg="gray"]   { background: var(--h-gray); }
[data-bg="brown"]  .blk-body, .blk-content [data-bg="brown"]  { background: var(--h-brown); }
[data-bg="orange"] .blk-body, .blk-content [data-bg="orange"] { background: var(--h-orange); }
[data-bg="yellow"] .blk-body, .blk-content [data-bg="yellow"] { background: var(--h-yellow); }
[data-bg="green"]  .blk-body, .blk-content [data-bg="green"]  { background: var(--h-green); }
[data-bg="blue"]   .blk-body, .blk-content [data-bg="blue"]   { background: var(--h-blue); }
[data-bg="purple"] .blk-body, .blk-content [data-bg="purple"] { background: var(--h-purple); }
[data-bg="pink"]   .blk-body, .blk-content [data-bg="pink"]   { background: var(--h-pink); }
[data-bg="red"]    .blk-body, .blk-content [data-bg="red"]    { background: var(--h-red); }
.blk-content [data-bg] { padding: .1em .2em; border-radius: 2px; }
.block[data-bg] > .blk-body { border-radius: 4px; padding-left: 8px; padding-right: 8px; }

/* ---------- Status bar ---------- */
#statusbar {
  flex: 0 0 auto; display: flex; justify-content: space-between; gap: 12px;
  padding: 5px 14px; padding-bottom: max(5px, env(safe-area-inset-bottom));
  font-size: 11.5px; color: var(--text-faint);
  border-top: 1px solid var(--border); background: var(--bg);
}

/* ---------- Inline toolbar ---------- */
.inline-bar {
  position: fixed; z-index: 60;
  display: flex; align-items: center; gap: 1px;
  background: var(--bg-raised); border-radius: 5px; padding: 3px;
  box-shadow: var(--shadow-md);
}
.ib-btn {
  height: 27px; min-width: 27px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  border-radius: 3px; font-size: 14px; color: var(--text);
}
.ib-btn:hover { background: var(--hover); }
.ib-btn.is-on { color: var(--accent); }
.ib-text { font-size: 13.5px; color: var(--text-muted); }
.ib-code { font-family: var(--font-mono); font-size: 11.5px; }
.ib-caret { opacity: .6; }
.ib-swatch { font-weight: 600; }
.ib-sep { width: 1px; height: 18px; background: var(--border); margin: 0 3px; }

/* ---------- Popovers ---------- */
.pop {
  position: fixed; z-index: 70;
  background: var(--bg-raised); border-radius: 6px;
  box-shadow: var(--shadow-md); padding: 5px;
  max-height: min(420px, 70dvh); overflow-y: auto;
}
.pop-menu { min-width: 190px; }
.pop-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 6px 9px; border-radius: 3px; font-size: 14px;
  color: var(--text); text-align: left;
}
.pop-item:hover, .pop-item.is-cursor { background: var(--hover); }
.pop-item.is-danger { color: var(--danger); }
.pop-item-icon { width: 16px; flex: 0 0 16px; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 14px; }
.pop-item.is-danger .pop-item-icon { color: var(--danger); }
.pop-item-key { margin-left: auto; font-size: 11.5px; color: var(--text-faint); }
.pop-sep { height: 1px; background: var(--border); margin: 5px 0; }
.pop-head { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); padding: 7px 9px 4px; }

/* Colour menu */
.pop-color { min-width: 190px; }
.color-dot {
  width: 19px; height: 19px; flex: 0 0 19px; border-radius: 3px;
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}

/* ---------- Command (slash) menu ---------- */
.cmd-menu {
  position: fixed; z-index: 70; width: 300px;
  background: var(--bg-raised); border-radius: 6px;
  box-shadow: var(--shadow-md); padding: 5px;
  max-height: min(340px, 55dvh); overflow-y: auto;
  overscroll-behavior: contain;
}
.cmd-empty { padding: 14px 12px; font-size: 13.5px; color: var(--text-faint); }
.cmd-group { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); padding: 8px 8px 4px; }
.cmd-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 6px 8px; border-radius: 4px; text-align: left;
}
.cmd-item.is-cursor { background: var(--hover); }
.cmd-ico {
  width: 40px; height: 34px; flex: 0 0 40px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 3px;
  background: var(--bg); font-size: 16px;
}
.cmd-txt { min-width: 0; }
.cmd-name { font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-desc { font-size: 12px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Emoji picker ---------- */
.pop-emoji { width: 320px; padding: 8px; }
.emoji-head { display: flex; gap: 6px; margin-bottom: 8px; }
.emoji-head input {
  flex: 1; height: 28px; padding: 0 9px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--bg); outline: none; font-size: 13.5px;
}
.emoji-head input:focus { border-color: var(--accent); }
.emoji-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 1px; max-height: 240px; overflow-y: auto; }
.emoji-grid button { height: 31px; border-radius: 4px; font-size: 19px; line-height: 1; }
.emoji-grid button:hover { background: var(--hover); }
.emoji-cat { grid-column: 1 / -1; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); padding: 8px 2px 3px; }

/* ---------- Dialog ---------- */
.dialog-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(15, 15, 15, .45);
  display: flex; align-items: center; justify-content: center; padding: 18px;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
/* Flex column so the action row stays pinned while the body scrolls. */
.dialog {
  background: var(--bg-raised); border-radius: 8px;
  width: 100%; max-width: 400px; box-shadow: var(--shadow-md);
  max-height: 88dvh;
  display: flex; flex-direction: column; overflow: hidden;
}
.dialog-scroll { overflow-y: auto; min-height: 0; padding: 22px 22px 0; }
.dialog-wide { max-width: 520px; }
.dialog h2 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
.dialog-body { margin: -6px 0 14px; font-size: 13.5px; color: var(--text-muted); line-height: 1.5; white-space: pre-line; }

/* Confirmations must sit above the settings sheet, which is also a
   .dialog-scrim and comes later in the DOM (equal z-index would lose). */
#dialogScrim { z-index: 96; }

/* Multi-choice dialogs stack their actions on narrow screens. */
.dialog-actions { flex-wrap: wrap; }
.dialog-choice { flex: 1 1 auto; min-width: 140px; }
.dialog-warn {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--h-yellow); border-radius: 5px;
  padding: 10px 12px; margin: 0 0 14px;
  font-size: 13px; line-height: 1.5; color: var(--text);
}
.dialog-warn.is-danger { background: var(--h-red); }
.dialog-warn-icon { flex: 0 0 auto; font-size: 14px; line-height: 1.45; }
.dialog-stats {
  display: flex; gap: 18px; flex-wrap: wrap;
  padding: 11px 13px; margin: 0 0 14px;
  background: var(--bg-sunken); border-radius: 5px;
}
.dialog-stat strong { display: block; font-size: 17px; font-weight: 600; line-height: 1.25; }
.dialog-stat small { font-size: 11.5px; color: var(--text-muted); }
.dialog-fields { display: flex; flex-direction: column; gap: 10px; }
.dialog-fields:empty { display: none; }
.dialog-fields input {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--bg); outline: none; font-size: 14px;
}
.dialog-fields input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(35,131,226,.18); }
.dialog-fields label { font-size: 12.5px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }
.dialog-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  flex: 0 0 auto; padding: 16px 22px 20px;
  border-top: 1px solid transparent;
}
/* Hairline appears only when there is scrolled-away content above. */
.dialog.is-scrollable .dialog-actions { border-top-color: var(--border); }

.btn {
  height: 32px; padding: 0 13px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--bg);
  font-size: 13.5px; font-weight: 500; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;   /* stops "Delete all" wrapping onto two lines */
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1b6fc4; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }

/* Settings */
.set-section { margin-bottom: 22px; }
.set-section h3 { margin: 0 0 10px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.set-row:last-child { border-bottom: 0; }
.set-row-quiet { border-bottom: 0; }
.set-row strong { display: block; font-size: 14px; font-weight: 500; }
.set-row small { display: block; font-size: 12.5px; color: var(--text-muted); margin-top: 1px; }
.set-note { font-size: 12.5px; color: var(--text-muted); margin: -4px 0 12px; line-height: 1.5; }
.set-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.set-danger h3 { color: var(--danger); }

/* Shortcuts reference */
/* Sized so two columns fit inside .dialog-wide's own max-width (520px minus
   padding leaves ~476px) — otherwise the multi-column layout never engages
   at the dialog's default size and this list reads as one long column. */
.sc-groups { column-width: 205px; column-gap: 24px; margin-bottom: 4px; }
.sc-group { break-inside: avoid; margin-bottom: 20px; }
.sc-group h3 { margin: 0 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint); }
/* flex-wrap at both levels: the key cluster first tries to sit beside the
   label, drops to its own line under a long label when it won't fit, and —
   for rows with several alternatives (arrow keys) — wraps within itself
   rather than ever running past the column edge. */
.sc-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; column-gap: 14px; row-gap: 2px; padding: 5px 0; }
.sc-row span:first-child { flex: 1 1 auto; min-width: 0; font-size: 13.5px; color: var(--text); }
.sc-keys { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px; flex: 0 1 auto; min-width: 0; }
kbd.sc-key {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 4px; border: 1px solid var(--border-strong);
  background: var(--bg-sunken); box-shadow: 0 1px 0 var(--border-strong);
  font: 11.5px/1 var(--font-ui); font-weight: 500; color: var(--text-muted);
  white-space: nowrap; flex: 0 0 auto;
}
.sc-keys .sc-plus { font-size: 11px; color: var(--text-faint); white-space: nowrap; flex: 0 0 auto; }
.sc-hint { font-size: 12.5px; color: var(--text-muted); margin: -8px 0 16px; line-height: 1.5; }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 4px; overflow: hidden; flex: 0 0 auto; }
.seg button { padding: 5px 11px; font-size: 12.5px; color: var(--text-muted); border-right: 1px solid var(--border-strong); }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--hover); }
.seg button.is-on { background: var(--accent); color: #fff; }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: 0 0 38px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 22px; cursor: pointer; transition: background .16s; }
.switch span::before {
  content: ''; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: transform .16s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 100;
  left: 50%; bottom: max(22px, calc(env(safe-area-inset-bottom) + 16px));
  transform: translateX(-50%) translateY(8px);
  background: #2f2f2f; color: #fff;
  padding: 9px 15px; border-radius: 5px; font-size: 13.5px;
  box-shadow: var(--shadow-md); opacity: 0;
  transition: opacity .18s, transform .18s;
  max-width: calc(100vw - 32px); text-align: center;
}
html[data-theme="dark"] .toast { background: #3a3a3a; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Mobile format bar ---------- */
.mobile-bar {
  flex: 0 0 auto; background: var(--bg-raised);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-bar-scroll {
  display: flex; align-items: center; gap: 2px;
  padding: 5px 8px; overflow-x: auto; scrollbar-width: none;
}
.mobile-bar-scroll::-webkit-scrollbar { display: none; }
.mbar-btn {
  min-width: 38px; height: 36px; flex: 0 0 auto; padding: 0 9px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px; font-size: 15px; color: var(--text);
}
.mbar-btn:active, .mbar-btn.is-on { background: var(--hover-strong); }
.mbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex: 0 0 auto; }

/* ============================================================
   Responsive
   ============================================================ */

/* Tablet */
@media (max-width: 1100px) {
  :root { --gutter: 44px; }
}

/* Phone / small tablet — sidebar becomes a drawer */
@media (max-width: 820px) {
  :root { --gutter: 20px; --sidebar-w: 290px; --tap: 44px; }

  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    margin-left: 0 !important;
    transform: translateX(-102%);
    transition: transform .24s cubic-bezier(.3, 0, .2, 1);
    box-shadow: none; border-right: 0;
    width: min(var(--sidebar-w), 86vw);
    flex-basis: auto;
  }
  #app.drawer-open #sidebar { transform: translateX(0); box-shadow: var(--shadow-md); }
  .topbar-menu { display: inline-flex !important; }

  /* Bigger touch targets */
  .row { height: var(--tap); }
  .row-twist { width: 30px; height: 30px; flex-basis: 30px; }
  .row-icon { width: 24px; flex-basis: 24px; font-size: 15px; }
  .row-name { font-size: 15px; }
  .row-acts { opacity: 1; }
  .row-act { width: 30px; height: 30px; }
  .sb-action, .sb-search input { height: 38px; font-size: 15px; }
  .icon-btn { width: 34px; height: 34px; }

  /* Page */
  .page-head { padding-top: 22px; }
  .page-title { font-size: 29px; }
  .page-icon { font-size: 38px; }
  .page-head-tools { opacity: 1; }

  /* Gutter controls move inline — no hover on touch */
  .blk-gutter { display: none; }
  .block { padding-left: 0; }
  .block[data-indent="1"] { margin-left: 18px; }
  .block[data-indent="2"] { margin-left: 36px; }
  .block[data-indent="3"] { margin-left: 54px; }
  .block[data-indent="4"] { margin-left: 72px; }
  .block[data-indent="5"] { margin-left: 90px; }

  .blk-content { padding-top: 5px; padding-bottom: 5px; font-size: 16px; }
  .block[data-type="h1"] .blk-content { font-size: 25px; padding-top: 20px; }
  .block[data-type="h2"] .blk-content { font-size: 21px; padding-top: 16px; }
  .block[data-type="h3"] .blk-content { font-size: 18px; padding-top: 13px; }
  .blk-check input { width: 19px; height: 19px; }
  .blk-check input:checked::after { left: 5.5px; top: 2.5px; }
  .blk-check, .blk-bullet, .blk-number, .blk-twist { height: 31px; }

  /* Menus become bottom sheets */
  .cmd-menu {
    width: 100% !important; left: 0 !important; right: 0 !important;
    top: auto !important; bottom: var(--kb-inset, 0px) !important;
    border-radius: 12px 12px 0 0; max-height: 52dvh;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 24px rgba(0,0,0,.22);
  }
  .cmd-item { padding: 9px 8px; }
  .pop-menu, .pop-color {
    left: 0 !important; right: 0 !important; top: auto !important; bottom: var(--kb-inset, 0px) !important;
    width: 100%; min-width: 0; border-radius: 12px 12px 0 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    max-height: 60dvh; box-shadow: 0 -6px 24px rgba(0,0,0,.22);
  }
  .pop-item { padding: 11px 12px; font-size: 15px; }
  .pop-emoji {
    left: 0 !important; right: 0 !important; top: auto !important; bottom: var(--kb-inset, 0px) !important;
    width: 100%; border-radius: 12px 12px 0 0;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  }
  .emoji-grid { grid-template-columns: repeat(8, 1fr); max-height: 40dvh; }
  .emoji-grid button { height: 38px; font-size: 22px; }

  /* Inline toolbar hidden — the mobile bar takes over */
  .inline-bar { display: none !important; }

  /* Ancestor crumbs eat the whole bar on a phone — keep only the page. */
  .crumb:not(.is-last), .crumb-sep { display: none; }
  .crumb.is-last { max-width: none; font-size: 15px; }

  /* Dialogs become bottom sheets: thumb-reachable, with the action row
     always visible instead of buried below a long scroll. */
  .dialog-scrim { align-items: flex-end; padding: 0; }
  .dialog {
    max-width: none; width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 90dvh;
  }
  .dialog-scroll { padding: 18px 16px 0; }
  .dialog h2 { font-size: 17px; }
  /* Stacked full-width actions, ordered by intent: primary first,
     destructive in the middle, Cancel always last and reachable. */
  .dialog-actions {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--bg-raised);
    flex-direction: column; gap: 8px;
  }
  .dialog-actions .btn { height: 44px; width: 100%; flex: 0 0 auto; font-size: 15px; }
  .dialog-choice { min-width: 0; order: 1; }
  #dialogCancel { order: 99; }

  /* Single column — two 240px columns would not fit anyway, but be explicit
     rather than relying on the column-width collapse. */
  .sc-groups { column-width: auto; column-count: 1; }
  .sc-row { padding: 8px 0; }
  .sc-row span:first-child { font-size: 14.5px; }
  kbd.sc-key { min-width: 24px; height: 24px; font-size: 12.5px; }

  /* Label and control stop fighting for width — stack them instead. */
  .set-row { flex-direction: column; align-items: stretch; gap: 10px; padding: 13px 0; }
  .set-row > div:first-child { min-width: 0; }
  .set-row .seg { width: 100%; }
  .set-row .seg button { flex: 1 1 0; text-align: center; padding: 9px 6px; font-size: 13.5px; }
  .set-row .btn { align-self: flex-start; height: 38px; padding: 0 18px; }
  /* The row is a column here, so the switch's `flex: 0 0 38px` would set its
     HEIGHT and deform the pill into a circle. Pin both axes back. */
  .set-row .switch { align-self: flex-start; flex: 0 0 auto; width: 42px; height: 24px; }
  .set-row .switch span::before { width: 20px; height: 20px; }
  .set-row .switch input:checked + span::before { transform: translateX(18px); }
  .set-buttons .btn { flex: 1 1 auto; height: 40px; }
  .set-row strong { font-size: 15px; }
  .set-row small { font-size: 13px; }

  .dialog-stats { gap: 0 14px; }
  .dialog-stat { flex: 1 1 40%; }

  #statusbar { display: none; }
  #page { padding-bottom: 24vh; }
}

@media (max-width: 400px) {
  :root { --gutter: 14px; }
  .page-title { font-size: 26px; }
}

/* Pointer is coarse — never rely on hover */
@media (hover: none) {
  .row-acts, .page-head-tools, .blk-table-tools, .blk-copy { opacity: 1; }
}

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

/* ---------- Print ---------- */
@media print {
  #sidebar, #topbar, #statusbar, #scrim, .blk-gutter, .mobile-bar,
  .page-head-tools, .blk-table-tools, .blk-copy, .inline-bar, .pop, .cmd-menu { display: none !important; }
  #app, #main, #scroll { display: block; height: auto; overflow: visible; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .blocks, .page-head { max-width: none; padding: 0; }
  #page { padding: 0; }
  .block { break-inside: avoid; }
  .block[data-type="h1"], .block[data-type="h2"] { break-after: avoid; }
  a { color: #000; text-decoration: underline; }
}
