/* THcode editor chrome.
   Colors are CSS variables written by js/themes.js. Every block height is a
   multiple of --lh, which keeps the gutter's line numbers aligned with the text. */

:root {
  --fs: 14px;
  --lh: 20px;
  --font: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --side-w: 30ch;
  --gutter-w: 6ch;
  --status-h: 22px;
  --cmd-h: calc(var(--lh) + 14px);
  --out-h: calc(var(--lh) * 11);
  --term-h: calc(var(--cmd-h) + var(--head-h) + var(--out-h) + 1px);
  /* chrome sizes: one text line on desktop, finger-sized on touch screens (see bottom) */
  --row-h: var(--lh);
  --hud-h: calc(var(--lh) + 8px); /* the tab bar */
  --head-h: var(--lh);
  --crumbs-h: 22px;
  --bars-h: calc(var(--hud-h) + var(--crumbs-h)); /* pages start below the tabs + breadcrumbs */

  /* fallback palette if JS is off */
  --bg: #0a0c13; --side: #07090e; --panel: #0d1018; --hover: #161b26;
  --select: #e34c52; --select-fg: #07090e; --fg: #b9c2cf; --bright: #e4eaf1;
  --dim: #6b7588; --mute: #3b4354; --border: #141923; --accent: #e34c52;
  --accent-fg: #07090e; --link: #82aaff; --root: #e34c52;
  --status-bg: #07090e; --status-fg: #6b7588;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: var(--fs);
  line-height: var(--lh);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
a { color: inherit; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--bright); }
* { scrollbar-width: thin; scrollbar-color: var(--mute) transparent; }
.codicon[class*="codicon-"] { font-size: 1.08em; line-height: 1; vertical-align: -0.16em; }

.skip { position: absolute; left: -9999px; }
.nojs { padding: 2em; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 99; background: var(--accent); color: var(--accent-fg); padding: 0 1ch; }

#app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--status-h);
  height: 100vh;
  height: 100dvh;
}

/* ── explorer ─────────────────────────────────────────────── */
#sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden auto;
  background: var(--side);
  border-right: 1px solid var(--border);
}
body.side-hidden #app { grid-template-columns: 0 minmax(0, 1fr); }
body.side-hidden #sidebar { visibility: hidden; border: 0; }

.root {
  display: flex;
  align-items: center;
  gap: 1ch;
  height: var(--row-h);
  padding: 0 1ch;
  color: var(--root);
  text-decoration: none;
  white-space: nowrap;
}
.root img { width: 1.05em; height: 1.05em; transition: filter 0.15s, transform 0.15s; }
.root:hover { background: var(--hover); }
.root:hover img { filter: drop-shadow(0 0 5px color-mix(in srgb, var(--accent) 70%, transparent)); transform: rotate(-8deg); }
#tree-links { margin-top: auto; padding: var(--lh) 0 0; }

.row {
  display: flex;
  align-items: center;
  gap: 1ch;
  height: var(--row-h);
  padding: 0 1ch 0 calc(1ch + var(--d, 0) * 2ch);
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  outline: none;
  transition: background-color 0.12s, color 0.12s;
}
.row .nm { overflow: hidden; text-overflow: ellipsis; }
.row .codicon { transition: color 0.12s, filter 0.12s; }
.row:hover { background: var(--hover); color: var(--bright); }
.row:hover .codicon,
.row:focus-visible .codicon {
  color: var(--accent);
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--accent) 75%, transparent));
}
.row.sel { background: var(--select); color: var(--select-fg); }
.row.sel .codicon { color: inherit; filter: none; }
.row:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
.row .ext { margin-left: auto; opacity: 0; transition: opacity 0.12s; }
.row:hover .ext { opacity: 0.8; }

#sash { position: absolute; top: 0; right: 0; width: 4px; height: 100%; cursor: col-resize; z-index: 3; }
#sash:hover, body.resizing #sash { background: var(--accent); }
body.resizing { cursor: col-resize; user-select: none; }

