:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #ddd8cc;
  --brand: #23395b;
  --brand-2: #2f4b75;
  --brand-ink: #ffffff;
  --gold: #c9962b;
  --soft: #e8ecf3;
  --ok: #2e7d4f;
  --danger: #b3261e;
  --radius: 14px;
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161f; --card: #1b2130; --ink: #eef0f4; --muted: #9aa3b2; --line: #2c3446;
    --brand: #7fa2d9; --brand-2: #9db8e3; --brand-ink: #0f1420; --gold: #e9c46a; --soft: #232b3d;
    --ok: #6fcf97; --danger: #f2867e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161f; --card: #1b2130; --ink: #eef0f4; --muted: #9aa3b2; --line: #2c3446;
  --brand: #7fa2d9; --brand-2: #9db8e3; --brand-ink: #0f1420; --gold: #e9c46a; --soft: #232b3d;
  --ok: #6fcf97; --danger: #f2867e; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; color: var(--brand); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.icon-btn:active { background: var(--soft); }
.icon-btn svg { width: 24px; height: 24px; }
main { padding: 14px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 720px; margin: 0 auto; }
main.with-player { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 170px); }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--card); border-top: 1px solid var(--line);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 13px;
}
.bottomnav a svg { width: 26px; height: 26px; }
.bottomnav a.active { color: var(--brand); font-weight: 600; }

/* ---------- Elemente ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--soft); color: var(--brand); font-size: 14px; font-weight: 600; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; background: var(--soft); color: var(--brand); margin-left: 4px; }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

a.btn { text-decoration: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--brand); font-weight: 600;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.btn[disabled] { opacity: .5; }

label.field { display: block; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=password], input[type=date], input[type=number], select {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
}
input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 1px; }
input[type=range] { width: 100%; accent-color: var(--brand); }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); }

.banner-slot { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.banner-slot .banner { margin-top: 12px; }
.banner { padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--gold) 22%, var(--card)); font-size: 15px; }

/* ---------- Liedpläne ---------- */
.plan-card { display: flex; align-items: center; gap: 6px; }
.plan-card .grow { cursor: pointer; }
.plan-card h3 { margin: 0 0 4px; font-size: 18px; color: var(--brand); }

/* ---------- Plan bearbeiten ---------- */
.section-label { font-size: 15px; color: var(--muted); margin: 18px 4px 6px; display: flex; align-items: center; gap: 4px; }
.section-label input { min-height: 40px; }
.slot {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 64px; text-align: left;
  border: 1.5px dashed var(--line); border-radius: var(--radius); background: transparent; padding: 10px 12px;
}
.slot.filled { border-style: solid; background: var(--card); }
.slot .plus { color: var(--brand); width: 28px; height: 28px; flex: none; margin-left: auto; }
.slot .num { font-weight: 700; color: var(--brand); white-space: nowrap; }
.mini-actions { display: flex; gap: 2px; margin-left: auto; }
.mini-actions .icon-btn { width: 36px; height: 36px; }

