/* Ton-Zentrale – Eisblau-Palette wie die Gameshow, Poppins lokal (keine Google-Server). */
@font-face { font-family: 'Poppins'; font-weight: 400; font-display: swap; src: url('/fonts/poppins-400.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-weight: 600; font-display: swap; src: url('/fonts/poppins-600.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-weight: 700; font-display: swap; src: url('/fonts/poppins-700.woff2') format('woff2'); }

:root {
  color-scheme: light;
  --bg: #d6effa;
  --bg-pattern: rgba(255, 255, 255, 0.35);
  --surface: #fbfdff;
  --surface-soft: #eef8fd;
  --surface-strong: #d6effa;
  --text: #1d3550;
  --heading: #213c5c;
  --muted: #42607c;
  --line: #9cc3dc;
  --field-border: #4a6584;
  --primary: #236fa0;
  --primary-hover: #1d5c85;
  --on-primary: #ffffff;
  --accent: #5bb6e3;
  --gold: #f2bf43;
  --success: #1d7550;
  --success-soft: #e3f6ec;
  --danger: #b5352f;
  --danger-soft: #fdeaea;
  --focus: #0b4f86;
  --wave: #3a95c8;
  --wave-dim: #a9cfe4;
  --select: rgba(91, 182, 227, 0.22);
  --shadow: 0 1px 2px rgba(33, 60, 92, 0.12), 0 6px 20px rgba(33, 60, 92, 0.1);
  --radius: 16px;
  --pad: 6px;
  --font: 'Poppins', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0f1d2c;
    --bg-pattern: rgba(255, 255, 255, 0.03);
    --surface: #172a3e;
    --surface-soft: #1d3349;
    --surface-strong: #24405b;
    --text: #e4f1fa;
    --heading: #f5fbfe;
    --muted: #a9c3d8;
    --line: #34536f;
    --field-border: #7f9db8;
    --primary: #86cdef;
    --primary-hover: #b3e0f5;
    --on-primary: #0f1d2c;
    --accent: #5bb6e3;
    --success: #7fd8aa;
    --success-soft: #173b2c;
    --danger: #ff9b94;
    --danger-soft: #42201f;
    --focus: #f2bf43;
    --wave: #86cdef;
    --wave-dim: #3c5d79;
    --select: rgba(134, 205, 239, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0f1d2c; --bg-pattern: rgba(255, 255, 255, 0.03); --surface: #172a3e; --surface-soft: #1d3349; --surface-strong: #24405b;
  --text: #e4f1fa; --heading: #f5fbfe; --muted: #a9c3d8; --line: #34536f; --field-border: #7f9db8; --primary: #86cdef; --primary-hover: #b3e0f5;
  --on-primary: #0f1d2c; --success: #7fd8aa; --success-soft: #173b2c; --danger: #ff9b94; --danger-soft: #42201f; --focus: #f2bf43;
  --wave: #86cdef; --wave-dim: #3c5d79; --select: rgba(134, 205, 239, 0.16); --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scrollbar-gutter: stable; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 400 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
}
h1, h2, h3 { color: var(--heading); margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

:is(button, a[href], input, select, textarea, summary, [tabindex]:not([tabindex='-1'])):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

.app { max-width: 1100px; margin: 0 auto; padding: 16px 16px 64px; }

/* Kopf mit Reitern */
.top { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 32px; height: 32px; flex: none; }
.top-actions { margin-left: auto; display: flex; gap: 8px; }
.tabs {
  display: flex; gap: 4px; padding: var(--pad); margin: 0 0 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  flex-wrap: wrap;
}
.tab {
  flex: none; min-height: 40px; padding: 8px 14px; border: 0; background: transparent; cursor: pointer;
  border-radius: calc(var(--radius) - var(--pad) - 1px); font-weight: 600; color: var(--muted); white-space: nowrap;
}
.tab[aria-selected='true'] { background: var(--primary); color: var(--on-primary); }
@media (hover: hover) { .tab:not([aria-selected='true']):hover { background: var(--surface-soft); color: var(--text); } }

/* Knöpfe */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  border: 1.5px solid var(--field-border); background: var(--surface); font-weight: 600; line-height: 1.2;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: var(--surface); }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 14px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }
@media (hover: hover) {
  .btn:not(:disabled):hover { background: var(--surface-soft); }
  .btn.primary:not(:disabled):hover { background: var(--primary-hover); border-color: var(--primary-hover); }
  .btn.danger.solid:not(:disabled):hover { filter: brightness(1.08); background: var(--danger); }
}
.btn.playing { background: var(--surface-strong); }

/* Karten und Gruppen */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section { margin-bottom: 20px; }
.section-head { display: flex; align-items: baseline; gap: 8px 12px; flex-wrap: wrap; margin: 0 4px 8px; }
.section-head .muted { font-size: 14px; }
.muted { color: var(--muted); }
.intro { margin: 0 4px 16px; color: var(--muted); max-width: 70ch; }

/* Zeilen (randlose Liste in der Karte) */
.rows { list-style: none; margin: 0; padding: 0; overflow: hidden; border-radius: var(--radius); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-main { min-width: 0; }
.row-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.row-title h3 { min-width: 0; overflow-wrap: anywhere; }
.row-hint { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 720px) {
  .row { grid-template-columns: minmax(0, 1fr); }
  .row-actions { justify-content: flex-start; }
}

/* Status-Plaketten: Farbe plus Symbol plus Text */
.chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--line); background: var(--surface-soft); color: var(--muted); }
.chip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.own { background: var(--success-soft); color: var(--success); border-color: currentColor; }
.chip.inherit { background: var(--surface-strong); color: var(--text); }
.chip svg { width: 13px; height: 13px; flex: none; }

