:root {
  color-scheme: dark;
  --bg: #121419; --panel: #1d2027; --panel2: #252933; --line: #343947;
  --text: #d8dce6; --dim: #8a90a0; --accent: #f0a640; --accent2: #5ec8e5; --err: #ff6b6b;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; scrollbar-color: #3a3f4d transparent; scrollbar-width: thin; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, sans-serif; overflow: hidden; }
body { display: flex; flex-direction: column; }
button, select, input, textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; }
button { cursor: pointer; transition: border-color .12s, background .12s, color .12s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .38; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; }
button.icon { min-width: 30px; padding: 3px 6px; text-align: center; }
button.primary { background: #2c2416; border-color: #6d5426; }
kbd { font: 10.5px var(--mono); color: var(--dim); background: #171a20; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; margin-left: 2px; }
button.on kbd { color: var(--accent); border-color: #6d5426; }
button.on { background: #3b2d14; border-color: var(--accent); color: var(--accent); }
button.bot { background: #14303b; border-color: var(--accent2); color: var(--accent2); }
button.danger:hover { border-color: var(--err); color: var(--err); }
.mono, code { font-family: var(--mono); }
.dim { color: var(--dim); }
.small { font-size: 11.5px; }
.err { color: var(--err); }
a.link { color: var(--accent2); }

#top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; min-height: 46px; padding: 7px 12px; background: var(--panel); border-bottom: 1px solid var(--line); white-space: nowrap; flex-shrink: 0; }
#top .group.edit { gap: 3px; }
.brand { font-weight: 700; color: var(--accent); margin-right: 4px; }
.brand span { color: var(--accent2); font-weight: 600; }
.group { display: flex; align-items: center; gap: 6px; padding-left: 10px; border-left: 1px solid var(--line); }
#rate { width: 150px; padding: 0; accent-color: var(--accent); }
#rate-label { min-width: 74px; color: var(--accent); font-size: 12px; }
#ticks { font-size: 12px; }
#examples { max-width: 190px; }
#ticks { min-width: 120px; color: var(--accent2); }
.spacer { flex: 1; }

#main { display: flex; flex: 1; min-height: 0; }
#palette { width: 180px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 8px 8px 20px; }
#palette-search { width: 100%; margin-bottom: 2px; }
#palette h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); margin: 12px 0 4px; }
.pitem { display: flex; gap: 8px; align-items: center; padding: 3px 6px; border-radius: 4px; cursor: pointer; user-select: none; }
.pitem:hover { background: var(--panel2); }
.pitem:active { background: #3b2d14; }
.pitem.on { background: #3b2d14; color: var(--accent); }
.psym { width: 26px; text-align: center; font-family: var(--mono); color: var(--accent); }
.pbuttons { margin-top: 10px; }
.pbuttons button { width: 100%; }

#center { flex: 1; position: relative; display: flex; flex-direction: column; min-width: 0; }
#grid { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; }
#status { height: 22px; padding: 3px 10px; font-size: 11.5px; color: var(--dim); background: var(--panel); border-top: 1px solid var(--line); overflow: hidden; white-space: nowrap; }
#banner > div { padding: 5px 12px; font-size: 12.5px; }
#banner .err { background: #3a1f22; color: #ffb3b3; }
#toast { position: absolute; left: 50%; bottom: 36px; transform: translate(-50%, 6px); background: #2c3140; border: 1px solid var(--accent); padding: 8px 14px; border-radius: 6px; max-width: 70%; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#status { display: flex; justify-content: space-between; gap: 16px; }
#status .hint { color: #6d7486; }
.btnrow button { margin: 2px 0; }
table.keys { border-collapse: collapse; font-size: 12.5px; }
table.keys td { padding: 3px 12px 3px 0; vertical-align: top; }
table.keys td:first-child { white-space: nowrap; }

#inspector { width: 290px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 10px 14px 30px; }
#inspector h2 { font-size: 15px; margin: 4px 0 6px; }
#inspector h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); margin: 16px 0 6px; }
#inspector ul { padding-left: 18px; margin: 4px 0; }
.eq { font: 600 14px var(--mono); color: var(--accent2); background: #171a20; padding: 6px 8px; border-radius: 4px; }
.field { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.field > span { width: 92px; color: var(--dim); flex-shrink: 0; }
.field input, .field select, .field textarea { flex: 1; min-width: 0; }
.field.col { flex-direction: column; align-items: stretch; }
table.res, table.ports { width: 100%; border-collapse: collapse; }
table.res td { padding: 2px 0; border-bottom: 1px solid #262a33; }
table.res td:last-child { text-align: right; font-family: var(--mono); color: var(--accent2); }
table.res tr.sum td { font-weight: 600; }
table.ports input { width: 100%; padding: 1px 4px; }
table.ports td:nth-child(3) { width: 52px; }
.mini { padding: 0 6px; font-size: 11px; }
ul.loops li { margin: 3px 0; font-size: 12px; word-break: break-all; }
.legend { display: flex; height: 12px; border-radius: 3px; overflow: hidden; }
.legend .bar { flex: 1; }
.legend .neg { background: linear-gradient(to left, #22282f, #0b3a5c, #13668f, #2a9bbd, #59c7d9, #a6e6ea, #e6fbff); }
.legend .pos { background: linear-gradient(to right, #2a2233, #3b0f70, #8c2981, #de4968, #fe9f6d, #fcd06a, #fcfdbf); }
.legend-labels { display: flex; justify-content: space-between; font: 10px var(--mono); color: var(--dim); }
pre.code { background: #11131a; border: 1px solid var(--line); border-radius: 4px; padding: 8px; overflow: auto; font: 12px/1.45 var(--mono); color: #cdd6e8; }
pre.code.small { font-size: 11px; white-space: pre-wrap; word-break: break-all; }
details summary { cursor: pointer; color: var(--dim); margin-top: 12px; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; max-width: 900px; width: 80vw; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
#code-dlg pre { max-height: 65vh; }
ol.crit { padding-left: 22px; margin: 4px 0; }
#style-pop { position: absolute; top: 8px; right: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px 4px; z-index: 5; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
#style-pop fieldset { border: none; padding: 0; margin: 6px 0; }
#style-pop legend { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); margin-bottom: 2px; }
#style-pop label { display: block; cursor: pointer; padding: 1px 0; }
body.embed #top, body.embed #palette, body.embed #inspector, body.embed #status, body.embed #toast, body.embed #banner { display: none; }
body.embed #main { flex: 1; }
