:root {
  --bg: #f4f6f7; --punkte: #d5dbe0; --panel: #e9edf0; --panel-rand: #cdd5db; --text: #1d2733; --leise: #66727f;
  --karte: #ffffff; --karte-rand: #34495e; --zahl: #1f77c9; --zahl-hell: #e8f2fc; --ablauf: #222b35;
  --start: #27ae60; --start-hell: #eafaf1; --ende: #c0392b; --ende-hell: #fdedec; --feld: #ffffff; --feld-rand: #b0b8bf;
  --warn: #8a5200; --warn-hell: #fff4e0; --ok: #1e7a3c; --gefahr: #d6453a; --akzent: #1565c0;
}
:root[data-dunkel='1'] {
  --bg: #3c3f44; --punkte: #54585e; --panel: #2b2e32; --panel-rand: #44484e; --text: #e4e7eb; --leise: #a5adb6;
  --karte: #2f3237; --karte-rand: #8fa3b5; --zahl: #6db3f2; --zahl-hell: #263748; --ablauf: #dfe6ec;
  --start: #4cc47e; --start-hell: #24382d; --ende: #ef7a6f; --ende-hell: #402a28; --feld: #1f2124; --feld-rand: #565b62;
  --warn: #f1b45c; --warn-hell: #3a2f1c; --ok: #5fd08a; --gefahr: #ef7a6f; --akzent: #4a8fe2;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", system-ui, sans-serif; overflow: hidden; background: var(--bg); color: var(--text); }
#haupt { display: flex; height: 100vh; }

/* Kästchen-Liste links */
#palette { flex: 0 0 214px; background: var(--panel); border-right: 1px solid var(--panel-rand); padding: 12px 10px; overflow-y: auto; }
#palette h3 { margin: 4px 2px 8px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--leise); display: flex; align-items: center; gap: 8px; }
#palette h3::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--ablauf); }
#palette h3.zahl::before { background: var(--zahl); }
#palette h3.signal::before { background: radial-gradient(circle, var(--panel) 0 2px, var(--ablauf) 2.5px); }
#palette .gruppe + h3 { margin-top: 18px; }
.eintrag { display: block; width: 100%; text-align: left; margin: 0 0 8px; padding: 10px 12px; font: inherit; font-size: 15px; font-weight: 600; color: var(--text); background: var(--karte); border: 2px solid var(--karte-rand); border-radius: 8px; cursor: grab; }
.eintrag.zahl { border-color: var(--zahl); color: var(--zahl); }
.eintrag.signal { border-style: dashed; }
.eintrag:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,.18); }
.eintrag:focus-visible { outline: 3px solid var(--akzent); outline-offset: 1px; }
.tipp { margin: 14px 2px 0; font-size: 13px; color: var(--leise); line-height: 1.45; }

/* Fläche */
#flaeche { flex: 1; min-width: 0; position: relative; overflow: auto; outline: none; background: var(--bg); }
#blatt { position: relative; width: 2400px; height: 1800px; background-image: radial-gradient(var(--punkte) 1.2px, transparent 1.2px); background-size: 20px 20px; }
#drahtnetz { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; overflow: visible; pointer-events: none; }
#hinweis { position: sticky; bottom: 10px; left: 10px; float: left; margin: 0 0 0 10px; transform: translateY(-10px); z-index: 30; max-width: 70%; padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; background: var(--karte); border: 1px solid var(--panel-rand); box-shadow: 0 2px 8px rgba(0,0,0,.18); pointer-events: none; }
#hinweis.warn { background: var(--warn-hell); color: var(--warn); border-color: var(--warn); }
#hinweis.ok { color: var(--ok); }
#hinweis:empty { display: none; }