/* ── editor ───────────────────────────────────────────────── */
#editor { position: relative; overflow: hidden; min-width: 0; background: var(--bg); }

body.at-home { --crumbs-h: 0px; --bars-h: var(--hud-h); } /* the welcome page has no breadcrumbs, like VS Code's */
#field, #gl {
  position: absolute;
  top: var(--bars-h);
  left: var(--gutter-w);
  width: calc(100% - var(--gutter-w));
  height: calc(100% - var(--cmd-h) - var(--bars-h));
  pointer-events: none;
  z-index: 0;
}
#gl { opacity: 0; transition: opacity 0.5s ease; }
body.at-home #gl.live { opacity: 1; }

#scroller {
  position: absolute;
  inset: var(--bars-h) 0 var(--cmd-h) 0;
  z-index: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: var(--gutter-w) minmax(0, 1fr);
  align-items: start;
}
#editor.term-open #scroller { bottom: var(--term-h); }

#gutter { position: relative; z-index: 1; padding-right: 2ch; text-align: right; color: var(--mute); user-select: none; font-variant-numeric: tabular-nums; }
#gutter span { display: block; height: var(--lh); }
#gutter .t { opacity: 0.75; }
#gutter .on { color: var(--fg); }
#curline {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--lh);
  background: var(--hover);
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}
#curline.on { opacity: 0.55; }

#doc { position: relative; z-index: 1; min-width: 0; max-width: 98ch; padding: 0 3ch 0 1ch; outline: none; }
#doc.home { max-width: none; padding: 0; }
body.at-home #scroller { cursor: grab; touch-action: none; }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; }

/* document blocks */
.h { color: var(--bright); font-weight: 700; }
.h .mk { color: var(--mute); font-weight: 400; }
.p { color: var(--fg); overflow-wrap: break-word; }
.p.lead { color: var(--bright); }
.p.dim { color: var(--dim); }
.p.com { color: var(--syn-com); font-style: italic; }
.p.err { color: var(--c1); }
strong, b { color: var(--bright); font-weight: 700; }
.gap { height: calc(var(--lh) * var(--n, 1)); }
.ul { list-style: none; }
.ul li { position: relative; padding-left: 2ch; }
.ul li::before { content: "-"; position: absolute; left: 0; color: var(--accent); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 3ch; }
.kv .k { color: var(--syn-key); }
.tags { display: flex; flex-wrap: wrap; column-gap: 1ch; }
.idx-i { padding-left: 4ch; text-indent: -2ch; }
.idx-i .d { color: var(--dim); }
.idx-i .m { color: var(--dim); }

.pill {
  --pc: var(--accent);
  display: inline;
  padding: 0 0.6ch;
  color: var(--pc);
  background: color-mix(in srgb, var(--pc) 14%, transparent);
  border-radius: 2px;
  text-decoration: none;
  text-indent: 0;
  white-space: nowrap;
  transition: background-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.pill .codicon { margin-right: 0.6ch; }
/* smart pills inside sentences: a live clock and a quietly breathing status dot */
.pill .tz { font-variant-numeric: tabular-nums; }
.pill .dot { display: inline-block; width: 0.5em; height: 0.5em; margin-right: 0.7ch; border-radius: 50%; background: currentColor; vertical-align: 0.08em; animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.35; } }
.pill .ext { margin-left: 0.5ch; opacity: 0.7; }
a.pill:hover, a.pill:focus-visible, button.pill:hover:not(:disabled), button.pill:focus-visible {
  background: var(--pc);
  color: var(--bg);
  box-shadow: 0 0 14px color-mix(in srgb, var(--pc) 45%, transparent);
  outline: none;
}
.pill code.ic { color: inherit; background: none; padding: 0; }
.tag { cursor: default; }
.tag:hover { background: color-mix(in srgb, var(--pc) 26%, transparent); }
code.ic {
  font: inherit;
  color: var(--syn-str);
  background: color-mix(in srgb, var(--fg) 9%, transparent);
  padding: 0 0.4ch;
  border-radius: 2px;
}

