:root {
  --bg: #0b0b12; --card: #151520; --card2: #1c1c2a; --line: #2a2a3c; --text: #ececf4; --muted: #9a9ab0;
  --accent: #00c8ff; --accent2: #ff4fa3; --ok: #2fd26b; --warn: #ffb020; --bad: #ff4d5e;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding: env(safe-area-inset-top) 0 calc(24px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
code { background: var(--card2); padding: 1px 5px; border-radius: 5px; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; }
.brand { font-weight: 700; font-size: 1.25rem; display: flex; align-items: center; gap: 10px; letter-spacing: .3px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px #ffffff10; }
.dot.ok { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.pill { border: 1px solid var(--line); background: var(--card2); border-radius: 999px; padding: 6px 16px; font-weight: 600; cursor: pointer; }
.pill[aria-pressed="true"] { background: var(--ok); color: #04140a; border-color: transparent; }

.screen { padding: 4px 16px 10px; }
.led-wrap { position: relative; background: #050507; border-radius: var(--radius); padding: 10px; border: 1px solid #1e1e2a;
  box-shadow: inset 0 0 30px #000, 0 10px 30px #0008; }
#led { width: 100%; height: auto; display: block; image-rendering: pixelated; }
.led-tag { position: absolute; top: 6px; right: 10px; font-size: .72rem; background: var(--accent2); color: #fff; padding: 1px 8px; border-radius: 999px; }
.nowline { display: flex; justify-content: space-between; align-items: center; margin: 8px 2px 6px; gap: 8px; }
.banner { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center;
  background: #2a1730; border: 1px solid #5a2a5e; border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; font-size: .92rem; }
.slider { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.slider input { flex: 1; accent-color: var(--accent); }

.tabs { display: flex; gap: 4px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; position: sticky; top: 0;
  background: var(--bg); z-index: 5; padding-top: 6px; padding-bottom: 6px; }
.tabs button { flex: 1 0 auto; background: none; border: none; color: var(--muted); padding: 9px 12px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.tabs button.active { background: var(--card2); color: var(--text); }

main { padding: 0 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 8px; }
.card h3 { margin: 20px 0 8px; font-size: 1rem; }
.card h3:first-child { margin-top: 0; }

textarea, input:not([type]), input[type=text], input[type=number], input[type=time], select {
  width: 100%; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
textarea { resize: vertical; font-size: 1.1rem; }
input.num { width: 90px; }
input[type=color] { width: 44px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--card2); padding: 2px; }
.row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; }
.row > select, .row > input:not([type=checkbox]):not([type=color]) { flex: 1; }
.label { width: 78px; flex: 0 0 78px; color: var(--muted); font-size: .9rem; }
.check { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: .88rem; }
.chip:hover { border-color: var(--accent); }

.swatches { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; background: var(--c); cursor: pointer; box-shadow: 0 0 8px var(--c); }
.sw.on { border-color: #fff; transform: scale(1.12); }
.sw.rainbow { background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); box-shadow: none; }

.seg { display: inline-flex; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: none; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: .9rem; }
.seg button.on { background: var(--accent); color: #001018; }

.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
button.primary { background: var(--accent); color: #001018; border: none; border-radius: 10px; padding: 11px 18px; font-weight: 700; cursor: pointer; }
button.ghost { background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; cursor: pointer; }
button.small { padding: 6px 12px; font-size: .88rem; }
button:disabled { opacity: .5; cursor: default; }
.hint { min-height: 1.2em; margin: 10px 0 0; }

.rit-wrap { background: #050507; border-radius: 10px; padding: 6px; touch-action: none; }
#rit { width: 100%; height: auto; display: block; cursor: crosshair; touch-action: none; }

.upload .row { margin-top: 10px; }
.filknapp { display: block; border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; cursor: pointer; color: var(--muted); }
.filknapp input { display: none; }
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.libitem { background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.libitem canvas { width: 100%; image-rendering: pixelated; background: #000; border-radius: 6px; }
.libitem .namn { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.libitem .knappar { display: flex; gap: 4px; }
.libitem .knappar button { flex: 1; padding: 5px 4px; font-size: .8rem; }

.list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 6px; }
.list li { display: flex; align-items: center; gap: 8px; background: var(--card2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.list li .namn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li input.num { width: 64px; padding: 6px 8px; }
.list li button { background: none; border: none; cursor: pointer; padding: 4px 6px; font-size: 1rem; color: var(--muted); }
.list li.off .namn { color: var(--muted); text-decoration: line-through; }
.list.compact li input { padding: 6px 8px; }
.switch { position: relative; width: 40px; height: 24px; flex: 0 0 40px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #3a3a50; border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(16px); }

.deps { list-style: none; padding: 0; margin: 8px 0; font-size: .9rem; }
.deps li { display: flex; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.badge { display: inline-block; min-width: 30px; text-align: center; border-radius: 5px; padding: 0 5px; font-weight: 700; font-size: .8rem; }
.deps .min { margin-left: auto; font-weight: 700; }
.ok-text { color: var(--ok); } .bad-text { color: var(--bad); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #23233a; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; box-shadow: 0 8px 30px #000a; z-index: 20; max-width: 90vw; }
.toast.fel { border-color: var(--bad); }

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; display: flex; align-items: center; gap: 10px; }
.logo-dots { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.fel { color: var(--bad); margin: 0; }

@media (max-width: 420px) {
  .label { width: 64px; flex-basis: 64px; }
  .seg button { padding: 6px 9px; }
}
