:root {
  --bg: #0a0d11;
  --panel: #10141a;
  --panel-2: #161b23;
  --line: #232a34;
  --line-2: #2f3844;
  --text: #dde3ea;
  --muted: #8791a0;
  --faint: #5d6674;
  --accent: #38bdf8;
  --lumen: #fae652;
  --eem: #00c763;
  --user: #ff7ab6;
  --radius: 8px;
  color-scheme: dark;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

/* top bar */
.topbar {
  flex: none; display: flex; align-items: center; gap: 16px;
  height: 44px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.logo {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--accent);
  box-shadow: inset 0 0 0 3px var(--panel), inset 0 0 0 6px var(--accent);
}
.exam-title { flex: 1; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.load { display: flex; align-items: center; gap: 10px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.load-bar { width: 140px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.load-bar > div { width: 0; height: 100%; background: var(--accent); transition: width .2s linear; }
.load-bar.done > div { background: var(--eem); }

/* layout */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 272px minmax(0, 1fr) 300px; }
.sidebar { min-height: 0; overflow-y: auto; background: var(--panel); }
.sidebar.left { border-right: 1px solid var(--line); }
.sidebar.right { border-left: 1px solid var(--line); }
.sidebar section { padding: 14px; border-bottom: 1px solid var(--line); }
h2 { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.h2-sub { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); }
.muted { margin: 0; color: var(--muted); }
.hint { margin: 10px 0 0; font-size: 11.5px; line-height: 1.45; color: var(--faint); }

/* exams */
.exam-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.exam {
  width: 100%; display: grid; gap: 3px; padding: 9px 10px; text-align: left; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.exam:hover { border-color: var(--line-2); }
.exam.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, var(--panel-2)); }
.exam-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.exam-name { font-weight: 600; }
.tag { padding: 1px 7px; border-radius: 99px; background: var(--line-2); font-size: 11px; font-weight: 600; }
.exam-sub { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.meta { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 12px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* bookmarks */
.bookmarks { display: grid; gap: 8px; }
.bm { display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 10px; }
.bm-thumb {
  padding: 0; overflow: hidden; cursor: zoom-in; aspect-ratio: 1030 / 924;
  background: #000; border: 1px solid var(--line); border-radius: 6px;
}
.bm-thumb:hover { border-color: var(--accent); }
.bm-thumb canvas { display: block; width: 100%; height: 100%; }
.bm-jump { display: grid; gap: 2px; padding: 4px 0; text-align: left; cursor: pointer; background: none; border: 0; }
.bm-jump b { color: var(--accent); }
.bm-jump span { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bm-jump:hover b { text-decoration: underline; }

/* stage */
.stage { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #000; }
.cross { position: relative; flex: 1; min-height: 220px; }
.long { position: relative; flex: none; height: 30%; min-height: 150px; max-height: 300px; }
.cross canvas, .long canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }
.cross canvas.tool-pan { cursor: grab; }
.cross canvas.tool-line, .cross canvas.tool-poly { cursor: crosshair; }
.cross canvas.handle { cursor: move; }
.cross canvas.grabbing { cursor: grabbing; }
.long canvas { cursor: ew-resize; }

.toolbar {
  position: absolute; right: 12px; bottom: 12px; display: flex; gap: 3px; padding: 4px;
  background: rgba(16, 20, 26, .86); border: 1px solid var(--line); border-radius: 10px; backdrop-filter: blur(6px);
}
.toolbar button, .transport button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; min-width: 30px; padding: 0 8px; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
}
.toolbar button:hover, .transport button:hover { background: var(--panel-2); }
.toolbar button.active {
  color: #fff; background: color-mix(in srgb, var(--accent) 20%, transparent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}
svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
svg.stroke { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
kbd {
  padding: 0 4px; font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted);
  border: 1px solid var(--line-2); border-radius: 3px;
}

.transport {
  flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 6px 10px;
  background: var(--panel); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.transport .play { width: 38px; color: #03131c; background: var(--accent); }
.transport .play:hover { background: #7dd3fc; }
.play .i-pause, .play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
#frameSlider { flex: 1; min-width: 140px; margin: 0 8px; }
.frame-label { min-width: 160px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { accent-color: var(--accent); }
select { padding: 4px 6px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; }
.check { display: inline-flex; align-items: center; gap: 6px; margin-left: 6px; color: var(--muted); cursor: pointer; user-select: none; }
.check input { margin: 0; accent-color: var(--accent); }

/* tables & lists */
table.data { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.data th { padding: 4px; text-align: right; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--line); }
.data td { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; }
.data th:first-child, .data td:first-child { text-align: left; }
.data tr:hover td { background: var(--panel-2); }
.data tr.current td { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.data .lumen { color: var(--lumen); }
.data .eem { color: var(--eem); }
.badge { margin-left: 4px; padding: 0 4px; font-size: 9.5px; font-weight: 600; color: #111; background: var(--lumen); border-radius: 3px; vertical-align: 1px; }
.bm-label { margin-left: 5px; font-size: 10.5px; color: var(--accent); }

.user-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.user-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel-2); border-radius: 6px; font-variant-numeric: tabular-nums; }
.user-list .txt { flex: 1; }
.swatch { width: 8px; height: 8px; flex: none; border-radius: 2px; background: var(--user); }
.icon-btn { padding: 0 4px; font-size: 16px; line-height: 1; color: var(--muted); background: none; border: 0; cursor: pointer; }
.icon-btn:hover { color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.chip { padding: 2px 8px; font-size: 11.5px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; cursor: pointer; }
.chip:hover { color: var(--text); border-color: var(--line-2); }
.btn { padding: 5px 10px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.row-actions { display: flex; gap: 6px; margin-top: 10px; }

.control { display: grid; grid-template-columns: 70px 1fr 40px; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 12px; }
.control label { color: var(--muted); }
.control output { text-align: right; font-variant-numeric: tabular-nums; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.checks .check { margin: 0; }

details summary { cursor: pointer; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 5px 10px; margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.keys dt { text-align: right; white-space: nowrap; }
.keys dd { margin: 0; }

/* dialog */
dialog {
  width: 100%; max-width: min(96vw, 1100px); padding: 0; color: var(--text);
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px;
}
dialog::backdrop { background: rgba(0, 0, 0, .72); }
dialog form { margin: 0; }
.dialog-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { flex: 1; margin: 0; font-size: 14px; }
#dialogCanvas { display: block; width: 100%; height: auto; background: #000; }

/* welcome / local files */
.stage { position: relative; }
.btn-open { white-space: nowrap; }
.welcome {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 50% 38%, #0f1b26 0%, #000 72%);
}
.welcome[hidden] { display: none; }
.welcome-card { max-width: 470px; display: grid; justify-items: center; gap: 12px; text-align: center; }
.welcome h1 { margin: 4px 0 0; font-size: 22px; }
.welcome p { margin: 0; line-height: 1.5; color: var(--muted); }
.welcome-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.welcome .drop-hint { font-size: 12px; }
.welcome .privacy { font-size: 12px; color: var(--faint); }
.welcome .status { min-height: 1.5em; color: var(--text); font-variant-numeric: tabular-nums; }
.btn.primary { font-weight: 600; color: #03131c; background: var(--accent); border-color: var(--accent); }
.btn.primary:hover { background: #7dd3fc; }
.logo.big { width: 44px; height: 44px; border-width: 3px; box-shadow: inset 0 0 0 7px #0b131b, inset 0 0 0 13px var(--accent); }
body.dropping .stage::after {
  content: 'Loslassen zum Öffnen'; position: absolute; inset: 10px; z-index: 6; display: grid; place-items: center;
  font-size: 16px; font-weight: 600; color: var(--accent); pointer-events: none;
  background: rgba(56, 189, 248, .08); border: 2px dashed var(--accent); border-radius: 12px;
}

@media (max-width: 1180px) {
  body { overflow: auto; height: auto; }
  .layout { grid-template-columns: 250px minmax(0, 1fr); }
  .stage { height: calc(100vh - 44px); min-height: 560px; }
  .sidebar.right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .stage { order: -1; height: 88vh; }
  .sidebar.left { border-right: 0; }
  .load-bar { width: 70px; }
  .frame-label { min-width: 0; }
}
