@font-face {
  font-family: "Areal UI";
  src: url("fonts/ABCArealSuperfamilyVariable.woff2") format("woff2");
  font-weight: 400 700;
}

/* Zwei Stufen Schriftgröße, zwei Schnitte. Bedienelemente sind Pillen mit feiner Kontur,
   Ausgewähltes wird blau gefüllt. Abschnitte liegen in Squircle-Karten, darin feine Trennlinien. */
:root {
  color-scheme: light;
  --bg: #fff;
  --card: #f4f4f3;
  --line: #d2d2d0;   /* Kontur der Pillen */
  --hair: #e3e3e1;   /* Trennlinien */
  --text: #0c0c0c;
  --dim: #686866;
  --acc: #1536ff;      /* Füllung bei Auswahl */
  --acc-2: #0e28cc;    /* dieselbe, gedrückt/überfahren */
  --acc-ink: #fff;     /* Schrift auf der Füllung */
  --acc-t: #1536ff;    /* Blau als Schrift und Linie */
  --acc-soft: #e3e7ff; /* helle Abstufung: Reglerfüllung, Hauptaktion */
  --acc-mid: #8d9cff;  /* mittlere Abstufung: Kante der Reglerfüllung */
  --rec: #e02a1a;
  --shadow: 0 14px 44px rgba(0, 0, 0, 0.14);
  --s: 12px;
  --l: 19px;
  --ph: 30px;  /* Höhe aller Pillen */
  --r: 18px;   /* Radius der Karten */
  --pad: 16px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111;
  --card: #1b1b1b;
  --line: #3e3e3e;
  --hair: #2c2c2c;
  --text: #f1f1f1;
  --dim: #969696;
  --acc: #2f4dff;
  --acc-2: #4a64ff;
  --acc-ink: #fff;
  --acc-t: #8fa0ff;
  --acc-soft: #1e2657;
  --acc-mid: #4359d6;
  --rec: #ff5a4a;
  --shadow: 0 14px 44px rgba(0, 0, 0, 0.5);
}
/* Echte Squircles, wo der Browser sie kann – sonst gewöhnliche Rundung */
@supports (corner-shape: squircle) {
  :root { --r: 30px; }
  .sec, .pop, #stage, textarea { corner-shape: squircle; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 var(--s)/1.3 "Areal UI", "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template: auto minmax(0, 1fr) 34px / 448px minmax(0, 1fr);
  grid-template-areas: "top top" "side stage" "side status";
  height: var(--app-h, 100%);
}

/* ---------- Kopfzeile ---------- */
#top { grid-area: top; position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 6px; padding: 12px var(--pad); }
.brand { font-weight: 700; flex: none; padding: 0 12px 0 4px; }
.grp { display: flex; gap: 6px; align-items: center; }
.spacer { flex: 1; }
.cap { color: var(--dim); }
#more { display: contents; }
@media (min-width: 761px) {
  .mob { display: none !important; }
  /* feine Trennung zwischen den Gruppen */
  .g-rnd, .g-view, .g-exp, .g-rec, .g-pre { margin-left: 6px; padding-left: 12px; border-left: 1px solid var(--hair); }
  .brk { display: none; }
}
/* Schmales Fenster: zwei saubere Zeilen statt eines zufälligen Umbruchs – Export, Aufnahme und Presets rücken in die zweite */
@media (min-width: 761px) and (max-width: 1400px) {
  .brk { display: block; flex: 0 0 100%; height: 0; }
  .g-exp, .g-pre { margin-left: 0; padding-left: 0; border-left: 0; }
  .g-pre { margin-left: auto; }
}
/* Feiner Balken: Fortschritt der Aufnahme */
#recBar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none; }
#recBar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--rec); }

