/* Writing surface (story 005). Blocks render without chrome; marks are the only decoration. */
.editor { position: relative; isolation: isolate; }   /* own stacking context so the selection wash (z-index -1) paints above the sheet */
.blocks { display: flex; flex-direction: column; gap: 4px; }
.blk { position: relative; }
.ed { outline: none; min-height: 1em; white-space: pre-wrap; word-break: break-word; }
/* placeholders (story 024): only the block the caret is in asks for input; a fresh page's single block keeps its hint */
.ed:focus:empty::before, .blocks > .blk:only-child > .ed.body:empty::before { content: attr(data-ph); color: var(--g5); pointer-events: none; }
.body { font: 400 var(--page-size) / 1.65 var(--page-font); color: var(--g9); text-align: var(--page-align); text-wrap: pretty; margin: 0 0 12px; }
.hd { font-family: var(--page-font); font-weight: 600; letter-spacing: -.01em; text-wrap: balance; color: var(--g9); margin: 20px 0 8px; }
.hd.h2 { font-size: calc(var(--page-size) * 1.45); line-height: 1.2; }
.hd.h3 { font-size: calc(var(--page-size) * 1.15); line-height: 1.3; }
.hd.h4 { font-size: var(--page-size); line-height: 1.4; margin-top: 16px; }   /* story 040: the fourth level is the body size, bold */
/* story 040: heading anchors — a link button at the end of a hovered heading */
.hd { position: relative; }
.anchor-btn { position: absolute; right: -28px; top: 50%; transform: translateY(-50%); width: var(--h-icon); height: var(--h-icon); display: grid; place-items: center; color: var(--g6); border-radius: var(--r-s); opacity: 0; transition: opacity 120ms ease-out; font: var(--nav-text); }
.blk:hover .anchor-btn, .anchor-btn:focus-visible { opacity: 1; }
.anchor-btn:hover { background: var(--g3); color: var(--g8); }
.anchor-btn.copied { opacity: 1; width: auto; padding: 0 6px; color: var(--g7); }
.blk.landed > .hd { animation: land 1.6s ease-out; }
@keyframes land { from { background: var(--selection-block); } to { background: transparent; } }
.blk:first-child .hd { margin-top: 0; }
.callout { margin: 4px 0 12px; padding: 12px 14px 12px 40px; border-radius: var(--r-m); background: var(--wash, var(--g2)); position: relative; }
.callout > .i { position: absolute; left: 14px; top: 14px; color: var(--g7); }   /* story 040: one small icon per kind, in the margin */
.callout .body { margin: 0; }
.callout.v-quote { background: none; padding: 0 0 0 14px; border-left: 2px solid var(--g4); border-radius: 0; }
.callout.v-quote .body { font-style: italic; color: var(--g7); hanging-punctuation: first; }
.callout.v-warning { background: var(--callout-warn); }
.callout.v-tip { background: var(--callout-tip); }
.callout.v-info { background: var(--callout-info); }
.callout.v-caution { background: var(--callout-caution); }
.callout.v-important { background: var(--callout-important); }
.code { margin: 4px 0 12px; padding: 8px 14px 12px; border-radius: var(--r-m); background: var(--wash, var(--g2)); overflow: auto; }
/* story 039: the code bar — nothing at rest but a set file name or language in --g6; the rest on hover or focus */
.code-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 20px; margin: 0 0 4px; font: 400 12px/20px var(--mono); color: var(--g6); }
.code-title { flex: 1; min-width: 2ch; outline: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-title:empty::before { content: attr(data-ph); color: var(--g5); opacity: 0; transition: opacity 120ms ease-out; }
.code:hover .code-title:empty::before, .code:focus-within .code-title:empty::before { opacity: 1; }
.code-tools { display: flex; gap: 2px; flex: none; }
.code-tools button { height: 20px; padding: 0 6px; border-radius: var(--r-xs); font: 400 12px/20px var(--font); color: var(--g6); opacity: 0; transition: opacity 120ms ease-out; }
.code.has-lang .code-lang { opacity: 1; }
.code:hover .code-tools button, .code:focus-within .code-tools button { opacity: 1; }
.code-tools button:hover { background: var(--g3); color: var(--g8); }
.hl-kw { font-weight: 600; color: var(--g9); }
.hl-str { color: var(--g7); }
.hl-cm { color: var(--g6); font-style: italic; }
.hl-num { color: var(--g8); }
.code code { font: 400 calc(var(--page-size) * .8125)/1.55 var(--mono); color: var(--g8); white-space: pre; display: block; }
.li { position: relative; padding-left: 26px; }
.li::before { position: absolute; left: 0; width: 18px; text-align: right; color: var(--g7); font: 400 var(--page-size)/1.65 var(--page-font); }
/* issue 80: bullets are drawn, not typed — the glyph "•" is a tiny square in Instrument Sans and a fat dot in the serif */
.li.s-bullet::before { content: ""; box-sizing: border-box; width: 7px; height: 7px; left: 5px; top: calc(var(--page-size) * .825 - 3.5px); border-radius: 50%; background: var(--g7); }   /* dot and ring share one outer size (owner, v53) */
.li.s-number::before { content: attr(data-n); font-variant-numeric: tabular-nums; }
.li .body { margin: 0 0 4px; }
.li.ind-1 { margin-left: 26px; } .li.ind-2 { margin-left: 52px; }   /* story 033: ⇥ indents, markers change per level */
.li.ind-1.s-bullet::before { background: transparent; border: 1.5px solid var(--g7); }   /* ring */
.li.ind-2.s-bullet::before { width: 5px; height: 5px; left: 6px; border-radius: 0; top: calc(var(--page-size) * .825 - 2.5px); }   /* small square */
/* story 033 / issue 79: selected blocks — one continuous wash behind the whole run, drawn by .selbox; the blocks themselves stay untouched */
.selbox { position: absolute; z-index: -1; pointer-events: none; background: var(--selection-block); border-radius: var(--r-m); transition: top 60ms ease-out, height 60ms ease-out; }
.blk.sel *::selection { background: transparent; }
.rule { border: 0; border-top: 1px solid var(--g4); margin: 16px 0; }
.blk[tabindex]:focus { outline: none; }
.blk[tabindex]:focus .rule { border-top-color: var(--g8); }
.ed a { color: var(--g9); text-decoration: underline; text-decoration-color: var(--g5); text-underline-offset: 2px; }
/* story 041: page links — a gone target shows dotted in --g5 */
.ed a.pl.dead { text-decoration-style: dotted; color: var(--g7); }
/* story 046: variables — a known {name} is dotted with its value as a tooltip; an unknown one fades */
.ed .var { text-decoration: underline dotted var(--g5); text-underline-offset: 3px; }
.ed .var.unknown { color: var(--g5); }
.blk.shared > .gut::after { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--g6); align-self: center; margin-left: 2px; }   /* a shared block's mark, with the gutter */
.slash.pick button small { display: block; }
.slash.pick button { display: block; }
/* selection color: `.canvas *::selection` in app.css (story 017/B3 — `.ed ::selection` never matched the block's own text) */

