:root {
  --bg: #0f1114;
  --panel: #191d22;
  --panel2: #20252c;
  --line: #2b323b;
  --text: #e9edf2;
  --muted: #9aa4b2;
  --accent: #ff9f1c;
  --accent-ink: #1a1206;
  --loop: #2ec4b6;
  --danger: #ef5b5b;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.error { color: var(--danger); }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Buttons */
.btn {
  font: inherit; font-weight: 600;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; cursor: pointer;
  transition: background .12s, border-color .12s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #29303a; border-color: #3a434f; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: #ffb24d; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 14px; }
.btn.round { width: 52px; height: 52px; border-radius: 50%; font-size: 26px; padding: 0; }
.btn.on, .btn.toggle.on { background: var(--loop); border-color: var(--loop); color: #06201d; }
.btn.flash { animation: flash .25s; }
@keyframes flash { from { box-shadow: 0 0 0 4px rgba(255,159,28,.6); } to { box-shadow: 0 0 0 0 transparent; } }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=number], input:not([type]), select {
  font: inherit; color: var(--text); background: #12161a;
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
input[type=number] { width: 76px; }
input.wide { width: 100%; }
input[type=range] { accent-color: var(--accent); width: 100%; }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin: 4px 14px 4px 0; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Kopfzeile */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: #0b0d10; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; color: var(--accent); margin-right: 8px; }
.song { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.song-title { font-size: 18px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.hq { color: var(--loop); border-color: rgba(46,196,182,.5); }
.badge.warn { color: var(--accent); border-color: rgba(255,159,28,.5); }

/* ---------- Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-rows: auto auto 1fr auto;
  grid-template-areas:
    "stage side"
    "tl side"
    "tr side"
    "panel panel";
  gap: 12px; padding: 12px 16px 24px;
}
.transport { align-self: start; }
.stage { grid-area: stage; min-width: 0; }
.side { grid-area: side; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.timeline-wrap { grid-area: tl; min-width: 0; }
.transport { grid-area: tr; }
.panel { grid-area: panel; }

/* Tablet/Hochformat: Video bleibt oben stehen, darunter Transport, dann Tempo + Loop nebeneinander,
   Zeitleiste, unterer Bereich und zuletzt die Abschnittsliste */
/* gilt nur im Hochformat (bzw. bei schmalen Fenstern); Tablets quer behalten die Spalte rechts */
@media (max-width: 1100px) and (orientation: portrait), (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: none;
    grid-template-areas: "stage stage" "tr tr" "tempo loop" "tl tl" "panel panel" "sec sec";
  }
  .side { display: contents; }
  .card-tempo { grid-area: tempo; }
  .card-loop { grid-area: loop; }
  .side .sections { grid-area: sec; }
  .stage { position: sticky; top: var(--hdr, 0px); z-index: 15; background: var(--bg); padding-bottom: 6px; margin-bottom: -6px; }
  .tl-help { display: none; }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "tr" "tempo" "loop" "tl" "panel" "sec"; }
}

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card h2 { margin: 0 0 10px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* ---------- Video */
.video-box {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; width: 100%;
  /* Video so hoch, dass Zeitleiste und Transporttasten noch ohne Scrollen sichtbar sind */
  max-height: max(220px, calc(100vh - 520px));
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line);
}
.video-box.dragover { outline: 3px dashed var(--accent); outline-offset: -8px; }
.video-box video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.yt-host, .yt-host iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.audio-only { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: radial-gradient(circle at 50% 40%, #232a33, #0b0d10); font-size: 22px; font-weight: 700; padding: 20px; text-align: center; }
.note-ico { font-size: 72px; color: var(--accent); line-height: 1; }
.drop-hint { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); text-align: center; padding: 20px; }
.drop-big { font-size: 24px; font-weight: 700; color: var(--text); }
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 160px; font-weight: 900; color: var(--accent); background: rgba(0,0,0,.45); pointer-events: none; text-shadow: 0 4px 30px rgba(0,0,0,.6); }
.loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: rgba(10,12,15,.85); font-weight: 600; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tempo */
.speed-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.speed-val { font-size: 48px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); line-height: 1; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.quick .btn { font-size: 20px; padding: 10px 0; }
.quick .btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.note { margin-top: 8px; font-size: 13px; color: var(--accent); }
.note:empty { display: none; }

/* ---------- Loop */
.ab-grid { display: grid; grid-template-columns: 96px 1fr; gap: 6px 10px; align-items: center; }
.ab-btn { font-size: 18px; padding: 10px 0; }
.ab-time { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.nudge { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 6px; }
.nudge button { font: inherit; font-size: 13px; padding: 4px 0; background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.nudge button:hover { color: var(--text); border-color: #3a434f; }
.loop-row { display: flex; gap: 8px; margin: 6px 0 10px; }
.loop-row .toggle { flex: 1; font-size: 20px; padding: 12px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; }
.field-row > label { color: var(--muted); }
.rep { margin: 8px 0 4px; font-size: 15px; }
.rep b { font-size: 20px; color: var(--loop); }
details summary { cursor: pointer; color: var(--muted); margin-top: 6px; }
.ramp-grid { display: grid; grid-template-columns: auto 76px 1fr; gap: 6px 8px; align-items: center; margin-top: 6px; }

/* ---------- Abschnitte */
.sec-add { display: flex; gap: 8px; }
.sec-add input { flex: 1; min-width: 0; }
.sec-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.sec-list li { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 0; overflow: hidden; }
.sec-list li.active { border-color: var(--loop); }
.sec-color { width: 6px; align-self: stretch; flex: none; }
.sec-main { flex: 1; min-width: 0; cursor: pointer; padding: 4px 0; }
.sec-name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.icon-btn { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; padding: 6px; border-radius: 6px; }
.icon-btn:hover { background: #2c333d; color: var(--text); }

/* ---------- Zeitleiste */
.tl-tools { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.tl-help { margin-left: auto; font-size: 12px; color: var(--muted); }
.overview { display: block; width: 100%; height: 34px; border-radius: 8px 8px 0 0; border: 1px solid var(--line); border-bottom: 0; cursor: pointer; }
.timeline { display: block; width: 100%; height: 150px; border-radius: 0 0 8px 8px; border: 1px solid var(--line); touch-action: none; }

/* ---------- Transport (gross, auch aus Distanz bedienbar) */
.transport {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.time-box { min-width: 200px; display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.time-box span { font-size: 44px; font-weight: 800; }
.time-box small { font-size: 18px; color: var(--muted); }
.jumps { display: flex; gap: 8px; }
.tbtn {
  font: inherit; font-weight: 800; font-size: 24px; min-width: 78px; height: 78px; padding: 0 10px;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 16px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 2px; font-variant-numeric: tabular-nums;
  transition: background .1s, transform .05s;
}
.tbtn:hover { background: #2a313b; }
.tbtn:active { transform: translateY(2px); }
.tbtn svg { width: 36px; height: 36px; }
.tbtn.play { width: 110px; height: 96px; border-radius: 22px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tbtn.play svg { width: 48px; height: 48px; }
.tbtn.play:hover { background: #ffb24d; }
.tbtn .unit { font-size: 14px; font-weight: 600; opacity: .7; }
.tbtn.back { color: #ffd9a3; }
.tbtn.fwd { color: #bfe9e4; }

/* ---------- Unterer Bereich */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 16px 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 -16px 14px; padding: 0 12px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 700; background: none; border: 0; color: var(--muted); padding: 14px 14px 12px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-page h3 { margin: 4px 0 10px; font-size: 16px; }
.tab-page p { max-width: 75ch; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; }
.col .field-row select, .col .field-row input.wide { max-width: 260px; }

.eq { display: flex; gap: 18px; align-items: stretch; flex-wrap: wrap; }
.eq-band { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 92px; text-align: center; font-size: 13px; color: var(--muted); }
.eq-band output { color: var(--text); font-weight: 700; font-size: 15px; }
input.vert { writing-mode: vertical-lr; direction: rtl; width: 36px; height: 150px; }
.eq-side { flex: 1; min-width: 280px; }
.preset-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* ---------- Dialoge */
.dlg { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(560px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0,0,0,.6); }
.dlg h2 { margin: 0 0 12px; }
.dlg h3 { margin: 18px 0 8px; font-size: 15px; }
.wide-dlg { width: min(860px, calc(100vw - 32px)); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dlg ul { padding-left: 18px; }
.jump-cfg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; }
.jump-cfg label { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }
.midi-bar { display: flex; align-items: center; gap: 14px; margin: 10px 0; flex-wrap: wrap; }
.keys-table-wrap { max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.keys-table { width: 100%; border-collapse: collapse; }
.keys-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.keys-table tr:last-child td { border-bottom: 0; }
.keys-table td:first-child { color: var(--muted); width: 38%; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #12161a; border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px 3px 8px; margin: 2px 4px 2px 0; font-weight: 700; font-size: 14px; }
.chip.midi { border-color: rgba(46,196,182,.5); }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 14px; }
.chip button:hover { color: var(--danger); }
.add-btn { font: inherit; font-size: 13px; background: none; border: 1px dashed var(--line); color: var(--muted); border-radius: 6px; padding: 3px 8px; cursor: pointer; margin: 2px 4px 2px 0; }
.add-btn:hover { color: var(--text); border-color: var(--muted); }
.add-btn.recording { border-color: var(--accent); color: var(--accent); border-style: solid; animation: flash 1s infinite; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #222831; border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: calc(100vw - 32px); }

/* ---------- Touch / iPad */
button, .tbtn, .btn, canvas { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.timeline { touch-action: none; }
.tl-help-touch { display: none; margin-left: auto; font-size: 12px; color: var(--muted); }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
@media (pointer: coarse) {
  .tl-help { display: none; }
  .tl-help-touch { display: inline; }
  .nudge button { padding: 10px 0; font-size: 15px; }
  .icon-btn { font-size: 20px; padding: 10px 12px; }
  .btn.small { padding: 9px 14px; }
  .overview { height: 44px; }
  .timeline { height: 170px; }
  .sec-list { max-height: none; }
  input[type=range] { height: 32px; }
  label.check input { width: 24px; height: 24px; }
}
/* Hochformat / schmal: Zeit über den Sprungtasten, Tasten passen in eine Zeile */
@media (max-width: 1100px) {
  .time-box { flex-basis: 100%; justify-content: center; }
  .transport { gap: 8px; }
  .jumps { gap: 6px; }
  .tbtn { min-width: 64px; height: 72px; font-size: 21px; padding: 0 6px; }
  .tbtn.play { width: 96px; height: 84px; }
  .speed-val { font-size: 40px; }
}
@media (max-width: 1100px) and (orientation: portrait), (max-width: 900px) {
  /* kleiner, weil es beim Scrollen oben stehen bleibt */
  .video-box { max-height: 32vh; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .song { order: 10; flex-basis: 100%; padding: 0; }
  #btnKeys { margin-left: auto; }
}
/* Tablet quer, knapp unter 1100 px (z. B. iPad 9. Gen.: 1080 × 810): schmalere rechte Spalte */
@media (min-width: 901px) and (max-width: 1100px) and (orientation: landscape) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .ab-grid { grid-template-columns: 84px 1fr; }
}
@media (max-width: 700px) {
  .video-box { max-height: 26vh; }
  #btnKeys, #btnSettings { font-size: 14px; }
}

.brand-logo { width: 34px; height: 34px; border-radius: 9px; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.brand span { font-family: Georgia, "Times New Roman", serif; font-style: italic; letter-spacing: .01em; color: #f6e7c8; font-size: 20px; }
@media (max-width: 700px) { .brand span { display: none; } }

/* ---------- Tabulatur */
.tab-toolbar, .tab-subbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.tab-toolbar select { max-width: 280px; }
.spacer { flex: 1; }
.sens { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.sens input { width: 130px; }
.tab-progress { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; font-size: 14px; color: var(--muted); }
.tab-progress .bar { flex: 0 0 240px; height: 8px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
.tab-progress .bar > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.tab-empty p { max-width: 80ch; }
.warn-text { color: var(--accent); }
.tab-wrap { position: relative; display: flex; border: 1px solid var(--line); border-radius: 10px; background: #14171b; overflow: hidden; }
.tab-labels { position: relative; flex: 0 0 30px; border-right: 1px solid var(--line); background: #101317; }
.tab-labels span { position: absolute; left: 0; right: 0; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.tab-scroll { flex: 1; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.tab-scroll svg { display: block; }
.tab-svg .tn { cursor: pointer; }
.tab-svg .tn:hover rect { fill: #23303b; }
.tab-svg .tn.on rect { fill: var(--accent); }
.tab-svg .tn.on text { fill: var(--accent-ink) !important; }
.tab-svg .tn.sel rect { stroke: var(--loop) !important; stroke-width: 2.5px !important; stroke-dasharray: none !important; }
.tab-head { stroke: var(--accent); stroke-width: 2; pointer-events: none; }
.tab-editor { margin-top: 12px; padding: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; }
.te-head { margin-bottom: 8px; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.te-head b { font-size: 18px; }
.te-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 14px; }
.te-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.te-grid select, .te-grid input { width: 100%; }
.te-num { display: flex; gap: 4px; }
.te-num input { flex: 1; min-width: 0; width: auto; }
.te-num button { font: inherit; width: 34px; background: #12161a; color: var(--text); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.te-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
details.instrument { margin-top: 14px; }
.instr-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin-top: 8px; color: var(--muted); font-size: 14px; }
.instr-row label { display: inline-flex; gap: 8px; align-items: center; }
.instr-row input { width: 210px; }

.tabs button.flag::after { content: ' ●'; color: var(--accent); }

.tone-check { flex: 0 0 280px; padding: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; }
.tone-check h3 { margin: 0 0 6px; font-size: 15px; }
.tc-meter { height: 12px; background: #12161a; border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.tc-meter > div { height: 100%; width: 0; background: var(--loop); transition: width .08s; }
#tcStatus.bad { color: var(--danger); }
.tone-check .btn { margin: 8px 0 4px; }

/* Querformat mit wenig Höhe (Tablets): Video, Zeitleiste und Transport kompakter, damit alles ohne Scrollen passt */
@media (min-width: 901px) and (orientation: landscape) and (max-height: 920px) {
  .video-box { max-height: max(200px, calc(100vh - 590px)); }
  .timeline { height: 120px; }
  .transport { padding: 10px; gap: 8px; }
  .time-box { flex-basis: 100%; justify-content: center; }
  .time-box span { font-size: 34px; }
  .tbtn { min-width: 60px; height: 62px; font-size: 20px; padding: 0 6px; }
  .tbtn.play { width: 92px; height: 72px; }
  .jumps { gap: 6px; }
}
