/* CodeLab -- Tablet-first, hell/dunkel nach Systemeinstellung oder Umschalter. Keine externen Ressourcen.
   Grundgerüst aus GateLab übernommen; CodeLab-eigene Teile stehen am Ende. */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #5f6b7f;
  --line: #d5dae2;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --hi: #f59e0b;        /* Leitung = 1 */
  --hi-glow: rgba(245, 158, 11, .35);
  --lo: #6b7a90;        /* Leitung = 0 */
  --unk: #b4bcc8;       /* undefiniert */
  --ok: #15803d;
  --ok-bg: #e8f6ec;
  --bad: #dc2626;
  --bad-bg: #fdecec;
  --gate-fill: #ffffff;
  --gate-stroke: #1d2433;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

/* Dunkles Schema: per Systemeinstellung oder per Umschalter (data-theme, theme.ts) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161f;
    --panel: #1b212d;
    --ink: #e6e9ef;
    --muted: #9aa5b7;
    --line: #2f3747;
    --accent: #5b8cff;
    --hi: #fbbf24;
    --hi-glow: rgba(251, 191, 36, .35);
    --lo: #7c8aa1;
    --unk: #4a5468;
    --ok: #4ade80;
    --ok-bg: #173323;
    --bad: #f87171;
    --bad-bg: #3a1c1c;
    --gate-fill: #232a38;
    --gate-stroke: #e6e9ef;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161f;
  --panel: #1b212d;
  --ink: #e6e9ef;
  --muted: #9aa5b7;
  --line: #2f3747;
  --accent: #5b8cff;
  --hi: #fbbf24;
  --hi-glow: rgba(251, 191, 36, .35);
  --lo: #7c8aa1;
  --unk: #4a5468;
  --ok: #4ade80;
  --ok-bg: #173323;
  --bad: #f87171;
  --bad-bg: #3a1c1c;
  --gate-fill: #232a38;
  --gate-stroke: #e6e9ef;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
#app { padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
       max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
       max-width: 1500px; margin: 0 auto; }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
.loading, .load-error { color: var(--muted); padding: 2rem 0; }

/* ---------------------------------------------------------------- Übersicht */

.overview { max-width: 720px; margin: 0 auto; }
.overview h1 { font-size: 2.2rem; margin: .5rem 0 .25rem; }
.lead { color: var(--muted); margin: 0 0 .5rem; }
.total { font-weight: 600; color: var(--hi); margin: 0 0 1rem; }
.task-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.task-card {
  display: grid; grid-template-columns: 2.4rem 1fr auto auto; align-items: center; gap: 12px;
  padding: 14px 16px; min-height: 64px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.task-card:active { transform: scale(.99); }
.task-card .num {
  width: 2.2rem; height: 2.2rem; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg); font-weight: 700; color: var(--muted);
}
.task-card.done .num { background: var(--ok-bg); color: var(--ok); }
.task-card .title { font-weight: 600; font-size: 1.1rem; }
.task-card .parts { display: flex; gap: 2px; }
.task-card .parts svg { width: 28px; height: 24px; }
.task-card .stars { color: var(--hi); font-size: 1.2rem; letter-spacing: 1px; white-space: nowrap; }
.privacy { color: var(--muted); font-size: .85rem; margin-top: 1.5rem; }
.link-btn { background: none; border: 0; padding: 4px 0; margin-left: .4em; color: var(--accent);
  text-decoration: underline; cursor: pointer; font-size: inherit; }
.reset-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .9rem;
  padding: 10px 12px; border: 1px solid var(--bad); border-radius: 8px; background: var(--bad-bg); }
.reset-confirm[hidden] { display: none; }
.reset-confirm button { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--muted);
  background: var(--bg); cursor: pointer; }
.reset-confirm button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }

/* ---------------------------------------------------------------- Aufgabenkopf */

.task-head { margin-bottom: 10px; }
.task-head .back { display: inline-block; padding: 6px 0; text-decoration: none; font-weight: 600; }
.task-head h1 { font-size: 1.5rem; margin: 2px 0 4px; }
.task-head p { margin: 0; color: var(--muted); max-width: 70ch; }

