/* GateLab -- Tablet-first, hell/dunkel nach Systemeinstellung. Keine externen Ressourcen. */

: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;
}

@media (prefers-color-scheme: dark) {
  :root {
    --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; }

/* ---------------------------------------------------------------- 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;
}

.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); }
.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.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 { --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; }
.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); }
#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; }
}
