/* Sonne Ost – Pad: dunkel, kontrastreich, große Tippflächen */

:root {
  --bg: #000;
  --surface: #111;
  --surface-2: #1d1d1d;
  --line: #333;
  --text: #f7f7f7;
  --muted: #a3a3a3;
  --sun: #ffa51f;
  --go: #16a34a;
  --stop: #dc2626;
  --beat: #3b82f6;
  --danger: #f87171;
  --radius: 14px;
  --tap: 56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
a { color: var(--sun); }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand-sun {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 50% 60%, #ffd27a, var(--sun) 60%);
  box-shadow: 0 0 12px rgba(255, 165, 31, .6);
}

.tabs { display: flex; gap: 6px; margin: 0 auto; overflow-x: auto; }
.tabs a {
  display: flex; align-items: center;
  min-height: 48px; padding: 0 18px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}
.tabs a.active { background: var(--surface-2); color: var(--text); }

.status-chip {
  border: 1px solid var(--line);
  background: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.status-chip.ok { color: #4ade80; border-color: #166534; }
.status-chip.locked { color: var(--sun); border-color: var(--sun); }
.status-chip.display { color: var(--muted); }

@media (max-width: 640px) {
  .brand-name { display: none; }
  .tabs a { padding: 0 12px; }
}

main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
main.view-buehne { overflow: hidden; }
.boot { padding: 24px; color: var(--muted); }

/* ---------- Knöpfe und Formulare ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
}
.btn:active { filter: brightness(1.3); }
.btn.primary { background: var(--sun); border-color: var(--sun); color: #000; }
.btn.danger { color: var(--danger); border-color: #7f1d1d; background: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 18px; /* >= 16px verhindert Zoom auf iOS */
}
textarea { resize: vertical; min-height: 80px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

/* ---------- Seiten (Songs, Setlisten, Einstellungen) ---------- */

.page { max-width: 820px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 28px; }
.page-actions { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 68px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  color: var(--text); text-align: left; text-decoration: none;
}
.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-title { font-weight: 650; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-bpm { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row-bpm small { font-size: 13px; color: var(--muted); font-weight: 500; }
.row-chevron { font-size: 28px; color: var(--muted); }
.badge { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: rgba(255, 165, 31, .15); color: var(--sun); white-space: nowrap; }
.empty { color: var(--muted); padding: 24px 4px; }

.title-input { font-size: 24px !important; font-weight: 700; }

/* Sortierbare Setliste */
.sort-item {
  display: flex; align-items: center; gap: 10px;
  min-height: 68px; padding: 6px 6px 6px 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface);
  position: relative;
}
.sort-item.dragging { z-index: 2; background: var(--surface-2); border-color: var(--sun); box-shadow: 0 8px 24px rgba(0, 0, 0, .6); }
.sortable.sorting { user-select: none; }
.handle {
  display: flex; align-items: center; justify-content: center;
  width: 56px; align-self: stretch;
  font-size: 28px; color: var(--muted);
  touch-action: none; cursor: grab; user-select: none;
}
.sort-num { width: 28px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.btn-remove {
  width: 52px; height: 52px; flex-shrink: 0;
  border: none; border-radius: 12px; background: none;
  color: var(--muted); font-size: 28px;
}
.btn-remove:active { color: var(--danger); background: var(--surface-2); }

/* Einstellungen */
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card h2 { margin: 0; font-size: 18px; color: var(--muted); font-weight: 600; }
.hint { margin: 0; color: var(--muted); font-size: 15px; }
.hint.warn { color: var(--sun); }
.segmented { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented button { flex: 1; min-height: var(--tap); border: none; background: none; font-weight: 600; color: var(--muted); }
.segmented button.active { background: var(--sun); color: #000; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: var(--tap); }
.switch-row small { display: block; color: var(--muted); font-size: 14px; }
.switch-label { font-weight: 600; }
.switch {
  appearance: none; flex-shrink: 0;
  width: 64px; height: 36px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  position: relative; cursor: pointer; transition: background .15s;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch:checked { background: var(--sun); border-color: var(--sun); }
.switch:checked::after { transform: translateX(28px); background: #000; }
.sound-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.sound-option {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px;
  min-height: 72px; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); text-align: left;
}
.sound-option small { color: var(--muted); font-size: 14px; }
.sound-label { font-weight: 700; font-size: 18px; }
.sound-option.active { border-color: var(--sun); background: rgba(255, 165, 31, .12); }
.sound-option.active .sound-label { color: var(--sun); }
.custom-sounds { display: flex; flex-direction: column; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.sample-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.version { text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Dialog ---------- */

.dlg {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--text);
}
.dlg::backdrop { background: rgba(0, 0, 0, .75); }
.dlg-title { margin: 0 0 16px; font-size: 22px; }
.dlg-text { color: var(--muted); margin: 0 0 8px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.dlg-actions .push-left { margin-right: auto; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { color: var(--muted); font-size: 14px; font-weight: 600; }
.stepper { display: flex; gap: 6px; }
.stepper .btn { padding: 0; width: var(--tap); flex-shrink: 0; font-size: 24px; }
.bpm-input { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.len { display: flex; flex-direction: column; gap: 6px; }

.pick-list { list-style: none; margin: 0; padding: 0; max-height: 55dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.pick { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; min-height: 56px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 12px; }
.pick input { width: 26px; height: 26px; accent-color: var(--sun); }

/* ---------- Hinweis-Leiste ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 12px 20px; border-radius: 12px;
  background: #f7f7f7; color: #000; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Bühnen-Bildschirm ---------- */

.stage {
  height: 100%;
  display: grid;
  gap: 12px;
  padding: 12px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "now" "next" "bottom";
  user-select: none;
  -webkit-user-select: none;
}

@media (orientation: landscape) {
  .stage {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "now next" "bottom bottom";
  }
}

.now {
  grid-area: now;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; min-height: 0;
  padding: 16px;
  border-radius: 20px;
  background: var(--surface);
  text-align: center;
}
.now-head { align-self: stretch; display: flex; align-items: center; gap: 12px; }
.list-select { flex: 1; min-height: 48px; font-size: 16px; }
.now-counter { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.now-title {
  margin: 4px 0 0;
  font-size: clamp(34px, 6.5vw, 76px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.now-info { color: var(--muted); font-size: clamp(16px, 2vw, 22px); }
.now-note {
  color: var(--sun); font-size: clamp(16px, 2vw, 22px);
  padding: 4px 12px; border-left: 3px solid var(--sun);
}

.beats { display: flex; justify-content: center; flex-wrap: wrap; gap: clamp(8px, 1.4vw, 16px); margin-top: 6px; }
.beat {
  display: flex; align-items: center; justify-content: center;
  width: clamp(40px, 7vw, 76px); height: clamp(40px, 7vw, 76px);
  border-radius: 50%;
  border: 3px solid var(--line);
  color: var(--muted);
  font-size: clamp(16px, 2.4vw, 28px); font-weight: 700;
}
.beat.one { border-color: #666; }
.beat.on { background: var(--beat); border-color: var(--beat); color: #fff; }
.beat.one.on { background: #fff; border-color: #fff; color: #000; }
.beats.count-in .beat.on { background: var(--sun); border-color: var(--sun); color: #000; }

.now-pos {
  font-size: clamp(24px, 4vw, 44px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
}
.now-pos.count-in { color: var(--sun); }

.transport { display: flex; align-items: stretch; gap: 12px; width: 100%; max-width: 640px; margin-top: 6px; }
.btn-play {
  flex: 1;
  min-height: clamp(84px, 14vh, 140px);
  border: none; border-radius: 20px;
  background: var(--go); color: #fff;
  font-size: clamp(28px, 4vw, 44px); font-weight: 800; letter-spacing: .06em;
}
.btn-play.playing { background: var(--stop); }
.btn-play:disabled { background: var(--surface-2); color: var(--muted); }
.btn-play:active:not(:disabled) { filter: brightness(1.2); }
.btn-nav {
  width: clamp(72px, 10vw, 110px);
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface-2); font-size: 28px;
}
.btn-nav:disabled { opacity: .3; }

.upnext {
  grid-area: next;
  min-height: 0; overflow-y: auto;
  padding: 12px; border-radius: 20px; background: var(--surface);
}
.upnext-title { margin: 0 0 8px 4px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.upnext-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.upnext-item button {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 58px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); text-align: left;
}
.upnext-item:first-child button { border-color: #555; }
.upnext-item:first-child .upnext-name { font-size: 22px; }
.upnext-item button:disabled { opacity: .55; }
.upnext-num { width: 28px; color: var(--muted); font-variant-numeric: tabular-nums; }
.upnext-name { flex: 1; font-weight: 650; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upnext-meta { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.upnext-empty { color: var(--muted); padding: 8px 4px; }

.stage-bottom { grid-area: bottom; display: flex; gap: 12px; align-items: stretch; }
.tiles { display: flex; gap: 12px; flex: 1; min-width: 0; }
.tile {
  flex: 1; min-width: 0;
  min-height: 92px; padding: 10px 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 2px solid #1e3a8a; border-radius: 18px;
  background: #0b1530;
  touch-action: manipulation;
}
.tile-name { font-size: 22px; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-state { color: var(--muted); font-size: 15px; }
.tile.playing { background: var(--beat); border-color: #93c5fd; }
.tile.playing .tile-state { color: #fff; }
.tile.empty { border-style: dashed; border-color: var(--line); background: transparent; }
.tile:disabled { opacity: .4; }

.volumes { display: flex; flex-direction: column; justify-content: center; gap: 6px; width: min(42%, 380px); padding: 8px 14px; border-radius: 18px; background: var(--surface); }
.volume { display: flex; align-items: center; gap: 12px; min-height: 40px; }
.volume-label { width: 76px; color: var(--muted); font-weight: 600; font-size: 15px; }
.volume input { flex: 1; height: 40px; accent-color: var(--sun); }

@media (orientation: portrait) and (max-width: 600px) {
  .stage-bottom { flex-direction: column; }
  .volumes { width: 100%; }
}
