/* Layout: the device sits like a bench prototype, an instrument rack of settings beside it, the generated sketch below. */
:root {
  --bg: #e8edf1;
  --surface: #f7f9fb;
  --ink: #13202a;
  --muted: #566875;
  --line: #c8d2da;
  --accent: #1d68cf;
  --ok: #1f8a4c;
  --warn: #9a5c00;
  --bad: #c0362c;
  --panel: #06090c;
  --display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e151b; --surface: #16212a; --ink: #e2eaf0; --muted: #8b9daa; --line: #26343f; --accent: #5ea8ff;
    --ok: #4cc37f; --warn: #e3a440; --bad: #ef6d62;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e151b; --surface: #16212a; --ink: #e2eaf0; --muted: #8b9daa; --line: #26343f; --accent: #5ea8ff;
  --ok: #4cc37f; --warn: #e3a440; --bad: #ef6d62;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.55;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 1180px; margin: 0 auto; padding-block: 40px 64px; display: grid; gap: 40px; }
header { display: grid; gap: 10px; max-width: 70ch; }
.eyebrow { margin: 0; font-family: var(--mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
h1 { margin: 0; font-family: var(--display); font-weight: 700; font-size: clamp(34px, 6vw, 56px); line-height: 1; letter-spacing: -.02em; text-wrap: balance; }
h2.section { margin: 0; font-family: var(--display); font-weight: 500; font-size: 26px; letter-spacing: -.01em; text-wrap: balance; }
h3 { margin: 0; font-size: 15px; font-weight: 600; }
.lede { margin: 0; color: var(--muted); font-size: 16px; }
.error { margin: 0; padding: 12px 16px; border: 1px solid var(--bad); border-radius: 8px; color: var(--bad); background: var(--surface); }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .stage { grid-template-columns: 1fr; } }
.left { display: grid; gap: 16px; min-width: 0; }

.device { --ar: 2; background: var(--panel); border-radius: 14px; padding: 14px; display: grid; gap: 10px; box-shadow: 0 18px 40px -24px rgba(0,0,0,.6); }
.device canvas { display: block; width: 100%; max-width: 100%; max-height: 70vh; aspect-ratio: var(--ar); object-fit: contain; touch-action: none; cursor: crosshair; margin: 0 auto; }
.device canvas:focus-visible { outline: 2px solid #5ea8ff; outline-offset: 3px; }
.device-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-family: var(--mono); font-size: 11px; color: #7f8f9b; letter-spacing: .04em; width: 100%; }
.device-foot button { background: #121a21; border-color: #26323c; color: #cfdbe4; font-size: 12px; padding: 6px 10px; }
.device:fullscreen, .device.is-full { border-radius: 0; padding: 16px; align-content: center; justify-items: center; }
.device.is-full { position: fixed; inset: 0; z-index: 50; padding-top: calc(16px + env(safe-area-inset-top, 0px)); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.device:fullscreen canvas, .device.is-full canvas { width: min(100%, calc((100vh - 90px) * var(--ar))); max-height: none; }
.device:fullscreen .device-foot, .device.is-full .device-foot { width: min(100%, calc((100vh - 90px) * var(--ar))); }

.stats { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stats div { background: var(--surface); padding: 10px 14px; display: grid; gap: 2px; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums; }
.chip, .state { display: inline-flex; align-items: center; gap: 6px; font-family: var(--body); font-size: 13px; font-weight: 500; }
.chip::before, .state::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
[data-s="ok"] { color: var(--ok); } [data-s="warn"] { color: var(--warn); } [data-s="bad"] { color: var(--bad); }
.state { margin: 0; align-items: flex-start; overflow-wrap: anywhere; }
.state::before { margin-top: 6px; }

.controls { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; display: grid; }
@media (min-width: 901px) { .controls { position: sticky; top: calc(12px + env(safe-area-inset-top, 0px)); max-height: calc(100vh - 24px); overflow-y: auto; } }
details { border-top: 1px solid var(--line); }
details:first-child { border-top: 0; }
summary { list-style: none; cursor: pointer; padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-weight: 500; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; font-size: 15px; }
details[open] > summary::after { content: "−"; }
summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.body, .stack { display: grid; gap: 13px; }
.body { padding: 0 18px 18px; }
.slider { display: grid; gap: 3px; }
.slider .row, .field { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.slider output { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
select, input[type="number"] { font: 13px var(--body); padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); max-width: 62%; }
input[type="number"] { width: 76px; font-family: var(--mono); }
input[type="color"] { width: 40px; height: 26px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); padding: 2px; cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
button, .file-btn { font: 500 14px var(--body); padding: 7px 13px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
#presets button, #colPresets button { font-size: 12.5px; padding: 5px 9px; }
#colPresets i { display: inline-block; width: 24px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
button:hover, .file-btn:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.sub { margin: 4px 0 -4px; font-size: 12px; color: var(--muted); }

.sketch { display: grid; gap: 16px; }
.sketch-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .sketch-grid { grid-template-columns: 1fr; } }
.code { display: grid; gap: 10px; min-width: 0; }
.code-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#copyState { font-size: 13px; color: var(--muted); }
textarea { width: 100%; height: 420px; resize: vertical; font: 12px/1.5 var(--mono); padding: 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); white-space: pre; overflow: auto; tab-size: 2; }
.howto-wrap { display: grid; gap: 12px; }
.howto { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; counter-reset: s; }
.howto li { counter-increment: s; display: grid; grid-template-columns: 26px 1fr; gap: 8px; font-size: 14px; }
.howto li::before { content: counter(s); font-family: var(--mono); font-size: 12px; color: var(--accent); border: 1px solid var(--line); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.cmd { margin: 0; font: 12.5px/1.6 var(--mono); padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); overflow-x: auto; }
