/* Coded Slate plugin playground. The device's look (web/ui/style.css): all
   matte black, light-grey type, and the 1-bit Memory LCD as the one lit
   thing. The code is grey on black like the chassis; only the screen is paper. */
:root {
  color-scheme: dark;
  --slate: #0e0e0f;
  --well: #070708;
  --cap: #19191b;
  --cap-hi: #222225;
  --hair: #222225;
  --label: #85847f;
  --label-hi: #d6d4cc;
  --code: #c8c6be;
  --paper: #e3e2da;
  --ink: #18181a;
  --warn: #e0402e;
  --amber: #c9a24a;
  --ui: "Helvetica Neue", Helvetica, Arial, "Nimbus Sans", "Liberation Sans", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --r: 7px;
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--slate); color: var(--label-hi); font: 14px/1.45 var(--ui); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
html { overscroll-behavior-y: none; }
button, select { touch-action: manipulation; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 1.5px solid var(--label-hi); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.dim { color: var(--label); }
.num { font-variant-numeric: tabular-nums; }
h2 { font-size: 12px; font-weight: 600; color: var(--label); margin: 0; letter-spacing: 0.02em; }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding: max(10px, var(--sa-t)) max(14px, var(--sa-r)) max(12px, var(--sa-b)) max(14px, var(--sa-l)); gap: 10px; }