/* slash menu — transient pop-over */
.slash { position: absolute; z-index: var(--z-inline); width: min(240px, calc(100vw - 32px)); max-height: min(320px, 40dvh); overflow-y: auto; background: var(--g0); border: 1px solid var(--g4); border-radius: var(--r-m); box-shadow: var(--float); padding: 4px; display: grid; }
.slash button { display: grid; text-align: left; padding: 6px 10px; border-radius: var(--r-s); font: var(--nav-type); color: var(--g8); }
.slash button small { font: var(--nav-text); color: var(--g7); }
.slash button:hover { background: var(--g2); color: var(--g9); }\n.slash button.on { background: var(--g3); color: var(--g9); }

/* selection toolbar — floating */
.fmt { position: absolute; z-index: var(--z-inline); display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--g0); border: 1px solid var(--g4); border-radius: var(--r-m); box-shadow: var(--float); }
.fmt button { width: var(--h-ctl); height: var(--h-ctl); border-radius: var(--r-s); display: grid; place-items: center; font: 500 13px var(--font); color: var(--g8); }
.fmt button:hover { background: var(--g2); }
.fmt button.on { background: var(--g3); color: var(--g9); }
.fmt .sep { width: 1px; height: 16px; background: var(--g3); margin: 0 4px; }
.fmt .mono-mark { font: 600 13px var(--mono); }
.fmt button.text { width: auto; padding: 0 8px; }
.ed code { font: .9em var(--mono); background: var(--wash, var(--g2)); padding: 1px 4px; border-radius: var(--r-xs); }   /* inline code (story 034) */
.linkpop { position: absolute; z-index: var(--z-inline); display: flex; align-items: center; gap: 4px; padding: 4px; background: var(--g0); border: 1px solid var(--g4); border-radius: var(--r-m); box-shadow: var(--float); }
.linkpop input { width: 260px; height: var(--h-ctl); }
.linkpop button.text { height: var(--h-ctl); padding: 0 8px; border-radius: var(--r-s); font: var(--nav-type); color: var(--g8); }
.linkpop button.text:hover { background: var(--g2); }
.linkpop button.danger { color: var(--danger); }
.fmt [data-color] { width: 18px; height: 18px; border-radius: 50%; background: var(--c); margin: 0 2px; border: 1px solid var(--g4); }
.fmt [data-color].none { background: var(--g0); position: relative; }
.fmt [data-color].none::after { content: ""; position: absolute; inset: 7px 2px; border-top: 1px solid var(--g6); transform: rotate(-45deg); }