/* ---------- Bedienelemente: Pillen ---------- */
.btn, .sel, .inp, textarea {
  font: inherit; letter-spacing: inherit; color: var(--text);
  background: none; outline: none; margin: 0;
}
.btn, .sel, .inp {
  height: var(--ph); border: 1px solid var(--line); border-radius: 999px; padding: 0 13px;
}
/* Aktion = Text in voller Farbe (Beschriftungen sind grau) */
.btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--text); }
.btn:active:not(:disabled) { background: var(--acc-soft); }
.btn:disabled { color: var(--dim); border-color: var(--hair); cursor: default; }
.btn:focus-visible, .sel:focus-visible, .inp:focus-visible, .sl:focus-visible { border-color: var(--acc-t); box-shadow: 0 0 0 2px var(--acc-soft); }
/* Schalter: eingeschaltet blau gefüllt */
.btn.tg.on, .btn.tg.on:active { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.btn.tg.on:hover { background: var(--acc-2); border-color: var(--acc-2); }
/* Hauptaktion: helle Abstufung des Blau */
.btn.pri { background: var(--acc-soft); border-color: var(--acc-soft); color: var(--acc-t); }
.btn.pri:hover:not(:disabled) { border-color: var(--acc-t); }
.btn.rec { color: var(--rec); border-color: var(--rec); }

.sel, .inp { min-width: 0; }
.sel {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 30px; text-overflow: ellipsis;
  background:
    linear-gradient(45deg, transparent 50%, var(--text) 50%) right 16px top 50% / 4px 4px no-repeat,
    linear-gradient(-45deg, transparent 50%, var(--text) 50%) right 12px top 50% / 4px 4px no-repeat;
}
.sel:hover, .inp:hover { border-color: var(--text); }
.inp { user-select: text; -webkit-user-select: text; width: 100%; }
.inp::placeholder { color: var(--dim); }
input[type=number].inp { appearance: textfield; -moz-appearance: textfield; }
input[type=number].inp::-webkit-inner-spin-button { display: none; }

/* Aufklappendes Formular unter der Kopfzeile */
.pop {
  position: absolute; z-index: 30; top: calc(100% - 4px); right: var(--pad); width: 344px;
  display: grid; gap: 10px; padding: 18px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
}
.pop h3 { margin: 0; font-size: var(--l); font-weight: 700; line-height: 1.15; letter-spacing: -0.015em; }
.pop p { margin: 0; }
.pop .msg { color: var(--acc-t); }

/* ---------- Seitenleiste ---------- */
#side { grid-area: side; display: flex; flex-direction: column; min-height: 0; }
.textbar { padding: 0 var(--pad) 10px; display: grid; gap: 8px; }
textarea {
  display: block; width: 100%; height: 68px; resize: none; user-select: text; -webkit-user-select: text;
  font-size: var(--l); line-height: 1.2; padding: 11px 14px;
  background: var(--card); border: 1px solid transparent; border-radius: var(--r);
}
textarea::placeholder { color: var(--dim); }
textarea:focus { border-color: var(--acc-t); }
.glyphs .sel { flex: 1; }

/* Reiter: eine Pille als Schiene, die blaue Marke gleitet zur Auswahl */
.tabs {
  position: relative; flex: none; display: flex; margin: 0 var(--pad) 10px; padding: 3px;
  border: 1px solid var(--line); border-radius: 999px;
}
.tab {
  position: relative; z-index: 1; flex: 1 1 auto; height: 30px; padding: 0 6px;
  font: inherit; letter-spacing: inherit; color: var(--dim); white-space: nowrap;
  background: none; border: 0; border-radius: 999px; cursor: pointer; outline: none;
  transition: color 0.18s;
}
.tab:hover, .tab:focus-visible { color: var(--text); }
.tab.on { color: var(--acc-ink); }
.tabs .ind { position: absolute; left: 0; top: 3px; width: 0; height: 30px; border-radius: 999px; background: var(--acc); }
.tabs.live .ind { transition: transform 0.28s cubic-bezier(0.3, 0.8, 0.3, 1), width 0.28s cubic-bezier(0.3, 0.8, 0.3, 1); }

.panes { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.pane:not(.on) { display: none; }
.pane { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--pad) 6px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
/* Abschnitt = Karte */
.sec { display: grid; gap: 8px; margin-bottom: 10px; padding: 16px 16px 18px; background: var(--card); border-radius: var(--r); }
.sec > h3 { margin: 0 0 6px; font-size: var(--l); font-weight: 700; line-height: 1.15; letter-spacing: -0.015em; }
.sec > h3 { cursor: pointer; outline: none; }
.sec > h3 em { font-style: normal; font-weight: 400; color: var(--dim); }
/* Einklappen: Pfeil vor dem Titel, eingeklappt bleibt nur die Titelzeile */
.chev { display: inline-block; width: 7px; height: 7px; margin: 0 11px 4px 2px; border: solid var(--dim); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); transition: transform 0.18s; }
.sec > h3:hover .chev, .sec > h3:focus-visible .chev { border-color: var(--acc-t); }
.sec.shut { padding-bottom: 16px; }
.sec.shut > h3 { margin-bottom: 0; }
.sec.shut > h3 .chev { transform: translate(-2px, 1px) rotate(-45deg); }
.sec.shut > :not(h3) { display: none; }
.sec > h3 em.dirty { color: var(--acc-t); }
.sec > p { margin: 0; }
.row { display: flex; gap: 6px; align-items: center; min-width: 0; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.row > label { color: var(--dim); width: 72px; flex: none; }
.row.tight { flex-wrap: nowrap; }
/* Reihe aus Aktionen: nach Reglern und Auswahlfeldern durch eine feine Linie abgesetzt */
.sec > :not(h3):not(.acts) + .acts { margin-top: 4px; padding-top: 12px; border-top: 1px solid var(--hair); }
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.g2 > .wide { grid-column: 1 / -1; }

/* Regler: eine Pille, die sich blau füllt; Name links, Wert rechts */
.sl {
  position: relative; height: var(--ph); border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
  cursor: ew-resize; outline: none; touch-action: none;
}
.sl:hover { border-color: var(--text); }
.sl i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--acc-soft); border-right: 1px solid var(--acc-mid); pointer-events: none; }
.sl.bi i { border-left: 1px solid var(--acc-mid); }
.sl:hover i, .sl:focus-visible i, .sl.drag i { border-color: var(--acc-t); }
.sl span, .sl b { position: absolute; top: 0; line-height: calc(var(--ph) - 2px); pointer-events: none; white-space: nowrap; }
.sl span { left: 12px; color: var(--dim); }
.sl:hover span, .sl:focus-visible span { color: var(--text); }
.sl b { right: 12px; font-weight: 400; }