/* Anmeldung */
.login { max-width: 400px; margin: 12vh auto 0; padding: 24px; display: grid; gap: 16px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--field-border);
  background: var(--surface); min-width: 0;
}
.input::placeholder { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; font-weight: 600; }
.error:empty { display: none; }

/* Hochladen */
.drop {
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; padding: 16px; margin-bottom: 16px;
  border: 2px dashed var(--field-border); border-radius: var(--radius); background: var(--surface);
}
.drop.over { border-style: solid; border-color: var(--primary); background: var(--surface-soft); }
.drop p { flex: 1 1 260px; min-width: 0; }
.quota { margin: 0 4px 16px; font-size: 13px; color: var(--muted); }
.meter { height: 6px; border-radius: 999px; background: var(--surface-strong); overflow: hidden; margin-top: 4px; max-width: 320px; }
.meter i { display: block; height: 100%; background: var(--primary); }

.empty { padding: 24px 16px; text-align: center; display: grid; gap: 12px; justify-items: center; }

/* Dialog (Zuschnitt, Löschen, Umbenennen) */
dialog {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
dialog.narrow { width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 25, 40, 0.55); }
/* Dialoge öffnen ohne Animation: man öffnet sie sehr oft (UI-Regel P28). */
.dialog-body { padding: 20px; display: grid; gap: 16px; overflow-y: auto; max-height: calc(100dvh - 32px - 72px); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); }
.dialog-head { display: grid; gap: 4px; }

.choice { display: flex; flex-wrap: wrap; gap: 8px; border: 0; padding: 0; margin: 0; min-width: 0; }
.choice legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
.choice label {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px; border-radius: 999px;
  border: 1.5px solid var(--field-border); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.choice label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.choice input { width: 16px; height: 16px; margin: 0; accent-color: var(--on-primary); }
.choice label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

.file-pick { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.file-pick .field { flex: 1 1 240px; }

/* Wellenform mit Griffen */
.wave-wrap { display: grid; gap: 6px; }
.wave {
  position: relative; height: 140px; border-radius: 12px; background: var(--surface-soft); border: 1px solid var(--line);
  touch-action: none; user-select: none;
}
/* Griffe dürfen über den Rand ragen, damit sie auch bei 0 % und 100 % ganz greifbar sind. */
.wave canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; }
.wave .sel { position: absolute; top: 0; bottom: 0; background: var(--select); pointer-events: none; }
.wave .playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger); pointer-events: none; display: none; }
.handle {
  position: absolute; top: 0; bottom: 0; width: 24px; margin-left: -12px; cursor: ew-resize; display: flex; justify-content: center;
  background: transparent; border: 0; padding: 0;
}
.handle::before { content: ''; width: 3px; height: 100%; background: var(--primary); border-radius: 2px; }
.handle::after {
  content: ''; position: absolute; top: 50%; width: 14px; height: 28px; margin-top: -14px; border-radius: 7px;
  background: var(--primary); border: 2px solid var(--surface);
}
.handle:focus-visible { outline: none; }
.handle:focus-visible::after { outline: 3px solid var(--focus); outline-offset: 1px; }
.wave-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.wave-loading { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 8px; text-align: center; border-radius: inherit; background: var(--surface-soft); color: var(--muted); font-size: 14px; }

.grid-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.num { font-variant-numeric: tabular-nums; }
.range-field input[type='range'] { width: 100%; min-height: 32px; accent-color: var(--primary); }
.range-line { display: flex; justify-content: space-between; gap: 8px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.note { font-size: 13px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100vw - 32px);
  padding: 10px 18px; border-radius: 999px; background: var(--heading); color: var(--bg); font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity 160ms ease-out; z-index: 10;
}
.toast.show { opacity: 1; }
.toast.bad { background: var(--danger); color: #fff; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (pointer: coarse) {
  .btn, .btn.small, .tab, .choice label, .input, select.input { min-height: 44px; }
  .input, select.input { font-size: 16px; }
  .handle { width: 44px; margin-left: -22px; }
}

.stack { display: grid; gap: 16px; min-width: 0; }
.range-label { font-size: 13px; font-weight: 600; color: var(--muted); }
