/* Layout: workbench (category rail · command palette · canvas · script pane); reference = sidebar + article.
   Fonts, neutrals and shapes come from ../theme.css (--wl-*); this file keeps PowerBlocks' blue accent and the
   category colours. Monospace is used only for real code: the script, code samples and expression fields. */
:root {
  --bg: var(--wl-bg);
  --surface: var(--wl-bg);
  --surface-2: var(--wl-surface);
  --surface-3: var(--wl-surface-2);
  --line: var(--wl-edge);
  --line-strong: color-mix(in srgb, var(--wl-ink) 16%, var(--wl-bg));
  --fg: var(--wl-ink);
  --muted: var(--wl-ink-2);
  --faint: var(--wl-ink-3);
  --accent: #2F5BEA;
  --accent-ink: #FFFFFF;
  --accent-soft: color-mix(in srgb, var(--accent) 10%, var(--wl-bg));
  --canvas: var(--wl-surface);
  --field: var(--wl-bg);
  --field-line: var(--wl-edge);
  --expr-bg: var(--wl-surface);
  --need: #B7791F;
  --bad: #D92D20;
  --ok: #157F3B;
  /* script pane */
  --ed-bg: var(--wl-surface);
  --ed-2: var(--wl-surface-2);
  --ed-line: var(--wl-edge);
  --ed-fg: var(--wl-ink);
  --ed-dim: var(--wl-ink-3);
  --ed-hl: color-mix(in srgb, var(--accent) 8%, transparent);
  --tk-cmd: #9A5B00; --tk-par: #3D5A99; --tk-str: #2E7D32; --tk-var: #C2410C; --tk-kw: #8E3FC4;
  --tk-op: #0E7C86; --tk-num: #A0522D; --tk-com: #7A828E; --tk-type: #1D6FD6; --tk-mem: #4D535C;
  --hl-bar: var(--accent);
  --shadow: var(--wl-shadow);
  --font-body: var(--wl-font);
  --font-mono: var(--wl-mono);
}
:root:not([data-theme="light"]) {
  --surface: var(--wl-surface);
  --surface-2: var(--wl-surface-2);
  --surface-3: color-mix(in srgb, var(--wl-ink) 12%, var(--wl-surface));
  --accent: #7C9CFF; --accent-ink: #101114; --accent-soft: color-mix(in srgb, var(--accent) 16%, var(--wl-bg));
  --canvas: var(--wl-bg); --field: var(--wl-bg); --expr-bg: #0B0C0F;
  --need: #E3A33B; --bad: #FF6B5E; --ok: #4ADE80;
  --ed-bg: #15171B; --ed-2: var(--wl-surface); --ed-line: var(--wl-edge); --ed-fg: #E3E6EB;
  --tk-cmd: #E9C46A; --tk-par: #93A9D4; --tk-str: #9CCC7A; --tk-var: #F2A66B; --tk-kw: #C792EA;
  --tk-op: #5FC3CF; --tk-num: #D6A07A; --tk-com: #7A8494; --tk-type: #6CB6FF; --tk-mem: #C4CDD9;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font-body); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--wl-focus); outline-offset: 2px; }
code, kbd, .kbd { font-family: var(--font-mono); font-size: .88em; }
.prose code, .plain code, .note code, .syn-plain code, .pfacts code { background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }
kbd, .kbd { display: inline-block; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0 6px; background: var(--surface); }
a { color: var(--accent); }

.app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }

/* ── Header ── */
.top { display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); font-weight: 750; font-size: 17px; letter-spacing: -.025em; }
.mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font: 700 12.5px/1 var(--font-body); letter-spacing: -.02em; }
.tabs { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--wl-pill); }
.tab { padding: 5px 16px; border-radius: var(--wl-pill); text-decoration: none; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.tab:hover { color: var(--fg); }
.tab[aria-current="true"] { background: var(--bg); color: var(--fg); box-shadow: var(--shadow); }
.ver { margin-left: auto; padding: 4px 12px; border-radius: var(--wl-pill); background: var(--surface-2); color: var(--muted); font-size: 12.5px; font-weight: 500; }
.top .wl-theme { background: var(--surface-2); }   /* the shared light/dark button (../theme.js) sits on the header surface */

/* ── Builder grid ── */
.builder { position: relative; display: grid; grid-template-columns: 64px 280px minmax(0, 1fr) minmax(360px, 34%); min-height: 0; }
.rail { display: flex; flex-direction: column; gap: 4px; padding: 10px 6px; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; }
.rail-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0 7px; border: 0; border-radius: 12px; background: none; color: var(--muted); cursor: pointer; font-size: 10.5px; font-weight: 500; line-height: 1.15; }
.rail-btn svg { color: var(--c); }
.rail-btn:hover { background: var(--surface-2); color: var(--fg); }
.rail-btn.on { background: color-mix(in srgb, var(--c) 14%, var(--surface)); color: var(--fg); font-weight: 650; }

