:root {
  --slate-900: #171a21;
  --slate-800: #1f232c;
  --slate-700: #282d38;
  --slate-600: #353b48;
  --ink: #dde2ea;
  --ink-dim: #8e97a6;
  --signal: #5aa9e6;
  --tally: #e5484d;
  --warn: #e2b93b;
  --ok: #3fb67a;
  --font: "IBM Plex Sans", system-ui, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--slate-900); }
body {
  margin: 0; color: var(--ink); font: 15px/1.4 var(--font);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--slate-800); border-bottom: 1px solid var(--slate-600);
}
.nav { margin-left: auto; display: flex; gap: 12px; font-size: 14px; }
.nav a { color: var(--ink-dim); text-decoration: none; }
.nav a:hover { color: var(--ink); }
[hidden] { display: none !important; }
.conn { font-size: 13px; color: var(--ink-dim); display: flex; align-items: center; gap: 7px; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--slate-600); }
.conn.ok::before { background: var(--ok); }
.conn.warn { color: var(--warn); }
.conn.warn::before { background: var(--warn); }

main { max-width: 900px; margin: 0 auto; padding: 14px 14px 40px; display: flex; flex-direction: column; gap: 22px; }
h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--ink-dim); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-head h2 { margin: 0; }

/* ---------- Live ---------- */
.live { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.live-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 16px; min-height: 84px; border-radius: 8px;
  background: var(--slate-800); border: 1px solid var(--slate-600); cursor: pointer; text-align: left;
}
.lb-title { font-size: 18px; font-weight: 600; }
.lb-sub { font-size: 14px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.live-btn.on { background: var(--tally); border-color: var(--tally); }
.live-btn.on .lb-sub { color: #fff; }
.live-btn:disabled { opacity: .45; cursor: default; }

/* ---------- Kacheln ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.tile {
  position: relative; min-height: 66px; padding: 12px;
  border-radius: 6px; border: 1px solid var(--slate-600);
  background: var(--slate-800); cursor: pointer;
  font-weight: 500; text-align: left; overflow-wrap: anywhere;
}
.tile:active { transform: scale(.98); }
.tile:disabled { opacity: .45; cursor: default; transform: none; }
.scenes .tile.current { background: rgba(90, 169, 230, .2); border-color: var(--signal); box-shadow: inset 0 0 0 1px var(--signal); }
.buttons .tile { border: 0; }
.tile.busy { opacity: .6; }
.tile.flash-ok { box-shadow: 0 0 0 2px var(--ok); }
.tile.flash-err { box-shadow: 0 0 0 2px var(--tally); }
.tile.add { border: 1px dashed var(--slate-600); background: none; color: var(--ink-dim); text-align: center; }
.tile .move { position: absolute; bottom: 6px; right: 6px; display: flex; gap: 4px; }
.tile .move span { padding: 0 7px; border-radius: 3px; background: rgba(0,0,0,.3); }
.empty { color: var(--ink-dim); font-size: 14px; margin: 0; }

/* ---------- Zeilen ---------- */
.rows { display: flex; flex-direction: column; border: 1px solid var(--slate-600); border-radius: 6px; overflow: hidden; }
.rows:empty { display: none; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; background: var(--slate-800); }
.row + .row { border-top: 1px solid var(--slate-700); }
.row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .kind { color: var(--ink-dim); font-size: 13px; }

.switch {
  width: 46px; height: 28px; border-radius: 14px; padding: 0; flex: none;
  background: var(--slate-600); border: 0; position: relative; cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .15s;
}
.switch.on { background: var(--signal); }
.switch.live.on { background: var(--tally); }
.switch.on::after { transform: translateX(18px); }
.mute-btn { padding: 6px 12px; border-radius: 4px; border: 1px solid var(--slate-600); background: var(--slate-700); cursor: pointer; }
.mute-btn.muted { background: var(--tally); border-color: var(--tally); color: #fff; }

button.small { padding: 4px 10px; font-size: 13px; border-radius: 4px; border: 1px solid var(--slate-600); background: var(--slate-700); cursor: pointer; }

/* ---------- Editor ---------- */
dialog {
  width: min(560px, 96vw); max-height: 90vh; padding: 18px;
  background: var(--slate-800); color: var(--ink);
  border: 1px solid var(--slate-600); border-radius: 8px;
}
dialog::backdrop { background: rgba(8, 10, 14, .7); }
dialog h3 { margin: 0 0 12px; font-size: 17px; font-weight: 600; }
#editor-body { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--ink-dim); }
input[type=text], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 8px; border-radius: 4px;
  background: var(--slate-900); border: 1px solid var(--slate-600);
}
input[type=color] { width: 52px; height: 36px; padding: 0; border: 1px solid var(--slate-600); background: none; border-radius: 4px; }
.action {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border-radius: 6px; background: var(--slate-700);
}
.action-head { display: flex; gap: 6px; }
.action-head select { flex: 1; }
.action-head button, .dialog-actions button, .add-action {
  padding: 7px 12px; border-radius: 4px; border: 1px solid var(--slate-600); background: var(--slate-700); cursor: pointer;
}
.action-head button { background: var(--slate-800); }
.hint { font-size: 13px; color: var(--ink-dim); margin: 0; }
.copy { display: flex; gap: 6px; }
.copy input { font-size: 12px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.dialog-actions .spacer { flex: 1; }
.dialog-actions .primary { background: var(--signal); border-color: var(--signal); color: #0d1a26; font-weight: 600; }
.dialog-actions .danger { color: var(--tally); }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px); max-width: 92vw;
  padding: 10px 14px; border-radius: 6px;
  background: var(--slate-700); border: 1px solid var(--slate-600);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .live-btn { min-height: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
