@font-face {
  font-family: "mdi";
  src: url("/fonts/mdi.ttf") format("truetype");
  font-display: block;
}

:root {
  --bg: #0b0e13;
  --panel: #12161d;
  --panel-2: #181d26;
  --line: #262c37;
  --text: #e6e9ee;
  --muted: #8a93a1;
  --accent: #4f9cf9;
  --accent-2: #2f7de0;
  --ok: #52c470;
  --warn: #f5a23c;
  --bad: #ec5454;
  --sel: #4f9cf9;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; margin: 0; }
.mdi { font-family: "mdi"; font-style: normal; font-weight: normal; line-height: 1; display: inline-block; }

button, select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
button { padding: 6px 12px; cursor: pointer; }
button:hover { border-color: #3a4352; background: #1e2430; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent); }
button.ghost { background: transparent; border-color: transparent; }
button.danger { color: var(--bad); }
.icon-btn { padding: 5px 8px; font-size: 16px; }
.icon-btn .mdi { font-size: 18px; vertical-align: -3px; }
select, input { padding: 5px 7px; }
input[type="color"] { padding: 1px; width: 34px; height: 28px; cursor: pointer; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

/* Login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 30%, #172030, var(--bg) 70%); }
.login-box { width: min(340px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 12px; text-align: center; }
.login-box h1 { margin: 4px 0 0; font-size: 20px; }
.login-box p { margin: 0; }
.login-mark { font-size: 40px; color: var(--accent); }
.login-box input { padding: 10px 12px; }
.login-box button { padding: 10px; }

/* Kopfzeile */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.brand .mdi { color: var(--accent); font-size: 20px; }
.tools, .actions, .status { display: flex; align-items: center; gap: 6px; }
.status { flex: 1; justify-content: center; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.chk, .color-inline { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.chip { padding: 3px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: #24502f; }
.chip.warn { color: var(--warn); border-color: #5a3d17; }
.chip.bad { color: var(--bad); border-color: #5a2222; }
#publish.pending::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #fff; margin-left: 7px; vertical-align: 1px; }

/* Arbeitsfläche */
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px 1fr 330px; }
.panel { background: var(--panel); overflow-y: auto; padding: 12px; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
.panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 0 8px; }
.panel h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; margin-left: 4px; }
.palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 16px; }
.palette button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; font-size: 11px; }
.palette .mdi { font-size: 20px; color: var(--accent); }

.layers { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.layers li { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.layers li:hover { background: var(--panel-2); }
.layers li.selected { background: #1a2638; border-color: #2c4a70; }
.layers .mdi { color: var(--muted); font-size: 16px; width: 18px; text-align: center; }
.layers .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layers .warn { color: var(--warn); }
.layers .mini { padding: 0 5px; font-size: 13px; background: transparent; border-color: transparent; color: var(--muted); }
.layers .mini:hover { color: var(--text); background: var(--panel-2); }

.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; background:
  linear-gradient(45deg, #0e1218 25%, transparent 25%, transparent 75%, #0e1218 75%) 0 0 / 24px 24px,
  linear-gradient(45deg, #0e1218 25%, transparent 25%, transparent 75%, #0e1218 75%) 12px 12px / 24px 24px, #0b0e13; }
#stage-wrap { flex: 1; overflow: auto; display: grid; place-items: center; padding: 24px; }
#stage { position: relative; box-shadow: 0 0 0 1px #2a3140, 0 18px 50px rgba(0,0,0,.55); border-radius: 3px; background: #000; }
#preview { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; user-select: none; }
#grid { position: absolute; inset: 0; pointer-events: none; opacity: .18; }
#overlay { position: absolute; inset: 0; touch-action: none; }
.box { position: absolute; border: 1px dashed transparent; cursor: move; }
.box:hover { border-color: rgba(79,156,249,.55); }
.box.selected { border: 1px solid var(--sel); box-shadow: 0 0 0 1px rgba(0,0,0,.6); }
.box.invalid { border: 1px dashed var(--warn); background: rgba(245,162,60,.08); }
.handle { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid var(--sel); border-radius: 2px; }
.handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle.e { right: -6px; top: calc(50% - 5px); cursor: ew-resize; }
.handle.s { bottom: -6px; left: calc(50% - 5px); cursor: ns-resize; }
.handle.pt { border-radius: 50%; cursor: crosshair; margin: -6px 0 0 -6px; }
.hint { padding: 6px 14px 10px; color: var(--muted); font-size: 12px; text-align: center; }
.banner { margin: 10px 16px 0; padding: 8px 12px; border-radius: var(--radius); background: #3a1d1d; border: 1px solid #6b2a2a; color: #ffb4b4; }

/* Eigenschaften */
.props-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.props-head .mdi { font-size: 22px; color: var(--accent); }
.props-head h3 { margin: 0; font-size: 15px; flex: 1; }
.group { border-top: 1px solid var(--line); padding: 10px 0 6px; }
.group > .gtitle { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.row { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; margin-bottom: 7px; }
.row > label { color: var(--muted); }
.row .inline { display: flex; gap: 6px; align-items: center; min-width: 0; }
.row input[type="text"], .row input[type="number"], .row select { width: 100%; min-width: 0; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pair label { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.pair input { width: 100%; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 4px 9px; background: transparent; }
.seg button.on { background: #22324a; color: #fff; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid #00000066; padding: 0; cursor: pointer; }
.swatch.none { background: linear-gradient(135deg, transparent 45%, var(--bad) 45%, var(--bad) 55%, transparent 55%), var(--panel-2); }
.pick { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; overflow: hidden; }
.pick .mdi { font-size: 18px; }
.pick .sub { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .txt { overflow: hidden; min-width: 0; }
.pick .main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table { display: grid; gap: 5px; }
.trow { display: grid; gap: 5px; align-items: center; }
.trow.th { grid-template-columns: 74px 1fr 34px 28px; }
.trow.st { grid-template-columns: 1fr 1fr 34px 28px; }
.trow.st.withicon { grid-template-columns: 1fr 1fr 34px 34px 28px; }
.trow input { min-width: 0; width: 100%; }
.trow .icon-cell { padding: 2px; font-size: 18px; }
.small-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.small-btns button { padding: 4px 9px; font-size: 12px; }
.empty-props { color: var(--muted); padding: 12px 4px; line-height: 1.6; }
.empty-props .mdi { font-size: 28px; color: #3a4352; display: block; margin-bottom: 6px; }
.note { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.note.warn { color: var(--warn); }

/* Dialoge */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20; }
.modal-box { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 64px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.modal-head { display: flex; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; flex: 1; font-size: 15px; }
#modal-body { padding: 12px 14px; overflow: auto; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.search { width: 100%; padding: 8px 10px; }
.list { display: grid; gap: 2px; overflow: auto; max-height: 55vh; }
.list button { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; text-align: left; border-color: transparent; background: transparent; }
.list button:hover { background: var(--panel-2); border-color: var(--line); }
.list .id { color: var(--muted); font-size: 11px; grid-column: 1; }
.list .val { grid-row: 1 / span 2; grid-column: 2; align-self: center; color: var(--muted); }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 4px; overflow: auto; max-height: 55vh; }
.icon-grid button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px; font-size: 10px; color: var(--muted); border-color: transparent; background: transparent; overflow: hidden; }
.icon-grid button .mdi { font-size: 26px; color: var(--text); }
.icon-grid button:hover { background: var(--panel-2); border-color: var(--line); }
.icon-grid span.name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist { display: grid; gap: 6px; }
.hist .item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.hist .item .v { font-weight: 700; width: 40px; }
.hist .item .t { flex: 1; color: var(--muted); }
.hist img { width: 160px; border-radius: 4px; border: 1px solid var(--line); align-self: center; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1d2a3d; border: 1px solid #2f4a70; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); z-index: 30; max-width: calc(100vw - 32px); }
.toast.bad { background: #3a1d1d; border-color: #6b2a2a; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 210px 1fr 300px; }
  .status { order: 5; flex-basis: 100%; justify-content: flex-start; }
}
@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; grid-auto-rows: auto; overflow-y: auto; }
  .panel.left, .panel.right { border: 0; border-top: 1px solid var(--line); }
  .center { min-height: 70vh; }
}
