:root {
  --bg: #f3ede2;
  --panel: #fffaf1;
  --ink: #222634;
  --muted: #5f6472;
  --line: #ddd2bf;
  --accent: #3a6ea5;
  --run: #e8590c;
  --run-dark: #a63c05;
  --board: #263445;
  --sig-on: #ffb000;
  --sig-off: #7b8798;
  --target: #5ee0a0;
  --ok: #2e7d4f;
  --ok-bg: #e2f3e8;
  --bad: #b8323d;
  --bad-bg: #fbe5e7;
  --radius: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ---------- Layout ---------- */
/* Handy/Tablet: Szene steht über der Werkbank, damit man beides gleichzeitig sieht. */
.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 16px 16px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "top" "bit" "scene" "bench" "table";
}

@media (min-width: 700px) {
  .app {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    /* Bit steht rechts, damit die Werkbank links nicht springt, wenn Bits Text wechselt. */
    grid-template-areas:
      "top   top"
      "bench bit"
      "bench scene"
      "bench table";
    grid-template-rows: auto auto auto 1fr;
    align-items: start;
  }
  .bit-line { min-height: calc(1.45em * 4); }
  .bubble { font-size: .93rem; }
}

.top { grid-area: top; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 1rem; }
.level-name {
  font-weight: 700; font-size: .9rem; color: var(--accent);
  background: #e6eef8; padding: 2px 10px; border-radius: 999px;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}
.scene-panel { grid-area: scene; padding: 8px; }
.bench { grid-area: bench; }
.table-panel { grid-area: table; transition: border-color .2s, box-shadow .2s; }

/* ---------- Bit ---------- */
.bit-card { grid-area: bit; display: flex; gap: 12px; align-items: flex-start; }
.bit-avatar { width: 56px; height: 56px; flex: none; }
.bit-avatar.big { width: 84px; height: 84px; margin: 0 auto; }
.bubble {
  position: relative; flex: 1; min-width: 0;
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px;
}
.bubble::before {
  content: ""; position: absolute; left: -9px; top: 18px;
  width: 14px; height: 14px; background: var(--panel);
  border-left: 2px solid var(--line); border-bottom: 2px solid var(--line);
  transform: rotate(45deg);
}
.job { margin: 0 0 6px; color: var(--muted); font-size: .95rem; }
.job strong { color: var(--ink); }
.bit-line { margin: 0; font-weight: 600; }
.step-badge {
  display: inline-block; margin-right: 6px; padding: 0 8px;
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: .75rem; font-weight: 800; vertical-align: 1px;
}

/* ---------- Hervorhebungen der Einführung ---------- */
@keyframes hint-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 176, 0, 0); }
  50% { box-shadow: 0 0 0 6px rgba(255, 176, 0, .6); }
}
.palette-btn.hint, #run-btn.hint { animation: hint-glow 1.2s ease-in-out infinite; }
.table-panel.hint { border-color: var(--sig-on); animation: hint-glow 1.2s ease-in-out infinite; }

/* ---------- Bit als Coach (Kopf mit Sprechblase am Bedienelement) ---------- */
.coach {
  position: absolute; z-index: 15;
  display: flex; gap: 8px; align-items: flex-start;
  width: max-content; max-width: min(280px, calc(100vw - 16px));
  padding: 10px 12px;
  background: #fff; color: var(--ink);
  border: 2.5px solid var(--accent); border-radius: 14px;
  box-shadow: 0 10px 28px rgba(20, 24, 34, .22);
  font-size: .92rem; font-weight: 600; line-height: 1.35;
  pointer-events: none;   /* verdeckt nie, was man anklicken will */
}
.coach p { margin: 0; }
.coach-head { width: 38px; height: 38px; flex: none; margin-top: -2px; }
.coach::after {
  content: ""; position: absolute; width: 14px; height: 14px;
  background: #fff; border: 2.5px solid var(--accent); transform: rotate(45deg);
}
.coach[data-place="below"]::after { top: -9px; left: calc(var(--arrow-x) - 7px); border-right: none; border-bottom: none; }
.coach[data-place="above"]::after { bottom: -9px; left: calc(var(--arrow-x) - 7px); border-top: none; border-left: none; }
.coach[data-place="right"]::after { left: -9px; top: calc(var(--arrow-y) - 7px); border-top: none; border-right: none; }
.coach[data-place="left"]::after { right: -9px; top: calc(var(--arrow-y) - 7px); border-bottom: none; border-left: none; }
.coach.pop { animation: coach-pop .3s ease-out; }
@keyframes coach-pop { from { opacity: 0; transform: translateY(6px) scale(.94); } to { opacity: 1; transform: none; } }