/* Kästchen auf der Fläche */
.knoten { position: absolute; z-index: 2; width: 184px; min-height: 84px; padding: 24px 12px 28px; text-align: center; background: var(--karte); border: 3px solid var(--karte-rand); border-radius: 10px; box-shadow: 2px 4px 10px rgba(0,0,0,.14); user-select: none; cursor: grab; }
.knoten.zahlkn { border-color: var(--zahl); }
.knoten.gewaehlt { box-shadow: 0 0 0 3px var(--akzent), 2px 4px 10px rgba(0,0,0,.2); }
.knoten.start { border-color: var(--start); background: var(--start-hell); width: 150px; min-height: 60px; padding: 14px 10px 16px; }
.knoten.ende { border-color: var(--ende); background: var(--ende-hell); width: 150px; min-height: 60px; padding: 18px 10px 12px; }
.titel { font-weight: 700; font-size: 16px; pointer-events: none; }
.zahlkn .titel { color: var(--zahl); }
/* UND / ODER: Viereck, das Wort groß in der Mitte */
.knoten.logikkn { width: 150px; min-height: 104px; padding: 22px 10px 26px; }
.logikkn .titel { font-size: 26px; letter-spacing: .06em; margin-top: 4px; }
.knoten.start .titel { color: var(--start); font-size: 18px; }
.knoten.ende .titel { color: var(--ende); font-size: 17px; }
.untertitel { margin-top: 2px; font-size: 12px; color: var(--leise); pointer-events: none; }
.knoten select, .knoten input { display: block; width: 100%; margin-top: 8px; padding: 5px 4px; font: inherit; font-size: 14px; font-weight: 600; text-align: center; color: var(--text); background: var(--feld); border: 1px solid var(--feld-rand); border-radius: 5px; cursor: auto; }
.knoten label { display: block; margin-top: 6px; font-size: 12px; color: var(--leise); pointer-events: none; }
.weg { position: absolute; top: 3px; right: 4px; width: 22px; height: 22px; padding: 0; border: none; border-radius: 50%; background: transparent; color: var(--leise); font-size: 15px; line-height: 20px; cursor: pointer; }
.weg:hover { background: var(--gefahr); color: #fff; }

/* Anschlüsse */
.port { position: absolute; width: 18px; height: 18px; border: 3px solid var(--karte); border-radius: 50%; z-index: 5; cursor: crosshair; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.port.ablauf { background: var(--ablauf); }
.port.zahl { background: var(--zahl); }
.port.signal { background: radial-gradient(circle, var(--karte) 0 3px, var(--ablauf) 3.5px); }
.port:hover, .port.ziel { transform: scale(1.35) translateX(var(--tx, 0)); box-shadow: 0 0 0 3px var(--akzent); }
.port.o-mitte, .port.u-mitte { left: 50%; --tx: -37%; margin-left: -9px; }
.port.o-links, .port.u-links { left: 24%; margin-left: -9px; }
.port.o-rechts, .port.u-rechts { left: 76%; margin-left: -9px; }
.port.o-mitte, .port.o-links, .port.o-rechts { top: -11px; }
.port.u-mitte, .port.u-links, .port.u-rechts { bottom: -11px; }
.plabel { position: absolute; font-size: 11px; font-weight: 600; color: var(--leise); pointer-events: none; }
.plabel.o-links, .plabel.o-mitte, .plabel.o-rechts { top: 9px; }
.plabel.u-links, .plabel.u-mitte, .plabel.u-rechts { bottom: 8px; }
.plabel.o-links, .plabel.u-links { left: 24%; transform: translateX(-50%); }
.plabel.o-mitte, .plabel.u-mitte { left: 50%; transform: translateX(-50%); }
.plabel.o-rechts, .plabel.u-rechts { left: 76%; transform: translateX(-50%); }
.plabel.zahl { color: var(--zahl); }

/* Linien */
path.draht { fill: none; stroke-width: 4; pointer-events: stroke; cursor: pointer; }
path.draht.ablauf { stroke: var(--ablauf); }
path.draht.zahl { stroke: var(--zahl); stroke-dasharray: 7 5; }
path.draht.signal { stroke: var(--ablauf); stroke-dasharray: 0.1 8; stroke-linecap: round; stroke-width: 5; }
path.draht:hover { stroke: var(--gefahr); stroke-width: 6; }
path.draht.vorlaeufig { stroke: #f39c12; stroke-dasharray: 4 4; pointer-events: none; }

/* Dialoge (wie bei den Blöcken) */
.dlg-huelle { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.dlg-huelle[hidden] { display: none; }