/* ===== story 006: gutter, table, image, columns ===== */
.blk { padding-left: 0; }
.gut { position: absolute; left: -40px; top: 2px; display: flex; gap: 2px; opacity: 0; transition: opacity 120ms ease-out; }
/* align the gutter with the block's first text line, not the wrapper top (block top margins differ) */
.blk:has(> .hd) .gut { top: 22px; }
.blk:first-child:has(> .hd) .gut { top: 3px; }
.blk:has(> .callout) .gut { top: 18px; }
.blk:has(> .callout.v-quote) .gut { top: 6px; }
.blk:has(> .code) .gut { top: 32px; }
.blk:has(> .tbl-box) .gut { top: 9px; }
.blk:has(> .img) .gut, .blk:has(> .img-empty) .gut { top: 6px; }
.blk:has(> .rule) .gut { top: 6px; }
.blk:hover .gut, .blk:focus-within .gut { opacity: 1; }
.bmenu button:focus-visible { background: var(--g2); outline: none; }   /* story 057: the focused menu item reads like the hovered one */
.gut .grip, .gut .plus { width: 18px; height: var(--h-icon); border-radius: var(--r-s); display: grid; place-items: center; color: var(--g6); }
.gut .plus:hover { background: var(--g3); color: var(--g7); }
.gut .grip { cursor: grab; transform: rotate(90deg); }
.gut .grip:hover { background: var(--g3); color: var(--g7); }
.blk.dragging { opacity: .4; }
.blk.drop-before::before, .blk.drop-after::after { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--g8); border-radius: 1px; z-index: 2; }
.blk.drop-before::before { top: -3px; } .blk.drop-after::after { bottom: -3px; }
.bmenu { position: absolute; left: -40px; right: auto; top: 26px; z-index: var(--z-menu); min-width: 180px; width: max-content; background: var(--g0); border: 1px solid var(--g4); border-radius: var(--r-m); box-shadow: var(--float); padding: 4px; display: grid; }
.bmenu button { height: var(--h-ctl); padding: 0 10px; border-radius: var(--r-s); font: var(--nav-type); text-align: left; color: var(--g8); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.bmenu kbd { font: var(--nav-text); color: var(--g7); }
.bmenu button:hover { background: var(--g2); }
.bmenu button.danger { color: var(--danger); }

.tbl-box { position: relative; margin: 4px 0 12px; }
.tbl-wrap { overflow-x: auto; padding: 8px 0 0 8px; margin: -8px 0 0 -8px; }   /* room for the handles inside the scroll box */
.tbl { width: 100%; border-collapse: collapse; font: 400 calc(var(--page-size) * .9) / 1.5 var(--page-font); }
.tbl th, .tbl td { position: relative; border: 1px solid var(--g3); padding: 0; vertical-align: top; min-width: 80px; }
.tbl th { background: var(--wash, var(--g2)); font-weight: 600; text-align: left; }
.tbl .cell { padding: 6px 10px; min-height: var(--h-row); outline: none; }
.tbl .cell:focus { background: var(--focus-wash); }
/* story 032: handles for the hovered row / column, edge adders while the table is hovered — nothing at rest */
.tbl .rowh, .tbl .colh, .cols .colh, .cols .cadd, .tadd { position: absolute; display: grid; place-items: center; color: var(--g5); background: var(--g0); border-radius: var(--r-xs); opacity: 0; transition: opacity 120ms ease-out; z-index: 1; }
.tbl .rowh, .tbl .colh, .cols .colh, .cols .cadd { width: 14px; height: 14px; }
.tbl .rowh .i, .tbl .colh .i, .cols .colh .i, .cols .cadd .i, .tadd .i { width: 12px; height: 12px; }
.tbl .rowh { left: -7px; top: 50%; transform: translateY(-50%) rotate(90deg); }   /* ⋮ beside the row, ⋯ above the column */
.tbl .colh { top: -7px; left: 50%; transform: translateX(-50%); }
.tbl .rowh.show, .tbl .colh.show { opacity: 1; }
.tbl .rowh:hover, .tbl .colh:hover, .cols .colh:hover, .cols .cadd:hover, .tadd:hover { color: var(--g7); background: var(--g3); }
.tadd { border-radius: var(--r-xs); }
.tadd-col { top: 0; bottom: 0; right: -16px; width: 14px; }
.tadd-row { left: 0; right: 0; bottom: -16px; height: 14px; }
.tbl-box:hover .tadd { opacity: 1; }
.bmenu.mini { left: auto; top: auto; min-width: 140px; }

.img { margin: 4px 0 12px; display: grid; gap: 6px; }
/* story 043: the image bar — caption and alt on hover or focus; a set caption reads at rest */
.img-bar { display: grid; gap: 2px; font: var(--nav-text); color: var(--g7); letter-spacing: -.005em; }
.img-cap, .img-alt { outline: none; min-height: 18px; }
.img-cap:empty::before, .img-alt:empty::before { content: attr(data-ph); color: var(--g5); }
.img-alt, .img-cap:empty { opacity: 0; transition: opacity 120ms ease-out; }
.img-alt { color: var(--g6); }
.img-alt::before { content: "Alt · "; color: var(--g5); }
.img-alt:empty::before { content: attr(data-ph); }
.blk:hover .img-alt, .blk:focus-within .img-alt, .blk:hover .img-cap, .blk:focus-within .img-cap { opacity: 1; }
.img img { max-width: 100%; border-radius: var(--r-m); display: block; }
.img-empty { margin: 4px 0 12px; padding: 20px; border: 1px dashed var(--g4); border-radius: var(--r-m); display: flex; align-items: center; gap: 12px; }
.img-empty .btn.small { width: auto; }
.img-empty .note { margin: 0; }
.blk[tabindex]:focus .img-empty { border-color: var(--g6); }

/* story 047: tabs — a quiet strip, the active label in the ink with a hairline; plus and × on hover */
.tabs { margin: 4px 0 12px; }
.tabbar { display: flex; align-items: center; gap: 2px; border-bottom: 1px solid var(--g3); margin-bottom: 8px; font: var(--nav-type); color: var(--g7); letter-spacing: -.005em; }
.tab-l { display: inline-flex; align-items: center; gap: 4px; height: var(--h-ctl); padding: 0 8px; margin-bottom: -1px; border-bottom: 1px solid transparent; cursor: pointer; }
.tab-l:hover { color: var(--g8); }
.tab-l.on { color: var(--g9); border-bottom-color: var(--g9); cursor: text; }
.tab-name { outline: none; min-width: 1ch; white-space: nowrap; }
.tab-name:empty::before { content: attr(data-ph); color: var(--g5); }
.tab-del, .tab-add { width: 18px; height: 18px; display: grid; place-items: center; border-radius: var(--r-xs); color: var(--g6); opacity: 0; transition: opacity 120ms ease-out; }
.tab-del .i, .tab-add .i { width: 12px; height: 12px; }
.tabs:hover .tab-del, .tabs:hover .tab-add, .tabs:focus-within .tab-add, .tabs:focus-within .tab-del { opacity: 1; }   /* story 057: the strip shows while the pane has focus */
.tab-del:hover, .tab-add:hover { background: var(--g3); color: var(--g8); }
.tabs .pane { margin: 0; min-height: 1.65em; }
.blk:has(> .tabs) .gut { top: 6px; }
.cols { display: grid; gap: 24px; margin: 4px 0 12px; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); }
.cols .colw { position: relative; min-width: 0; }
.cols .col { margin: 0; min-height: 1.65em; }
/* story 032: at rest a columns block reads like prose; while hovered the gaps show a hairline, empty columns their hint, and a plus per gap */
.cols .colw + .colw::before { content: ""; position: absolute; left: -12px; top: 0; bottom: 0; border-left: 1px solid var(--g3); opacity: 0; transition: opacity 120ms ease-out; }
.cols:hover .colw + .colw::before { opacity: 1; }
.cols:hover .col:empty::before { content: attr(data-ph); color: var(--g5); pointer-events: none; }
.cols .cadd { left: -19px; top: -4px; }
.cols .colh { left: 50%; top: -14px; transform: translateX(-50%); }   /* ⋯ above the column, like the table's */
.cols:hover .cadd { opacity: 1; }
.cols .colw:hover .colh { opacity: 1; }