/* ---------------------------------------------------------------- Werkbank */

.workbench {
  display: grid; gap: 12px;
  grid-template-columns: 116px minmax(0, 1fr) 300px;
  align-items: start;
}

/* Viele Tabellenspalten (z. B. 2-Bit-Rechenwerk): breitere Tabelle, engere Zellen */
@media (min-width: 1101px) {
  .workbench.wide { grid-template-columns: 116px minmax(0, 1fr) 390px; }
}
.workbench.wide .truth th, .workbench.wide .truth td { padding: 6px 2px; }

.palette, .side, .canvas-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.palette { padding: 8px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 8px;
           transition: background .15s, border-color .15s; }
.palette-title { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
                 text-align: center; }
.part {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px; min-height: 84px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); cursor: grab; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.part svg { width: 64px; height: 52px; }
.part:disabled { opacity: .35; cursor: not-allowed; }
.part-name { font-size: .8rem; font-weight: 600; }
.part .count { position: absolute; top: 4px; right: 6px; font-size: .75rem; color: var(--muted); }
.trash-hint { display: none; font-size: .8rem; text-align: center; color: var(--bad); padding: 6px 2px; }
.palette.trash-hot { background: var(--bad-bg); border-color: var(--bad); }
.palette.trash-hot .trash-hint { display: block; }

.canvas-wrap { overflow: hidden; }
.canvas { display: block; width: 100%; height: auto; touch-action: none; user-select: none;
          -webkit-user-select: none; -webkit-touch-callout: none; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
.toolbar .spacer { flex: 1; }
.toolbar button {
  min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer;
}
.toolbar button:disabled { opacity: .4; cursor: default; }
.toolbar button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
                          font-weight: 700; padding: 0 22px; }

/* ---------------------------------------------------------------- SVG-Elemente */

.gate-body { fill: var(--gate-fill); stroke: var(--gate-stroke); stroke-width: 2.5; }
.gate-bubble { fill: var(--gate-fill); stroke: var(--gate-stroke); stroke-width: 2.5; } /* Negation: Teil des Gatters */
.gate-sym { font-size: 26px; font-weight: 600; text-anchor: middle; fill: var(--gate-stroke); }
.gate-label { font-size: 13px; text-anchor: middle; fill: var(--muted); }
.gate-out { font-size: 15px; font-weight: 600; text-anchor: end; fill: var(--gate-stroke); }
.stub { stroke: var(--gate-stroke); stroke-width: 2.5; }
.gate-hit { fill: transparent; }
.gate { cursor: grab; }
.gate.selected .gate-body { stroke: var(--accent); stroke-width: 4; }
.gate.error .gate-body { stroke: var(--bad); stroke-width: 4; }
.gate.ghost { opacity: .5; pointer-events: none; }

