/* Flussdiagramm: Blockeditor, Diagramm und Ausführung.
   Eigenständig: Farben und Grundstile wie auf unold.info, hell/dunkel nach Systemeinstellung. */

/* ---------- Grundlage ---------- */
:root {
  color-scheme: light dark;
  --hg:        #f3f2ee;   /* Hintergrund */
  --flaeche:   #e8e6e0;   /* Blöcke, Kästen */
  --linie:     #c9c6bd;
  --text:      #24262a;
  --leise:     #5f6066;
  --akzent:    #b4530f;
  --akzent-hg: #f6dcc6;
  --ok:        #3c7a3a;
  --schrift: ui-monospace, "Cascadia Code", "JetBrains Mono", "SFMono-Regular",
             Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --hg:        #1b1d20;
    --flaeche:   #24272b;
    --linie:     #3a3e44;
    --text:      #d9d6cd;
    --leise:     #9a9890;
    --akzent:    #f0913f;
    --akzent-hg: #3a2a1c;
    --ok:        #8cc47f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--hg);
  color: var(--text);
  font-family: var(--schrift);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
:focus-visible { outline: 2px solid var(--akzent); outline-offset: 3px; }

.huelle { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
main { flex: 1; padding: 32px 0 64px; }

h1, h2 { line-height: 1.3; margin: 0 0 12px; }
h1 { font-size: 1.9rem; }
p { margin: 0 0 14px; }
.leise { color: var(--leise); }

/* Befehlszeile als Abschnittsüberschrift */
.befehl { color: var(--leise); margin: 0 0 6px; }
.befehl::before { content: "$ "; color: var(--akzent); font-weight: 700; }
h2.befehl {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--linie);
}

@media (max-width: 600px) { main { padding-top: 24px; } }

/* ---------- Seite ---------- */

.fd-raster {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  margin-top: 28px;
}
.fd-lauf { margin-top: 40px; }

/* ---------- Bausteine ---------- */
.fd-baukasten {
  display: grid;
  grid-template-columns: 10.5rem minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.fd-palette { display: flex; flex-direction: column; gap: 6px; }

.art-bewegung   { --farbe: var(--akzent); }
.art-faerben    { --farbe: var(--ok); }
.art-kontrolle  { --farbe: var(--leise); }

.fd-baustein {
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  color: var(--text);
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-left: 4px solid var(--farbe);
  border-radius: 4px;
  padding: 5px 8px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.fd-baustein:hover { border-color: var(--farbe); }

.fd-programm {
  min-height: 220px;
  padding: 8px 10px 10px;
  border: 1px solid var(--linie);
  border-radius: 6px;
  background: var(--hg);
  font-size: 0.88rem;
}
.fd-programm::before { content: "▶ Start"; display: block; color: var(--leise); font-size: 0.8rem; }

.block {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-left: 4px solid var(--farbe);
  border-radius: 4px;
}
.kopfzeile {
  display: flex;
  align-items: center;
  gap: 4px 6px;
  white-space: nowrap;
  min-height: 32px;
  padding: 2px 4px 2px 2px;
  border-radius: 3px;
}
.kopfzeile.zwischen { min-height: 24px; padding-left: 26px; color: var(--leise); }
.innen {
  margin: 0 4px 0 12px;
  padding: 0 4px 0 6px;
  background: var(--hg);
  border-radius: 3px;
}
.abschluss { height: 8px; }

.block.aktiv > .kopfzeile:first-child {
  background: var(--akzent-hg);
  box-shadow: inset 0 0 0 1px var(--akzent);
}
.block.gezogen { opacity: 0.35; }

.griff {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  color: var(--leise);
  padding: 2px 4px;
}
.weg {
  margin-left: auto;
  font: inherit;
  color: var(--leise);
  background: none;
  border: 0;
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
}
.weg:hover { color: var(--akzent); }

.kopfzeile select, .kopfzeile input {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--hg);
  border: 1px solid var(--linie);
  border-radius: 3px;
  padding: 1px 2px;
}
.kopfzeile select { min-width: 4.5em; flex: 0 1 auto; text-overflow: ellipsis; }
.kopfzeile input { width: 3.6em; flex: none; }

/* Einfügestellen zwischen den Blöcken */
.stelle {
  position: relative;
  height: 8px;
  margin: 1px 0;
  border-radius: 3px;
  cursor: pointer;
}
.stelle:hover { background: var(--linie); }
.stelle.leer {
  height: auto;
  margin: 4px 0;
  padding: 1px 8px;
  font-size: 0.78rem;
  color: var(--leise);
  border: 1px dashed var(--linie);
}
.stelle.hier:not(.leer) {
  height: 12px;
  background: linear-gradient(var(--akzent), var(--akzent)) no-repeat 14px 50% / calc(100% - 14px) 2px;
}
.stelle.hier:not(.leer)::before {
  content: "▸";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-52%);
  font-size: 16px;
  line-height: 1;
  color: var(--akzent);
}
@media (pointer: coarse) { .stelle.hier:not(.leer) { height: 14px; } }
.stelle.leer.hier { border-color: var(--akzent); color: var(--akzent); }
.stelle.leer.hier::before { content: "▸ "; }
.stelle.ziel, .stelle.ziel:hover { background: var(--akzent); }
.stelle.leer.ziel { color: var(--hg); }
@media (pointer: coarse) { .stelle { height: 14px; } }

.fd-hinweis { font-size: 0.8rem; margin-top: 10px; }

/* Beim Ziehen */
.zieht, .zieht * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
.geist {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--flaeche);
  border: 1px solid var(--akzent);
  border-left: 4px solid var(--farbe, var(--akzent));
  border-radius: 4px;
  padding: 4px 8px;
  opacity: 0.92;
  white-space: nowrap;
}

