:root {
  --bg: #0c0e13;
  --bg-stage: #08090c;
  --panel: #12151c;
  --panel-2: #181c25;
  --line: #232835;
  --line-2: #2e3442;
  --text: #e8eaf0;
  --muted: #8d94a5;
  --faint: #5b6273;
  --accent: #7c6cff;
  --accent-2: #9d90ff;
  --accent-soft: rgba(124, 108, 255, .14);
  --ok: #3ddc97;
  --warn: #ffb547;
  --err: #ff5c7a;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 3px 5px; border-radius: 5px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted);
}
[hidden] { display: none !important; }

/* Kopfzeile */
.top {
  height: 56px; flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #b27cff); display: grid; place-items: center; }
.logo svg { width: 20px; height: 20px; fill: #fff; stroke: none; }
.name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.tag { color: var(--muted); font-size: 13px; padding-left: 10px; border-left: 1px solid var(--line-2); white-space: nowrap; }
.actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--panel-2);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s, transform .05s;
}
.btn:hover:not(:disabled) { background: #20252f; border-color: #3a4253; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn.icon { width: 36px; padding: 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.big { height: 46px; font-size: 15px; width: 100%; border-radius: 11px; }
.btn.small { height: 30px; font-size: 12.5px; padding: 0 10px; margin-top: 10px; width: 100%; }
.btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: 300px; flex: none; overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 0;
}
.group { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h2 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; border-radius: 11px; background: var(--bg); border: 1px solid var(--line); }
.seg button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 2px 6px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 11.5px; cursor: pointer;
}
.seg button:hover { color: var(--text); background: var(--panel-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent-2); box-shadow: inset 0 0 0 1px rgba(124,108,255,.35); }

.slider { display: block; margin-top: 14px; }
.slider > span { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.slider b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 20px; margin: 0; }