.code { font: inherit; white-space: pre-wrap; color: var(--fg); tab-size: 2; }
.tk-k { color: var(--syn-key); }
.tk-s { color: var(--syn-str); }
.tk-n { color: var(--syn-num); }
.tk-w { color: var(--syn-kw); }
.tk-p { color: var(--syn-punc); }
.sw { display: inline-block; width: 0.85em; height: 0.85em; margin-right: 0.5ch; border: 1px solid var(--mute); vertical-align: -0.08em; }

.win-wrap { padding: calc(var(--lh) / 2) 0; }
.win { position: relative; border: 1px solid var(--mute); padding: calc(var(--lh) / 2 - 1px) 2ch; }
.win-t {
  position: absolute;
  top: calc(var(--lh) / -2 - 1px);
  right: 2ch;
  height: var(--lh);
  line-height: var(--lh);
  padding: 0 0.6ch;
  background: var(--bg);
  color: var(--dim);
}
.win-t:hover, .win-t:focus-visible { color: var(--bright); outline: none; }
.win.closed .win-b { display: none; }
.pdf { display: block; width: 100%; height: calc(var(--lh) * 34); border: 0; background: #fff; }

/* contact form: every field is a whole number of lines so the gutter stays aligned */
.cform { display: grid; grid-template-columns: max-content minmax(0, 60ch); column-gap: 3ch; }
.cform .k { color: var(--syn-key); line-height: var(--lh); }
.cform input, .cform textarea {
  width: 100%;
  height: var(--lh);
  padding: 0 1ch;
  font: inherit;
  line-height: var(--lh);
  color: var(--bright);
  background: color-mix(in srgb, var(--fg) 7%, transparent);
  border: 0;
  box-shadow: inset 0 -1px 0 var(--mute);
  outline: 0;
  resize: none;
}
.cform textarea { height: calc(var(--lh) * 6); }
.cform input:focus, .cform textarea:focus { box-shadow: inset 0 -1px 0 var(--accent), inset 2px 0 0 var(--accent); }
.cf-act { display: flex; flex-wrap: wrap; align-items: center; column-gap: 2ch; min-height: var(--lh); }
.cf-act button { cursor: pointer; }
.cf-act button:disabled { opacity: 0.5; cursor: progress; }
.cf-status { color: var(--dim); }
.cf-status.ok { color: var(--c4); }
.cf-status.err { color: var(--c1); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* home */
#doc.home .hl { height: var(--lh); text-align: center; white-space: nowrap; }
/* the Explore button: two lines tall so the line grid holds */
#doc.home .hl.hl2 { height: calc(var(--lh) * 2); display: flex; align-items: center; justify-content: center; }
.pill.explore { display: inline-flex; align-items: center; height: calc(var(--lh) * 2 - 4px); padding: 0 1.8ch; font-size: 1.2em; }
.mask { background: var(--bg); padding: 0 1ch; }
.ttl { color: var(--bright); font-weight: 700; letter-spacing: 0.04em; }
.hint { color: var(--dim); }

/* ── tab bar (open pages + control panel) ─────────────────── */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: stretch;
  gap: 2ch;
  height: var(--hud-h);
  padding-right: 1ch;
  font-size: 11px;
  color: var(--dim);
  background: var(--side);
  border-bottom: 1px solid var(--border);
}
#hud > .cp-wrap, #hud > #fps, #hud > #side-btn { align-self: center; }

#tabs { flex: 1; display: flex; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.8ch;
  max-width: 28ch;
  padding: 0 0.6ch 0 1.4ch;
  font-size: 12px;
  color: var(--dim);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  border-right: 1px solid var(--border);
  outline: none;
  transition: background-color 0.12s, color 0.12s;
}
.tab .nm { overflow: hidden; text-overflow: ellipsis; }
.tab .dir { font-size: 0.9em; color: var(--dim); }
.tab img { width: 1em; height: 1em; }
.tab:hover { color: var(--fg); background: var(--hover); }
.tab.on { color: var(--bright); background: var(--bg); }
/* the active tab: an accent line on top, and it joins the page below (no bottom border) */
.tab.on::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--accent); }
.tab.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--bg); }
.tab.on .codicon:first-child { color: var(--accent); }
.tab:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
.tab .x { display: inline-flex; align-items: center; justify-content: center; width: 2.2ch; height: 2.2ch; color: inherit; opacity: 0; border-radius: 3px; }
.tab:hover .x, .tab.on .x, .tab:focus-visible .x { opacity: 0.8; }
.tab .x:hover { opacity: 1; background: color-mix(in srgb, var(--fg) 16%, transparent); }
.tab.dragging { opacity: 0.4; }
.tab.drop-l { box-shadow: inset 2px 0 0 var(--accent); }
.tab.drop-r { box-shadow: inset -2px 0 0 var(--accent); }

