:root {
  --color-bg: #f5f7fb;
  --color-panel: #ffffff;
  --color-border: #dbe1ea;
  --color-text: #1f2937;
  --color-primary: #3b82f6;
  --color-primary-dark: #2563eb;
  --color-unvisited: #cbd5e1;
  --color-queued: #fbbf24;
  --color-current: #3b82f6;
  --color-done: #22c55e;
  --color-correct: #16a34a;
  --color-incorrect: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
}

.top-bar {
  background: var(--color-panel);
  border-bottom: 1px solid var(--color-border);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-bar h1 { margin: 0 0 10px 0; font-size: 1.3rem; }

.nav { display: flex; gap: 8px; flex-wrap: wrap; }
.nav[hidden] { display: none; }
.nav-btn {
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
.nav-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

main { max-width: 1800px; margin: 0 auto; padding: 20px; }

.section { display: none; }
.section.active { display: block; }

.hint {
  background: #eef4ff;
  border: 1px solid #c9dcff;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.5;
}
.red { color: #dc2626; font-weight: bold; }

.layout-2col {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  align-items: start;
}
.layout-2col > * { min-width: 0; }
@media (max-width: 800px) {
  .layout-2col { grid-template-columns: 1fr; }
}

/* Tree views need more height/width than the default side-panel layout provides. */
#sec-demo-tree .layout-2col,
#sec-ex-tree .layout-2col {
  grid-template-columns: 1fr 1fr;
}

.graph-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.graph-canvas.small { aspect-ratio: 16 / 12; }
.tree-build-canvas { min-height: 360px; }
#sec-apply-dfs .dfs-workspace > .graph-canvas {
  aspect-ratio: auto;
  height: min(420px, max(280px, calc(100vh - 620px)));
}
#sec-apply-dfs-variant .dfs-workspace > .graph-canvas {
  aspect-ratio: auto;
  height: min(420px, max(280px, calc(100vh - 620px)));
}