.modes { display: grid; gap: 8px; }
.mode input { position: absolute; opacity: 0; pointer-events: none; }
.mode .card { display: block; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; transition: border-color .15s, background .15s; }
.mode .card:hover { border-color: var(--line-2); }
.mode input:checked + .card { border-color: var(--accent); background: var(--accent-soft); }
.mode input:focus-visible + .card { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.mh { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.mh svg { width: 16px; height: 16px; color: var(--accent-2); }
.md { display: block; color: var(--muted); font-size: 12.5px; margin-top: 3px; padding-left: 24px; }

.model { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.mrow { display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(61,220,151,.15); }
.dot.load { background: var(--warn); animation: pulse 1s infinite alternate; }
.dot.err { background: var(--err); }
@keyframes pulse { to { opacity: .35; } }
.bar { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #b27cff); transition: width .15s; }

details summary { cursor: pointer; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); list-style: none; display: flex; align-items: center; gap: 6px; }
details summary::before { content: "▸"; transition: transform .15s; }
details[open] summary::before { transform: rotate(90deg); }
details summary::-webkit-details-marker { display: none; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--faint); }

.run { display: grid; gap: 8px; }
.btn.detect { height: 40px; width: 100%; border-color: rgba(124,108,255,.45); color: var(--accent-2); background: var(--accent-soft); font-weight: 600; }
.btn.detect:hover:not(:disabled) { background: rgba(124,108,255,.22); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 13px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.foot { color: var(--faint); font-size: 12px; }
.privacy { display: flex; gap: 8px; margin: 0 0 12px; color: var(--muted); }
.privacy svg { width: 15px; height: 15px; margin-top: 1px; color: var(--ok); }
.keys { margin: 0; line-height: 2.1; }
.keys kbd { margin-right: 2px; }

/* Bühne */
.stage {
  position: relative; flex: 1; min-width: 0; overflow: hidden;
  background-color: var(--bg-stage);
  background-image: radial-gradient(circle at 1px 1px, #1a1e27 1px, transparent 0);
  background-size: 22px 22px;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.board { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 0 0 1px rgba(255,255,255,.06), var(--shadow); background: repeating-conic-gradient(#2a2e38 0% 25%, #1f222a 0% 50%) 0 0 / 16px 16px; }
.board canvas { position: absolute; left: 0; top: 0; display: block; }
.board.pixel canvas { image-rendering: pixelated; }
#maskView { opacity: .55; }
.board.comparing #maskView { display: none; }

.stage.nopointer { cursor: none; }
.stage.loaded.t-rect { cursor: crosshair; }
.stage.loaded.t-pan, .stage.panning { cursor: grab; }
.zoombar { cursor: default; }
.stage.panning:active { cursor: grabbing; }

.cursor {
  position: absolute; left: 0; top: 0; pointer-events: none; border-radius: 50%;
  border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.4);
  transform: translate(-50%, -50%);
}
.cursor.eraser { border-style: dashed; }
.rectsel { position: absolute; pointer-events: none; border: 1.5px dashed #fff; background: rgba(255, 61, 113, .3); box-shadow: 0 0 0 1px rgba(0,0,0,.5); }

.drop { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; }
.dropcard {
  width: min(520px, 100%); text-align: center; padding: 40px 32px;
  border: 1.5px dashed var(--line-2); border-radius: 20px; background: rgba(18, 21, 28, .85);
  transition: border-color .15s, background .15s;
}
.stage.dragover .dropcard { border-color: var(--accent); background: rgba(124, 108, 255, .08); }
.stage.dragover .board { opacity: .4; }
.dropicon { width: 56px; height: 56px; margin: 0 auto 18px; border-radius: 16px; background: var(--accent-soft); color: var(--accent-2); display: grid; place-items: center; }
.dropicon svg { width: 26px; height: 26px; }
.dropcard h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: -.02em; }
.dropcard p { margin: 0 0 18px; color: var(--muted); }
.dropcard .btn { height: 42px; padding: 0 22px; }
.steps { list-style: none; padding: 0; margin: 28px 0 0; display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.steps li { display: flex; align-items: center; gap: 8px; }
.steps b { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text); }
.dropcard .small { margin: 18px 0 0; font-size: 12px; color: var(--faint); }

.zoombar {
  position: absolute; right: 16px; bottom: 16px; display: flex; align-items: center; gap: 2px;
  padding: 4px; border-radius: 11px; background: rgba(18, 21, 28, .92); border: 1px solid var(--line); box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.zoombar span { min-width: 52px; text-align: center; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.zoombar .btn.icon { width: 32px; height: 32px; }

.badge { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); padding: 6px 12px; border-radius: 999px; background: rgba(18,21,28,.92); border: 1px solid var(--line-2); font-size: 12.5px; font-weight: 600; }

.busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 9, 12, .55); backdrop-filter: blur(2px); z-index: 5; }
.busycard { width: min(340px, calc(100% - 32px)); padding: 24px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line-2); box-shadow: var(--shadow); text-align: center; }
.spinner { width: 34px; height: 34px; margin: 0 auto 14px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btext { font-weight: 600; }
.bsub { margin-top: 6px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  padding: 10px 16px; border-radius: 10px; background: #1f2430; border: 1px solid var(--line-2); box-shadow: var(--shadow);
  font-size: 13.5px; max-width: calc(100% - 32px);
  animation: tin .2s ease-out;
}
.toast.err { border-color: rgba(255, 92, 122, .5); }
@keyframes tin { from { opacity: 0; transform: translate(-50%, 8px); } }

/* Mobil */
@media (max-width: 820px) {
  .tag, .actions .btn span, .sep { display: none; }
  .actions .btn:not(.icon) { width: 36px; padding: 0; }
  .top { padding: 0 10px; }
  .layout { flex-direction: column-reverse; }
  .panel {
    width: auto; max-height: 46vh; border-right: 0; border-top: 1px solid var(--line);
    display: grid; grid-template-columns: 1fr; padding: 0;
  }
  .group { padding: 12px 16px; }
  .run { grid-template-columns: 1fr 1fr; order: -1; position: sticky; top: 0; background: var(--panel); z-index: 2; }
  .run .btn.big { height: 42px; grid-column: 1 / -1; order: -1; }
  .run .btn.ghost, .run .btn.detect { height: 40px; }
  .foot .keys { display: none; }
  .dropcard { padding: 28px 18px; }
  .dropcard h1 { font-size: 20px; }
  .zoombar { right: 10px; bottom: 10px; }
}