/* ── breadcrumbs ──────────────────────────────────────────── */
#crumbs {
  position: absolute;
  top: var(--hud-h);
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  height: var(--crumbs-h);
  padding: 0 1ch;
  overflow: hidden;
  font-size: 12px;
  white-space: nowrap;
  color: var(--dim);
  background: var(--bg);
}
body.at-home #crumbs { display: none; }
#crumbs .sep { padding: 0 0.3ch; color: var(--mute); }
.crumb { display: inline-flex; align-items: center; gap: 0.6ch; padding: 0 0.5ch; color: inherit; border-radius: 3px; }
.crumb:hover, .crumb[aria-expanded="true"] { color: var(--bright); background: var(--hover); }
.crumb:last-child { color: var(--fg); }
#crumb-menu {
  position: absolute;
  z-index: 6;
  min-width: 22ch;
  max-height: calc(var(--lh) * 14);
  overflow: auto;
  padding: 3px 0;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}
#crumb-menu button { display: flex; align-items: center; gap: 1ch; width: 100%; padding: 1px 1.5ch; color: var(--fg); text-align: left; white-space: nowrap; outline: none; }
#crumb-menu button:hover, #crumb-menu button:focus-visible { color: var(--select-fg); background: var(--select); }
#crumb-menu button[aria-current="page"] { color: var(--accent); }
#crumb-menu .more { margin-left: auto; padding-left: 2ch; opacity: 0.7; }
#crumb-menu button[aria-current="page"]:hover, #crumb-menu button[aria-current="page"]:focus-visible { color: var(--select-fg); }

/* ── control panel ────────────────────────────────────────── */
.hud-b { padding: 0 0.8ch; color: var(--fg); background: color-mix(in srgb, var(--side) 88%, transparent); transition: color 0.12s, background-color 0.12s; }
.hud-b:hover, .hud-b[aria-expanded="true"] { color: var(--bright); background: var(--hover); }
#side-btn { display: none; }
.cp-wrap { position: relative; display: inline-flex; }
#cp-hint {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  white-space: pre;
  color: var(--accent);
  pointer-events: none;
  animation: hint-bob 1.6s ease-in-out infinite;
  transition: opacity 0.4s;
}
#cp-hint.out { opacity: 0; }
@keyframes hint-bob { 50% { transform: translate(-50%, -3px); } }
#fps { color: var(--dim); font-variant-numeric: tabular-nums; }

#cp {
  position: absolute;
  top: var(--hud-h);
  right: 1ch;
  z-index: 5;
  width: min(56ch, calc(100% - 2ch));
  max-height: calc(100% - var(--cmd-h) - var(--lh) * 2);
  overflow: auto;
  padding-bottom: 0.6em;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}
