:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5b6270;
  --line: #e1e4ea;
  --accent: #d92d20;
  --accent-ink: #ffffff;
  --soft: #f1f2f5;
  --ok: #1a7f37;
  --warn-bg: #fff6e5;
  --warn-line: #f0c36b;
  --code: #eef0f4;
  --led-off: #3a1614;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101216; --card: #181b21; --text: #e8eaee; --muted: #9aa1ad; --line: #2a2f38;
    --accent: #ff4d3d; --soft: #20242c; --ok: #4ac26b; --warn-bg: #2b2414; --warn-line: #7a5d1e;
    --code: #232730; --led-off: #2a1210;
  }
}
:root[data-theme="dark"] {
  --bg: #101216; --card: #181b21; --text: #e8eaee; --muted: #9aa1ad; --line: #2a2f38;
  --accent: #ff4d3d; --soft: #20242c; --ok: #4ac26b; --warn-bg: #2b2414; --warn-line: #7a5d1e;
  --code: #232730; --led-off: #2a1210;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
code { background: var(--code); padding: 0.05em 0.35em; border-radius: 4px; font-size: 0.9em; }
.wrap { max-width: 900px; margin: 0 auto; padding: 0 16px; }

header { padding-top: 28px; padding-bottom: 8px; }
.brand { display: flex; gap: 16px; align-items: flex-start; }
.dot {
  flex: none; width: 44px; height: 44px; border-radius: 50%; margin-top: 4px;
  background: radial-gradient(circle at 50% 50%, var(--accent) 0 30%, #111 32%);
  box-shadow: 0 0 0 3px var(--line);
}
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
h1 span { color: var(--muted); font-weight: 500; }
.lead { margin: 4px 0 0; color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; margin: 16px 0;
}
h2 { margin: 0 0 14px; font-size: 1.15rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 small { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.num {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 0.9rem;
}

.fw-select, .presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.fw-select label {
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; cursor: pointer; background: var(--soft);
}
.fw-select label:has(input:checked) { border-color: var(--accent); }
.fw-select small { color: var(--muted); }
.presets button {
  font: inherit; font-size: 0.85rem; border: 1px solid var(--line); background: transparent; color: var(--text);
  border-radius: 999px; padding: 4px 12px; cursor: pointer;
}
.presets button:hover { border-color: var(--accent); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 600; font-size: 0.9rem; }
.field small { color: var(--muted); font-size: 0.8rem; }
.in { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.in:focus-within { border-color: var(--accent); }
.in input, .in select {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: transparent; border: 0; padding: 8px 10px; outline: none;
}
.in select option { background: var(--card); color: var(--text); }
.in em { font-style: normal; color: var(--muted); padding-right: 10px; }
#cfgArea.disabled { opacity: 0.45; pointer-events: none; }

details.adv { margin-top: 14px; }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; }
details[open] summary { margin-bottom: 12px; }

.preview {
  display: flex; gap: 18px; align-items: center; margin-top: 18px; padding: 14px;
  background: var(--soft); border-radius: 12px;
}
.led-box { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); }
.led {
  width: 46px; height: 46px; border-radius: 50%; background: var(--led-off);
  box-shadow: inset 0 -4px 8px rgba(0, 0, 0, 0.4);
}
.led.on { background: #ff3b30; box-shadow: 0 0 24px 8px rgba(255, 59, 48, 0.75), inset 0 -3px 6px rgba(0, 0, 0, 0.2); }
.preview-main { flex: 1; min-width: 0; }
#timeline { width: 100%; height: 70px; display: block; }
#timeline .axis { stroke: var(--line); stroke-width: 1; }
#timeline .pulse { fill: var(--accent); }
#timeline text { fill: var(--muted); font-size: 11px; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.85rem; color: var(--muted); }
.stats b { color: var(--text); }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  border-radius: 10px; padding: 9px 18px; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.filename { font-family: ui-monospace, monospace; color: var(--muted); font-size: 0.85rem; word-break: break-all; }
.muted { color: var(--muted); }
.cmd { display: flex; gap: 8px; align-items: flex-start; background: var(--code); border-radius: 8px; padding: 10px; }
.cmd code { flex: 1; min-width: 0; background: none; padding: 0; white-space: pre-wrap; word-break: break-all; font-size: 0.8rem; }
.copy { font: inherit; font-size: 0.8rem; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 6px; padding: 2px 10px; cursor: pointer; }

.prog-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; margin-bottom: 14px; }
.prog { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.prog:has(input:checked) { border-color: var(--accent); background: var(--soft); }
.prog input { margin-top: 4px; }
.prog small { color: var(--muted); }
.tag { font-style: normal; font-size: 0.7rem; border-radius: 999px; padding: 1px 8px; border: 1px solid var(--line); color: var(--muted); }
.tag.ok { border-color: var(--ok); color: var(--ok); }
.conn { margin-bottom: 4px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; }
.device { font-size: 0.9rem; padding: 8px 12px; border-radius: 8px; background: var(--soft); }
.device.found { border-left: 3px solid var(--ok); }
.warn, .notice { margin: 12px 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); border: 1px solid var(--warn-line); font-size: 0.9rem; }
.actions { margin-top: 16px; }

.progress { height: 6px; background: var(--soft); border-radius: 3px; overflow: hidden; margin: 12px 0 8px; }
#bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
#bar.done { background: var(--ok); }
.log {
  margin: 0; min-height: 4.5em; max-height: 260px; overflow: auto; background: var(--code); border-radius: 8px;
  padding: 10px; font-size: 0.8rem; white-space: pre-wrap; word-break: break-word;
}
.log .err { color: var(--accent); font-weight: 600; }
.log .ok { color: var(--ok); font-weight: 600; }

.help details { margin: 8px 0; }
.help p, .help ul { margin: 6px 0; }
footer { padding-bottom: 32px; font-size: 0.85rem; }

@media (max-width: 560px) {
  .preview { flex-direction: column; align-items: stretch; }
  .led-box { flex-direction: row; justify-content: center; }
  h1 { font-size: 1.3rem; }
}