/* ---------- Gottesdienst-Ansicht ---------- */
.step { color: var(--muted); font-size: 15px; padding: 6px 4px; display: flex; align-items: center; gap: 8px; }
.step::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--line); flex: none; }
.play-item {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 76px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card);
}
.play-item .go {
  flex: none; width: 52px; height: 52px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; justify-content: center;
}
.play-item .go svg { width: 26px; height: 26px; }
.play-item.current { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.play-item.current .go { background: var(--gold); }
.play-item.missing .go { background: var(--line); color: var(--muted); }
.play-item .lbl { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.play-item .ttl { font-size: 18px; font-weight: 600; }

/* ---------- Abspielleiste ---------- */
.playerbar {
  position: fixed; left: 0; right: 0; z-index: 25;
  bottom: calc(var(--nav-h) + var(--safe-b));
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 18px rgba(0,0,0,.08);
  padding: 10px 16px 12px;
}
.playerbar .inner { max-width: 720px; margin: 0 auto; }
.progress { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--gold); width: 0; transition: width .2s linear; }
.stop-btn { background: var(--danger) !important; border-color: var(--danger) !important; color: #fff !important; min-width: 120px; }
.vol { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.vol svg { width: 20px; height: 20px; flex: none; }

/* ---------- Liednummer-Tastatur ---------- */
.np-display { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.np-number { font-size: 44px; font-weight: 700; color: var(--brand); letter-spacing: .02em; min-height: 56px; }
.np-number .ph { color: var(--line); }
.np-info { min-height: 52px; padding: 8px 0; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--brand); font-size: 22px; font-weight: 700; }
.stepper output { min-width: 28px; text-align: center; font-size: 22px; font-weight: 700; }
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.keypad button {
  height: 62px; border-radius: 14px; border: 0; background: var(--brand); color: var(--brand-ink);
  font-size: 26px; font-weight: 700;
}
.keypad button:active { background: var(--brand-2); }
.keypad button.alt { background: var(--soft); color: var(--brand); }
.keypad button svg { width: 26px; height: 26px; }
.keypad .play { grid-column: span 2; background: var(--gold); color: #1d2433; font-size: 20px; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* ---------- Liste der Lieder ---------- */
.song-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.song-row .num { width: 64px; flex: none; font-weight: 700; color: var(--brand); }

/* ---------- Sheet (Dialog von unten) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto; background: var(--bg);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(var(--safe-b) + 20px);
}
.sheet .grip { width: 44px; height: 5px; background: var(--line); border-radius: 3px; margin: 4px auto 10px; }
.sheet h2 { margin: 4px 0 12px; font-size: 20px; color: var(--brand); }
.upload-slot { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.upload-slot:last-child { border-bottom: 0; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); font-size: 15px;
}
#toast.show { opacity: .95; }
body.has-player #toast { bottom: calc(var(--nav-h) + var(--safe-b) + 190px); }

.login { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { color: var(--brand); text-align: center; }

/* ---------- Gottesdienst-Check ---------- */
.gcheck summary { cursor: pointer; display: flex; align-items: center; gap: 8px; min-height: 32px; }
.checklist { list-style: none; margin: 10px 0 0; padding: 0; }
.checklist li { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.checklist .ck { width: 24px; flex: none; text-align: center; }

/* ---------- Liederliste, Import, Massen-Upload ---------- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
table.report { width: 100%; border-collapse: collapse; font-size: 14px; table-layout: fixed; }
table.report th, table.report td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
table.report th:nth-child(1) { width: 38%; }
table.report tr.st-warn td:last-child { color: var(--danger); }
table.report tr.st-repl td:last-child { color: var(--gold); }
table.report tr.st-ok td:last-child, table.report tr.st-new td:last-child { color: var(--ok); }
.errlist { margin: 8px 0 0; padding-left: 18px; color: var(--danger); }
details.lic { margin-top: 6px; }
details.lic summary { cursor: pointer; color: var(--muted); }
code { font-size: 13px; background: var(--soft); padding: 1px 4px; border-radius: 4px; }

/* ---------- Phase 3: Liedpläne ---------- */
h2.group { font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 4px 8px; display: inline-block; }
details.archive > summary { cursor: pointer; list-style: none; }
details.archive > summary::-webkit-details-marker { display: none; }
details.archive > summary h2::after { content: ' ▸'; }
details.archive[open] > summary h2::after { content: ' ▾'; }
textarea { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font: inherit; color: inherit; resize: vertical; }
.item-note { margin-top: 6px; font-size: 15px; }
.label-input { flex: 1; min-width: 0; border: 0 !important; background: transparent !important; padding: 0 4px !important; color: var(--ink); min-height: 40px !important; }
.sec { position: relative; }
.sec.dragging { opacity: .85; z-index: 5; background: var(--bg); box-shadow: 0 8px 24px rgba(0,0,0,.18); border-radius: var(--radius); }
.drag { cursor: grab; touch-action: none; color: var(--muted); width: 36px; height: 40px; }
.drag:active { cursor: grabbing; }
.linkbtn { border: 0; background: none; color: var(--brand); text-decoration: underline; padding: 0; font-size: inherit; cursor: pointer; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tpl-list { display: grid; gap: 8px; margin-top: 4px; }
.tpl { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; }
.tpl.on { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 30%, transparent) inset; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg a { text-align: center; padding: 10px; text-decoration: none; color: var(--brand); font-weight: 600; background: var(--card); }
.seg a.on { background: var(--brand); color: var(--brand-ink); }

/* Druckansicht (immer schwarz auf weiß) */
.print-sheet { background: #fff; color: #111; border: 1px solid var(--line); border-radius: 8px; padding: 22px 20px; margin-top: 16px; }
.print-sheet h1 { font-size: 24px; margin: 0 0 4px; color: #111; }
.print-sheet header p { margin: 0 0 6px; color: #444; }
.print-sheet .pnote { font-style: italic; }
table.ablauf { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 15px; }
table.ablauf td { border-bottom: 1px solid #ddd; padding: 7px 6px; vertical-align: top; }
table.ablauf td.al { width: 38%; color: #444; }
table.ablauf tr.has-song td.al { color: #111; font-weight: 600; }
table.ablauf .inote { color: #555; font-size: 13px; margin-top: 3px; }
.tafel-rows { display: grid; gap: 4px; }
.tafel-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; border-bottom: 2px solid #111; padding: 4px 6px;
  font-family: Georgia, "Times New Roman", serif; font-weight: 700; color: #111; }
.tafel-row .tn { font-size: clamp(44px, 13vw, 96px); line-height: 1.1; }
.tafel-row .tv { font-size: clamp(26px, 7vw, 56px); }
@media print {
  @page { margin: 15mm; }
  body { background: #fff !important; }
  .topbar, .bottomnav, .noprint, #playerbar, #toast, .banner-slot { display: none !important; }
  main { padding: 0 !important; max-width: none; }
  .print-sheet { border: 0; padding: 0; margin: 0; }
  .tafel-row .tn { font-size: 110pt; }
  .tafel-row .tv { font-size: 60pt; }
  table.ablauf tr { break-inside: avoid; }
}

/* ---------- Phase 4: Abspielleiste ---------- */
.playerbar .row .btn[data-r=soft] { padding: 8px 10px; font-size: 14px; line-height: 1.15; min-height: 48px; }
.playerbar .row .btn[disabled] { opacity: .45; }
