:root {
  --bg: #16181d;
  --bg2: #1f2229;
  --bg3: #2a2e37;
  --line: #333844;
  --fg: #eceef2;
  --fg2: #9aa1ae;
  --accent: #f2a93b;
  --accent-fg: #1a1a1a;
  --chord: #f2a93b;
  --chorus-bg: rgba(242, 169, 59, 0.07);
  --danger: #e5534b;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --song-size: 22px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #fafaf7;
  --bg2: #ffffff;
  --bg3: #eeeee9;
  --line: #dcdcd4;
  --fg: #1b1c1f;
  --fg2: #6b6f78;
  --accent: #c46a00;
  --accent-fg: #fff;
  --chord: #b55d00;
  --chorus-bg: rgba(196, 106, 0, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
.view, .vcontent, .sheet-body { overscroll-behavior: contain; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; -webkit-user-select: text; user-select: text; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* ---------- Grundlayout ---------- */
#app { display: flex; flex-direction: column; height: 100%; }
#main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar #top-back { margin-left: -10px; margin-right: -8px; }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; }
.view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.tabbar {
  display: flex; border-top: 1px solid var(--line); background: var(--bg2);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; color: var(--fg2); font-size: 12px;
}
.tabbar button.active { color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  background: var(--bg3); font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; }
.ibtn {
  min-width: 44px; height: 44px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
}
.ibtn:active, .btn:active { opacity: .6; }
.ibtn.on { background: var(--accent); color: var(--accent-fg); }

/* ---------- Liste ---------- */
.toolbar { display: flex; gap: 8px; padding: 12px 16px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.search {
  flex: 1; min-width: 0; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg2); padding: 0 14px; font-size: 17px; outline: none;
}
.search:focus { border-color: var(--accent); }
select.sel { height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); padding: 0 10px; }

.list { list-style: none; margin: 0; padding: 0 0 24px; }
.list .letter {
  padding: 14px 16px 4px; color: var(--accent); font-weight: 700; font-size: 14px;
}
.row {
  display: flex; align-items: center; gap: 12px; min-height: 60px;
  padding: 8px 16px; border-bottom: 1px solid var(--line);
}
.row:active { background: var(--bg3); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 14px; color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .badge {
  font-size: 13px; font-weight: 700; color: var(--fg2); background: var(--bg3);
  border-radius: 6px; padding: 3px 8px; min-width: 36px; text-align: center;
}
.row .num { width: 28px; color: var(--fg2); font-weight: 700; text-align: right; }
.row .acts { display: flex; gap: 2px; }
.row .acts .ibtn { min-width: 40px; height: 40px; font-size: 16px; color: var(--fg2); }
.row.checked { background: var(--chorus-bg); }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center;
}
.row.checked .check { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.row.checked .check::after { content: "✓"; font-weight: 800; font-size: 15px; }

.empty-state { text-align: center; padding: 60px 24px; color: var(--fg2); }
.empty-state h2 { color: var(--fg); margin: 0 0 8px; }
.empty-state p { max-width: 420px; margin: 0 auto 20px; }
.empty-state .btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Einstellungen ---------- */
.settings { padding: 16px; max-width: 720px; margin: 0 auto; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; overflow: hidden; }
.card h3 { margin: 0; padding: 14px 16px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg2); }
.field { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 54px; border-top: 1px solid var(--line); }
.card h3 + .field { border-top: 0; }
.field label { flex: 1; }
.field small { display: block; color: var(--fg2); font-size: 13px; }
.seg-ctl { display: inline-flex; background: var(--bg3); border-radius: 10px; padding: 3px; }
.seg-ctl button { padding: 8px 14px; border-radius: 8px; font-size: 15px; }
.seg-ctl button.on { background: var(--bg2); box-shadow: 0 1px 3px rgba(0,0,0,.3); font-weight: 600; }
.card p { padding: 0 16px 12px; margin: 0; color: var(--fg2); font-size: 14px; }

/* ---------- Song-Ansicht ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column;
}
.vbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 6px) 8px 6px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  transition: margin-top .2s;
}
.viewer.immersive .vbar { display: none; }
.vtitle { flex: 1; min-width: 0; }
.vtitle div:first-child { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vtitle div:last-child { font-size: 13px; color: var(--fg2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vtools { display: flex; align-items: center; gap: 4px; }
.grp { display: flex; align-items: center; background: var(--bg3); border-radius: 10px; }
.grp .val { min-width: 42px; text-align: center; font-weight: 700; color: var(--accent); }
.grp small { font-size: 14px; }

.scrollbar-panel {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.scrollbar-panel input { flex: 1; accent-color: var(--accent); }
.scrollbar-panel span { min-width: 54px; text-align: right; color: var(--fg2); font-size: 14px; }

.vcontent {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px max(20px, 4vw) 50vh;
  font-size: var(--song-size);
}
.song-head { margin-bottom: 1em; }
.song-head h2 { margin: 0; font-size: 1.35em; line-height: 1.2; }
.song-head .meta { color: var(--fg2); font-size: .7em; margin-top: 4px; display: flex; gap: 14px; flex-wrap: wrap; }
.song-head .meta b { color: var(--fg); font-weight: 600; }

.song { line-height: 1.25; }
.song .ln { white-space: pre-wrap; min-height: 1.25em; }
.song .ln.empty { height: .6em; min-height: 0; }
.song .ln.wc { display: flex; flex-wrap: wrap; align-items: flex-end; margin-top: .15em; }
.song .sg { display: inline-flex; flex-direction: column; }
.song .ch { color: var(--chord); font-weight: 700; font-size: .85em; padding-right: .35em; min-height: 1.2em; white-space: pre; }
.song .ch.nc { padding-right: 0; }
.song .ly { white-space: pre; }
.song .sg.gap .ch { padding-right: 1.2em; }
.song .sec { margin: .5em 0 .9em; }
.song .sec-label {
  font-size: .62em; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  color: var(--fg2); margin-bottom: .2em;
}
.song .sec.chorus { border-left: 4px solid var(--accent); padding: .2em 0 .3em .7em; background: var(--chorus-bg); border-radius: 0 8px 8px 0; }
.song .sec.chorus > .sec-label { color: var(--accent); }
.song .sec.bridge { border-left: 4px solid var(--fg2); padding-left: .7em; }
.song .cmt { display: inline-block; background: var(--bg3); border-radius: 6px; padding: .1em .5em; margin: .3em 0; font-size: .8em; font-style: italic; color: var(--fg2); }
.song pre.tab { font-size: .7em; overflow-x: auto; background: var(--bg2); padding: .6em; border-radius: 8px; }
.vcontent.lyrics-only .song .ch { display: none; }

.pdfwrap { padding: 0; }
.pdfslot { width: 100%; margin: 0 auto 12px; background: #fff; border-radius: 4px; overflow: hidden; }
.pdfslot .pdfpage { margin: 0; border-radius: 0; }
.pdfpage { display: block; width: 100%; height: auto; margin: 0 auto 12px; background: #fff; border-radius: 4px; }
.vcontent.pdf-mode { padding: 8px 8px 30vh; }

.setnav {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px calc(var(--safe-bottom) + 6px);
  background: var(--bg2); border-top: 1px solid var(--line);
}
.viewer.immersive .setnav { display: none !important; }
.setnav button { min-height: 44px; padding: 0 14px; border-radius: 10px; background: var(--bg3); max-width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.setnav button:disabled { opacity: .3; }
.setnav #sn-pos { color: var(--fg2); font-size: 14px; }

/* ---------- Bottom Sheet / Dialog ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.sheet {
  position: fixed; z-index: 41; left: 50%; transform: translateX(-50%);
  bottom: 0; width: min(640px, 100%); max-height: 92%;
  background: var(--bg2); border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -8px 30px rgba(0,0,0,.4);
}
@media (min-width: 768px) {
  .sheet { bottom: auto; top: 50%; transform: translate(-50%, -50%); border-radius: 16px; max-height: 86%; }
}
.sheet.full { width: min(980px, 100%); height: 100%; max-height: 100%; border-radius: 0; top: 0; transform: translateX(-50%); }
@media (min-width: 768px) { .sheet.full { height: 92%; top: 4%; border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px 18px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-body.pad { padding: 16px; }
.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px;
  padding: 0 18px; border-bottom: 1px solid var(--line); text-align: left; font-size: 17px;
}
.menu-item:active { background: var(--bg3); }
.menu-item.danger { color: var(--danger); }
.menu-item svg { color: var(--fg2); }
.menu-item.danger svg { color: var(--danger); }

.form { display: grid; gap: 12px; }
.form .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.form label { font-size: 13px; color: var(--fg2); display: grid; gap: 4px; }
.form input, .form textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; outline: none;
}
.form input:focus, .form textarea:focus { border-color: var(--accent); }
.form textarea { min-height: 50vh; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; line-height: 1.45; resize: vertical; white-space: pre; overflow-wrap: normal; }
.hint { font-size: 13px; color: var(--fg2); }
.hint code { background: var(--bg3); padding: 1px 5px; border-radius: 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 80px);
  background: var(--fg); color: var(--bg); padding: 12px 18px; border-radius: 12px;
  z-index: 60; font-weight: 600; max-width: 90%; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.35);
}
.update-banner {
  position: fixed; z-index: 55; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-top) + 10px); width: min(560px, calc(100% - 24px));
  background: var(--bg2); border: 1px solid var(--accent); border-radius: 14px;
  padding: 12px 12px 12px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
.update-banner .ub-text { flex: 1; min-width: 180px; display: grid; gap: 2px; }
.update-banner .ub-text span { color: var(--fg2); font-size: 14px; }
.update-banner .ub-btns { display: flex; gap: 8px; }
.dropzone-active::after {
  content: "Dateien hier ablegen zum Importieren"; position: fixed; inset: 12px; z-index: 50;
  border: 3px dashed var(--accent); border-radius: 18px; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: #fff;
}

@media (max-width: 600px) {
  .vtools .grp:nth-child(2) { display: none; }
  .vtitle { visibility: hidden; }
  .form .grid { grid-template-columns: repeat(2, 1fr); }
}