/* Farbfelder */
.chips { display: flex; gap: 8px; flex: 1; }
.chip {
  width: 22px; height: 22px; border: 0; border-radius: 50%; cursor: pointer; padding: 0;
  background: none; color: var(--dim); font: inherit; line-height: 22px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.chip.on { outline: 2px solid var(--acc-t); outline-offset: 2px; }
.pal { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.sw { display: flex; gap: 8px; align-items: center; }
.sw input[type=color] { width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; flex: none; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.sw input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.sw input[type=color]::-webkit-color-swatch { border: 0; }
.sw .inp.bad { color: var(--rec); }

/* Globale Presets: Liste mit feinen Trennlinien, das geladene ist gefüllt */
.gplist { display: grid; margin: 0 -8px; }
.gp {
  display: flex; align-items: center; gap: 12px; min-height: 36px; padding: 0 12px; text-align: left;
  font: inherit; letter-spacing: inherit; color: var(--text); background: none; cursor: pointer; outline: none;
  border: 0; border-radius: 999px; box-shadow: 0 -1px 0 var(--hair);
}
.gp:first-child, .gp.on, .gp.on + .gp, .gp:hover, .gp:hover + .gp { box-shadow: none; }
.gp b { flex: 1; min-width: 0; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gp span { flex: none; max-width: 55%; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gp:hover, .gp:focus-visible { background: var(--acc-soft); }
.gp.on { background: var(--acc); color: var(--acc-ink); }
.gp.on span { color: inherit; opacity: 0.8; }

/* ---------- Bühne ---------- */
#stage { grid-area: stage; position: relative; overflow: hidden; margin-right: var(--pad); background: var(--card); border-radius: var(--r); }
#wrap { position: absolute; outline: 1px solid var(--line); }
#cv, #ov, #sov { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* Lesekopf des Klangs: Differenz-Mischung, damit er auf jeder Palette sichtbar bleibt */
#sov { pointer-events: none; mix-blend-mode: difference; }
#sov .ph { fill: #fff; opacity: 0.22; }
#sov .nt { fill: #fff; opacity: 0.85; }
#ov { overflow: visible; touch-action: none; }
#ov.hidden { display: none; }
#ov .fb { fill: transparent; stroke: none; cursor: move; }
#ov .fb.on { stroke: var(--acc); }
#ov .eg { stroke: transparent; }
#ov .dot { fill: #000; stroke: #fff; pointer-events: none; }
#ov .hit { fill: transparent; }
#ov .plus { cursor: pointer; }
#ov .plus rect { fill: transparent; }
#ov .plus path { stroke: var(--dim); fill: none; stroke-linecap: round; }
#ov .plus:hover path { stroke: var(--acc); }
#ov .guide { stroke: var(--acc); pointer-events: none; }

#status { grid-area: status; display: flex; align-items: center; gap: 22px; padding: 0 var(--pad) 0 6px; color: var(--dim); white-space: nowrap; overflow: hidden; }
#status b { color: var(--text); font-weight: 400; }

/* ============================================================
   Mobil: Bühne oben (zwei Drittel samt Kopfzeile), Bedienung unten (ein Drittel)
   ============================================================ */
@media (max-width: 760px) {
  :root { --ph: 36px; --pad: 12px; }
  .desk { display: none !important; }

  /* --side-f: Anteil des Bedienfelds an der Höhe – mit dem Griff aufziehbar (app.js) */
  #app {
    grid-template: auto minmax(0, 1fr) calc(var(--app-h, 100dvh) * var(--side-f, 0.3333)) / 100%;
    grid-template-areas: "top" "stage" "side";
    height: var(--app-h, 100dvh);
  }
  #status { display: none; }

  /* Kopfzeile: eingeklappt eine knappe Zeile, ausgeklappt Format, Aufnahme, Export, Ansicht, Presets */
  #top { align-content: flex-start; padding: calc(env(safe-area-inset-top) + 8px) var(--pad) 8px; }
  .brand { padding-right: 6px; }
  #top > .btn, .g-rnd .btn { padding: 0 11px; }
  /* Aufnahme-Status und „Video sichern“ bekommen eine eigene Zeile */
  #recInfo { order: 1; flex: 0 0 100%; }
  #more { display: none; order: 2; }
  #top.open #more { display: grid; flex: 0 0 100%; gap: 8px; padding: 6px 0 4px; }
  #more .grp { flex-wrap: wrap; }
  #more .grp .cap { width: 64px; flex: none; }
  #more .g-fmt { order: 1; }
  #more .g-rec { order: 2; }
  #more .g-exp { order: 3; }
  #more .g-view { order: 4; }
  #more .g-pre { order: 5; }
  #more .g-theme { order: 6; padding-left: 70px; }
  .pop { left: var(--pad); right: var(--pad); width: auto; }

  #stage { margin: 0 var(--pad); }

  /* Bedienfläche; oben der Griff zum Aufziehen */
  #side { grid-area: side; padding-bottom: env(safe-area-inset-bottom); }
  .grab { flex: none; height: 22px; display: grid; place-items: center; touch-action: none; cursor: ns-resize; }
  .grab::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: var(--line); }
  .grab:active::before { background: var(--acc-t); }
  body.editing .grab { display: none; }
  .textbar { padding: 0 var(--pad) 6px; gap: 6px; }
  body.editing .textbar { padding-top: 8px; }
  .textbar textarea { height: 40px; padding: 7px 14px; border-radius: 20px; }
  .textbar .glyphs { display: none; }

  .tabs { margin: 0 var(--pad) 8px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; padding: 0 14px; }

  /* Reiter nebeneinander, seitlich wischen – rastet je Reiter ein */
  .panes {
    flex: 1; min-height: 0; display: flex; flex-direction: row;
    overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain; scrollbar-width: none;
  }
  .panes::-webkit-scrollbar { display: none; }
  .pane, .pane:not(.on) {
    display: block; flex: 0 0 100%; width: 100%; height: 100%;
    scroll-snap-align: start; scroll-snap-stop: always;
    overflow-y: auto; overscroll-behavior-y: contain; padding: 0 var(--pad) 20px;
  }
  .sec { padding: 14px 14px 16px; }
  .sec > h3 { margin-bottom: 4px; }
  .g2 { gap: 8px; }

  /* Regler: höher, waagerecht ziehen – senkrecht scrollt */
  .sl { height: 42px; touch-action: pan-y; }
  .sl span, .sl b { line-height: 40px; }
  .sl.drag { border-color: var(--acc-t); }
  .sl.drag span { color: var(--text); }

  .chip, .sw input[type=color] { width: 28px; height: 28px; line-height: 28px; }
  .chips { gap: 10px; }
  .gp { min-height: 42px; }

  /* Beim Tippen: nur Textfeld und Zeichenauswahl, die Bühne bleibt über der Tastatur */
  body.editing #app { grid-template-rows: auto minmax(0, 1fr) auto; }
  body.editing .tabs, body.editing .panes { display: none; }
  body.editing .textbar { padding-bottom: 10px; }
  body.editing .textbar textarea { height: 62px; }
  body.editing .textbar .glyphs { display: flex; }
}

/* Schmales Telefon: der Name weicht, damit Zufall und Zurück in die Kopfzeile passen */
@media (max-width: 430px) { .brand { display: none; } }

/* Feiner Zeiger fehlt: auch am Tablet griffigere Knöpfe */
@media (pointer: coarse) {
  :root { --ph: 36px; }
  .sl { touch-action: pan-y; }
}
