:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --line: #dfe5ec;
  --text: #13202f;
  --text-2: #5b6b7d;
  --accent: #2f9ed8;
  --accent-ink: #ffffff;
  --accent-soft: #e3f2fb;
  --danger: #d6455d;
  --warn-bg: #fff4e0;
  --warn-ink: #8a5300;
  --stage: radial-gradient(1200px 600px at 50% 40%, #f9fbfd, #e3e9ef);
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 8px 24px rgba(16, 32, 48, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d141c; --surface: #141d27; --surface-2: #1a2531; --line: #263342; --text: #e6edf4; --text-2: #93a3b5;
    --accent: #4db3e8; --accent-ink: #06121c; --accent-soft: #15334a; --warn-bg: #3a2a10; --warn-ink: #f4c27a;
    --stage: radial-gradient(1200px 600px at 50% 40%, #1b2632, #0b1118); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d141c; --surface: #141d27; --surface-2: #1a2531; --line: #263342; --text: #e6edf4; --text-2: #93a3b5;
  --accent: #4db3e8; --accent-ink: #06121c; --accent-soft: #15334a; --warn-bg: #3a2a10; --warn-ink: #f4c27a;
  --stage: radial-gradient(1200px 600px at 50% 40%, #1b2632, #0b1118); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 'Inter', system-ui, sans-serif; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
.icon-btn svg, .btn svg, .seg svg, .empty-insp svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- Kopfzeile --- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: relative; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; color: var(--accent); text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.brand span { color: var(--text); }
.doc-name { flex: 1 1 160px; min-width: 120px; max-width: 320px; border: 1px solid transparent; background: transparent; padding: 6px 10px; border-radius: 8px; font-weight: 600; }
.doc-name:hover { border-color: var(--line); }
.doc-name:focus { outline: none; border-color: var(--accent); background: var(--surface-2); }
.top-actions { display: flex; gap: 6px; align-items: center; margin-left: auto; flex-wrap: wrap; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.icon-btn { border: 1px solid transparent; background: transparent; width: 34px; height: 34px; border-radius: 8px; display: inline-grid; place-items: center; cursor: pointer; color: var(--text-2); }
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Arbeitsbereich --- */
.workspace { flex: 1; display: grid; grid-template-columns: 320px 1fr 290px; min-height: 0; }
.panel { background: var(--surface); overflow-y: auto; min-height: 0; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); padding: 16px; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); position: sticky; top: 0; background: var(--surface); z-index: 2; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 12px 4px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text-2); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { display: none; padding: 16px; }
.tab-body.active { display: block; }
.tab-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); margin: 20px 0 10px; display: flex; justify-content: space-between; }
.tab-body h3:first-child { margin-top: 0; }
.tab-body h3 small { text-transform: none; letter-spacing: 0; font-weight: 500; }
h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-2); margin: 0 0 8px; }
.hint { color: var(--text-2); font-size: 12.5px; margin: 0 0 12px; }
.warn { background: var(--warn-bg); color: var(--warn-ink); font-size: 12.5px; padding: 8px 10px; border-radius: 8px; margin: 8px 0; }

/* Vorlagen */
.template-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.tpl { border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius); padding: 10px; cursor: pointer; text-align: left; transition: border-color .15s, transform .15s; }
.tpl:hover { border-color: var(--accent); transform: translateY(-1px); }
.tpl.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.tpl span { display: block; font-weight: 600; font-size: 13px; margin-top: 8px; }
.tpl-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tpl-svg svg { width: 100%; height: auto; border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* Daten */
.logo-drop { display: flex; gap: 12px; align-items: center; border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; transition: border-color .15s, background .15s; }
.logo-drop:hover, .logo-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.logo-drop strong { display: block; }
.logo-drop span { display: block; font-size: 12px; color: var(--text-2); }
.logo-drop .private { margin-top: 4px; color: var(--accent); }
.logo-preview { width: 64px; height: 64px; flex: none; border-radius: 10px; background: repeating-conic-gradient(var(--surface-2) 0 25%, var(--surface) 0 50%) 0 0/12px 12px; display: grid; place-items: center; border: 1px solid var(--line); }
.logo-preview img { max-width: 52px; max-height: 52px; }
.logo-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 0; }
.logo-tools[hidden] { display: none; }
.palette-from-logo { margin: 14px 0 0; }
.palette-from-logo:empty { display: none; }
.fields { margin-top: 16px; display: grid; gap: 10px; }