/* top bar */
.top { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 14px; white-space: nowrap; }
.brand b { font-weight: 700; letter-spacing: 0.01em; }
.brand span:last-child { color: var(--label); }
.mark { width: 9px; height: 9px; border-radius: 50%; background: var(--label-hi); box-shadow: 0 0 8px #d6d4cc55; }
.actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
button, select { background: var(--cap); border: 1px solid var(--hair); border-radius: var(--r); padding: 6px 11px; cursor: pointer; color: var(--label-hi); }
button:hover:not(:disabled), select:hover { background: var(--cap-hi); }
button:disabled { color: #55544f; cursor: not-allowed; }
button.primary { background: var(--label-hi); color: var(--ink); border-color: var(--label-hi); }
select { appearance: none; padding-right: 26px; background-image: linear-gradient(45deg, transparent 50%, var(--label) 50%), linear-gradient(135deg, var(--label) 50%, transparent 50%); background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.pick select { min-width: 170px; }
.box-btn[data-state="none"] { color: var(--label); }
.box-btn::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #3a3936; margin-right: 7px; vertical-align: 1px; }
.box-btn[data-state="ready"]::before { background: var(--label-hi); }

/* panes */
.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px minmax(0, 1fr) minmax(360px, 430px); gap: 10px; }
.panes > * { min-height: 0; background: var(--well); border: 1px solid var(--hair); border-radius: 10px; display: flex; flex-direction: column; }
.pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 10px 12px 8px; }

/* blocks */
#block-q { margin: 0 10px 8px; background: var(--slate); border: 1px solid var(--hair); border-radius: var(--r); padding: 7px 10px; color: var(--label-hi); }
.block-list { list-style: none; margin: 0; padding: 0 4px 10px; overflow: auto; flex: 1; }
.block-list li { padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.block-list li:hover, .block-list li:focus-visible { background: var(--cap); }
.block-list .bn { font-family: var(--mono); font-size: 12.5px; color: var(--label-hi); display: flex; justify-content: space-between; gap: 6px; }
.block-list .bc { color: var(--label); font-family: var(--ui); font-size: 11px; font-variant-numeric: tabular-nums; }
.block-list .bd { font-size: 12px; color: var(--label); margin-top: 1px; }
.block-list .ba { display: none; margin-top: 6px; font-family: var(--mono); font-size: 11px; color: #a9a7a0; line-height: 1.6; }
.block-list li.open .ba { display: block; }
.block-list .ba span { color: var(--label); }
.block-list .group { padding: 12px 8px 4px; font-size: 11px; color: #5f5e59; cursor: default; }
.block-list .group:hover { background: none; }

/* code */
.code { overflow: hidden; }
.state { font-size: 12px; color: var(--label); white-space: nowrap; }
.state::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: #3a3936; vertical-align: 0; }
.state[data-s="ok"]::before { background: var(--label-hi); }
.state[data-s="warn"]::before { background: var(--amber); }
.state[data-s="error"]::before { background: var(--warn); }
.editor { flex: 1; min-height: 160px; overflow: hidden; border-top: 1px solid var(--hair); }
.editor .cm-editor { height: 100%; }
.plain-editor { width: 100%; height: 100%; resize: none; border: 0; background: var(--well); color: var(--code); font: 13px/1.5 var(--mono); padding: 10px 12px; outline: none; tab-size: 2; }
.results { flex: 0 0 34%; min-height: 150px; display: flex; flex-direction: column; border-top: 1px solid var(--hair); }
.tabs { display: flex; gap: 2px; padding: 6px 8px 0; }
.tabs button { background: none; border: 0; border-bottom: 1.5px solid transparent; border-radius: 0; padding: 5px 9px 6px; color: var(--label); }
.tabs button[aria-selected="true"] { color: var(--label-hi); border-bottom-color: var(--label-hi); }
.count { font-variant-numeric: tabular-nums; color: var(--label); margin-left: 3px; }
.tabpane { flex: 1; overflow: auto; padding: 6px 4px 10px; }
.row-item { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 4px 8px; padding: 7px 10px; border-radius: 6px; cursor: pointer; align-items: baseline; }
.row-item:hover { background: var(--cap); }
.glyph { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--label-hi); }
.glyph.error, .glyph.fail { background: var(--warn); }
.glyph.warning { background: var(--amber); }
.glyph.pass { background: transparent; border: 1.5px solid var(--label-hi); }
.row-item .t { color: var(--label-hi); }
.row-item code, .code-line { font-family: var(--mono); font-size: 12px; }
.row-item .loc { font-size: 12px; color: var(--label); font-variant-numeric: tabular-nums; }
.row-item .sub { grid-column: 2 / 4; font-size: 12.5px; color: var(--label); }
.row-item .sub b { color: #b9b7af; font-weight: 500; }
.empty { padding: 14px 12px; color: var(--label); font-size: 13px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; padding: 8px 10px; }
.metric { background: var(--slate); border: 1px solid var(--hair); border-radius: 8px; padding: 7px 10px; }
.metric b { display: block; font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums; }
.metric span { font-size: 11.5px; color: var(--label); }
.render-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 10px; }
.render-bar a { color: var(--label-hi); }

/* listen */
.listen { padding: 12px; gap: 12px; overflow: auto; }
.lcd-wrap { background: #030303; border-radius: 9px; padding: 9px; box-shadow: inset 0 0 0 1px #1b1b1d, inset 0 2px 12px #000; }
#lcd { display: block; width: 100%; aspect-ratio: 536 / 336; image-rendering: pixelated; border-radius: 2px; background: var(--paper); }
.transport { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.play { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; }
.play .tri { width: 0; height: 0; border-left: 9px solid var(--label-hi); border-top: 6px solid transparent; border-bottom: 6px solid transparent; }
.play[aria-pressed="true"] .tri { width: 9px; height: 11px; border: 0; border-left: 3px solid var(--label-hi); border-right: 3px solid var(--label-hi); }
.ab { display: inline-flex; border: 1px solid var(--hair); border-radius: var(--r); overflow: hidden; }
.ab button { border: 0; border-radius: 0; background: var(--slate); color: var(--label); padding: 8px 12px; }
.ab button[aria-pressed="true"] { background: var(--cap-hi); color: var(--label-hi); }
.src { margin-left: auto; }
.src select { max-width: 200px; }

/* knob tiles: the box's footer tiles, one per P1..P9 */
.knobs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.knob { position: relative; background: var(--cap); border: 1px solid var(--hair); border-radius: var(--r); padding: 8px 10px 9px; cursor: ns-resize; touch-action: none; user-select: none; min-height: 58px; }
.knob:hover { background: var(--cap-hi); }
.knob .kn { font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em; color: var(--label-hi); display: flex; justify-content: space-between; }
.knob .kn i { font-style: normal; font-weight: 400; color: #5f5e59; letter-spacing: 0; }
.knob .kv { font-size: 15px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.knob .arc { position: absolute; left: 10px; right: 10px; bottom: 6px; height: 2px; background: #2c2c2f; border-radius: 1px; }
.knob .arc i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--label-hi); border-radius: 1px; }
.knob.switch { cursor: pointer; }
.knob.switch .kv { letter-spacing: 0.04em; font-weight: 600; font-size: 13.5px; }
.knobs .none { grid-column: 1 / -1; color: var(--label); font-size: 13px; padding: 4px 2px; }

.fit { background: var(--slate); border: 1px solid var(--hair); border-radius: 9px; padding: 10px 12px; }
.fit-line { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.fit-line .num { font-weight: 400; color: var(--label); }
.fit-bar { position: relative; height: 4px; background: #232326; border-radius: 2px; margin: 8px 0 6px; overflow: hidden; }
.fit-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--label-hi); }
.fit[data-fit="no"] .fit-bar i { background: var(--warn); }
.fit[data-fit="no"] #fit-verdict { color: var(--warn); }
.fit p { margin: 0; font-size: 12px; }
.engine-note { font-size: 12px; margin: 0; }

/* dialog + toast */
dialog { background: var(--cap); color: var(--label-hi); border: 1px solid var(--hair); border-radius: 12px; padding: 18px; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: #000a; }
.box-form { display: flex; flex-direction: column; gap: 12px; }
.box-form h2 { font-size: 15px; color: var(--label-hi); }
.box-form p { margin: 0; font-size: 13px; }
.box-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--label); flex: 1; }
.box-form input, .box-form select { background: var(--slate); border: 1px solid var(--hair); border-radius: var(--r); padding: 7px 10px; color: var(--label-hi); }
.box-form .row { display: flex; gap: 10px; }
.box-form .end { justify-content: flex-end; flex-wrap: wrap; }
.box-log { margin: 0; max-height: 180px; overflow: auto; background: var(--slate); border-radius: 8px; padding: 8px 10px; font: 12px/1.5 var(--mono); white-space: pre-wrap; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; background: var(--label-hi); color: var(--ink); padding: 8px 14px; border-radius: 8px; font-size: 13px; pointer-events: none; transition: opacity 0.15s, transform 0.15s; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* narrower: catalogue under, listen beside */
@media (max-width: 1180px) {
  .panes { grid-template-columns: minmax(0, 1fr) minmax(340px, 400px); grid-template-rows: minmax(0, 1fr) 220px; }
  .blocks { grid-column: 1 / -1; grid-row: 2; }
}
/* touch: 44 pt targets; fields at 16px (iOS zooms into anything smaller) */
@media (pointer: coarse) {
  button, select { min-height: 40px; }
  select, input, #block-q, .box-form input, .box-form select { font-size: 16px; }
  .tabs button { min-height: 40px; }
  .ab button { min-height: 38px; }
  .block-list li { padding: 10px 8px; }
}
/* phone (and phone landscape): one column, the page scrolls */
@media (max-width: 760px), (orientation: landscape) and (max-height: 500px) {
  .app { height: auto; min-height: 100dvh; padding: max(10px, var(--sa-t)) max(16px, var(--sa-r)) max(16px, var(--sa-b)) max(16px, var(--sa-l)); gap: 12px; }
  .top { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding-top: 4px; }
  .brand { font-size: 16px; }
  .brand span:last-child { font-size: 14px; }
  .pick, .pick select { width: 100%; }
  .pick { min-width: 0; }
  .pick select { height: 44px; min-width: 0; }
  .actions { margin-left: 0; display: grid; grid-template-columns: 1fr 1fr 1fr 1.35fr; gap: 6px; }
  .actions button { height: 44px; padding: 0 6px; font-size: 14px; white-space: nowrap; }
  .panes { display: flex; flex-direction: column; gap: 12px; }
  .panes > * { border-radius: 12px; }
  .code { order: 1; height: 72svh; min-height: 380px; }
  .results { flex: 0 0 auto; min-height: 0; }
  .tabpane { min-height: 76px; max-height: 240px; }
  .listen { order: 2; overflow: visible; }
  .blocks { order: 3; height: 70svh; }
  .knobs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .src { margin-left: 0; flex: 1 0 100%; }
  .src select { max-width: none; width: 100%; }
  .toast { bottom: max(20px, var(--sa-b)); }
}
@media (orientation: landscape) and (max-height: 500px) {
  .top { grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; }
  .actions { grid-template-columns: repeat(4, auto); }
  .code { height: calc(100svh - 24px); min-height: 0; }
  .listen { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .lcd-wrap { grid-row: span 4; }
}
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