.cp-sec { padding: 0.7em 1.5ch 0.25em; color: var(--accent); }
.cp-sec::before { content: "// "; color: var(--mute); }
.cp-row { display: grid; grid-template-columns: 15ch minmax(0, 1fr) 4ch; align-items: center; gap: 1ch; padding: 0.15em 1.5ch; }
.cp-row .k { color: var(--dim); }
.cp-row .v { color: var(--dim); text-align: right; font-variant-numeric: tabular-nums; }
.cp-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.cp-row select { width: 100%; padding: 0.1em 0.5ch; color: var(--fg); background: var(--bg); border: 1px solid var(--border); }
.seg { display: flex; flex-wrap: wrap; gap: 2px; }
.seg button { padding: 0 0.7ch; color: var(--dim); background: var(--bg); border: 1px solid var(--border); }
.seg button:hover { color: var(--bright); }
.seg button[aria-pressed="true"] { color: var(--select-fg); background: var(--select); border-color: var(--select); }
.tog { justify-self: start; color: var(--dim); }
.tog:hover { color: var(--bright); }
.tog[aria-pressed="true"] { color: var(--accent); }
.cp-foot { display: flex; justify-content: space-between; gap: 1ch; padding: 0.7em 1.5ch 0; color: var(--dim); }
.cp-foot button { color: var(--dim); }
.cp-foot button:hover { color: var(--bright); }

/* ── command line + output ────────────────────────────────── */
#term {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  background: var(--side);
  border-top: 1px solid var(--border);
}
.term-head, #term-out { display: none; }
#editor.term-open .term-head { display: flex; }
#editor.term-open #term-out { display: block; }
.term-head {
  align-items: center;
  gap: 2.5ch;
  height: var(--head-h);
  padding: 0 2ch;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
}
.term-head .on { color: var(--bright); box-shadow: inset 0 -1px 0 var(--accent); }
.term-head .sp { flex: 1; }
.term-head button { text-transform: uppercase; letter-spacing: inherit; color: var(--dim); }
.term-head button:hover { color: var(--bright); }
#term-out {
  height: var(--out-h);
  overflow: auto;
  padding: 0 2ch;
  background: var(--panel);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#term-out > div { min-height: var(--lh); }
#term-out a { color: var(--link); text-decoration: none; }
#term-out a:hover { text-decoration: underline; }
.t-echo { color: var(--bright); }
.t-echo .pc { color: var(--accent); }
.t-h { color: var(--accent); font-weight: 700; }
.t-dim { color: var(--dim); }
.t-k { color: var(--syn-key); }
.t-err { color: var(--c1); }
.t-ok { color: var(--c4); }
.t-acc { color: var(--accent); }
.t-code { color: var(--syn-str); }
.t-dir { color: var(--link); font-weight: 700; }
.t-lnk { color: var(--c5); }
.t-tag { color: var(--c5); }
.t-li { padding-left: 4ch; text-indent: -2ch; }
/* git blame: wrapped lines align after the "hash (source date)" annotation */
.t-blame { padding-left: 41ch; text-indent: -41ch; }
@media (max-width: 760px) { .t-blame { padding-left: 2ch; text-indent: -2ch; } }
.t-in { padding-left: 2ch; }

.cmd {
  display: flex;
  align-items: center;
  gap: 1ch;
  height: var(--cmd-h);
  padding: 0 2ch;
  background: var(--panel);
  box-shadow: inset 2px 0 0 var(--accent);
  cursor: text;
}
.cmd:focus-within { box-shadow: inset 2px 0 0 var(--accent), inset 0 1px 0 var(--accent); }
.cmd .prompt { white-space: nowrap; color: var(--dim); }
.pu, .pc { color: var(--accent); }
/* a command asking a question (mail): the question replaces user@host path */
.pask { color: var(--accent); }
.pask:empty, .cmd.asking .pu, .cmd.asking .pd { display: none; }
/* contribution graph: GitHub-style shades of the theme's green */
.cg0 { color: var(--dim); opacity: 0.45; }
.cg1 { color: var(--c4); opacity: 0.5; }
.cg2 { color: var(--c4); opacity: 0.7; }
.cg3 { color: var(--c4); opacity: 0.85; }
.cg4 { color: var(--c4); }
.pd { color: var(--link); }
.cmd.idle .pc { animation: blink 1.1s steps(1) infinite; }
#cmd {
  flex: 1;
  min-width: 0;
  color: var(--bright);
  background: transparent;
  border: 0;
  outline: 0;
  caret-color: var(--accent);
}
#cmd::placeholder { color: var(--dim); opacity: 0.75; }
.kbd { padding: 0 0.6ch; font-size: 11px; line-height: 1.6; color: var(--dim); border: 1px solid var(--border); white-space: nowrap; }
@keyframes blink { 50% { opacity: 0; } }

