:root {
  --bg: #0c0a1f;
  --bg2: #141130;
  --panel: #19163a;
  --panel2: #211d4a;
  --line: rgba(160, 150, 255, .16);
  --ink: #ece9ff;
  --dim: #a39fc9;
  --primary: #8b5cf6;
  --accent: #22d3ee;
  --pink: #f472b6;
  --ok: #4ade80;
  --bad: #f87171;
  --gold: #fbbf24;
  --r: 14px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(1200px 600px at 80% -10%, rgba(139, 92, 246, .18), transparent), var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
code, .code { font-family: 'Cascadia Mono', Consolas, monospace; font-size: 13px; background: rgba(255,255,255,.06); padding: 2px 6px; border-radius: 6px; }
pre.code { padding: 14px; overflow: auto; white-space: pre-wrap; }
h1 { font-size: 26px; margin: 0 0 18px; letter-spacing: -.3px; }
h2 { font-size: 17px; margin: 18px 0 12px; color: #d8d2ff; }
h2:first-child { margin-top: 0; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; }
.muted { color: var(--dim); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

.app { display: flex; min-height: 100vh; }
.side { width: 230px; flex: 0 0 230px; background: rgba(10, 8, 28, .7); border-right: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-size: 20px; font-weight: 800; padding: 0 10px 18px; letter-spacing: -.3px; }
.brand.big { font-size: 28px; padding: 0 0 16px; text-align: center; }
.brand-star { color: var(--accent); text-shadow: 0 0 12px var(--accent); }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--dim); text-decoration: none; padding: 9px 12px; border-radius: 10px; font-weight: 500; }
.side nav a:hover { background: rgba(255,255,255,.05); color: var(--ink); }
.side nav a.active { background: linear-gradient(90deg, rgba(139, 92, 246, .35), rgba(34, 211, 238, .12)); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.side nav a.logout { margin-top: 16px; color: #fca5a5; }
.nav-toggle { display: none; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1400px; }

.card { background: linear-gradient(180deg, var(--panel), rgba(25, 22, 58, .85)); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 22px; margin-bottom: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.grid2.top { align-items: start; }
.grid3 > .card, .grid4 > .card, .grid2 > .card { margin-bottom: 0; }
.grid2 + .card, .grid3 + .grid4 { margin-top: 18px; }
.full { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }

.form label, label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--dim); font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-weight: 500; font-size: 14px; }
input, select, textarea { font: inherit; color: var(--ink); background: rgba(8, 6, 24, .6); border: 1px solid rgba(160, 150, 255, .25); border-radius: 10px; padding: 9px 12px; outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
input[type=color] { padding: 2px; height: 40px; }
input[type=range] { padding: 0; accent-color: var(--accent); background: none; border: none; }
input[readonly] { opacity: .7; }
textarea { resize: vertical; }
.row input, .row select { width: auto; }
.row input.grow { width: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; cursor: pointer; color: var(--ink); background: rgba(255,255,255,.07); border: 1px solid rgba(160, 150, 255, .25); padding: 9px 16px; border-radius: 10px; text-decoration: none; transition: background .15s, transform .1s; white-space: nowrap; }
.btn:hover { background: rgba(255,255,255,.12); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--primary), #6d28d9); border-color: transparent; box-shadow: 0 6px 18px rgba(139, 92, 246, .35); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: #fecaca; border-color: rgba(248, 113, 113, .4); background: rgba(127, 29, 29, .25); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.done { background: rgba(74, 222, 128, .25) !important; border-color: var(--ok) !important; }
.btn:disabled { opacity: .6; cursor: wait; }
.inline { display: inline; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; }
.alert.ok { background: rgba(74, 222, 128, .1); border-color: rgba(74, 222, 128, .4); color: #bbf7d0; }
.alert.err { background: rgba(248, 113, 113, .1); border-color: rgba(248, 113, 113, .4); color: #fecaca; }

.table-wrap { overflow-x: auto; border-radius: var(--r); border: 1px solid var(--line); }
.table { width: 100%; border-collapse: collapse; background: rgba(20, 17, 48, .6); }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .8px; color: var(--dim); background: rgba(255,255,255,.03); }
.table th a { color: var(--dim); }
.table tr:hover td { background: rgba(255,255,255,.025); }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions form { display: inline; }
.av { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.pill { font: inherit; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; cursor: pointer; border: 1px solid; }
.pill.on { background: rgba(74, 222, 128, .15); color: var(--ok); border-color: rgba(74, 222, 128, .4); }
.pill.off { background: rgba(255,255,255,.05); color: var(--dim); border-color: var(--line); }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .row { margin: 0; }
.pager { justify-content: center; }
details summary { cursor: pointer; font-weight: 600; color: #d8d2ff; }
details[open] summary { margin-bottom: 12px; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; position: sticky; top: 0; z-index: 5; padding: 8px 0; background: var(--bg); }
.tabs a { padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.05); border: 1px solid var(--line); text-decoration: none; color: var(--dim); font-size: 13px; font-weight: 600; }
.tabs a:hover { color: #fff; }
.steps { padding-left: 22px; }
.steps li { margin: 8px 0; }

/* Dashboard */
.stat-label { color: var(--dim); font-size: 13px; text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
.stat-value { font-size: 26px; font-weight: 800; margin: 6px 0 2px; }
.stat-value.small { font-size: 20px; }
.stat-value.ok { color: var(--ok); }
.stat-value.bad { color: var(--bad); }
.card.mini { padding: 14px 18px; display: flex; flex-direction: column; }
.card.mini span { color: var(--dim); font-size: 13px; }
.card.mini b { font-size: 22px; }
.log { max-height: 420px; overflow-y: auto; font-size: 14px; }
.log-row { display: grid; grid-template-columns: 80px 26px 180px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.log-row .lt { color: var(--dim); font-family: Consolas, monospace; font-size: 12px; padding-top: 2px; }
.log-row .lu { color: #c4b5fd; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-row.t-geschenk .lx { color: var(--gold); }
.log-row.t-bridge .lx { color: var(--dim); }

/* Orakel */
.oracle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin-bottom: 18px; }
.oracle-card { padding: 0; overflow: hidden; margin: 0; }
.oracle-card.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 30px rgba(34, 211, 238, .25); }
.oc-preview { background: radial-gradient(circle at 50% 40%, #2a1e66, #0b0826); aspect-ratio: 3 / 4; }
.oc-preview canvas { width: 100%; height: 100%; display: block; }
.oc-3d { height: 100%; display: grid; place-items: center; font-size: 54px; font-weight: 800; color: rgba(255,255,255,.25); }
.oc-body { padding: 14px 16px; }
.oc-name { font-weight: 800; font-size: 18px; }
.badge { font-size: 11px; font-weight: 800; background: var(--accent); color: #06202a; padding: 2px 8px; border-radius: 999px; vertical-align: 3px; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 18px; align-items: start; }
.editor-side { position: sticky; top: 16px; }
.preview-box { position: relative; margin: 10px auto; border-radius: 14px; overflow: hidden; background: radial-gradient(circle at 50% 35%, #2a1e66, #0b0826 70%); border: 1px solid var(--line); }
.preview-box.p { width: 360px; height: 640px; }
.preview-box.l { width: 360px; height: 202.5px; }
.pv-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
.mouth-handle { position: absolute; border: 2px dashed var(--pink); border-radius: 50%; cursor: move; z-index: 5; box-shadow: 0 0 0 9999px rgba(0,0,0,0); touch-action: none; }
.mouth-handle:hover { background: rgba(244, 114, 182, .12); }
.inline-range { flex-direction: row; align-items: center; gap: 8px; }
.inline-range input { width: 140px; }
.upload { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px dashed rgba(160, 150, 255, .35); border-radius: 12px; }
.upload span { font-weight: 600; color: var(--dim); font-size: 13px; }
.upload img { max-width: 100%; max-height: 220px; object-fit: contain; border-radius: 8px; background: #0b0826; }
.upload.inline-up { flex-direction: row; align-items: center; flex-wrap: wrap; }
.upload.inline-up input { width: auto; }
.slot-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.slot-tabs .tab { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--dim); cursor: pointer; }
.slot-tabs .tab span { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: rgba(255,255,255,.1); font-size: 11px; }
.slot-tabs .tab.active { background: linear-gradient(90deg, rgba(139, 92, 246, .45), rgba(34, 211, 238, .2)); color: #fff; border-color: var(--accent); }
.sheet-wrap { overflow: auto; border-radius: 10px; border: 1px solid var(--line); background: #000; }
#sheetCanvas { width: 100%; display: block; cursor: crosshair; touch-action: none; }
.frame-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.frame-item { position: relative; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; }
.frame-item.sel { border-color: var(--gold); }
.frame-item canvas { display: block; }
.frame-item .btn { position: absolute; top: 4px; right: 4px; padding: 1px 7px; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-box.wide { max-width: 520px; }
.login-box h3 { margin: 10px 0 0; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .grid4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .side { width: auto; flex: none; height: auto; position: static; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .brand { padding: 0; }
  .nav-toggle { display: inline-flex; font: inherit; color: var(--ink); background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; }
  .side nav { display: none; width: 100%; margin-top: 10px; }
  body.nav-open .side nav { display: flex; }
  .main { padding: 18px 16px 40px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .log-row { grid-template-columns: 64px 22px 1fr; }
  .log-row .lx { grid-column: 1 / -1; }
  .preview-box.p { width: 300px; height: 533px; }
  .row.nowrap { flex-wrap: wrap; }
}
