/* Rack Unit Designer: a three-column workspace on the site's black pearl */
/* An app, not a page: the bar on top, then the rail, the tool panel, the stage and the inspector side by
   side, each scrolling on its own - the page itself never scrolls (on a wide enough screen) */
body.designer { height: 100vh; height: 100dvh; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.d-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px var(--gut); background: rgba(10, 9, 8, .92); border-bottom: 1px solid var(--line); }
.d-top h1 { margin: 0; font-size: 1.1rem; letter-spacing: .02em; color: var(--accent); }
.d-home { color: var(--muted); text-decoration: none; font-size: .9rem; }
.d-home:hover { color: var(--ink); }
.d-top-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.designer button { font: inherit; font-size: .85rem; color: var(--ink); background: rgba(255, 255, 255, .04); border: 1px solid var(--line2);
  border-radius: 10px; padding: 7px 12px; cursor: pointer; }
.designer button:hover { background: rgba(255, 255, 255, .09); }
.designer button:focus-visible, .designer input:focus-visible, .designer select:focus-visible, .designer textarea:focus-visible, .d-stage:focus-visible
  { outline: 2px solid var(--teal); outline-offset: 2px; }
.designer button.primary { background: var(--pearl); color: #0b0a08; border-color: transparent; font-weight: 700; }
.designer button[aria-pressed="true"] { border-color: var(--teal); color: var(--teal); }

.d-main { display: grid; grid-template-columns: 64px 290px minmax(0, 1fr) 290px; gap: 0; min-height: 0; height: 100%; }
.d-panel { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; padding: 14px; scrollbar-gutter: stable; }
.d-left { border-right: 1px solid var(--line); background: rgba(255, 255, 255, .012); }
.d-right { border-left: 1px solid var(--line); background: rgba(255, 255, 255, .012); }
.d-panel section { background: var(--glass), var(--fill); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px; }
.d-panel h2 { margin: 0 0 10px; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.d-panel label { display: grid; gap: 4px; margin-bottom: 9px; font-size: .82rem; color: var(--muted); }
.d-panel label.row { display: flex; align-items: center; gap: 8px; }
.d-panel input, .d-panel select, dialog textarea { font: inherit; font-size: .88rem; color: var(--ink); background: #0b0d11; border: 1px solid var(--line2);
  border-radius: 8px; padding: 6px 8px; width: 100%; box-sizing: border-box; }
.d-panel input[type="checkbox"] { width: auto; }
.d-panel input[type="color"] { width: 44px; height: 28px; padding: 2px; }
.d-panel input[type="range"] { padding: 0; accent-color: var(--teal); }
.d-palette, .d-templates, .d-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.d-kind { margin: 0 0 8px; font-weight: 700; color: var(--ink); }

.d-stage-wrap { min-width: 0; display: flex; flex-direction: column; min-height: 0; }   /* (the stage fills the column: the unit sits in the middle of it) */
.d-zoom { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.d-zoom output { min-width: 3.5em; text-align: center; color: var(--muted); font-size: .85rem; }
.d-stage { overflow: auto; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: radial-gradient(120% 90% at 50% 40%, #1a1511 0%, #0b0908 60%, #050506 100%); padding: 16px; flex: 1; min-height: min(62vh, 560px); touch-action: none;
  display: flex; }
.d-stage svg { display: block; margin: auto; user-select: none; }   /* (auto margins in a flex box: centred both ways, and still scrollable from its edge when bigger) */
.d-part { cursor: grab; }
.d-part:active { cursor: grabbing; }
body.playing .d-part { cursor: ns-resize; }
.d-hint { color: var(--dim); font-size: .8rem; margin: 8px 2px 0; }

dialog { max-width: min(560px, 92vw); color: var(--ink); background: #0b0d11; border: 1px solid var(--line2); border-radius: var(--r-sm); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog h2 { margin-top: 0; }
dialog label { display: grid; gap: 6px; margin: 12px 0 8px; color: var(--muted); font-size: .85rem; }
dialog textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: .78rem; word-break: break-all; }
dialog hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
#import-msg { color: var(--pink); min-height: 1.2em; }
.d-noscript { padding: 24px var(--gut); }


.designer .d-stage-wrap, .designer .d-panel section { margin: 0; }
.designer section.d-stage-wrap { padding: 0; }
#selftest { white-space: pre-wrap; font: .8rem ui-monospace, monospace; padding: 16px var(--gut); color: var(--ink); }
dialog h2 { font-size: 1.25rem; line-height: 1.3; letter-spacing: 0; }

/* Picture dropdowns */
.d-field { display: grid; gap: 4px; margin-bottom: 9px; font-size: .82rem; color: var(--muted); }
.d-pick { position: relative; }
.designer .d-pick-btn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 3px 10px 3px 4px; text-align: left; background: #0b0d11; border-radius: 8px; }
.designer .d-pick-btn::after { content: "▾"; margin-left: auto; color: var(--dim); }
.d-pick-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; max-height: 320px; overflow: auto;
  background: #14120f; border: 1px solid var(--line2); border-radius: 10px; box-shadow: 0 18px 40px -12px #000; }
.d-pick-list li { display: flex; align-items: center; gap: 10px; padding: 3px 8px 3px 4px; border-radius: 8px; cursor: pointer; color: var(--ink); font-size: .85rem; }
.d-pick-list li:hover, .d-pick-list li:focus { background: rgba(224, 227, 127, .10); outline: none; }
.d-pick-list li[aria-selected="true"] { box-shadow: inset 0 0 0 1px var(--teal); }
.d-pick svg { flex: none; border-radius: 6px; background: radial-gradient(circle at 40% 30%, #2a2622, #0c0b0a); }

/* My designs */
.d-save { display: flex; gap: 6px; }
.d-save input { flex: 1; }
.d-lib { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.d-lib li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
.d-lib-name { font-weight: 700; color: var(--ink); flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.designer .d-lib button { padding: 3px 8px; font-size: .78rem; }
.designer button.danger { border-color: rgba(240, 192, 112, .4); color: var(--pink); }

/* Views */
.d-views { display: inline-flex; margin-right: 10px; }
.designer .d-views button { border-radius: 0; }
.designer .d-views button:first-child { border-radius: 10px 0 0 10px; }
.designer .d-views button:last-child { border-radius: 0 10px 10px 0; }
.d-stage3d { position: relative; border-radius: var(--r-sm); border: 1px solid var(--line); overflow: hidden; margin-bottom: 10px;
  background: radial-gradient(120% 90% at 50% 0%, #2a2018 0%, #0d0a08 60%, #050506 100%); }
.d-stage3d canvas { display: block; width: 100%; height: min(58vh, 560px); cursor: grab; touch-action: none; }
.d-stage3d canvas:active { cursor: grabbing; }
.d-stage[hidden] { display: none; }   /* (its display: flex would otherwise beat [hidden]: in 3D view it stayed) */
.d-stage3d { flex: 0 0 auto; }
.d-stage3d.both canvas { height: min(36vh, 340px); }            /* (never squeezed by the 2D stage beside it in the column) */
.d-3dnote { position: absolute; left: 12px; bottom: 8px; margin: 0; font-size: .75rem; color: var(--dim); pointer-events: none; }
.d-stage svg { max-width: none; }

/* Preset cards: a picture of each design over its name */
.d-templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.designer button.d-tpl { display: grid; gap: 5px; justify-items: center; padding: 6px; font-size: .75rem; line-height: 1.2; text-align: center; }
.d-tpl svg, .d-tpl img { display: block; width: 100%; height: auto; border-radius: 4px; }
.d-tpl-pic { display: block; width: 100%; min-height: 28px; border-radius: 4px; background: rgba(255, 240, 220, .03); }
.d-templates .d-tpl { content-visibility: auto; contain-intrinsic-size: auto 90px; }


/* The top bar's grouped buttons */
.d-group { display: inline-flex; }
.designer .d-group button { border-radius: 0; }
.designer .d-group button:first-child { border-radius: 10px 0 0 10px; }
.designer .d-group button:last-child { border-radius: 0 10px 10px 0; }
.designer .d-group button + button { border-left-width: 0; }

/* The tool rail */
.d-rail { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 10px 6px; border-right: 1px solid var(--line); background: rgba(0, 0, 0, .25); }
.designer .d-rail button { display: grid; justify-items: center; gap: 3px; padding: 8px 2px; border: 1px solid transparent; background: none; border-radius: 10px; color: var(--muted); font-size: .68rem; letter-spacing: .04em; }
.designer .d-rail button:hover { color: var(--ink); background: rgba(255, 255, 255, .05); }
.designer .d-rail button[aria-selected="true"] { color: var(--teal); border-color: rgba(224, 227, 127, .35); background: rgba(224, 227, 127, .08); }
.d-rail svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* The stage column: its toolbar, then the stage (and 3D view, and the description) scrolling under it */
.d-stage-wrap { display: flex; flex-direction: column; min-height: 0; height: 100%; padding: 12px 16px !important; }
.d-stage-scroll { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.d-stage { max-height: none; flex: none; }
.d-hint { flex: none; }
.d-panel section[hidden] { display: none; }
.d-panel textarea { font: inherit; font-size: .88rem; color: var(--ink); background: #0b0d11; border: 1px solid var(--line2); border-radius: 8px; padding: 8px; width: 100%; box-sizing: border-box; resize: vertical; line-height: 1.45; }
.d-row2 { display: flex; gap: 18px; }
.d-hint-inline { margin: -4px 0 10px; }

/* The description, under the unit */
.d-about { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px 16px; background: var(--glass), var(--fill); }
.d-about h2 { margin: 0 0 6px; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.d-about p { margin: 0; white-space: pre-wrap; line-height: 1.55; color: var(--ink); max-width: 75ch; }

/* Narrow screens: back to one scrolling column, the rail as a row of tabs above the tools */
@media (max-width: 1100px) {
  body.designer { height: auto; overflow: auto; display: block; }
  .d-main { grid-template-columns: 1fr; height: auto; }
  .d-top { position: static; }
  .d-rail { flex-direction: row; justify-content: center; border-right: 0; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 4; background: #0b0a08; }
  .d-stage-wrap { order: -1; height: auto; }
  .d-stage-scroll { overflow: visible; }
  .d-panel { overflow: visible; border: 0; }
}

/* The shared gradients and filters (see designer.js render): rendered, but takes no room */
.d-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Share: send buttons, the code itself tucked away */
.d-share-send { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.d-code summary { cursor: pointer; color: var(--muted); font-size: .85rem; margin: 6px 0; }
.d-sub { margin: 0 0 8px; font-size: 1rem; }
.d-stage.drop { outline: 2px dashed var(--teal); outline-offset: -6px; }
dialog { max-height: 92vh; overflow: auto; }

/* The knob maker */
.d-ck-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.d-ck-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.d-ck-list li.on { border-color: var(--teal); }
.d-ck-list li span { flex: 1; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.designer .d-ck-list button { padding: 3px 8px; font-size: .75rem; }
.d-ck-edit { margin-top: 12px; }
.d-ck-preview { display: grid; place-items: center; margin: 4px 0 12px; border-radius: 12px; background: radial-gradient(circle at 50% 35%, #2a2622, #0c0b0a); }

/* The Sound tab (designer-audio.js) */
.snd-transport { display: flex; gap: 8px; align-items: end; }
.snd-transport label { flex: 1; }
.snd-meter { height: 6px; border-radius: 3px; background: rgba(255, 236, 205, .08); overflow: hidden; margin: 8px 0 12px; }
.snd-meter i { display: block; height: 100%; background: linear-gradient(90deg, #7aa35a, #e0a84a 70%, #d8502b); transform-origin: 0 50%; transform: scaleX(0); }
.snd-chain { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 8px; }
.snd-block { border: 1px solid var(--line2); border-radius: 10px; padding: 8px 10px; background: rgba(0, 0, 0, .2); }
.snd-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.snd-head b { flex: 1; font-size: .9rem; }
.snd-head button { padding: 2px 7px; min-width: 0; }
.snd-param { display: grid; grid-template-columns: 1fr 1.2fr auto; align-items: center; gap: 6px; font-size: .8rem; margin: 2px 0; }
.snd-param output { min-width: 64px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- UX: preset search, quick start, shortcuts, toasts ---- */
.d-search { width: 100%; margin: 0 0 6px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line2); background: rgba(0, 0, 0, .35); color: var(--ink); font: inherit; font-size: .88rem; }
.d-search::placeholder { color: var(--dim); }
.d-tpl[hidden] { display: none !important; }
.d-start .d-steps { list-style: none; counter-reset: st; margin: 6px 0 0; padding: 0; display: grid; gap: 10px; }
.d-start .d-steps li { counter-increment: st; position: relative; padding: 10px 10px 10px 40px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 240, 220, .025); font-size: .86rem; color: var(--muted); display: grid; gap: 8px; }
.d-start .d-steps li::before { content: counter(st); position: absolute; left: 10px; top: 10px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: .72rem; font-weight: 800; color: #0b0a08; background: var(--pearl); }
.d-start .d-steps b { color: var(--ink); }
.d-start .d-steps button { justify-self: start; }
.d-start .d-steps .d-btns { display: flex; gap: 6px; flex-wrap: wrap; }
/* Guided start: big, plain choices */
.d-guide { max-width: 640px; }
.d-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 6px 0 14px; }
.d-choices button { display: grid; gap: 2px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 240, 220, .03); color: var(--ink); font: inherit; cursor: pointer; }
.d-choices button small { color: var(--muted); font-size: .76rem; }
.d-choices button[aria-checked="true"] { border-color: transparent; background: var(--pearl); color: #0b0a08; }
.d-choices button[aria-checked="true"] small { color: #2a2520; }
.d-choices .d-chip { width: 100%; height: 10px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, .2); }
.designer button.d-link { background: none; border: 0; padding: 0 2px; color: var(--accent); font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line2); border-bottom-width: 2px; background: rgba(255, 255, 255, .05); font: 600 .78em/1.5 var(--mono); color: var(--ink); text-align: center; }
.d-keys dl { display: grid; gap: 6px; margin: 0 0 14px; }
.d-keys dl div { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 12px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.d-keys dt { color: var(--muted); font-size: .86rem; }
.d-keys dd { margin: 0; font-size: .9rem; }
.d-toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); padding: 9px 16px; border-radius: 999px; background: var(--pearl); color: #0b0a08; font-weight: 700; font-size: .86rem;
  box-shadow: 0 14px 40px -12px #000; opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s; z-index: 100; }
.d-toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .d-toast { transition: none; } }

/* Parts tab: the parts on the panel, and the design check */
.d-layers { list-style: none; margin: 6px 0 12px; padding: 0; display: grid; gap: 3px; max-height: 260px; overflow: auto; }
.d-layers li { display: flex; gap: 4px; align-items: center; }
.d-layers li.on .d-layer-name { border-color: var(--accent, #e0a84a); color: var(--text, #fff); }
.designer .d-layers button { padding: 3px 7px; font-size: .75rem; }
.designer .d-layers .d-layer-name { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-layers button[aria-pressed="true"] { color: var(--accent, #e0a84a); }
.d-issues { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; }
.designer .d-issue button { width: 100%; text-align: left; font-size: .78rem; padding: 5px 8px; border-left: 3px solid var(--line); }
.designer .d-issue.bad button { border-left-color: #e0412e; }
.designer .d-issue.warn button { border-left-color: #e0a84a; }
.designer .d-issue.info button { border-left-color: #6b7a8c; }
/* Look tab: ideas */
.d-ideas-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.designer .d-ideas-head button { white-space: nowrap; flex: none; }
.d-ideas:empty { display: none; }
.d-ideas { margin-bottom: 12px; }

/* Look: colours to snap to (3.8.0.1) */
.d-swatches { display: grid; gap: 6px; margin: 4px 0 12px; }
.d-sw-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.d-sw-row > span { flex: 0 0 100%; font-size: .72rem; color: var(--dim); letter-spacing: .06em; text-transform: uppercase; }
.designer button.d-sw { width: 20px; height: 20px; min-width: 0; padding: 0; border-radius: 5px; border: 1px solid rgba(255, 255, 255, .25); }
.designer button.d-sw:hover { transform: scale(1.15); border-color: #fff; }