/* ---------- Flussdiagramm ---------- */
.fd-diagramm {
  border: 1px solid var(--linie);
  border-radius: 6px;
  background: var(--hg);
  overflow: auto;
  max-height: 78vh;
}
.fd-diagramm svg { display: block; margin: 0 auto; }
.fd-form { fill: var(--flaeche); stroke: var(--leise); stroke-width: 1.2; }
.fd-knoten text {
  font: 12px var(--schrift);
  fill: var(--text);
  text-anchor: middle;
  dominant-baseline: central;
}
.fd-kante { fill: none; stroke: var(--leise); stroke-width: 1.2; }
.fd-spitze, .fd-punkt { fill: var(--leise); }
.fd-zweig { font: 11px var(--schrift); fill: var(--leise); }
.fd-knoten.aktiv .fd-form { fill: var(--akzent-hg); stroke: var(--akzent); stroke-width: 2; }
.fd-zweig.aktiv { fill: var(--akzent); font-weight: 700; }

/* ---------- Ausführung ---------- */
.fd-steuerung {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  margin-bottom: 10px;
  font-size: 0.9rem;
}
.fd-steuerung select {
  font: inherit;
  color: var(--text);
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: 4px;
  padding: 3px 4px;
}
.fd-steuerung input[type="range"] { vertical-align: middle; width: 110px; accent-color: var(--akzent); }
.fd-knoepfe { display: flex; flex-wrap: wrap; gap: 8px; }
.fd-knopf {
  font: inherit;
  color: var(--text);
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: 4px;
  padding: 4px 12px;
  cursor: pointer;
}
.fd-knopf:hover { border-color: var(--akzent); }
.fd-knopf.haupt { color: var(--akzent); border-color: var(--akzent); min-width: 7.5em; }
.fd-knopf.haupt:hover { background: var(--akzent-hg); }

.fd-welt svg { display: block; width: 100%; height: auto; }
.fd-feld { fill: var(--flaeche); stroke: var(--linie); }
.fd-feld.gefaerbt { fill: var(--akzent); fill-opacity: 0.5; }
.fd-markierung { fill: var(--text); }
.fd-fehlt { fill: none; stroke: var(--akzent); stroke-width: 2.5; stroke-dasharray: 5 4; }
.fd-falsch { stroke: var(--text); stroke-width: 2.5; }
.fd-roboter { transition: transform var(--dauer, 0.2s) ease-in-out; }
.fd-roboter rect { fill: var(--text); }
.fd-roboter text {
  font: 700 22px var(--schrift);
  fill: var(--hg);
  text-anchor: middle;
  dominant-baseline: central;
}
.fd-roboter.stoss rect { fill: var(--akzent); }
@media (prefers-reduced-motion: reduce) { .fd-roboter { transition: none; } }

.fd-protokoll {
  margin: 12px 0 0;
  padding: 10px 12px;
  min-height: 9.6em;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--leise);
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: 6px;
}
.fd-protokoll b { color: var(--text); font-weight: 400; }
.fd-protokoll .gut { color: var(--ok); }
.fd-protokoll .schlecht { color: var(--akzent); }

@media (max-width: 900px) {
  .fd-raster { grid-template-columns: minmax(0, 1fr); }
  .fd-diagramm { max-height: 70vh; }
}
@media (max-width: 600px) {
  .fd-baukasten { grid-template-columns: minmax(0, 1fr); }
  .fd-palette { flex-direction: row; flex-wrap: wrap; }
  .fd-baustein { font-size: 0.82rem; padding: 4px 7px; }
}