.fld { display: grid; gap: 5px; font-size: 12.5px; color: var(--text-2); }
.fld > span { font-weight: 600; }
.fld.check { grid-template-columns: auto 1fr; align-items: center; }
.fld.check > span { order: 2; }
.fld input:not([type=checkbox]):not([type=range]):not([type=color]), .fld select, .fld textarea, .num input {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; color: var(--text); font-size: 14px;
}
.fld textarea { resize: vertical; font-family: inherit; }
.fld input:focus, .fld select:focus, .fld textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.num { position: relative; }
.num em { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 12px; color: var(--text-2); pointer-events: none; }
.num input { padding-right: 32px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.range input { width: 100%; accent-color: var(--accent); }
.range output { font-size: 12px; min-width: 44px; text-align: right; color: var(--text); }

/* Farben */
.palette-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pal-swatch { display: grid; gap: 4px; justify-items: center; font-size: 11.5px; color: var(--text-2); cursor: pointer; }
.pal-swatch input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0; background: none; cursor: pointer; }
.pal-swatch input::-webkit-color-swatch-wrapper { padding: 3px; }
.pal-swatch input::-webkit-color-swatch { border: 0; border-radius: 7px; }
.pal-swatch input::-moz-color-swatch { border: 0; border-radius: 7px; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.preset { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 9px; padding: 7px 9px; cursor: pointer; font-size: 12.5px; font-weight: 600; text-align: left; }
.preset:hover { border-color: var(--accent); }
.preset .dots { display: flex; }
.preset .dots i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--surface); margin-left: -4px; box-shadow: 0 0 0 1px var(--line); }
.preset .dots i:first-child { margin-left: 0; }
.color-ctl { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.on, .color-ctl input.on { box-shadow: 0 0 0 2px var(--accent); }
.swatch.none { background: linear-gradient(135deg, transparent 45%, var(--danger) 45% 55%, transparent 55%), var(--surface) !important; }
.color-ctl input[type=color] { width: 30px; height: 30px; border: 0; padding: 0; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); border-radius: 50%; cursor: pointer; }
.color-ctl input[type=color]::-webkit-color-swatch-wrapper { padding: 4px; }
.color-ctl input[type=color]::-webkit-color-swatch { border-radius: 50%; border: 2px solid var(--surface); }
.color-ctl input[type=color]::-moz-color-swatch { border-radius: 50%; border: 2px solid var(--surface); }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.small button { padding: 5px 9px; font-size: 12.5px; }
#bgEditor { display: grid; gap: 12px; }
.pattern-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pattern-btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 4px; cursor: pointer; font-size: 11px; color: var(--text-2); display: grid; gap: 3px; }
.pattern-btn svg { width: 100%; height: auto; border-radius: 4px; }
.pattern-btn.on { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 2px var(--accent-soft); }