/* ===== ghost text (story 008) — the machine hand: mono, quiet, dotted */
.ed .ghost { font-family: var(--mono); font-size: .9em; color: var(--g5); border-bottom: 1px dotted var(--g4); pointer-events: none; user-select: none; }
.body:has(> .ghost) { text-wrap: auto; }   /* issue 83: no "pretty" re-wrapping of the writer's lines while a ghost streams in */
.ed .chk { text-decoration: underline dotted var(--g5); text-underline-offset: 3px; }   /* off-caret check hint (decision §6, row 38) */
.ed .ghost.done::after { content: " ⇥"; color: var(--g5); font-size: .8em; }   /* the marker is as visible as the ghost (story 027) */
.ed .ghost.wait::after { content: " ···"; color: var(--g5); animation: ghost-wait 1.2s ease-in-out infinite; }   /* issue 82: the continuation is on its way */
@keyframes ghost-wait { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ed .ghost.wait::after { animation: none; } }
.assist .goto { margin-left: 6px; color: var(--g6); width: 18px; height: 16px; display: inline-grid; place-items: center; vertical-align: -3px; border-radius: var(--r-xs); }
.assist .goto .i { width: 12px; height: 12px; }
.assist .goto:hover { background: var(--g3); color: var(--g8); }

/* ===== responsive / touch ===== */
@media (pointer: coarse) {
  .fmt button { width: 32px; height: 32px; }
  .slash button { padding: 8px 10px; }
}
@media (max-width: 719px) {
  .cols { grid-template-columns: 1fr; }
  .cols .colw + .colw::before, .cols .cadd { display: none; }
  .gut { left: -20px; }
  .gut .plus { display: none; }   /* the grip stays — it is the menu button now */
  .bmenu { left: -20px; }
}