/* ---------- Palette ---------- */
.palette { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.palette-title { font-weight: 700; margin-right: 4px; }
.palette-btn {
  display: flex; align-items: center; gap: 6px;
  min-height: 52px; padding: 4px 14px 4px 6px;
  border: 2px solid var(--ink); border-radius: 12px; background: #fff;
  font: inherit; font-weight: 700; color: var(--ink);
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.palette-btn svg { width: 44px; height: 44px; }
.palette-btn:disabled { opacity: .5; cursor: not-allowed; }
.new-badge {
  background: var(--sig-on); color: var(--ink); border-radius: 999px;
  padding: 0 7px; font-size: .7rem; font-weight: 800; text-transform: uppercase;
}

.ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 20; opacity: .85; }
.ghost svg { width: 100%; height: 100%; }

/* ---------- Werkbank (SVG) ---------- */
.board {
  display: block; width: 100%; height: auto; max-height: 64vh;
  background: var(--board); border-radius: 12px;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
@media (min-width: 700px) { .board { max-height: 58vh; } }

.node-box { fill: var(--panel); stroke: #11161d; stroke-width: 2; }
.node-label { font-size: 12px; font-weight: 700; text-anchor: middle; fill: var(--ink); pointer-events: none; }
.lamp { fill: #3b4350; stroke: #11161d; stroke-width: 1.5; pointer-events: none; }
.node.on .lamp { fill: var(--sig-on); filter: url(#glow); }
.lamp-val { font-size: 14px; font-weight: 800; fill: var(--ink); pointer-events: none; }

/* Sensoren sind Schalter */
.sensor { cursor: pointer; }
.sensor.locked { cursor: default; }
.sensor.locked .switch-track, .sensor.locked .switch-knob { opacity: .45; }
.switch-track { fill: #c9ccd3; stroke: #11161d; stroke-width: 1.5; pointer-events: none; transition: fill .15s; }
.sensor.on .switch-track { fill: var(--sig-on); filter: url(#glow); }
.switch-knob { fill: #fff; stroke: #11161d; stroke-width: 1.5; pointer-events: none; }
.sensor.hint .node-box { stroke: var(--sig-on); stroke-width: 4; animation: blink 1.2s ease-in-out infinite; }

.stub { stroke-width: 4; stroke-linecap: round; pointer-events: none; }
.stub.off, .wire.off .wire-line { stroke: var(--sig-off); }
.stub.on, .wire.on .wire-line { stroke: var(--sig-on); filter: url(#glow); }

.wire-line { fill: none; stroke-width: 4; stroke-linecap: round; pointer-events: none; }
.wire-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
.wire-hit-mid { fill: transparent; cursor: pointer; }
.wire.selected .wire-line { stroke-width: 6; }
.wire-sel { fill: none; stroke: #7ee8fa; stroke-width: 12; stroke-linecap: round; opacity: .35; pointer-events: none; }

/* Löschen: ✕-Knopf am ausgewählten Element und Mülleimer beim Ziehen */
.del-btn { animation: pop .15s ease-out; transform-box: fill-box; transform-origin: center; }
.del-bg { fill: #d1495b; stroke: #fff; stroke-width: 2; }
.del-btn path { stroke: #fff; stroke-width: 2.5; stroke-linecap: round; pointer-events: none; }
.del-hit { fill: transparent; cursor: pointer; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.trash { pointer-events: none; animation: pop .15s ease-out; transform-box: fill-box; transform-origin: center; }
.trash rect { fill: rgba(255, 255, 255, .07); stroke: #8a97a8; stroke-width: 2; stroke-dasharray: 5 4; }
.trash-icon { fill: none; stroke: #c3cad4; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.trash text { font-size: 10px; font-weight: 700; fill: #c3cad4; text-anchor: middle; }
.trash.active rect { fill: rgba(209, 73, 91, .45); stroke: #ff6b7d; stroke-dasharray: none; }
.trash.active .trash-icon { stroke: #fff; }
.trash.active text { fill: #fff; }
.wire-temp { fill: none; stroke: #fff; stroke-width: 3; stroke-dasharray: 6 6; pointer-events: none; }
.hint-wire {
  fill: none; stroke: var(--sig-on); stroke-width: 3; stroke-dasharray: 4 8; stroke-linecap: round;
  opacity: .9; pointer-events: none; animation: flow .8s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -24; } }

.sig-label { pointer-events: none; }
.sig-label rect { fill: var(--board); stroke-width: 1.5; }
.sig-label text { font-size: 11px; font-weight: 800; text-anchor: middle; }
.wire.on .sig-label rect { stroke: var(--sig-on); }
.wire.on .sig-label text { fill: var(--sig-on); }
.wire.off .sig-label rect { stroke: var(--sig-off); }
.wire.off .sig-label text { fill: #c3cad4; }
body.labels-off .sig-label { display: none; }

/* Anschlüsse: leuchten, wenn man dort etwas tun kann */
.port-dot { fill: #fff; stroke: #11161d; stroke-width: 2; pointer-events: none; }
.port-ring { fill: none; stroke-width: 3; opacity: 0; pointer-events: none; }
.port-hit { fill: transparent; cursor: crosshair; }
.port.hint .port-ring { stroke: var(--sig-on); animation: blink 1s ease-in-out infinite; }
.port.hint .port-dot { fill: #ffe6a6; }
.port.target .port-ring { stroke: var(--target); opacity: 1; }
.port.target .port-dot { fill: var(--target); }
.port.pending .port-ring { stroke: var(--sig-on); animation: blink .7s ease-in-out infinite; }
.port.pending .port-dot { fill: var(--sig-on); }
@keyframes blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.gate-body { fill: #e9eef5; stroke: #11161d; stroke-width: 2.5; cursor: grab; }
.gate.dragging .gate-body { cursor: grabbing; fill: #fff; }
.gate.selected .gate-body { stroke: #7ee8fa; stroke-width: 3.5; }
.gate.removing { opacity: .45; }
.gate.removing .gate-body { stroke: var(--bad); stroke-dasharray: 6 4; }
.gate-label { text-anchor: middle; fill: var(--ink); pointer-events: none; }
.gate-term { font-size: 14px; font-weight: 800; fill: var(--accent); }

/* ---------- Buttons ---------- */
.bench-actions { display: flex; justify-content: center; margin-top: 12px; }
.btn {
  font: inherit; font-weight: 800; font-size: 1.1rem;
  min-height: 52px; padding: 10px 22px;
  border: none; border-radius: 14px; cursor: pointer;
}
.btn.primary { background: var(--run); color: #fff; box-shadow: 0 4px 0 var(--run-dark); }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--run-dark); }
.btn.secondary { background: #fff; color: var(--ink); border: 2px solid var(--ink); }
.success-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn:disabled { opacity: .45; cursor: not-allowed; animation: none; }
.btn:focus-visible, .palette-btn:focus-visible, .truth tr:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
#run-btn { width: 100%; max-width: 320px; }

/* ---------- Testszene ---------- */
.scene { display: block; width: 100%; height: auto; border-radius: 12px; overflow: hidden; }
.sky { fill: #8ecdf2; transition: fill .3s; }
.scene.night .sky { fill: #1d2747; }
.sun { fill: #ffd23f; transition: opacity .3s; }
.scene.night .sun { opacity: 0; }
.moon, .stars { opacity: 0; transition: opacity .3s; }
.scene.night .moon, .scene.night .stars { opacity: 1; }
.stars circle { fill: #fff; }
.night-shade { fill: #0b1430; opacity: 0; transition: opacity .3s; pointer-events: none; }
.scene.night .night-shade { opacity: .38; }
.ground { fill: #7bb662; }
.road { fill: #c9a66b; }
.wall { fill: #b0aaa0; stroke: #6d675e; stroke-width: 2; }
.stone { fill: none; stroke: #8c867c; stroke-width: 1.5; }
.gate-hole { fill: #2b2420; }
.portcullis { transition: transform .3s ease-in-out; }
.portcullis path { fill: none; stroke: #4a4540; stroke-width: 3; }
.scene.gate-open .portcullis { transform: translateY(-62px); }

.guard .tunic { fill: #b23a48; }
.skin { fill: #e8be94; }
.helmet { fill: #8d99ae; }
.spear { stroke: #5c4033; stroke-width: 2.5; }
.leg, .arm { stroke: #2b2f3a; stroke-width: 3; stroke-linecap: round; fill: none; }
.coat { fill: #4c7a5a; }
.hair { fill: #5a3b22; }
.pass rect { fill: #fff3b0; stroke: #8a6d1a; stroke-width: 1; }
.pass path { stroke: #8a6d1a; stroke-width: 1; }
.pass { transition: opacity .2s; }

#visitor { transition: transform .7s ease-out, opacity .4s ease; }
.visitor .leg { transform-box: fill-box; transform-origin: top center; }
.scene.walking .leg-l { animation: swing .16s ease-in-out infinite alternate; }
.scene.walking .leg-r { animation: swing .16s ease-in-out infinite alternate-reverse; }
@keyframes swing { from { transform: rotate(-20deg); } to { transform: rotate(20deg); } }

.speech { opacity: 0; transition: opacity .15s; }
.speech.show { opacity: 1; }
.speech rect, .speech path { fill: #fff; stroke: var(--ink); stroke-width: 1.5; }
.speech text { font-size: 11px; font-weight: 800; text-anchor: middle; fill: var(--ink); }

/* ---------- Szene Level 2: Wachturm ---------- */
.turm .post { fill: #6b4a2f; }
.turm .roof { fill: #8a3b2e; stroke: #5c2a20; stroke-width: 1.5; }
.turm .sign path { stroke: #6b4a2f; stroke-width: 3; }
.turm .sign rect { fill: #d9b77e; stroke: #6b4a2f; stroke-width: 1.5; }
.turm .sign text { font-size: 8px; font-weight: 800; text-anchor: middle; fill: #4a3320; }
.watchman .tunic { fill: #3a6ea5; }
.bell path { fill: #e0a526; stroke: #8a6212; stroke-width: 1.5; }
.bell circle { fill: #8a6212; }
.bell { transform-box: fill-box; transform-origin: 50% 0; }
.turm.ringing .bell { animation: bell-swing .22s ease-in-out infinite alternate; }
@keyframes bell-swing { from { transform: rotate(-24deg); } to { transform: rotate(24deg); } }
.waves path { fill: none; stroke: #e0a526; stroke-width: 2; stroke-linecap: round; }
.waves { opacity: 0; transition: opacity .15s; }
.turm.ringing .waves { opacity: 1; animation: blink .44s ease-in-out infinite; }
.enemy { transition: transform .7s ease-out, opacity .3s ease; }
.enemy .cloak { fill: #5b3a6b; }
.goblin { fill: #7fae5a; }
.enemy .eye { fill: #d1495b; }

/* ---------- Prüfliste ---------- */
.table-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.progress { font-size: .85rem; font-weight: 700; color: var(--muted); }
.sub { margin: 4px 0 0; font-size: .85rem; color: var(--muted); }
.truth {
  width: 100%; margin-top: 6px;
  border-collapse: separate; border-spacing: 0 5px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.truth th { font-size: .82rem; color: var(--muted); font-weight: 700; padding: 2px 4px; }
.truth td {
  padding: 3px 4px; background: #f1ebdf; font-weight: 800;
  border-top: 3px solid transparent; border-bottom: 3px solid transparent;
  transition: background .2s;
}
.truth td:first-child { border-radius: 8px 0 0 8px; border-left: 3px solid transparent; }
.truth td:last-child { border-radius: 0 8px 8px 0; border-right: 3px solid transparent; }
.truth tbody tr { cursor: pointer; }
.truth tbody tr.locked { cursor: default; }
.truth tbody tr:not(.locked):hover td { background: #e9e1d1; }
.truth tr.current td { border-color: var(--accent); }
.truth tr.ok td, .truth tr.ok:hover td { background: var(--ok-bg); color: var(--ok); }
.truth tr.bad td, .truth tr.bad:hover td { background: var(--bad-bg); color: var(--bad); }
.truth .got { color: var(--muted); }
.truth tr.ok .got, .truth tr.bad .got { color: inherit; }

/* ---------- Sprachwechsel (oben rechts am Rand) ---------- */
.lang-switch {
  position: absolute; top: 8px; right: 8px; z-index: 12;
  display: flex; gap: 2px; padding: 3px;
  background: #fff; border: 2px solid var(--line); border-radius: 999px;
  box-shadow: 0 3px 10px rgba(20, 24, 34, .12);
}
.lang-btn {
  width: 42px; height: 34px; padding: 0; display: grid; place-items: center;
  background: none; border: 2px solid transparent; border-radius: 999px; cursor: pointer;
  opacity: .5; transition: opacity .15s, background .15s;
}
.lang-btn svg { width: 26px; height: 17px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .2); }
.lang-btn:hover { opacity: .85; }
.lang-btn[aria-pressed="true"] { opacity: 1; background: #e6eef8; border-color: var(--accent); }
.lang-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
/* Platz für den Umschalter in der Kopfzeile des Spiels */
.app .top { padding-right: 104px; }

/* ---------- Auftragsbrief ---------- */
.briefing-open {
  margin-left: auto; font: inherit; font-size: .85rem; font-weight: 700;
  color: var(--accent); background: none; border: 2px solid var(--accent);
  border-radius: 999px; padding: 4px 12px; min-height: 34px; cursor: pointer;
}
.briefing-overlay { align-items: flex-start; overflow-y: auto; padding: 24px 16px; }
.briefing-card {
  width: 100%; max-width: 540px; margin: auto;
  background: var(--panel); border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
  animation: letter-in .4s ease-out;
}
@keyframes letter-in { from { opacity: 0; transform: translateY(24px) rotate(-1deg); } to { opacity: 1; transform: none; } }
.briefing-head {
  display: flex; gap: 12px; align-items: center;
  background: var(--accent); color: #fff; padding: 14px 18px;
}
.briefing-icon { width: 44px; height: 44px; flex: none; }
.briefing-meta { font-size: .85rem; line-height: 1.4; }
.briefing-kicker { font-weight: 800; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; opacity: .9; }
.meta-label { opacity: .75; }
.briefing-content { padding: 16px 20px 20px; }
.briefing-content h2 { font-size: 1.25rem; margin: 0 0 8px; }
.briefing-content h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
#briefing-text p { margin: 0 0 8px; }
.briefing-task {
  margin: 14px 0; padding: 10px 14px;
  background: #fff3dc; border-left: 5px solid var(--sig-on); border-radius: 8px;
}
.briefing-task p { margin: 0; font-weight: 700; font-size: 1.05rem; }
.briefing-tools ul { margin: 0 0 16px; padding-left: 20px; }
.briefing-tools li { margin-bottom: 3px; }
#briefing-start { width: 100%; }

/* ---------- Erfolg ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(20, 24, 34, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.success-card {
  background: var(--panel); border-radius: 20px; padding: 22px;
  width: 100%; max-width: 420px; text-align: center;
  max-height: calc(100vh - 32px); overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.success-card h2 { margin: 8px 0 6px; font-size: 1.4rem; }
.lesson {
  background: #e6eef8; border: 2px solid var(--accent); border-radius: 12px;
  padding: 10px 12px; font-weight: 600;
}

/* ---------- Tablet (Zwei Spalten, Werkbank breiter) ---------- */
@media (min-width: 700px) and (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
  .palette-title { display: none; }
}

/* ---------- Hauptmenü ---------- */
/* Am Desktop passt alles auf einen Bildschirm; auf dem Handy wird normal gescrollt. */
.menu { max-width: 1120px; margin: 0 auto; padding: 18px 16px 12px; }
.hero { display: grid; gap: 18px 32px; align-items: center; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) { .hero { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); } }
.hero-kicker {
  margin: 0 0 4px; font-weight: 800; font-size: .8rem; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent);
}
.hero-title { margin: 0; font-size: clamp(2.2rem, 6vw, 3.3rem); line-height: 1.05; letter-spacing: -.02em; }
.hero-lead { font-size: 1.05rem; color: #3b4050; margin: 10px 0 16px; max-width: 34em; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn.big { font-size: 1.2rem; min-height: 56px; padding: 12px 30px; }
.btn.small { font-size: .95rem; min-height: 44px; padding: 8px 16px; }
@media (min-width: 820px) { .only-sm { display: none; } }

.mini-steps { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-weight: 700; }
.mini-steps li { display: flex; align-items: center; gap: 6px; }
.mini-steps b {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--run); color: #fff; font-size: .8rem;
}
.facts { list-style: none; padding: 0; margin: 10px 0 0; display: flex; gap: 4px 16px; flex-wrap: wrap; color: var(--muted); font-weight: 600; font-size: .88rem; }

.hero-visual { position: relative; max-width: 440px; width: 100%; justify-self: center; }
.hero-art { display: block; width: 100%; height: auto; border-radius: 18px; box-shadow: 0 16px 36px rgba(38, 52, 69, .28); }
.hero-bit { display: flex; gap: 8px; align-items: flex-end; margin: -24px 8px 0 auto; max-width: 320px; position: relative; }
.hero-bit .bit-avatar { width: 52px; height: 52px; }
.hero-bubble {
  position: relative; margin: 0 0 4px; padding: 8px 12px;
  background: #fff; border: 2.5px solid var(--accent); border-radius: 14px;
  font-size: .88rem; font-weight: 600; line-height: 1.35;
  box-shadow: 0 8px 20px rgba(20, 24, 34, .14);
}

.menu-grid { display: grid; gap: 16px; margin-top: 18px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) { .menu-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.menu-panel { background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; }
.menu-panel h2 { font-size: 1.1rem; margin: 0 0 10px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.badge-count { font-weight: 700; font-size: .85rem; color: var(--muted); }

/* Level als kompakte Zeilen */
.level-list { display: grid; gap: 8px; }
.level-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px;
}
.level-card.open { border-color: var(--accent); box-shadow: 0 4px 14px rgba(58, 110, 165, .15); }
.level-card.locked { opacity: .6; }
.level-card.upcoming { display: block; border-style: dashed; background: transparent; color: var(--muted); font-size: .9rem; }
.level-meta { font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.level-card.solved .level-status { color: var(--ok); }
.level-card.open .level-status { color: var(--accent); }
.level-card h3 { margin: 0; font-size: 1.05rem; }
.level-card h3 small { font-size: .8rem; color: var(--muted); font-weight: 700; }
.level-card p { margin: 0; font-size: .88rem; color: var(--muted); line-height: 1.3; }
.level-gate { width: 54px; height: 48px; flex: none; background: #e6eef8; border: 2px solid #c9d7ea; border-radius: 10px; padding: 5px; }
.level-gate svg { width: 100%; height: 100%; }
.locked-note { font-size: .8rem; font-weight: 700; color: var(--muted); text-align: right; max-width: 90px; }

/* Abzeichen */
.badge-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.badge { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 12px; }
.badge.earned { background: #fff7e0; }
.medal {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.25rem; font-weight: 900;
  background: radial-gradient(circle at 35% 30%, #ffe08a, #ffb000 70%);
  border: 3px solid #c98a00; color: #5a3d00; box-shadow: 0 3px 0 #c98a00;
}
.medal svg { width: 30px; height: 30px; }
.badge.locked .medal { background: #e4e0d8; border-color: #c9c3b8; box-shadow: none; filter: grayscale(1); opacity: .55; }
.badge-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.badge-text strong { font-size: .92rem; }
.badge-text span { font-size: .8rem; color: var(--muted); }
.badge.locked .badge-text strong { color: var(--muted); }
.cert-btn { margin-top: 12px; }
.badge-grid .cert-btn { margin: 0; align-self: center; justify-self: start; }
@keyframes medal-pop { 0% { transform: scale(.3) rotate(-30deg); opacity: 0; } 70% { transform: scale(1.15) rotate(6deg); } 100% { transform: none; opacity: 1; } }

.menu-footer {
  margin-top: 14px; padding-top: 10px; border-top: 2px solid var(--line);
  display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap;
  color: var(--muted); font-size: .8rem;
}
.link-btn { font: inherit; color: var(--accent); background: none; border: none; padding: 0; cursor: pointer; text-decoration: underline; }

/* Neue Abzeichen im Erfolgsbildschirm */
.new-badges { margin: 12px 0 4px; padding: 10px; border-radius: 12px; background: #fff7e0; text-align: left; }
.new-badges h3 { margin: 0 0 6px; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: #8a6212; text-align: center; }
.new-badges .badge { padding: 4px 0; }
.new-badges .medal { animation: medal-pop .6s ease-out both; }
.new-badges .badge:nth-child(3) .medal { animation-delay: .15s; }
.new-badges .badge:nth-child(4) .medal { animation-delay: .3s; }
.new-badges .badge:nth-child(5) .medal { animation-delay: .45s; }

/* Urkunde */
.cert-overlay { z-index: 20; align-items: flex-start; overflow-y: auto; }
.cert-card {
  width: 100%; max-width: 760px; margin: auto;
  background: var(--panel); border-radius: 20px; padding: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.cert-card h2 { margin: 0 0 10px; font-size: 1.3rem; }
.cert-label { display: block; font-weight: 700; margin-bottom: 4px; }
.cert-input {
  width: 100%; font: inherit; font-size: 1.1rem; padding: 10px 12px; min-height: 48px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
}
.cert-input:focus { outline: none; border-color: var(--accent); }
.cert-hint { margin: 4px 0 12px; font-size: .82rem; color: var(--muted); }
#cert-canvas { display: block; width: 100%; height: auto; border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, .15); margin-bottom: 14px; }

/* Rückweg ins Menü aus dem Spiel */
.home-link { color: inherit; text-decoration: none; }
.home-link:hover { color: var(--accent); }
.menu-link { display: inline-block; margin-top: 12px; color: var(--accent); font-weight: 600; }

/* ---------- Handy ---------- */
@media (max-width: 599px) {
  .app { gap: 8px; padding-top: 8px; }
  .top { flex-wrap: nowrap; }
  .top { gap: 8px; }
  h1 { font-size: 1.05rem; white-space: nowrap; }
  .level-name { font-size: .7rem; padding: 2px 8px; white-space: nowrap; }
  .panel { padding: 8px; }
  .scene-panel { padding: 5px; }
  .bit-card { gap: 8px; }
  .bit-avatar { width: 34px; height: 34px; }
  .bubble { font-size: .85rem; line-height: 1.35; padding: 7px 10px; }
  .bubble::before { top: 12px; }
  .job { font-size: .8rem; margin-bottom: 4px; }
  .bit-line { min-height: calc(1.35em * 5); }   /* feste Höhe, damit die Werkbank nicht springt */
  .palette { margin-bottom: 8px; }
  .palette-title { display: none; }
  .hide-sm { display: none; }
  .briefing-open { padding: 4px 10px; flex: none; }
  .lang-switch { top: 6px; right: 6px; }
  .lang-btn { width: 36px; height: 30px; }
  .lang-btn svg { width: 22px; height: 15px; }
  .app .top { padding-right: 84px; }
  .menu { padding-top: 50px; }   /* Platz für den Sprachwechsel oben rechts */
  .briefing-overlay { padding: 12px 10px; }
  .palette-btn { min-height: 46px; padding-right: 10px; }
  .palette-btn svg { width: 34px; height: 34px; }
  .bench-actions { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