.edges-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.edge { stroke: #94a3b8; stroke-width: 0.6; }
.edge-active { stroke: #3b82f6; stroke-width: 1; }
.edge-dim { stroke: #cbd5e1; }
.edge-hidden { display: none; }
#sec-dfs-tree-demo .edge-active,
#sec-dfs-tree-exercise .edge-active { stroke: #dc2626; stroke-width: 1.4; }
#sec-dfs-tree-demo .node-order,
#sec-dfs-tree-exercise .node-order { display: none; }
.edge-clickable { pointer-events: stroke; cursor: pointer; stroke-width: 2; }
.edge-clickable:hover:not(.edge-active) { stroke: #f87171; }

.node {
  position: absolute;
  transform: translate(-50%, -50%);
}
.node-circle {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-unvisited);
  border: 2px solid #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.95rem;
  color: #1f2937;
  transition: background 0.3s, border-color 0.3s, transform 0.2s;
}
.node-circle.root-node { border-color: #2563eb; border-width: 3px; }

.node-circle.st-unvisited { background: var(--color-unvisited); }
.node-circle.st-queued { background: var(--color-queued); }
.node-circle.st-current { background: var(--color-current); color: white; transform: scale(1.12); box-shadow: 0 0 0 4px rgba(59,130,246,0.25); }
.node-circle.st-done { background: var(--color-done); color: white; }

.node-circle.correct { box-shadow: 0 0 0 4px rgba(22,163,74,0.45); }
.node-circle.incorrect { box-shadow: 0 0 0 4px rgba(220,38,38,0.45); }

.node-circle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  line-height: 1;
}
.node-label { font-size: 0.8rem; }
.node-dist { font-size: 0.95rem; font-weight: bold; min-height: 1em; }

.node-order {
  position: absolute;
  top: -6px;
  right: -6px;
  background: white;
  color: #dc2626;
  border: 1px solid #dc2626;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.62rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dropzone { cursor: pointer; }
.dropzone.drag-over { outline: 2px dashed #3b82f6; background: rgba(59,130,246,0.15); }
.node-dist.dropzone {
  min-width: 26px;
  min-height: 20px;
  border: 1px dashed #94a3b8;
  border-radius: 6px;
  padding: 0 2px;
}
.node-order.dropzone { border: 1px dashed #dc2626; }
.node-dist.filled, .node-order.filled { font-weight: bold; border-style: solid; }
.node-dist.correct, .node-order.correct { background: #dcfce7; }
.node-dist.incorrect, .node-order.incorrect { background: #fee2e2; }

/* Farblogik für die BFS-Übung: grau = nicht entdeckt, blau = entdeckt, lila = abgearbeitet */
.node-circle.ex-unvisited { background: var(--color-unvisited); }
.node-circle.ex-discovered { background: #3b82f6; color: white; }
.node-circle.ex-processed { background: #8b5cf6; color: white; }
.node-circle.start-marker { outline: 3px solid #f59e0b; outline-offset: 2px; }

.side-panel { display: flex; flex-direction: column; gap: 12px; }
.side-panel h3 { margin: 0 0 4px 0; font-size: 1rem; }

.queue-box {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 46px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.queue-label { font-weight: bold; margin-right: 4px; }
.queue-chip {
  background: var(--color-queued);
  border-radius: 6px;
  padding: 3px 8px;
  font-weight: bold;
  font-size: 0.85rem;
}
.queue-empty { color: #94a3b8; font-style: italic; }
.state-box[hidden] { display: none; }

.algorithm-layout { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(240px, 1fr); gap: 16px; margin-bottom: 16px; }
.algorithm-code { margin: 0; padding: 14px; overflow-x: auto; background: #172033; color: #e2e8f0; border-radius: var(--radius); line-height: 1.5; }
.algorithm-state { display: flex; flex-direction: column; gap: 10px; }
.help-toggle { display: inline-flex; gap: 8px; align-items: center; margin: 4px 0 12px; font-weight: 600; }
.help-level { margin: 4px 0 12px; padding: 6px 8px; border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-panel); }
.dfs-help { margin: 0 0 12px; padding: 10px 12px; background: #fff7ed; border: 1px solid #fdba74; border-radius: var(--radius); }
.dfs-workspace { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-top: 16px; }
.dfs-panel { display: flex; flex-direction: column; gap: 8px; }
.dfs-panel h3 { margin: 4px 0 0; font-size: 1rem; }
.dfs-create-list { width: 100%; margin-top: 8px; }
.dfs-dropzone { min-height: 52px; }
.dfs-chip { display: inline-flex; align-items: center; gap: 5px; }
.dfs-pending { border-color: #f59e0b; background: #fef3c7; }
.stack-remove { border: 0; background: transparent; color: #991b1b; cursor: pointer; font-weight: bold; padding: 0 2px; }
@media (max-width: 800px) {
  .algorithm-layout, .dfs-workspace { grid-template-columns: 1fr; }
  #sec-apply-dfs .dfs-workspace > .graph-canvas { height: auto; aspect-ratio: 16 / 10; }
  #sec-apply-dfs-variant .dfs-workspace > .graph-canvas { height: auto; aspect-ratio: 16 / 10; }
  #dfs-tree-demo-graph,
  #dfs-tree-exercise-ref { aspect-ratio: 1 / 1; }
}

.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  padding: 8px;
  background: var(--color-panel);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}
.chip {
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: bold;
  cursor: grab;
  border: 1px solid var(--color-border);
  background: #eef4ff;
  user-select: none;
}
.chip-dist { background: #dbeafe; }
.chip-order { background: #fee2e2; color: #b91c1c; }
.chip-node { background: #e0f2fe; }

.btn-row { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-panel);
  cursor: pointer;
  font-size: 0.9rem;
}
.btn:hover { background: #f1f5f9; }
.btn-primary { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }

.feedback {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  min-height: 20px;
}
.feedback-ok { background: #dcfce7; border: 1px solid #86efac; color: #14532d; }
.feedback-error { background: #fee2e2; border: 1px solid #fca5a5; color: #7f1d1d; }
.feedback-warn { background: #fef9c3; border: 1px solid #fde68a; color: #713f12; }

.player-bar {
  margin-top: 14px;
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
}
.player-controls { display: flex; gap: 8px; margin-bottom: 8px; }
.scrubber { width: 100%; margin-bottom: 8px; }
.step-desc { font-size: 0.88rem; color: #334155; min-height: 20px; }

/* Pseudocode-Anzeige mit hervorgehobener aktueller Zeile */
.pseudocode {
  font-family: "Cascadia Code", Consolas, monospace;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: 10px 0;
  font-size: 0.82rem;
  line-height: 1.6;
  overflow-x: auto;
}
.pseudocode-line { display: flex; gap: 10px; padding: 2px 14px; white-space: pre; }
.pseudocode-num { color: #64748b; min-width: 1.5em; text-align: right; user-select: none; }
.pseudocode-line.active { background: #1e3a8a; color: #fff; border-radius: 4px; }
.pseudocode-line.active .pseudocode-num { color: #93c5fd; }

/* Stapel-Visualisierung (LIFO) */
.stack-panel {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 46px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stack-top-label { font-size: 0.78rem; color: #64748b; font-style: italic; }
.stack-item {
  background: var(--color-queued);
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: bold;
  font-size: 0.9rem;
}
.stack-item.clickable { cursor: pointer; }
.stack-item.clickable:hover { outline: 2px solid var(--color-primary); }
.stack-item-top { border: 2px solid var(--color-primary-dark); }
.stack-empty { color: #94a3b8; font-style: italic; }

/* Entscheidungs-Panel der DFS-Übung */
.decision-question p { margin: 0 0 8px 0; font-size: 0.92rem; }

.replay-wrap { display: none; margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--color-border); }
.replay-wrap.active { display: block; }