.wire { fill: none; stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.wire.hi { stroke: var(--hi); filter: drop-shadow(0 0 4px var(--hi-glow)); }
.wire.lo { stroke: var(--lo); }
.wire.unk { stroke: var(--unk); stroke-dasharray: 6 6; }
.wire.selected { stroke: var(--accent); stroke-width: 6; stroke-dasharray: none; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 22; cursor: pointer; }
.dot { stroke: none; }
.dot.hi { fill: var(--hi); } .dot.lo { fill: var(--lo); } .dot.unk { fill: var(--unk); }
.rubber { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 8 6; pointer-events: none; }

.pin { cursor: crosshair; }
.pin-hit { fill: transparent; }
/* Anschlüsse: ausgefüllte Punkte in Signalfarbe -- bewusst anders als der hohle Negationskreis */
.pin-dot { stroke: none; fill: var(--unk); }
.pin-dot.hi { fill: var(--hi); } .pin-dot.lo { fill: var(--lo); }
.pin-dot.open { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.pin.hot .pin-dot { fill: var(--accent); stroke: var(--accent); r: 10; }
.pin.error .pin-dot { fill: var(--bad); stroke: var(--bad); r: 9; }

.terminal text { text-anchor: middle; }
.term-name { font-size: 22px; font-weight: 700; fill: var(--ink); }
.term-val { font-size: 22px; font-weight: 700; }
.terminal.input { cursor: pointer; }
.terminal.const { cursor: default; }
.terminal.const rect { stroke-dasharray: 6 4; }
.terminal.const .term-name { font-size: 15px; }
.terminal.input rect { stroke-width: 2.5; }
.terminal.input.lo rect { fill: var(--panel); stroke: var(--lo); }
.terminal.input.lo .term-val { fill: var(--lo); }
.terminal.input.hi rect { fill: var(--hi); stroke: var(--hi); filter: drop-shadow(0 0 6px var(--hi-glow)); }
.terminal.input.hi .term-val { fill: #1d2433; }
.lamp { stroke-width: 2.5; fill: var(--panel); stroke: var(--unk); }
.terminal.output.lo .lamp { stroke: var(--lo); }
.terminal.output.hi .lamp { fill: var(--hi); stroke: var(--hi); filter: drop-shadow(0 0 10px var(--hi-glow)); }
.terminal.output .term-val { fill: var(--muted); }
.terminal.output.hi .term-val { fill: #1d2433; }
.terminal.output.error .lamp { stroke: var(--bad); stroke-width: 4; }

/* ---------------------------------------------------------------- Seitenleiste */

.side { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.truth { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.truth th, .truth td { text-align: center; padding: 6px 4px; }
.truth thead th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.truth thead tr:last-child th { font-size: 1rem; color: var(--ink); border-bottom: 2px solid var(--line); }
.truth tbody tr { cursor: pointer; border-bottom: 1px solid var(--line); }
.truth tbody td { height: 40px; }
.truth .soll { background: color-mix(in srgb, var(--bg) 70%, transparent); }
.truth .ist { font-weight: 700; }
.truth tr.current { outline: 3px solid var(--accent); outline-offset: -3px; }
.truth tr.ok .mark { color: var(--ok); }
.truth tr.bad .mark, .truth tr.bad .ist { color: var(--bad); }
.truth tr.wrong { background: var(--bad-bg); }
.tip { margin: 0; font-size: .85rem; color: var(--muted); }

.feedback { border-radius: 10px; padding: 10px 12px; }
.feedback ul { margin: 6px 0 0; padding-left: 1.2em; }
.feedback.success { background: var(--ok-bg); color: var(--ok); }
.feedback.error { background: var(--bad-bg); color: var(--bad); }
.feedback .stars { font-size: 2rem; color: var(--hi); letter-spacing: 3px; }
.hints { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.hints ul { margin: 6px 0 0; padding-left: 1.2em; }

/* ---------------------------------------------------------------- Schmale Bildschirme */

@media (max-width: 1100px) {
  .workbench { grid-template-columns: 104px minmax(0, 1fr); }
  .side { grid-column: 1 / -1; }
  .side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .side .truth { grid-row: span 3; }
}

@media (max-width: 700px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .palette { position: static; flex-direction: row; overflow-x: auto; }
  .palette-title { display: none; }
  .part { min-width: 84px; }
  .side { display: flex; }
  .toolbar button { padding: 0 10px; }
}

/* ---------------------------------------------------------------- Hörsaal-Barometer */

.barometer { margin: 2px 0 6px !important; color: var(--hi) !important; font-weight: 600; }

/* ---------------------------------------------------------------- Kopfzeile mit Logo */

:root { --logo: #2a2068; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --logo: #c9c3f2; } }
:root[data-theme="dark"] { --logo: #c9c3f2; }

.site-header {
  display: flex; align-items: center; gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px
           max(16px, env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.site-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
              max-width: 1500px; width: 100%; margin: 0 auto; }
.theme-toggle { flex: none; display: grid; place-items: center; width: 44px; height: 44px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--bg); color: var(--ink); cursor: pointer; }
.theme-toggle .icon { width: 22px; height: 22px; }
.hs-logo { height: 30px; width: auto; color: var(--logo); flex: none; }
.site-org { font-weight: 600; color: var(--logo); }
.site-name { font-weight: 800; padding-left: 10px; border-left: 2px solid var(--line); }
.site-brand a { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.site-brand .hs-link:hover .site-org { text-decoration: underline; }
.site-footer { text-align: center; font-size: .8rem; color: var(--muted);
               padding: 24px 16px max(16px, env(safe-area-inset-bottom)); }
.site-footer a { color: inherit; }
#app { padding-top: 12px; }

@media (max-width: 500px) {
  .site-org { display: none; }
  .site-name { padding-left: 0; border-left: 0; }
}

/* ---------------------------------------------------------------- Symbole */

.icon { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex: none; }
.toolbar button { display: inline-flex; align-items: center; gap: 6px; }

/* ---------------------------------------------------------------- Phase 4: Level, Badges, Effekte */

.overview h2 { font-size: 1.2rem; margin: 28px 0 10px; display: flex; gap: 10px; align-items: baseline; }
.overview h2 .muted { color: var(--muted); font-size: .9rem; font-weight: 500; }
.progress { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; font-weight: 700; color: var(--hi); }
.progress .bar { flex: 1; height: 12px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress .bar div { height: 100%; background: var(--hi); border-radius: 999px; transition: width .6s ease; }

.level-path .task-card.done .num { background: var(--ok-bg); color: var(--ok); }
.level-path .task-card.next { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.level-path .task-card.next .num { background: var(--accent); color: var(--accent-ink); }
.level-path .task-card .title { display: flex; flex-direction: column; gap: 2px; }
.level-path .tag { align-self: flex-start; font-size: .75rem; font-weight: 700; color: var(--accent-ink);
                   background: var(--accent); border-radius: 999px; padding: 1px 8px; }

.badge-shelf { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px;
               grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.badge { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius);
         background: var(--panel); border: 1px solid var(--line); opacity: .45; filter: grayscale(1); }
.badge.earned { opacity: 1; filter: none; }
.badge-icon { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
              font-weight: 800; font-size: 1.1rem; color: #1d2433; background: var(--hi);
              box-shadow: inset 0 0 0 3px color-mix(in srgb, #fff 45%, transparent); }
.badge-text { display: flex; flex-direction: column; }
.badge-text small { color: var(--muted); }

.next-task { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; padding: 10px 14px;
             border-radius: 10px; background: var(--ok); color: var(--panel); font-weight: 700; text-decoration: none; }

.stars.pop { animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); transform-origin: left center; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* Signal „fließt“: Strichmuster wandert von der Quelle zum Ziel */
.canvas.flowing .wire.hi { stroke-dasharray: 14 8; animation: flow .5s linear infinite; }
.canvas.flowing .terminal.output.hi .lamp { animation: glow .55s ease-in-out infinite alternate; }
@keyframes flow { to { stroke-dashoffset: -22; } }
@keyframes glow { to { filter: drop-shadow(0 0 18px var(--hi)); } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; gap: 12px;
         align-items: center; padding: 10px 16px 10px 10px; border-radius: 999px; background: var(--panel);
         border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
         animation: toast-in .4s ease; transition: opacity .5s, transform .5s; }
.toast small { display: block; color: var(--muted); font-size: .75rem; }
.toast.leave { opacity: 0; transform: translateX(-50%) translateY(20px); }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(20px); } }

.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 40; }

@media (prefers-reduced-motion: reduce) {
  .stars.pop, .toast, .canvas.flowing .wire.hi, .canvas.flowing .terminal.output.hi .lamp { animation: none; }
}

/* ================================================================ CodeLab */

.task-card .typ { font-size: .8rem; font-weight: 600; color: var(--muted); border: 1px solid var(--line);
                  border-radius: 999px; padding: 2px 10px; white-space: nowrap; }

.workbench.maschine { grid-template-columns: minmax(0, 1fr) 320px; }
@media (max-width: 1100px) { .workbench.maschine { grid-template-columns: minmax(0, 1fr); } }

.box { fill: var(--gate-fill); stroke: var(--gate-stroke); stroke-width: 2.5; }
.box-title { font-size: 19px; font-weight: 800; text-anchor: middle; fill: var(--ink); }
.bus-label { font-size: 14px; font-weight: 700; fill: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.cpu-split { stroke: var(--line); stroke-width: 2; stroke-dasharray: 6 6; }
.sysbus { fill: none; stroke: var(--lo); stroke-width: 9; stroke-linecap: round; opacity: .55; }

/* Palette mit Befehlsbausteinen */
.pal { fill: var(--bg); stroke: var(--line); stroke-width: 2; }
.palette-box.trash-hot .pal { fill: var(--bad-bg); stroke: var(--bad); }
.trash-text { font-size: 12px; text-anchor: middle; fill: var(--muted); }
.palette-box.trash-hot .trash-text { fill: var(--bad); font-weight: 700; }
.tile { cursor: grab; }
.tile-box { fill: var(--panel); stroke: var(--accent); stroke-width: 2.5; }
.tile-box.halt { stroke: var(--lo); }
.tile:hover .tile-box { fill: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.tile-sym { font-size: 24px; font-weight: 800; text-anchor: middle; fill: var(--accent); }
.tile-box.halt + .tile-sym { fill: var(--lo); }
.tile-name { font-size: 15px; font-weight: 700; fill: var(--ink); }
.tile-code { font-size: 12px; fill: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.ghost { pointer-events: none; opacity: .85; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .25)); }

/* CPU */
.unit-title { font-size: 13px; font-weight: 700; fill: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.reg-name { font-size: 14px; font-weight: 700; fill: var(--ink); text-anchor: end; }
.reg-sub { font-size: 12px; fill: var(--muted); text-anchor: end; }
.reg-dez { font-size: 15px; font-weight: 700; fill: var(--muted); }
.nib-label { font-size: 11px; fill: var(--muted); text-anchor: middle; }
.cells.decode .cell:nth-of-type(-n+4) { stroke: var(--accent); stroke-width: 3; }
.decoder { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
.decoder.active { stroke: var(--accent); stroke-width: 2.5; }
.decoder-text { font-size: 14px; font-weight: 700; text-anchor: middle; fill: var(--ink); font-family: ui-monospace, Menlo, monospace; }
.phase rect { fill: var(--bg); stroke: var(--line); stroke-width: 1.5; }
.phase text { font-size: 12.5px; font-weight: 700; text-anchor: middle; fill: var(--muted); }
.phase.active rect { fill: var(--accent); stroke: var(--accent); }
.phase.active text { fill: var(--accent-ink); }
.zyklus-note { font-size: 12px; text-anchor: middle; fill: var(--muted); }
.alu rect { fill: var(--hi); stroke: var(--hi); filter: drop-shadow(0 0 8px var(--hi-glow)); }
.alu text { font-size: 17px; font-weight: 800; text-anchor: middle; fill: #1d2433; }

/* Bits in Registern und Speicherzellen */
.cell { stroke-width: 1.5; }
.cell.lo { fill: var(--panel); stroke: var(--lo); }
.cell.hi { fill: var(--hi); stroke: var(--hi); }
.cell.unk { fill: var(--bg); stroke: var(--unk); stroke-dasharray: 3 3; }
.cell-val { font-size: 14px; font-weight: 700; text-anchor: middle; fill: var(--ink); font-variant-numeric: tabular-nums; pointer-events: none; }
.cell.hi + .cell-val { fill: #1d2433; }

/* Speicher als Fächerregal */
.fach { cursor: pointer; }
.fach > rect { fill: transparent; stroke: transparent; stroke-width: 2.5; }
.fach.daten { cursor: default; }
.fach.daten > rect { fill: color-mix(in srgb, var(--ok) 9%, transparent); }
.fach.daten .cell { opacity: .8; }
.fach.cursor > rect { stroke: var(--accent); }
.fach.drop > rect { stroke: var(--accent); stroke-dasharray: 6 4; fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.fach.bz > rect { fill: color-mix(in srgb, var(--hi) 22%, transparent); }
.fach.sel > rect { stroke: var(--hi); stroke-dasharray: 6 4; }
.fach.changed > rect { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.adr-bit { cursor: pointer; }
.adr-bit .cell { stroke: var(--accent); stroke-width: 2.5; }
.fach-adr { font-size: 15px; font-weight: 700; fill: var(--ink); font-family: ui-monospace, Menlo, monospace; }
.fach-dez { font-size: 13px; fill: var(--muted); }
.fach-label { text-anchor: end; }
.fach-head { font-size: 11px; font-weight: 700; fill: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.fach-head.end { text-anchor: end; }
.deutung { font-size: 13px; font-weight: 700; fill: var(--ink); font-family: ui-monospace, Menlo, monospace; }
.deutung .leer { fill: var(--unk); font-weight: 500; }
.deutung .dname { fill: var(--ok); }
.fach .lock circle { fill: var(--panel); stroke: var(--muted); stroke-width: 1.5; }
.fach .lock path { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.fach .lock rect { fill: var(--muted); stroke: none; }
.bz-zeiger path { fill: var(--hi); }
.bz-zeiger text { font-size: 11px; font-weight: 800; fill: var(--hi); }
.flash > rect, .cells.flash .cell { animation: flash 1s ease-out; }
@keyframes flash {
  0% { fill: var(--hi); stroke: var(--hi); filter: drop-shadow(0 0 12px var(--hi)); }
}

/* Fliegendes Bitpaket (Befehl, Adresse oder Datum unterwegs über den Bus) */
.paket { pointer-events: none; }
.paket rect { fill: var(--hi); stroke: var(--hi); filter: drop-shadow(0 0 8px var(--hi)); }
.paket text { font-size: 14px; font-weight: 800; text-anchor: middle; fill: #1d2433; font-family: ui-monospace, Menlo, monospace; }

/* Seitenleiste */
.ziel { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.ziel ul { list-style: none; margin: 6px 0 0; padding: 0; }
.ziel li { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.ziel .mark { width: 1.2em; color: var(--muted); font-weight: 700; }
.ziel li.ok .mark { color: var(--ok); }
.note { margin: 0; padding: 8px 12px; border-left: 4px solid var(--hi); background: var(--bg); border-radius: 6px; }
.protokoll, .befehlstabelle { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: .95rem; }
.protokoll th, .befehlstabelle th { font-size: .8rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--line); padding: 4px; }
.protokoll td { text-align: center; padding: 4px; }
.befehlstabelle td { padding: 3px 4px; border-bottom: 1px solid var(--line); font-size: .85rem; }
.protokoll .mono, .befehlstabelle .mono { font-family: ui-monospace, Menlo, monospace; }
.protokoll tr.event td { text-align: left; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--line); padding-top: 0; }
.protokoll tr.empty td { color: var(--muted); font-style: italic; }

@media (prefers-reduced-motion: reduce) {
  .flash > rect, .cells.flash .cell { animation: none; }
}

/* ---------------------------------------------------------------- Assembler-Editor */

.workbench.maschine.asm { grid-template-columns: 250px minmax(0, 1fr) 320px; }
@media (max-width: 1100px) { .workbench.maschine.asm { grid-template-columns: minmax(0, 1fr); } }
.editor { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
          padding: 10px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 8px; }
.editor-head { display: flex; justify-content: space-between; align-items: baseline; }
.editor-head span { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.editor-body { display: grid; grid-template-columns: auto minmax(0, 1fr); border: 1px solid var(--line);
               border-radius: 8px; overflow: hidden; background: var(--bg); }
.editor-body:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.gutter, .editor textarea { font: 16px/1.5 ui-monospace, Menlo, monospace; margin: 0; padding: 8px; }
.gutter { color: var(--muted); font-size: 12px; line-height: 24px; text-align: right; overflow: hidden;
          border-right: 1px solid var(--line); user-select: none; min-width: 5.2em; max-height: 420px; }
.gutter .err { color: var(--bad); font-weight: 700; }
.gutter .akt { color: var(--accent-ink); background: var(--accent); border-radius: 4px; padding: 0 3px; }
.editor textarea { line-height: 24px; border: 0; outline: none; resize: vertical; min-height: 300px; max-height: 420px;
                   background: transparent; color: var(--ink); white-space: pre; overflow: auto; }
.editor textarea:disabled { opacity: .6; }
.asm-fehler { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.asm-fehler:empty { display: none; }
.asm-fehler li { color: var(--bad); background: var(--bad-bg); border-radius: 6px; padding: 6px 8px; font-size: .9rem; }
@media (max-width: 1100px) {
  .editor { position: static; }
  .editor textarea { min-height: 170px; }
}
