:root {
  --bg: #15171a;
  --panel: #23262b;
  --text: #e6e7e9;
  --muted: #9aa0a8;
  --accent: #e7c15b;
  --danger: #ff7a70;
  --ok: #7bd88f;
  --shell-top: #5e6164;
  --shell-bottom: #4b4e51;
  --print: #b8bcbf;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid #2d3036;
}
.bar h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.bar h1 span { color: var(--muted); font-weight: 400; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.button, select {
  background: var(--panel); color: var(--text); border: 1px solid #3a3e45; border-radius: 8px;
  padding: 7px 12px; font: inherit; cursor: pointer;
}
.button:hover:not(:disabled) { border-color: #5a606a; }
.button:disabled { opacity: .45; cursor: default; }
.button.primary { background: var(--accent); color: #1b1b1b; border-color: var(--accent); font-weight: 600; }
[hidden] { display: none !important; }
main {
  display: grid; gap: 16px; padding: 16px;
  grid-template-columns: minmax(0, 1fr) 300px; align-items: start;
  max-width: 1500px; margin: 0 auto;
}
@media (max-width: 1000px) { main { grid-template-columns: minmax(0, 1fr); } }

/* Device panel: children are placed in a 1288×740 design space (panel.js);
   sizes in cqw scale with the panel's width. */
.device {
  position: relative; width: 100%; aspect-ratio: 1288 / 740; container-type: inline-size;
  border-radius: 2.6% / 4.5%;
  background:
    radial-gradient(120% 90% at 30% 0%, #ffffff12, transparent 60%),
    linear-gradient(180deg, var(--shell-top), var(--shell-bottom));
  box-shadow:
    0 2.2cqw 4cqw #000a, 0 .3cqw .5cqw #0008,
    inset 0 .15cqw 0 #ffffff26, inset 0 -.3cqw .6cqw #0006;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.device.dragging { outline: 3px dashed var(--accent); outline-offset: 6px; }
.device > * { position: absolute; }
.well {
  background: linear-gradient(180deg, #1d1e20, #2a2b2e);
  border-radius: 1.6cqw;
  box-shadow: inset 0 .25cqw .6cqw #000c, 0 .1cqw 0 #ffffff1c;
}
.keys-well { border-radius: 3.6cqw; background: linear-gradient(180deg, #2b2526, #352e2e); }
.bezel {
  background: linear-gradient(160deg, #111214, #050506);
  border-radius: 2.8cqw;
  box-shadow: inset 0 0 0 .15cqw #2b2d31, inset 0 .3cqw .8cqw #000, 0 .12cqw 0 #ffffff1a;
}
.lcd-frame {
  position: absolute; left: 12.34%; top: 10.78%; width: 75.95%; height: 78.43%;
  background: #000; box-shadow: 0 0 0 .2cqw #000, 0 0 1.2cqw #000;
}
#lcd { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.drop-hint {
  position: absolute; inset: 8%; display: flex; flex-direction: column; justify-content: center;
  text-align: center; color: var(--muted); font-size: 1.5cqw; pointer-events: none;
}
.drop-hint.hidden { display: none; }
.print {
  display: flex; align-items: center; justify-content: center;
  color: var(--print); font: 700 1.55cqw/1 "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  letter-spacing: .12cqw; pointer-events: none; text-shadow: 0 .08cqw 0 #0006;
}
.dot { border-radius: 50%; background: #0b0a0a; box-shadow: 0 .05cqw 0 #ffffff1f; }

/* Knobs: a knurled skirt, a cap that turns, and its marker. */
.knob {
  border-radius: 50%; cursor: grab; outline: none;
  background: radial-gradient(circle, #0d0e0f 0 64%, #000 66% 100%);
  box-shadow: 0 .5cqw .8cqw #000b, 0 .1cqw .1cqw #000;
}
.knob.turning { cursor: grabbing; }
.knob:focus-visible { box-shadow: 0 0 0 .3cqw var(--accent), 0 .5cqw .8cqw #000b; }
.knob .cap {
  position: absolute; inset: 6%; border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #6b6d70 0 52%, transparent 53%),
    radial-gradient(circle at 38% 30%, #9a9ca0, #4d4f52 60%, #2c2d2f),
    repeating-conic-gradient(#1b1c1d 0 6deg, #4c4e51 6deg 12deg);
  box-shadow: inset 0 .15cqw .2cqw #ffffff40, inset 0 -.2cqw .3cqw #0009;
  transition: transform 60ms linear;
}
.knob .cap::before {
  content: ""; position: absolute; inset: 22%; border-radius: 50%;
  background: radial-gradient(circle at 40% 32%, #8c8e92, #55575a 55%, #3d3f42);
  box-shadow: 0 .05cqw .15cqw #0008;
}
.knob .mark {
  position: absolute; left: 46%; top: 10%; width: 8%; height: 22%; border-radius: 1cqw;
  background: #f1f1ee; box-shadow: 0 0 .2cqw #fff6;
}

/* Buttons and key pads; --led (0..1) is the LED under them. */
.ctl {
  --led: 0; --led-rgb: 255 246 222;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0; border: 0; cursor: pointer; color: var(--print);
  font: 700 1.25cqw/1.05 "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  letter-spacing: .06cqw; white-space: pre-line; text-align: center;
  transition: transform 40ms, box-shadow 40ms, filter 40ms;
}
.ctl[data-led="green"] { --led-rgb: 120 255 140; }
.ctl[data-led="red"] { --led-rgb: 255 90 80; }
.ctl::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(closest-side, rgb(var(--led-rgb) / .55), rgb(var(--led-rgb) / .12) 75%, transparent);
  opacity: var(--led); mix-blend-mode: screen;
}
.ctl .legend { position: relative; z-index: 1; pointer-events: none; }
.btn {
  border-radius: 1cqw;
  background: linear-gradient(180deg, #50565a, #3c4144);
  box-shadow: 0 .45cqw 0 #1b1d1f, 0 .55cqw .8cqw #000a, inset 0 .1cqw 0 #ffffff2e;
  text-shadow: 0 0 calc(var(--led) * 1cqw) rgb(var(--led-rgb) / .9);
}
.btn .legend { color: color-mix(in srgb, var(--print), rgb(var(--led-rgb)) calc(var(--led) * 100%)); }
.btn.oct { border-radius: .8cqw; font-size: 1.15cqw; }
.ctl:hover { filter: brightness(1.12); }
.btn.down {
  transform: translateY(.35cqw);
  box-shadow: 0 .1cqw 0 #1b1d1f, 0 .2cqw .3cqw #000a, inset 0 .1cqw 0 #ffffff1a;
}
.pad {
  border-radius: 999px;
  background: linear-gradient(180deg, #685a58, #574b49);
  box-shadow:
    0 0 0 .22cqw #2a2324, 0 .45cqw .2cqw #120e0e, 0 .6cqw .8cqw #000a,
    inset 0 .15cqw .1cqw #ffffff22, inset 0 -.3cqw .4cqw #0005;
  justify-content: flex-start; padding-top: 1.7cqw;
  gap: .9cqw;
}
.pad .groove {
  width: .5cqw; height: 3.4cqw; border-radius: 1cqw; flex: none;
  background: linear-gradient(90deg, #4a3f3e, #9b8f8c 50%, #4a3f3e);
  box-shadow: inset 0 .1cqw .15cqw #0006;
  position: relative; z-index: 1;
}
.pad.upper .groove { height: 3cqw; }
.pad:not(.upper) { padding-top: 2.6cqw; }
.pad .legend { font-size: .95cqw; font-weight: 600; opacity: .7; }
.pad.down {
  transform: translateY(.3cqw);
  background: linear-gradient(180deg, #5f5250, #504543);
  box-shadow:
    0 0 0 .22cqw #2a2324, 0 .15cqw .1cqw #120e0e, 0 .25cqw .4cqw #000a,
    inset 0 .3cqw .5cqw #0006;
}

.info { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.state {
  padding: 10px 12px; border-radius: 8px; background: var(--panel); border-left: 4px solid var(--muted);
  overflow-wrap: anywhere;
}
.state.running { border-color: var(--ok); }
.state.fault { border-color: var(--danger); color: #ffd5d1; }
.state.paused { border-color: var(--accent); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.stats div { background: var(--panel); border-radius: 8px; padding: 8px 10px; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; font-weight: 600; }
details { background: var(--panel); border-radius: 8px; padding: 8px 12px; }
summary { cursor: pointer; font-weight: 600; }
.help ul { padding-left: 18px; margin: 6px 0; }
.note { color: var(--muted); font-size: 13px; }
kbd {
  background: #1a1c20; border: 1px solid #444; border-bottom-width: 2px; border-radius: 4px;
  padding: 0 4px; font-size: 12px;
}
#serial {
  max-height: 260px; overflow: auto; background: #0e0f11; padding: 8px; border-radius: 6px;
  font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; margin: 8px 0;
}
#serial-input {
  width: 100%; background: #0e0f11; color: var(--text); border: 1px solid #3a3e45;
  border-radius: 6px; padding: 6px 8px; font: 13px ui-monospace, monospace;
}
footer { color: var(--muted); font-size: 13px; text-align: center; padding: 8px 16px 24px; }
select.primary { background: var(--accent); color: #1b1b1b; border-color: var(--accent); font-weight: 600; }
select.primary option, select.primary optgroup { background: var(--panel); color: var(--text); }
.about {
  padding: 10px 12px; border-radius: 8px; background: var(--panel); font-size: 14px; color: var(--text);
}
.about small { color: var(--muted); }
.about-error { margin: 0 0 8px; color: #ffd5d1; }
.firmware-card { background: var(--panel); border-radius: 8px; padding: 10px 12px; }
.firmware-card h2 { margin: 0 0 8px; font-size: 15px; }
.firmware-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.fw {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  background: #1a1c20; color: var(--text); border: 1px solid #3a3e45; border-radius: 8px;
  padding: 8px 10px; font: inherit; cursor: pointer; min-height: 48px;
}
.fw span { font-weight: 600; }
.fw small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.fw:hover { border-color: #5a606a; }
.fw.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.fw.own { border-style: dashed; }
@media (max-width: 600px) {
  .bar { padding: 10px 12px; }
  .actions { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  .actions #firmware { grid-column: 1 / -1; }
  .actions label.button { display: none; }   /* own files: in the firmware card */
  .actions .button, .actions select { padding: 8px 6px; text-align: center; }
}
.engine { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.engine-warn { color: #ffd5d1; }