.palwrap { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.palhead { padding: 12px 12px 10px; }
.search { width: 100%; height: 38px; padding: 0 14px; border: 1px solid transparent; border-radius: var(--wl-pill); background: var(--surface-2); outline: none; }
.palette { flex: 1; overflow: auto; padding: 0 12px 40px; position: relative; }
.pal-sec { --c: var(--accent); padding-top: 6px; }
.pal-h { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; margin: 0 -12px 6px; padding: 10px 14px 8px; background: var(--surface); font-size: 14px; font-weight: 700; letter-spacing: -.015em; }
.pal-h svg { color: var(--c); }
.pal-n { margin-left: auto; color: var(--faint); font-weight: 500; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.pal-sub { margin: 14px 2px 6px; font-size: 12.5px; font-weight: 650; color: var(--muted); }
.pal-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 2px 6px; margin-bottom: 6px; padding: 9px 10px 9px 12px; border: 0; border-radius: var(--wl-radius-md); background: color-mix(in srgb, var(--c) 7%, var(--surface-2)); cursor: grab; touch-action: pan-y; user-select: none; transition: background .15s, box-shadow .15s; }
.pal-item:hover { background: color-mix(in srgb, var(--c) 13%, var(--surface-2)); box-shadow: var(--shadow); }
.pal-name { font: 650 13px var(--font-body); letter-spacing: -.01em; color: color-mix(in srgb, var(--c) 70%, var(--fg)); overflow-wrap: anywhere; }
.pal-name.lang { font-family: var(--font-body); font-size: 13.5px; }
.pal-syn { grid-column: 1 / -1; font-size: 12px; line-height: 1.4; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { align-self: start; padding: 0 8px; border-radius: var(--wl-pill); background: var(--surface); color: var(--muted); font-size: 11px; font-weight: 600; line-height: 19px; white-space: nowrap; }
.pal-none { color: var(--muted); padding: 12px 4px; }
body.trash .palwrap, body.trash .rail { background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
body.trash .palette::after { content: "Drop here to delete"; position: sticky; bottom: 12px; display: block; text-align: center; padding: 10px; border-radius: var(--wl-pill); background: var(--bad); color: #fff; font-weight: 650; }

/* ── Workspace ── */
.wsarea { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); min-width: 0; min-height: 0; }
.wstools { display: flex; gap: 6px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.wstools .sp { flex: 1; }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border: 0; border-radius: var(--wl-pill); background: var(--surface-2); color: var(--fg); cursor: pointer; text-decoration: none; font-size: 13px; font-weight: 600; white-space: nowrap; transition: background .15s; }
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 86%, var(--fg)); }
.btn.confirm { background: var(--bad); color: #fff; }
.workspace { position: relative; overflow: auto; background-color: var(--canvas); }
.canvas { position: relative; min-width: 100%; min-height: 100%; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); pointer-events: none; gap: 4px; padding: 16px; }
.empty strong { color: var(--fg); font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.stack { position: absolute; }
.stack.floating { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; opacity: .96; filter: drop-shadow(0 16px 28px rgba(20, 22, 26, .2)); }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; }
.drop-ind { position: fixed; left: 0; top: 0; height: 4px; border-radius: 4px; background: var(--accent); z-index: 40; pointer-events: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

/* ── Blocks ── */
.list { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.blk { --c: #888; position: relative; width: max-content; max-width: 820px; background: color-mix(in srgb, var(--c) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 22%, transparent); border-radius: var(--wl-radius-md); box-shadow: var(--shadow); font-size: 13px; user-select: none; touch-action: none; cursor: grab; }
.blk.hl { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 45%, transparent); }
.blk.pop { animation: pop .3s ease-out; }
@keyframes pop { from { transform: translateY(-3px); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 35%, transparent); } to { transform: none; } }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 7px; padding: 6px 10px; min-height: 40px; }
.bname { font: 700 13.5px var(--font-body); letter-spacing: -.01em; color: color-mix(in srgb, var(--c) 72%, var(--fg)); margin-right: 2px; }
.lbl { font: 650 13px var(--font-body); color: color-mix(in srgb, var(--c) 72%, var(--fg)); white-space: pre; }
.pin { display: inline-flex; align-items: center; gap: 4px; position: relative; }
.pn { font: 500 12px var(--font-body); color: var(--muted); }
.dollar, .eq { font: 600 13px var(--font-mono); color: var(--muted); }
.fld { height: 26px; padding: 0 9px; border: 1px solid color-mix(in srgb, var(--c) 18%, var(--field-line)); border-radius: 8px; background: var(--field); color: var(--fg); font: 500 12.5px var(--font-body); min-width: 34px; cursor: text; }
.fld::placeholder { color: var(--faint); font-style: italic; }
.fld:hover { border-color: var(--line-strong); }
.fld:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.fld.k-expr { background: var(--expr-bg); border-style: dashed; font-family: var(--font-mono); font-size: 12px; }
.fld.k-int, .fld.k-num { text-align: center; }
.fld:disabled { opacity: 1; cursor: inherit; }
select.fld { cursor: pointer; padding-right: 4px; field-sizing: content; max-width: 260px; }
.k-text { display: block; width: min(560px, 70vw); height: auto; min-height: 44px; padding: 6px 9px; line-height: 1.5; resize: vertical; white-space: pre; background: var(--expr-bg); font-family: var(--font-mono); font-size: 12px; }
.textrow { position: relative; align-items: flex-start; padding-top: 0; }
.textrow .pn { padding-top: 5px; }
.tog { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border: 1px solid var(--field-line); border-radius: var(--wl-pill); background: var(--field); color: var(--muted); font: 500 12px var(--font-body); cursor: pointer; }
.tog input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.tog:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.tog::before { content: ""; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; border: 1.5px solid var(--line-strong); }
.tog.on { background: color-mix(in srgb, var(--c) 14%, var(--field)); border-color: color-mix(in srgb, var(--c) 55%, var(--field-line)); color: var(--fg); font-weight: 600; }
.tog.on::before { background: var(--c); border-color: var(--c); }
.need { outline: 1.5px dashed var(--need) !important; outline-offset: 1px; }
.bad { outline: 2px solid var(--bad) !important; outline-offset: 1px; }
.frompipe, .fixed { font: 500 12px var(--font-body); padding: 2px 9px; border-radius: var(--wl-pill); border: 1px dashed var(--line-strong); color: var(--muted); }
.fixed { border-style: solid; color: var(--fg); }
.mode, .addopt { field-sizing: content; height: 26px; border-radius: var(--wl-pill); border: 1px solid var(--line-strong); background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; padding: 0 10px; cursor: pointer; max-width: 210px; }
.mode { background: var(--surface-2); color: var(--fg); }
.addopt { border-style: dashed; appearance: none; -webkit-appearance: none; padding: 0 10px; }
.addopt:hover, .mode:hover { border-color: var(--c); color: var(--fg); }
.addopt option, .addopt optgroup, .mode option { color: var(--fg); background: var(--surface); }
.pipe, .help { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; border: 1px solid var(--field-line); background: var(--field); color: var(--muted); font: 700 12px var(--font-body); cursor: pointer; }
.help { border-radius: 50%; margin-left: 2px; font-size: 11.5px; }
.pipe:hover, .help:hover { color: var(--fg); border-color: var(--c); }
.pipe.on { background: var(--c); border-color: var(--c); color: #fff; }
.pipe.warn { background: var(--need); border-color: var(--need); color: #fff; }
.rm { position: absolute; top: -8px; right: -8px; display: none; width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 0; background: var(--fg); color: var(--bg); font-size: 11px; line-height: 18px; cursor: pointer; z-index: 3; box-shadow: var(--shadow); }
.pin:hover > .rm, .textrow:hover > .rm, .rm:focus-visible { display: block; }
.rm:hover { color: #fff; background: var(--bad); }
.blk.piped { margin-left: 24px; }
.blk.piped::before { content: ""; position: absolute; left: -18px; top: -8px; height: 24px; width: 12px; border-left: 2px solid color-mix(in srgb, var(--c) 55%, var(--line-strong)); border-bottom: 2px solid color-mix(in srgb, var(--c) 55%, var(--line-strong)); border-bottom-left-radius: 8px; }
.cblk > .row.head { border-bottom: 0; }
.slot { margin: 0 8px 0 14px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--canvas) 80%, transparent); min-width: 180px; }
.row.arm { min-height: 28px; padding-block: 4px; font: 650 12.5px var(--font-body); color: color-mix(in srgb, var(--c) 72%, var(--fg)); border-top: 0; }
.row.foot { min-height: 10px; padding-block: 4px; }
.row.foot:empty { min-height: 6px; padding: 0; }
.slot-empty { padding: 4px 12px; border: 1px dashed var(--line-strong); border-radius: 8px; color: var(--faint); font-size: 12px; }

/* Palette view filter */
.palbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 0 4px; font-size: 12.5px; color: var(--muted); }
.palcount { font-variant-numeric: tabular-nums; }
.linkbtn { border: 0; background: none; padding: 3px 8px; border-radius: var(--wl-pill); color: var(--accent); font-size: 12.5px; font-weight: 650; cursor: pointer; }
.linkbtn:hover { background: var(--accent-soft); }
.linkbtn.active::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--accent); vertical-align: 1px; }
.palpanel { flex: none; max-height: 70%; overflow: auto; margin: 0 12px 10px; padding: 4px 14px 14px; border-radius: var(--wl-radius-md); background: var(--surface-2); }
.pp-h { margin: 14px 0 6px; font-size: 13px; font-weight: 700; letter-spacing: -.01em; color: var(--fg); }
.pp-common { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--bg); cursor: pointer; font-size: 13px; }
.pp-common input { margin-top: 3px; accent-color: var(--accent); }
.pp-common small, .preset small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 400; line-height: 1.35; }
.presets { display: grid; gap: 6px; }
.preset { text-align: left; padding: 9px 12px; border: 1px solid transparent; border-radius: 12px; background: var(--bg); color: var(--fg); font-size: 13px; font-weight: 650; cursor: pointer; }
.preset:hover { border-color: var(--accent); }
.catlist { display: grid; gap: 2px; }
.catrow { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.catrow:hover { background: var(--bg); }
.catrow input { accent-color: var(--c); }
.caticon { display: inline-grid; color: var(--c); }
.caticon svg { width: 16px; height: 16px; }
.catname { flex: 1; }
.pp-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }

/* Before you run */
.tabn { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin-left: 4px; padding: 0 6px; border-radius: var(--wl-pill); background: var(--need); color: #1D1300; font-size: 11px; font-weight: 700; }
.checksbox h4 { margin: 18px 0 8px; font-size: 13.5px; font-weight: 700; letter-spacing: -.01em; color: var(--ed-fg); }
.explainbox.checksbox { padding: 4px 16px 24px; color: var(--ed-fg); }
.brx-run { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--ed-2); }
.brx-run code { flex: 1; min-width: 0; overflow-x: auto; white-space: pre; font: 12.5px var(--font-mono); }
.brx-note { margin: 6px 0 0; font-size: 12.5px; color: var(--ed-dim); }
.brx { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.brx li { position: relative; padding: 10px 12px 10px 32px; border: 1px solid transparent; border-radius: 12px; background: var(--ed-2); font-size: 13px; line-height: 1.5; }
.brx li::before { content: ""; position: absolute; left: 12px; top: 15px; width: 10px; height: 10px; border-radius: 50%; }
.brx li strong { color: var(--ed-fg); }
.brx li span { color: var(--wl-ink-2); }
.brx li a { color: var(--tk-type); }
.brx-must::before { border: 2px solid var(--need); }
.brx-warn { border-color: color-mix(in srgb, var(--bad) 55%, var(--ed-line)) !important; }
.brx-warn::before { background: var(--bad); }
.brx-info::before { background: var(--tk-type); }
.brx-ok::before { background: var(--ok); }

/* Reference buttons on palette items, parameters and options */
.pal-ref { align-self: start; width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 0; background: var(--surface); color: var(--muted); font: 700 11px/20px var(--font-body); cursor: pointer; }
.pal-ref:hover, .pal-ref:focus-visible { color: #fff; background: var(--c); border-color: var(--c); }
button.pnref { padding: 0; border: 0; background: none; cursor: help; text-decoration: underline dotted color-mix(in srgb, var(--muted) 60%, transparent); text-underline-offset: 3px; }
button.pnref:hover { color: var(--accent); text-decoration-color: currentColor; }
.pref { position: absolute; top: -8px; left: -8px; display: none; width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font: 700 10px/18px var(--font-body); cursor: pointer; z-index: 3; box-shadow: var(--shadow); }
.pin:hover > .pref, .pref:focus-visible { display: block; }
.pref:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Reference drawer */
.drawer { position: absolute; top: 0; right: 0; bottom: 0; z-index: 30; width: min(600px, 100%); display: grid; grid-template-rows: auto auto minmax(0, 1fr); background: var(--bg); border-left: 1px solid var(--line); box-shadow: -12px 0 40px -16px rgba(20, 22, 26, .3); animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.drawer-title { flex: 1; min-width: 0; font: 700 14.5px var(--font-body); letter-spacing: -.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dbtn { display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 10px; border: 0; border-radius: var(--wl-pill); background: var(--surface-2); color: var(--fg); font-size: 16px; cursor: pointer; text-decoration: none; }
.dbtn.link { font-size: 12.5px; font-weight: 600; }
.dbtn:hover { background: var(--surface-3); }
.drawer-ctx { margin: 0; padding: 8px 16px; font-size: 13px; color: var(--muted); background: var(--accent-soft); }
.drawer-body.refart { padding: 20px 20px 60px; }
.drawer-body .ref-title { font-size: 22px; }
.drawer-body .ref-title.mono { font-size: 22px; }
.drawer-body .lede { font-size: 15px; }
.padd { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.btn.small { height: 30px; padding: 0 12px; font-size: 12.5px; }
.tag.on { border-color: var(--ok); color: var(--ok); }
.pcard.flash, tr.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ── Editor pane ── */
.codearea { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: var(--ed-bg); color: var(--ed-fg); border-left: 1px solid var(--line); }
.codehead, .codefoot { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--ed-bg); border-bottom: 1px solid var(--ed-line); flex-wrap: wrap; }
.codefoot { border-bottom: 0; border-top: 1px solid var(--ed-line); justify-content: space-between; font-size: 12.5px; }
.ptabs { display: flex; gap: 2px; padding: 3px; border-radius: var(--wl-pill); background: var(--ed-2); }
.ptab { height: 30px; padding: 0 14px; border: 0; border-radius: var(--wl-pill); background: transparent; color: var(--ed-dim); font-weight: 600; font-size: 13px; cursor: pointer; }
.ptab:hover { color: var(--ed-fg); }
.ptab[aria-selected="true"] { background: var(--wl-bg); color: var(--ed-fg); box-shadow: var(--shadow); }
.fname { display: flex; align-items: center; margin-left: auto; min-width: 120px; font: 500 12.5px var(--font-mono); }
.fname input { width: 22ch; min-width: 0; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; color: var(--ed-fg); text-align: right; font: inherit; }
.fname input:hover, .fname input:focus { border-color: var(--ed-line); outline: none; }
.fname span { color: var(--ed-dim); }
.pane { display: grid; min-height: 0; }
.codebtns { display: flex; gap: 6px; flex-wrap: wrap; }
.cbtn { height: 32px; padding: 0 13px; border-radius: var(--wl-pill); border: 0; background: var(--ed-2); color: var(--ed-fg); cursor: pointer; font-size: 12.5px; font-weight: 600; }
.cbtn:hover { background: color-mix(in srgb, var(--ed-fg) 12%, var(--ed-2)); }
.cbtn.primary { background: var(--accent); color: var(--accent-ink); }
.cbtn.primary:hover { background: color-mix(in srgb, var(--accent) 86%, var(--fg)); }
.codebox, .explainbox { overflow: auto; padding: 12px 0; position: relative; }
.code { font: 12.5px/1.7 var(--font-mono); min-width: max-content; }
.ln { display: flex; padding-right: 16px; }
.ln.hl { background: var(--ed-hl); box-shadow: inset 3px 0 0 var(--hl-bar); }
.no { width: 44px; flex: none; padding-right: 14px; text-align: right; color: var(--ed-dim); user-select: none; font-variant-numeric: tabular-nums; }
.tx { white-space: pre; }
.code-empty { padding: 8px 20px; color: var(--ed-dim); font-family: var(--font-body); }
#status { display: flex; gap: 8px; align-items: center; color: var(--ed-dim); flex-wrap: wrap; }
#status .ok { color: var(--ok); }
.chipbtn { border: 0; border-radius: var(--wl-pill); padding: 2px 10px; font-weight: 650; cursor: pointer; font-size: 12px; }
.chipbtn.need { background: var(--need); color: #1D1300; outline: none !important; }
.chipbtn.bad { background: var(--bad); color: #fff; outline: none !important; }
.tk-cmd { color: var(--tk-cmd); } .tk-par { color: var(--tk-par); } .tk-str { color: var(--tk-str); } .tk-var { color: var(--tk-var); }
.tk-kw { color: var(--tk-kw); } .tk-op { color: var(--tk-op); } .tk-com { color: var(--tk-com); font-style: italic; } .tk-num { color: var(--tk-num); }
.tk-type { color: var(--tk-type); } .tk-mem { color: var(--tk-mem); }

/* Explanations (editor pane and reference) */
.xp h4 { margin: 16px 0 8px; font-size: 13.5px; font-weight: 700; letter-spacing: -.01em; color: var(--fg); }
.xp-steps { margin: 0; padding-left: 22px; }
.xp-steps li { margin: 3px 0 3px calc(var(--d, 0) * 18px); }
.xp-parts { display: grid; grid-template-columns: fit-content(38%) minmax(0, 1fr); gap: 6px 12px; margin: 0; align-items: baseline; }
.xp-parts dt { margin: 0; }
.xp-parts dd { margin: 0; font-size: 13px; line-height: 1.5; }
.pscode { display: inline-block; max-width: 280px; overflow-wrap: anywhere; white-space: pre-wrap; padding: 1px 7px; border-radius: 6px; background: var(--ed-bg); color: var(--ed-fg); font: 12px/1.5 var(--font-mono); }
.xp-kind { display: inline-block; padding: 0 7px; border-radius: var(--wl-pill); background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600; vertical-align: 1px; }
.explainbox .xp { padding: 0 18px 20px; color: var(--ed-fg); }
.explainbox .xp h4 { color: var(--ed-fg); }
.explainbox .xp-kind { background: var(--ed-2); color: var(--ed-dim); }
.explainbox .pscode { background: var(--ed-2); }
.xp-empty { color: var(--ed-dim); }

/* ── Context menu and toast ── */
.ctx { position: fixed; z-index: 60; min-width: 200px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--wl-radius-md); box-shadow: var(--wl-shadow-lift); display: grid; }
.ctx button { text-align: left; padding: 8px 12px; border: 0; background: none; border-radius: 8px; cursor: pointer; font-weight: 500; }
.ctx button:hover, .ctx button:focus-visible { background: var(--accent-soft); }
.ctx .danger { color: var(--bad); }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 16px); opacity: 0; z-index: 70; padding: 10px 18px; border-radius: var(--wl-pill); background: var(--fg); color: var(--bg); font-weight: 600; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); box-shadow: var(--wl-shadow-lift); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Reference ── */
.ref { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; }
.refside { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
#refnav { overflow: auto; padding: 4px 10px 40px; }
.ref-group { border-bottom: 0; padding: 2px 0; }
.ref-group summary { --c: var(--accent); display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; cursor: pointer; list-style: none; font-size: 13.5px; font-weight: 650; }
.ref-group summary::-webkit-details-marker { display: none; }
.ref-group summary::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.ref-group summary::after { content: "›"; margin-left: 4px; color: var(--faint); transition: transform .15s; }
.ref-group[open] summary::after { transform: rotate(90deg); }
.ref-group summary:hover { background: var(--surface-2); }
.ref-link { display: block; padding: 4px 10px 4px 27px; border-radius: 8px; color: var(--fg); text-decoration: none; font: 500 13px var(--font-body); overflow-wrap: anywhere; }
.ref-link.lang, .ref-link.guide { font-family: var(--font-body); font-size: 13px; }
.ref-link:hover { background: var(--surface-2); }
.ref-link.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.refart { overflow: auto; padding: 28px max(16px, calc((100% - 820px) / 2)) 80px; }
.eyebrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.eyebrow::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.ref-title { margin: 0 0 8px; font-size: 34px; line-height: 1.1; font-weight: 750; letter-spacing: -.035em; text-wrap: balance; overflow-wrap: anywhere; }
.ref-title.mono { font-family: var(--font-body); font-size: 32px; letter-spacing: -.03em; }
.lede { font-size: 17px; color: var(--muted); margin: 0; text-wrap: pretty; }
.refart h2 { font-size: 21px; font-weight: 700; margin: 40px 0 12px; padding-top: 0; border-top: 0; letter-spacing: -.025em; scroll-margin-top: 12px; }
.refart h3 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; margin: 22px 0 8px; }
.ref-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.onpage { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 18px; }
.onpage a { padding: 4px 12px; border-radius: var(--wl-pill); border: 0; background: var(--surface-2); color: var(--muted); text-decoration: none; font-size: 12.5px; font-weight: 500; }
.onpage a:hover { color: var(--fg); background: var(--surface-3); }
.plain { padding: 16px 20px; border: 0; border-radius: var(--wl-radius-md); background: var(--surface-2); }
.plain p { margin: 0 0 8px; font-size: 15px; line-height: 1.6; }
.facts { margin: 6px 0 0; padding-left: 18px; }
.facts li { margin: 5px 0; line-height: 1.55; }
.note { font-size: 13px; color: var(--muted); }
.syn-plain { font-size: 13px; color: var(--muted); margin: 6px 0 0; line-height: 1.7; }
.loading { color: var(--muted); }
.ref-block { padding: 18px; border-radius: var(--wl-radius-md); background-color: var(--canvas); border: 0; overflow-x: auto; }
.ref-block .blk { cursor: default; }
.prose { line-height: 1.65; }
.prose.small { font-size: 13.5px; }
.prose p { margin: 0 0 10px; }
.prose h2, .prose h3, .prose h4, .prose h5 { margin: 22px 0 8px; }
.prose h4 { font-size: 14px; } .prose h5 { font-size: 13px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li { margin: 4px 0; }
.callout { margin: 12px 0; padding: 12px 16px; border-radius: var(--wl-radius-md); border: 0; background: var(--accent-soft); }
.callout.warning, .callout.caution, .callout.important { background: color-mix(in srgb, var(--need) 13%, var(--bg)); }
.callout-k { display: block; font-size: 13px; font-weight: 700; color: var(--fg); margin-bottom: 2px; }
.callout p:last-child { margin-bottom: 0; }

.cb { margin: 12px 0; border: 0; border-radius: var(--wl-radius-md); overflow: hidden; background: var(--surface-2); }
.cb-bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; background: var(--ed-2); border-bottom: 0; }
.cb-k { font-size: 12.5px; font-weight: 650; color: var(--ed-dim); }
.cb-btn { margin-left: auto; height: 26px; padding: 0 11px; border-radius: var(--wl-pill); border: 0; background: var(--ed-bg); color: var(--ed-fg); font-size: 12px; font-weight: 600; cursor: pointer; }
.cb-btn:hover { background: color-mix(in srgb, var(--ed-fg) 10%, var(--ed-bg)); }
.cb-code { margin: 0; padding: 14px 16px; background: var(--ed-bg); color: var(--ed-fg); font: 12.5px/1.6 var(--font-mono); overflow-x: auto; white-space: pre; }
.cb-code.out { color: var(--wl-ink-2); }
.cb-x { border-top: 0; }
.cb-x > summary { padding: 9px 14px; cursor: pointer; font-size: 13px; font-weight: 650; color: var(--accent); }
.cb-x > summary:hover { background: var(--surface-3); }
.cb-x > .xp { padding: 0 14px 12px; }
.outd > summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 2px 0; }
.example { margin-bottom: 10px; }
.about-embed { margin: 8px 0; border: 0; border-radius: var(--wl-radius-md); background: var(--surface-2); }
.about-embed > summary { padding: 12px 16px; cursor: pointer; font-size: 13.5px; font-weight: 600; }
.about-embed > summary span { color: var(--muted); }
.about-embed > .prose, .about-embed > .loading { padding: 0 16px 12px; }

.pcards { display: grid; gap: 10px; }
.pcard { padding: 14px 16px; border: 0; border-radius: var(--wl-radius-md); background: var(--surface-2); scroll-margin-top: 12px; }
.pcard-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.pcard-n { font: 700 15px var(--font-body); letter-spacing: -.015em; }
.pcard-t { font: 12px var(--font-mono); color: var(--muted); }
.tag { padding: 0 8px; border-radius: var(--wl-pill); border: 1px solid var(--line-strong); font-size: 11.5px; font-weight: 600; color: var(--muted); line-height: 19px; }
.tag.req { border-color: var(--need); color: var(--need); }
.pcard-plain { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.pfacts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 14px; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12.5px; }
.pfacts dt { color: var(--muted); }
.pfacts dd { margin: 0; }
.io { margin: 8px 0; padding: 12px 16px; border: 0; border-radius: var(--wl-radius-md); background: var(--surface-2); }
.io > code { font-weight: 600; }
.glossary { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; }
.glossary dt { font-weight: 600; }
.glossary dd { margin: 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--wl-radius-md); background: var(--surface); margin: 10px 0; }
.ptable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ptable th { text-align: left; font-size: 12.5px; font-weight: 650; color: var(--muted); background: var(--surface-2); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ptable tr:last-child td { border-bottom: 0; }
.ptable td.mono { font-family: var(--font-body); font-weight: 650; white-space: nowrap; }
.ptable td.dim { color: var(--muted); font-weight: 400; }
.related { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 12px; border-radius: var(--wl-pill); border: 0; background: var(--surface-2); text-decoration: none; font: 600 12.5px var(--font-body); color: var(--fg) !important; }
.chip:hover { background: var(--accent-soft); }
.attrib { margin-top: 40px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); }

/* ── Narrow screens ── */
@media (max-width: 1200px) { .builder { grid-template-columns: 60px 250px minmax(0, 1fr) 340px; } }
@media (max-width: 940px) {
  .app { height: auto; min-height: 100%; }
  .builder { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 62vh auto; }
  .rail { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px 16px; }
  .rail-btn { flex: none; min-width: 62px; padding-inline: 4px; }
  .palwrap { border-right: 0; border-bottom: 1px solid var(--line); }
  .palette { max-height: 280px; padding-inline: 16px; }
  .pal-h { margin-inline: -16px; padding-inline: 16px; }
  .palhead { padding-inline: 16px; }
  .codearea { border-left: 0; min-height: 380px; }
  .codebox, .explainbox { max-height: 70vh; }
  .ref { grid-template-columns: minmax(0, 1fr); }
  .refside { border-right: 0; border-bottom: 1px solid var(--line); }
  #refnav { max-height: 300px; }
  .ver { display: none; }
  .xp-parts, .glossary { grid-template-columns: minmax(0, 1fr); }
  .xp-parts dd, .glossary dd { margin-bottom: 6px; }
}
@media (max-width: 940px) { .drawer { position: fixed; inset: 0; width: 100%; z-index: 65; } }
@media (prefers-reduced-motion: reduce) { .blk.pop, .drawer, .pcard.flash { animation: none; } .toast { transition: none; } }

/* Link back to the site homepage (Weblab), left of the brand. */
.home { display: grid; place-items: center; width: 34px; height: 34px; margin-right: -6px; border-radius: var(--wl-pill); background: var(--surface-2); color: var(--muted); }
.home:hover { background: var(--surface-3); color: var(--fg); }
.home svg { width: 16px; height: 16px; }