/* ── status bar ───────────────────────────────────────────── */
#status {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  height: var(--status-h);
  overflow: hidden;
  font-size: 12px;
  line-height: calc(var(--status-h) - 1px);
  white-space: nowrap;
  color: var(--status-fg);
  background: var(--status-bg);
  border-top: 1px solid var(--border);
}
#status .l, #status .r { display: flex; min-width: 0; }
.sb { display: inline-flex; align-items: center; gap: 0.6ch; padding: 0 1ch; color: inherit; text-decoration: none; transition: background-color 0.12s, color 0.12s; }
button.sb:hover, a.sb:hover { color: var(--bright); background: color-mix(in srgb, var(--fg) 12%, transparent); }
button.sb:hover .codicon, a.sb:hover .codicon { color: var(--accent); }
.sb.brand { padding: 0 1.2ch; color: var(--accent-fg); background: var(--accent); font-weight: 700; }
.sb.brand:hover, .sb.brand:hover .codicon { color: var(--accent-fg); background: color-mix(in srgb, var(--accent) 82%, #fff); }

/* ── palette ──────────────────────────────────────────────── */
#palette {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 11vh;
  background: rgba(0, 0, 0, 0.22);
}
#palette[hidden] { display: none; }
.pal { width: min(640px, calc(100vw - 32px)); padding: 6px; background: var(--panel); border: 1px solid var(--border); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45); }
.pal input { width: 100%; padding: 4px 1ch; color: var(--bright); background: var(--bg); border: 1px solid var(--accent); outline: 0; }
.pal-list { max-height: calc(var(--lh) * 15); margin-top: 6px; overflow: auto; }
.pi { display: flex; align-items: center; gap: 1ch; padding: 1px 1ch; color: var(--fg); white-space: nowrap; cursor: pointer; }
.pi .d { overflow: hidden; text-overflow: ellipsis; font-size: 0.9em; color: var(--dim); }
.pi .kb { margin-left: auto; font-size: 0.85em; color: var(--dim); }
.pi b { color: var(--accent); }
.pi.on { color: var(--select-fg); background: var(--select); }
.pi.on .d, .pi.on .kb, .pi.on b { color: inherit; }
.pal-empty { padding: 1px 1ch; color: var(--dim); }

/* ── toasts ───────────────────────────────────────────────── */
#toasts { position: fixed; right: 1ch; bottom: calc(var(--status-h) + var(--cmd-h) + 6px); z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none; }
.toast {
  display: flex;
  align-items: center;
  gap: 1ch;
  padding: 2px 1.5ch;
  font-size: 12px;
  color: var(--select-fg);
  background: var(--select);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast b { color: inherit; }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── effects ──────────────────────────────────────────────── */
body.fx-crt::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.2) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}
:root.fx-glow #doc, :root.fx-glow #sidebar, :root.fx-glow #term {
  text-shadow: 0 0 6px color-mix(in srgb, currentColor 45%, transparent);
}