/* Ebenen */
.add-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.layers { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.layers li { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; background: var(--surface-2); }
.layers li:hover { border-color: var(--accent); }
.layers li.on { border-color: var(--accent); background: var(--accent-soft); }
.ltype { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); min-width: 54px; }
.lname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Bühne --- */
.stage { position: relative; background: var(--stage); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-toolbar { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 14px; flex-wrap: wrap; }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.card-area { flex: 1; display: grid; place-items: center; padding: 20px 40px 30px; perspective: 1800px; min-height: 0; }
.card3d { --ratio: 85 / 55; position: relative; width: min(100%, 720px, calc((100vh - 230px) * 85 / 55)); aspect-ratio: var(--ratio); transform-style: preserve-3d; transition: transform .6s cubic-bezier(.3,.7,.3,1); }
.card3d.flipped { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 1.6%; box-shadow: 0 2px 4px rgba(10,20,30,.12), 0 20px 50px rgba(10,20,30,.22); }
.face.back { transform: rotateY(180deg); }
.face-svg { width: 100%; height: 100%; border-radius: inherit; overflow: hidden; touch-action: none; cursor: default; }
.face-svg [data-id] { cursor: move; }
.face-svg .sel { fill: none; stroke: var(--accent); stroke-width: 1.5px; vector-effect: non-scaling-stroke; stroke-dasharray: 4 3; }
.face-svg .handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5px; vector-effect: non-scaling-stroke; cursor: nwse-resize; }
.face-svg .snap { stroke: #e2366f; stroke-width: 1px; vector-effect: non-scaling-stroke; pointer-events: none; }
.stage-hint { text-align: center; color: var(--text-2); font-size: 12.5px; margin: 0 16px 14px; }

/* --- Inspektor --- */
.empty-insp { color: var(--text-2); text-align: center; padding: 24px 6px; }
.empty-insp svg { width: 34px; height: 34px; margin: 0 auto 10px; stroke-width: 1.4; }
.empty-insp .quick { display: grid; gap: 6px; margin-top: 24px; text-align: left; }
.insp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.insp-head h3 { margin: 0; font-size: 16px; }
.insp-acts { display: flex; }
.insp-group { border-top: 1px solid var(--line); padding: 14px 0; display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px; padding: 2px 9px; font-size: 11.5px; cursor: pointer; color: var(--text-2); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.align-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- Dialoge --- */
.dialog { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.dialog::backdrop { background: rgba(8, 16, 24, .55); backdrop-filter: blur(3px); }
.dialog form { padding: 20px; }
.dialog header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dialog h2 { margin: 0; font-size: 20px; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.export-card { text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 14px; cursor: pointer; display: grid; gap: 4px; }
.export-card:hover:not(:disabled) { border-color: var(--accent); }
.export-card strong { font-size: 15px; }
.export-card span { font-size: 12.5px; color: var(--text-2); }
.export-card:disabled { opacity: .5; cursor: progress; }
.export-status { min-height: 1.4em; color: var(--text-2); margin: 12px 0 0; }
.designs { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.design { display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.design.on { border-color: var(--accent); }
.design-thumb svg { width: 96px; height: auto; border-radius: 3px; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.design-meta { display: grid; min-width: 0; }
.design-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.design-meta span { font-size: 12px; color: var(--text-2); }
.design-acts { display: flex; gap: 4px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* --- Ansicht --- */
.mockup { position: fixed; inset: 0; z-index: 50; background: radial-gradient(900px 600px at 50% 30%, #3b4a58, #141b22 70%); display: grid; place-items: center; overflow: hidden; }
.mockup[hidden] { display: none; }
.mockup::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, rgba(255,255,255,.015) 0 2px, transparent 2px 7px), radial-gradient(circle at 30% 80%, rgba(255,255,255,.06), transparent 50%); pointer-events: none; }
.mockup-close { position: absolute; top: 16px; right: 16px; color: #fff; background: rgba(255,255,255,.1); z-index: 2; }
.mockup-scene { --ratio: 85 / 55; --rx: 0deg; --ry: 0deg; position: relative; width: min(560px, 80vw); aspect-ratio: var(--ratio); perspective: 1400px; transform-style: preserve-3d; cursor: pointer; }
.mock-card { position: absolute; inset: 0; border-radius: 1.6%; overflow: hidden; transition: transform .7s cubic-bezier(.3,.7,.3,1); box-shadow: 0 30px 60px rgba(0,0,0,.5), 0 6px 14px rgba(0,0,0,.35); }
.mock-card svg { width: 100%; height: 100%; }
.front-card { transform: rotateX(calc(18deg + var(--rx))) rotateY(var(--ry)) rotateZ(-6deg) translateZ(30px); }
.back-card { transform: rotateX(calc(18deg + var(--rx))) rotateY(var(--ry)) rotateZ(9deg) translate(16%, 12%); filter: brightness(.92); }
.mockup-scene.flip .front-card { transform: rotateX(calc(18deg + var(--rx))) rotateY(var(--ry)) rotateZ(9deg) translate(16%, 12%); filter: brightness(.92); z-index: 0; }
.mockup-scene.flip .back-card { transform: rotateX(calc(18deg + var(--rx))) rotateY(var(--ry)) rotateZ(-6deg) translateZ(30px); filter: none; z-index: 1; }
.mockup-hint { position: absolute; bottom: 20px; left: 0; right: 0; text-align: center; color: rgba(255,255,255,.6); font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #13202f; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- Schmalere Bildschirme --- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 300px 1fr; }
  .panel.right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  #inspector { max-width: 760px; margin: 0 auto; }
}
@media (max-width: 860px) {
  body { height: auto; }
  .workspace { display: flex; flex-direction: column; }
  .stage { order: -1; min-height: 0; }
  .card-area { padding: 8px 16px 16px; }
  .card3d { width: 100%; }
  .panel.left { border-right: 0; border-top: 1px solid var(--line); }
  .stage-hint { display: none; }
  .top-actions { width: 100%; margin-left: 0; }
  .top-actions .btn.ghost:not(#designsBtn) { display: none; }
  .top-actions .btn.primary { margin-left: auto; }
  .export-grid { grid-template-columns: 1fr; }
}
