:root {
  --navy: #13204d;
  --navy-deep: #0b1433;
  --surface: #17244f;
  --surface-2: #1d2b5c;
  --orange: #f26b2f;
  --orange-hover: #ff7d42;
  --text: #f4f5fa;
  --muted: #aab2cf;
  --border: rgba(255, 255, 255, 0.12);
  --velocity: #3d8bff;
  --acceleration: #ff4d4d;
  --force: #2fd16b;
  --chart-text: #aab2cf;
  --chart-grid: rgba(255, 255, 255, 0.08);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-height: 100vh; }
[hidden] { display: none !important; }

body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%) fixed;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

/* Kopfzeile */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 20, 51, 0.6);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand img { border-radius: 7px; }
.file-name { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Knöpfe */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn:hover { border-color: rgba(255, 255, 255, 0.3); }
.btn:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.btn.small { padding: 6px 11px; font-size: 0.88rem; }
.btn.icon { width: 34px; padding: 6px 0; font-size: 1rem; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--orange-hover); }
.btn.ghost { background: transparent; }
.btn.active { border-color: var(--orange); color: var(--orange); }
.btn:disabled { opacity: 0.45; cursor: default; }

/* Startseite */
.screen { flex: 1 0 auto; }
.start {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 16px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 56px 24px;
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone svg { color: var(--orange); margin-bottom: 8px; }
.dropzone strong { font-size: 1.25rem; }
.dropzone span, .dropzone small { color: var(--muted); }
.dropzone small { margin-top: 8px; }
.dropzone:hover, .dropzone.over { border-color: var(--orange); background: rgba(242, 107, 47, 0.08); }
/* Mediathek */
.library { display: flex; flex-direction: column; gap: 12px; }
.library header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.library h2 { font-size: 1rem; margin: 0; }
.library-list { display: flex; flex-direction: column; gap: 10px; }
.samples-list { display: grid; grid-template-columns: repeat(5, minmax(0, 170px)); gap: 10px; }
.sample-card {
  display: flex; flex-direction: column; gap: 6px; padding: 0 0 8px; border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; background: rgba(255, 255, 255, 0.04); color: inherit; font: inherit; cursor: pointer; text-align: center;
}
.sample-card img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: block; background: #000; }
.sample-card strong { font-size: 0.9rem; padding: 0 6px; }
.sample-card:hover { border-color: var(--orange); }
.sample-card:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.lib-card {
  display: grid; grid-template-columns: 120px minmax(0, 1fr) auto; align-items: center; gap: 14px;
  padding: 10px; border-radius: 14px; border: 1px solid var(--border); background: rgba(255, 255, 255, 0.04);
}
.lib-open { padding: 0; border: 0; border-radius: 10px; overflow: hidden; cursor: pointer; background: #000; aspect-ratio: 4 / 3; width: 120px; }
.lib-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-open:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.lib-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.lib-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-meta { color: var(--muted); font-size: 0.85rem; }
.lib-summary { color: var(--orange); font-size: 0.88rem; font-weight: 600; }
.lib-actions { display: flex; flex-direction: column; gap: 4px; }
.btn.danger { color: #ff8a8a; }
@media (max-width: 520px) {
  .lib-card { grid-template-columns: 96px minmax(0, 1fr); }
  .lib-open { width: 96px; }
  .lib-actions { grid-column: 1 / -1; flex-direction: row; justify-content: flex-end; }
  .samples-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.tips h2 { font-size: 1rem; margin: 0 0 10px; }
.tips ul { margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.7; }
.tips b { color: var(--text); font-weight: 600; }
.legal-links { margin-top: auto; display: flex; justify-content: center; gap: 16px; font-size: 0.82rem; }
.legal-links a { color: var(--muted); text-decoration: none; }
.legal-links a:hover { color: var(--text); text-decoration: underline; }
.warning { color: #ffd66b; background: rgba(255, 196, 0, 0.1); border: 1px solid rgba(255, 196, 0, 0.35); border-radius: 12px; padding: 12px 16px; margin: 0; line-height: 1.45; }
.warning b { color: #ffe08f; }
.error { color: #ff8a8a; background: rgba(255, 77, 77, 0.1); border: 1px solid rgba(255, 77, 77, 0.3); border-radius: 12px; padding: 12px 16px; margin: 0; }

/* Einlesen */
.loading { display: flex; align-items: center; justify-content: center; padding: 16px; }
.progress-card { width: min(420px, 100%); text-align: center; }
.progress-card p { margin: 0 0 14px; font-weight: 600; }
.progress-card small { display: block; margin-top: 10px; color: var(--muted); }
.progress { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--orange); border-radius: 4px; transition: width 0.2s; }

/* Auswertung */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 14px 16px 16px; gap: 10px; }
.panel {
  border-left: 1px solid var(--border);
  background: rgba(11, 20, 51, 0.45);
  overflow-y: auto;
  padding: 14px 14px 24px;
  max-height: calc(100vh - 53px);
  position: sticky;
  top: 53px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.expert { display: flex; flex-direction: column; gap: 20px; }

/* Einstellungen gruppiert wie in der App */
.group { display: flex; flex-direction: column; gap: 6px; }
.group h3 { margin: 0; padding: 0 12px; font-size: 0.76rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.list { background: rgba(255, 255, 255, 0.055); border-radius: 12px; overflow: hidden; }
.list > :not([hidden]) ~ :not([hidden]) { border-top: 1px solid rgba(255, 255, 255, 0.08); }
.item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 0; border-radius: 0; background: transparent; text-align: left;
  font-size: 0.92rem; cursor: pointer;
}
div.item { cursor: default; }
button.item:hover { background: rgba(255, 255, 255, 0.04); }
button.item:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }
.item .label { flex: 1; min-width: 0; }
.item:has(#slowmo) .label { flex: 1 0 auto; }
#slowmo { min-width: 0; }
.item .value { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .unit { color: var(--muted); }
.item select { width: auto; max-width: 55%; background: transparent; border: 0; color: var(--muted); padding: 2px 0; text-align: right; cursor: pointer; }
.item input[type=number] { width: 90px; text-align: right; }
.item.slider .label { flex: none; }
.item.slider input[type=range] { flex: 1; }
.item.slider output { min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.item.action { color: var(--orange); }
.item.danger { color: #ff8a8a; }
.chev { color: var(--muted); opacity: 0.7; font-size: 1.2rem; line-height: 1; transition: transform 0.15s; }
#expert-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.v { color: var(--velocity); }
.ico.a { color: var(--acceleration); }
.ico.f { color: var(--force); }
.footer { margin: 0; padding: 0 12px; font-size: 0.8rem; color: var(--muted); line-height: 1.4; }

/* Schalter */
.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 42px; height: 26px; border-radius: 13px; position: relative; cursor: pointer;
  background: rgba(255, 255, 255, 0.2); transition: background-color 0.15s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); transition: transform 0.15s;
}
.switch:checked { background: var(--orange); }
.switch:checked::after { transform: translateX(16px); }
.switch:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

.tabs { display: flex; gap: 4px; background: rgba(255, 255, 255, 0.06); padding: 4px; border-radius: 12px; align-self: flex-start; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.summary { margin: 0; font-weight: 600; color: var(--orange); min-height: 1.3em; font-variant-numeric: tabular-nums; text-align: center; }

.view { display: flex; flex-direction: column; gap: 10px; min-height: 0; flex: 1; }
.toolbar, .player-actions, .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.tool-hint {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: 10px;
  background: rgba(242, 107, 47, 0.12); border: 1px solid rgba(242, 107, 47, 0.35);
}
.tool-hint > span { flex: 1; min-width: 200px; }
.scale-input { display: inline-flex; align-items: center; gap: 6px; }
.scale-input input[type=number] { width: 90px; }

/* Bedienelemente unter Bild und Video (mittig, wie in der App) */
.controls { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; max-width: 640px; margin: 4px auto 0; }
.controls-title { font-size: 1rem; }
.count-row, .trim-row { display: flex; align-items: center; gap: 12px; width: 100%; }
.count-row input[type=range] { flex: 1; }
.count-row output { min-width: 24px; font-variant-numeric: tabular-nums; }
.trim-row .trim { flex: 1; }
.btn.round { border-radius: 50%; width: 38px; height: 38px; padding: 0; flex: none; }
.btn.continue { width: 100%; max-width: 420px; padding: 11px 14px; font-size: 1rem; }
.btn.link { background: none; border: 0; color: var(--orange); padding: 4px 8px; font-size: 0.9rem; }
.btn.link:hover { text-decoration: underline; }
.pick-row { min-height: 34px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.9rem; }
.replay-row { display: flex; justify-content: flex-end; width: 100%; }
.scale-row { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 40px; flex-wrap: wrap; }
.slowmo-warning { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; font-size: 0.88rem; color: #ffb340; }

.canvas-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 240px;
}
.frame { position: relative; max-width: 100%; line-height: 0; }
.frame > canvas:first-child, .frame > video {
  display: block;
  max-width: 100%;
  max-height: max(200px, calc(100dvh - 290px));
  width: auto;
  height: auto;
}
.tool-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
#tool-canvas { pointer-events: none; }
#tool-canvas.active { pointer-events: auto; cursor: crosshair; }
#video-overlay.picking, #video-overlay.drawing { cursor: crosshair; }
.busy {
  position: absolute; top: 12px; right: 12px;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(11, 20, 51, 0.85); font-size: 0.85rem;
}
.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25); border-top-color: var(--orange);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint { margin: 0; color: var(--muted); }
.muted { color: var(--muted); font-size: 0.88rem; }
.row .muted { flex: 1; min-width: 0; }

/* Felder */
input[type=range] { accent-color: var(--orange); width: 100%; }
input[type=checkbox] { accent-color: var(--orange); }
select, input[type=number] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  width: 100%;
}
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.92rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.note { margin: 0; font-size: 0.82rem; color: var(--muted); line-height: 1.45; }

/* Diagramme */
.chart-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.chart-picker .btn[aria-pressed="true"] { border-color: var(--orange); background: rgba(242, 107, 47, 0.15); }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px; }
.chart-card { background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chart-card header { display: flex; align-items: center; gap: 8px; }
.chart-card h4 { margin: 0; flex: 1; font-size: 0.95rem; }
.chart-card select { width: auto; font-size: 0.82rem; padding: 4px 6px; }
.chart-card canvas { width: 100%; height: 240px; display: block; }
.chart-card canvas.tall { height: 380px; }
.charts.combined { grid-template-columns: 1fr; }
.chart-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.segmented { display: inline-flex; background: rgba(255, 255, 255, 0.06); padding: 3px; border-radius: 10px; }
.segmented button { border: 0; background: transparent; padding: 5px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.legend-item > span { margin-right: 4px; }
.legend-item .btn.icon { width: 26px; height: 26px; padding: 0; }
.factor { border: 0; background: transparent; cursor: pointer; min-width: 40px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.85rem; }
.equations { display: flex; flex-direction: column; gap: 4px; }
.equations .equation { display: flex; align-items: center; gap: 6px; }
.chart-card .equation { margin: 0; font-size: 0.84rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Tabelle */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; max-height: calc(100vh - 230px); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 0.88rem; }
th, td { padding: 6px 12px; text-align: right; border-bottom: 1px solid rgba(255, 255, 255, 0.06); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); font-weight: 600; color: var(--muted); }

/* Hinweis unten */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 16px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4); z-index: 20;
  display: flex; gap: 12px; align-items: center;
}

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .panel { border-left: 0; border-top: 1px solid var(--border); max-height: none; position: static; }
  .frame > canvas:first-child, .frame > video { max-height: 70vh; }
  .charts { grid-template-columns: 1fr; }
}

/* Video: passt mit Zeitleiste und Bedienelementen in die Fensterhöhe */
.video-wrap { min-height: 160px; }
.video-wrap .frame > video { max-height: max(160px, calc(100dvh - 330px)); }
#view-video { gap: 8px; }

/* Zeitleiste mit gelben Griffen (wie in der App) */
.trim {
  --handle: 16px;
  position: relative;
  height: 52px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  user-select: none;
  touch-action: none;
  cursor: pointer;
}
.filmstrip { position: absolute; top: 0; bottom: 0; left: var(--handle); width: calc(100% - 2 * var(--handle)); height: 100%; display: block; }
.trim-shade { position: absolute; top: 0; bottom: 0; background: rgba(0, 0, 0, 0.6); pointer-events: none; }
.trim-frame { position: absolute; top: 0; bottom: 0; border: 3px solid #ffd60a; border-radius: 6px; pointer-events: none; }
.trim-handle {
  position: absolute; top: 0; bottom: 0; width: var(--handle);
  background: #ffd60a; color: rgba(0, 0, 0, 0.7);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; line-height: 1;
  cursor: ew-resize; touch-action: none;
}
.trim-handle.is-start { border-radius: 6px 0 0 6px; }
.trim-handle.is-end { border-radius: 0 6px 6px 0; }
.trim-handle::before { content: ""; position: absolute; inset: -6px -10px; }
.trim-handle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.playhead { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; background: #fff; border-radius: 2px; box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); pointer-events: none; }
.trim-tip {
  position: absolute; bottom: calc(100% + 8px); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; font-size: 0.82rem; white-space: nowrap; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
/* Einrichtung */
.setup-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: 2px 0 6px; border-bottom: 1px solid var(--border);
}
.setup-side { display: flex; gap: 6px; }
.setup-side.end { justify-content: flex-end; }
.setup-title { font-size: 1.05rem; text-align: center; }
.workspace.setup { grid-template-columns: 1fr; }
.workspace.setup .panel, .workspace.setup .tabs { display: none; }
.workspace.setup .stage { max-width: 1100px; width: 100%; margin: 0 auto; }

@media (max-width: 900px) {
  .video-wrap .frame > video { max-height: 55vh; }
}

/* Glättung */
.smoothing { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border); }
.smoothing label { font-weight: 600; font-size: 0.9rem; }
.smoothing input { width: 180px; }
.smoothing output { font-variant-numeric: tabular-nums; font-size: 0.88rem; min-width: 130px; }
.smooth-icon { color: var(--muted); }

/* Rückfrage */
.dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 22px; max-width: min(440px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog h2 { margin: 0 0 10px; font-size: 1.15rem; }
.dialog p { margin: 0 0 10px; line-height: 1.5; }
.dialog-buttons { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }

@media (max-width: 600px) {
  .smoothing input { width: 120px; }
}

/* Zeitlupe: erkannter Abschnitt */
.trim-slow { position: absolute; bottom: 0; height: 4px; background: var(--orange); pointer-events: none; border-radius: 2px; z-index: 1; }
.detected { color: var(--orange); font-weight: 600; }