/* ── small screens ────────────────────────────────────────── */
@media (max-width: 760px) {
  :root { --gutter-w: 4ch; }
  #app, body.side-hidden #app { grid-template-columns: minmax(0, 1fr); }
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: var(--status-h);
    z-index: 45;
    width: min(34ch, 86vw);
    visibility: visible;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.4);
  }
  body.side-open #sidebar { transform: none; }
  #sash { display: none; }
  #side-btn { display: inline-block; }
  #gutter { padding-right: 1ch; }
  #doc { padding-right: 1ch; }
  .sb.hide-m, .kbd, .cmd .pu, .cmd .pd { display: none; }
  .cp-row { grid-template-columns: 12ch minmax(0, 1fr) 4ch; }
}

/* ── touch screens (and the narrow widths the phone preview uses) ──
   Every control gets at least a 44×44px target (Apple's guideline, WCAG 2.5.5).
   Anything on the editor's line grid grows by whole lines so the gutter stays aligned. */
@media (pointer: coarse), (max-width: 760px) {
  :root {
    --tap: 44px;
    --row-h: var(--tap);
    --hud-h: var(--tap);
    --head-h: var(--tap);
    --crumbs-h: var(--tap);
    --status-h: calc(var(--tap) + 1px); /* + its top border */
    --cmd-h: 52px;
  }
  .tab { min-width: var(--tap); padding-left: 1.6ch; }
  .tab { padding-right: 0; }
  .tab .x { width: var(--tap); height: var(--tap); opacity: 0.8; }
  .crumb { min-height: var(--tap); }
  .hud-b { display: inline-flex; align-items: center; min-width: var(--tap); height: var(--tap); line-height: var(--tap); padding: 0 1.5ch; }
  .sb { justify-content: center; min-width: var(--tap); }
  .term-head button { min-width: var(--tap); height: var(--tap); }
  .pi { min-height: var(--tap); }
  .pal input { min-height: var(--tap); }
  .cp-row { min-height: var(--tap); }
  .seg button, .tog, .cp-foot button, .cp-row select { min-height: var(--tap); padding-inline: 1.2ch; }
  .cp-row input[type="range"] { height: var(--tap); }

  /* iPhones zoom the whole page when you tap a field whose text is under 16px */
  #cmd, .pal input, .cform input, .cform textarea, .cp-row select { font-size: 16px; }

  /* standalone links (link rows, the "next →" lines, form + resume buttons) become real
     buttons two lines tall (so they stay on the grid), plus an invisible edge to reach 44px.
     Links inside sentences keep their size: WCAG 2.5.8 exempts inline text links, and
     growing them would make neighbouring lines' hit areas overlap. */
  .p.nav { display: flex; flex-wrap: wrap; column-gap: 2ch; }
  .tags, .p.nav { row-gap: var(--lh); }
  .tags a.pill, .p.nav a.pill, .cf-act button.pill { display: inline-flex; align-items: center; height: calc(var(--lh) * 2); padding-inline: 1.2ch; }
  .tags a.pill, .p.nav a.pill, .cf-act button.pill, .idx-i a.pill { position: relative; }
  .tags a.pill::after, .p.nav a.pill::after, .cf-act button.pill::after { content: ""; position: absolute; inset: -2px -4px; }
  /* index lists: a blank line between items, so each link's larger hit area has room */
  .idx-i + .idx-i { margin-top: var(--lh); }
  .idx-i a.pill::after { content: ""; position: absolute; inset: -10px -4px; }
  .win-t::after { content: ""; position: absolute; inset: -12px -6px; } /* .win-t is already positioned */

  /* contact form: two lines per field */
  .cform input { height: calc(var(--lh) * 2); }
  .cform .k, .cf-act { line-height: calc(var(--lh) * 2); min-height: calc(var(--lh) * 2); }
  .cf-act button { min-height: calc(var(--lh) * 2); }
}

/* phones: no room for breadcrumbs or the FPS readout; the tabs get the space */
@media (max-width: 760px) {
  :root { --crumbs-h: 0px; }
  #crumbs, #fps { display: none; }
  #hud { gap: 1ch; }
}

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