:root {
  --bg: #1b1712;
  --panel: rgba(30, 26, 21, 0.94);
  --panel-solid: #221d17;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f3eee6;
  --muted: #b3aa9c;
  --accent: #f4c26b;
  --accent-ink: #1b1712;
  --red: #b5482f;
  --danger: #ff6b5b;
  --good: #4cd964;
  --warn: #ffb300;
  --radius: 12px;
  --gap: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }

/* ---------- Anmeldung ---------- */
body.gate { display: grid; place-items: center; overflow: auto; background: radial-gradient(circle at 30% 20%, #3a2a1c, var(--bg) 70%); }
.gate-card { width: min(360px, calc(100vw - 32px)); background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 14px; text-align: center; }
.gate-card h1 { margin: 0; font-size: 22px; }
.gate-card p { margin: 0; color: var(--muted); }
.gate-card label { display: grid; gap: 6px; text-align: left; color: var(--muted); }
.gate-card input { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: #15120e; }
.gate-card button { padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }
.gate-card img { justify-self: center; }
.err { color: var(--danger) !important; }

/* ---------- Bühne ---------- */
#app { position: fixed; inset: 0; }
.stage { position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.stage:active { cursor: grabbing; }
.tool-active .stage { cursor: crosshair; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage .overlay { pointer-events: none; }

/* ---------- Kopfleiste ---------- */
.topbar { position: absolute; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; z-index: 20; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.searchbox { flex: 1; min-width: 0; max-width: 520px; display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 0 14px; height: 44px; backdrop-filter: blur(8px); }
.searchbox .ic { color: var(--muted); }
.search-input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; height: 100%; }
.icon-btn { width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(8px); flex: none; }
.icon-btn:hover { background: #2e271f; }
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn.sm .ic { width: 18px; height: 18px; }
.topbar .icon-btn:first-of-type { margin-left: auto; }

.hud { position: absolute; top: calc(62px + var(--safe-t)); left: 14px; z-index: 10; display: grid; text-shadow: 0 1px 3px #000; pointer-events: none; }
.hud strong { font-size: 16px; }
.hud span { color: #e8e1d6; font-size: 13px; }

/* ---------- Suche ---------- */
.searchpanel { position: absolute; top: calc(60px + var(--safe-t)); left: 10px; width: min(520px, calc(100vw - 20px)); max-height: min(70vh, 560px); overflow: auto; background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); z-index: 30; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.filters { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; background: var(--panel-solid); }
.filters select { flex: 1; min-width: 110px; }
.sp-head { padding: 10px 14px 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.sp-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; }
.sp-item:hover, .sp-item.sel { background: #2b241c; }
.sp-item.hist .ic { color: var(--muted); }
.sp-text { flex: 1; min-width: 0; display: grid; cursor: pointer; }
.sp-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-text small { color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.6); }
.pad { padding: 14px; margin: 0; }
.muted { color: var(--muted); }

/* ---------- Steuerkreuz ---------- */
.dpad { position: absolute; right: 16px; bottom: calc(16px + var(--safe-b)); width: 168px; height: 168px; z-index: 15; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); opacity: .88; touch-action: none; }
.dp { border: 1px solid rgba(255,255,255,.25); background: rgba(20,17,13,.55); color: #fff; display: grid; place-items: center; cursor: pointer; backdrop-filter: blur(6px); touch-action: none; user-select: none; -webkit-user-select: none; }
.dp .ic { width: 28px; height: 28px; }
.dp.on, .dp:active { background: var(--accent); color: var(--accent-ink); }
.dp-forward { grid-area: 1 / 2; border-radius: 14px 14px 4px 4px; }
.dp-left { grid-area: 2 / 1; border-radius: 14px 4px 4px 14px; }
.dp-right { grid-area: 2 / 3; border-radius: 4px 14px 14px 4px; }
.dp-back { grid-area: 3 / 2; border-radius: 4px 4px 14px 14px; }
.dp-center { grid-area: 2 / 2; background: rgba(20,17,13,.35); border-radius: 4px; }
.floorbtns { position: absolute; right: 16px; bottom: calc(196px + var(--safe-b)); z-index: 15; display: grid; gap: 8px; }
.btn.floor { background: rgba(255,193,77,.92); color: var(--accent-ink); }

/* ---------- Minikarte ---------- */
.minimap { position: absolute; left: 12px; bottom: calc(12px + var(--safe-b)); width: 240px; height: 240px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); z-index: 14; display: flex; flex-direction: column; overflow: hidden; backdrop-filter: blur(8px); }
.minimap.big { width: min(480px, calc(100vw - 200px)); height: min(480px, calc(100vh - 140px)); }
.minimap.closed { display: none; }
.mm-head { display: flex; gap: 4px; padding: 6px; align-items: center; border-bottom: 1px solid var(--line); }
.mm-floors { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.mm-floors::-webkit-scrollbar { display: none; }
.mm-head .chip { padding: 3px 8px; font-size: 12px; }
.mm-canvas { flex: 1 1 0; height: 0; width: 100%; min-height: 0; touch-action: none; cursor: pointer; }
.grow { flex: 1; }

/* ---------- Bausteine ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: #2b241c; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #352d23; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 650; }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(255,107,91,.4); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn .ic { width: 18px; height: 18px; }
.chip { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: transparent; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row > input, .row > select { flex: 1; min-width: 0; }
input[type=text], input[type=number], input[type=password], input[type=search]:not(.search-input), select, textarea { background: #15120e; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; }
.form { display: grid; gap: 10px; }
.form label, .field { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.form label > input, .form label > select, .form label > textarea { color: var(--text); font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.switch, .radio { display: flex !important; gap: 10px; align-items: center; color: var(--text) !important; font-size: 14px !important; cursor: pointer; }
.switch input, .radio input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px var(--bg) inset; }
input[type=range] { accent-color: var(--accent); }
h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
code { background: #15120e; padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }

/* ---------- Bottom Sheet ---------- */
.sheet { position: absolute; left: 50%; bottom: 0; transform: translate(-50%, 105%); width: min(560px, 100vw); max-height: 82vh; background: var(--panel-solid); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; z-index: 40; display: flex; flex-direction: column; transition: transform .22s ease; box-shadow: 0 -10px 40px rgba(0,0,0,.5); }
.sheet.open { transform: translate(-50%, 0); }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 8px 18px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 4px 18px calc(18px + var(--safe-b)); overflow: auto; }
.details { display: grid; gap: 10px; }
.details p { margin: 0; }
.list { display: grid; }

/* ---------- Beschriften ---------- */
.editpanel { position: absolute; top: calc(62px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(560px, calc(100vw - 20px)); background: var(--panel); border: 1px solid rgba(244,194,107,.5); border-radius: var(--radius); padding: 10px 14px; z-index: 18; display: grid; gap: 6px; backdrop-filter: blur(8px); }
.editpanel p { margin: 0; }
.editing .hud { display: none; }
.quality.good { color: var(--good); }
.quality.warn { color: var(--warn); }
.quality.reject { color: var(--danger); }
.pickbar { position: absolute; left: 50%; bottom: calc(14px + var(--safe-b)); transform: translateX(-50%); width: min(560px, calc(100vw - 20px)); background: var(--panel-solid); border: 1px solid rgba(255,59,48,.6); border-radius: var(--radius); padding: 12px 14px; z-index: 45; display: grid; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.pick-text { display: grid; }
.pick-text span { color: var(--muted); font-size: 13px; }
.pickbar .row { justify-content: flex-end; }

/* ---------- Aufbau ---------- */
.side { position: absolute; top: 0; right: 0; bottom: 0; width: min(420px, 100vw); background: var(--panel-solid); border-left: 1px solid var(--line); z-index: 35; display: flex; flex-direction: column; }
.setup-open .dpad, .setup-open .floorbtns { right: calc(min(420px, 100vw) + 16px); }
.setup-open .topbar { right: calc(min(420px, 100vw) + 10px); }
.side-head { display: flex; align-items: center; padding: 12px 12px 6px 18px; }
.side-head h2 { flex: 1; margin: 0; font-size: 18px; }
.tabs { display: flex; gap: 4px; padding: 0 10px 8px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tab { padding: 7px 12px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.on { background: #2e271f; color: var(--text); }
.side-body { padding: 12px 16px 24px; overflow: auto; flex: 1; }
.drop { border: 2px dashed rgba(244,194,107,.5); border-radius: var(--radius); padding: 22px; display: grid; justify-items: center; gap: 6px; text-align: center; cursor: pointer; }
.drop.over { background: rgba(244,194,107,.08); }
.drop .ic { width: 30px; height: 30px; color: var(--accent); }
.drop small { color: var(--muted); }
.uplist, .nodelist, .edgelist { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.uplist li { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 6px 8px; border-radius: 8px; background: #1a1611; }
.uplist li small { color: var(--muted); text-align: right; }
.uplist li.ok small { color: var(--good); }
.uplist li.err small { color: var(--danger); }
.uplist li.run small { color: var(--accent); }
.nodelist li { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 8px; background: #1a1611; }
.nodelist img { border-radius: 6px; object-fit: cover; background: #000; }
.nodelist li div { display: grid; min-width: 0; }
.nodelist small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edgelist li { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 8px; background: #1a1611; font-size: 14px; }

/* ---------- Meldungen ---------- */
.toast { position: fixed; left: 50%; top: calc(66px + var(--safe-t)); transform: translate(-50%, -10px); opacity: 0; pointer-events: none; transition: .2s ease; z-index: 60; background: #f3eee6; color: #1b1712; border-radius: 10px; padding: 10px 16px; max-width: min(560px, calc(100vw - 24px)); box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.snacks { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(200px + var(--safe-b)); z-index: 60; display: grid; gap: 8px; justify-items: center; pointer-events: none; width: min(560px, calc(100vw - 24px)); }
.snackbar { background: #f3eee6; color: #1b1712; border-radius: 10px; padding: 10px 16px; box-shadow: 0 8px 30px rgba(0,0,0,.4); display: flex; gap: 12px; align-items: center; opacity: 0; transform: translateY(16px); transition: .2s ease; pointer-events: auto; }
.snackbar.show { opacity: 1; transform: none; }
.snackbar .btn { color: var(--red); font-weight: 700; border: 0; padding: 4px 6px; }
.dlg { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(380px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.55); }
.fatal, .empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; z-index: 5; }
.empty { pointer-events: none; }
.empty-card { pointer-events: auto; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; padding: 24px; max-width: 420px; display: grid; gap: 12px; justify-items: center; }
.empty-card h2, .empty-card p { margin: 0; }
.empty-card p { color: var(--muted); }

/* ---------- Handy ---------- */
@media (max-width: 640px) {
  .topbar { gap: 6px; }
  .icon-btn { width: 38px; height: 38px; }
  .searchbox { height: 38px; padding: 0 10px; }
  .topbar { left: 8px; right: 8px; gap: 5px; }
  .dpad { width: 144px; height: 144px; right: 12px; }
  .floorbtns { bottom: calc(166px + var(--safe-b)); right: 12px; }
  .minimap { width: 150px; height: 170px; }
  .minimap.big { width: calc(100vw - 24px); height: 60vh; z-index: 36; }
  .setup-open .dpad, .setup-open .floorbtns, .setup-open .topbar { right: 12px; }
  .side { top: auto; height: 62vh; width: 100vw; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; }
  .setup-open .minimap, .setup-open .dpad, .setup-open .floorbtns { display: none; }
  .snacks { bottom: calc(170px + var(--safe-b)); }
  .grid3 { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
}
@media (pointer: fine) {
  .dpad { opacity: .7; }
  .dpad:hover { opacity: .95; }
}
