:root {
  --bg: #14121f;
  --bg2: #1e1b2e;
  --card: #262238;
  --line: #3a3550;
  --text: #f4f1ff;
  --muted: #a39fbd;
  --accent: #ff4f8b;
  --accent2: #ffb84f;
  --green: #1ed760;
  --danger: #ff6b6b;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #3a1d4a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; max-width: 560px; margin: 0 auto;
}
.brand { font-weight: 800; letter-spacing: .02em; font-size: 18px; color: var(--text); text-decoration: none; }
.stats { flex: 1; text-align: right; color: var(--muted); font-size: 13px; }
.icon-btn { background: none; border: 0; padding: 6px; color: var(--muted); border-radius: 10px; }
.icon-btn:active { background: var(--bg2); }

main { max-width: 560px; margin: 0 auto; padding: 0 16px calc(88px + env(safe-area-inset-bottom)); }
a { color: var(--accent2); }

.stage {
  min-height: 56vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; text-align: center; padding: 16px 0;
}

.big-play {
  width: min(64vw, 240px); aspect-ratio: 1; border-radius: 50%;
  border: 0; background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 12px 40px #ff4f8b55;
  display: grid; place-items: center; color: #fff;
  transition: transform .12s;
}
.big-play:active { transform: scale(.96); }
.big-play svg { width: 42%; height: 42%; margin-left: 6%; }
.big-play[disabled] { opacity: .6; }

.title-lg { font-size: 22px; font-weight: 700; }
.muted { color: var(--muted); }

.btn {
  border: 0; border-radius: 999px; padding: 14px 22px;
  background: var(--accent); color: #fff; font-weight: 700;
}
.btn:active { filter: brightness(.9); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: #ff6b6b55; }
.btn.green { background: var(--green); color: #0b2a17; }
.btn.wide { width: 100%; max-width: 360px; padding: 18px; font-size: 18px; }
.small-btn { padding: 8px 14px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; width: 100%; }
.btn-row .btn { flex: 1; max-width: 175px; }
.link { background: none; border: 0; color: var(--accent2); padding: 0 4px; text-decoration: underline; }

/* Equalizer animation */
.eq { display: flex; gap: 6px; align-items: flex-end; height: 90px; }
.eq span {
  width: 14px; border-radius: 4px; background: linear-gradient(var(--accent2), var(--accent));
  animation: eq 1s ease-in-out infinite;
}
.eq span:nth-child(2) { animation-delay: -.3s; }
.eq span:nth-child(3) { animation-delay: -.6s; }
.eq span:nth-child(4) { animation-delay: -.15s; }
.eq span:nth-child(5) { animation-delay: -.45s; }
.eq.paused span { animation-play-state: paused; }
@keyframes eq { 0%, 100% { height: 18%; } 50% { height: 100%; } }

/* Reveal card */
.card {
  width: 100%; max-width: 360px; border-radius: var(--radius);
  background: linear-gradient(160deg, #ff4f8b, #8a4fff);
  padding: 24px 20px; box-shadow: 0 16px 50px #0008;
}
.card.anim { animation: flip .45s ease-out; }
@keyframes flip { from { transform: perspective(800px) rotateY(80deg); opacity: 0; } to { transform: none; opacity: 1; } }
.card .artist { font-size: 18px; font-weight: 600; opacity: .95; }
.card .year { font-size: 84px; font-weight: 900; line-height: 1; margin: 14px 0; letter-spacing: -.02em; }
.card .song { font-size: 20px; font-weight: 700; }
.card .meta { font-size: 12px; opacity: .75; margin-top: 12px; }
.card img { width: 72px; height: 72px; border-radius: 8px; float: right; margin-left: 10px; display: none; }
.card.cover img { display: block; }

.msg {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin: 0 0 16px; font-size: 14px;
}
.msg.error { border-color: #ff6b6b88; }
.msg .btn-row { margin-top: 10px; justify-content: flex-start; }

/* Year grid */
.years { background: var(--bg2); border-radius: 14px; padding: 10px 14px; border: 1px solid var(--line); }
.years summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.years summary span { color: var(--muted); font-weight: 400; font-size: 13px; }
.year-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; margin-top: 10px; }
.year-grid div {
  border-radius: 8px; padding: 5px 0; text-align: center; font-size: 13px;
  background: var(--card); color: var(--muted); font-variant-numeric: tabular-nums;
}
.year-grid div b { display: block; font-size: 11px; font-weight: 600; }
.year-grid .c1 { background: #4a3a1e; color: #ffd28a; }
.year-grid .c2 { background: #6b3a24; color: #ffc3a0; }
.year-grid .full { background: #5a1f33; color: #ff9ab8; text-decoration: line-through; }
.year-grid .off { opacity: .3; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 2px; }

/* Settings dialog */
dialog {
  border: 1px solid var(--line); border-radius: 20px; background: var(--bg2); color: var(--text);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0;
}
dialog::backdrop { background: #000a; }
.settings { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.settings h2 { margin: 0; font-size: 20px; }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; margin: 0; min-width: 0; }
legend { padding: 0 6px; color: var(--muted); font-size: 13px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
input, select {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; width: 100%; min-width: 0;
}
.row { display: flex; gap: 8px; align-items: center; }
.row select { flex: 1; }
.row.two > label { flex: 1; }
.row.end { justify-content: flex-end; }
.row #authStatus { flex: 1; }
.small { font-size: 12px; color: var(--muted); }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; word-break: break-all; color: var(--text); }

.setup ol { text-align: left; padding-left: 20px; color: var(--muted); font-size: 14px; }
.setup ol li { margin: 6px 0; }
.setup a { color: var(--accent2); }

/* ---------- Layout-Bausteine ---------- */
.center { text-align: center; }
.pad { padding: 8px 2px; }
.grow { flex: 1; }
.err { color: var(--danger); font-size: 14px; min-height: 1em; }
.panel {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; margin: 0 0 16px;
}
.panel h3, .panel h2 { margin: 0 0 10px; }
.panel.narrow { max-width: 400px; margin: 8vh auto 0; }
.hero { text-align: center; margin: 0 0 6px; font-size: 30px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input, .row > select { flex: 1; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; flex-wrap: wrap; }
.row.two > label { flex: 1; }
.check { flex-direction: row; align-items: center; gap: 10px; }
.check input { width: 20px; height: 20px; }
.btn-row.left { justify-content: flex-start; }
.btn-row.left .btn { flex: 0 0 auto; max-width: none; }
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.btn[disabled] { opacity: .5; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.toolbar select { flex: 1; }
.section-head { margin: 4px 0 14px; }
.section-head h2 { margin: 0 0 6px; font-size: 22px; }
.section-head .btn-row { margin-top: 12px; }
.sub-head { margin: 22px 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }
.back { display: inline-block; color: var(--muted); text-decoration: none; margin: 2px 0 8px; font-size: 14px; }
details summary { cursor: pointer; }
.panel details summary { color: var(--muted); font-size: 14px; padding: 4px 0; }

.seg { display: flex; background: var(--bg); border-radius: 999px; padding: 4px; margin: 16px 0; }
.seg button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 999px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--card); color: var(--text); }

/* Listen */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px;
  background: var(--bg2); border: 1px solid var(--line); color: var(--text); text-decoration: none;
}
.list-item:active { background: var(--card); }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 700; }
.li-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.chev { color: var(--muted); font-size: 24px; }

.song-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.song-row .sy { font-variant-numeric: tabular-nums; color: var(--accent2); font-weight: 700; width: 40px; flex: none; }
.song-row .st { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.song-row .flags { display: flex; gap: 4px; font-size: 13px; color: var(--muted); }
.song-row .flags .ok { color: var(--green); }
.song-row .thumb { width: 40px; height: 40px; border-radius: 6px; flex: none; background: var(--card); }
#catFilter { margin-bottom: 6px; }

/* Untere Navigation */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: rgba(20, 18, 31, .94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar[hidden] { display: none; }
.tabbar a {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; padding: 4px 0; border-radius: 10px;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }

/* Scanner */
.scan { display: flex; flex-direction: column; gap: 14px; padding-top: 8px; }
.video-wrap { position: relative; width: 100%; aspect-ratio: 1; border-radius: 20px; overflow: hidden; background: #000; }
.video-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scan-next { display: block; margin: 0 auto 12px; }

/* Dialog & Toast */
#dlg { padding: 0; }
.dialog-form { padding: 18px; }
.dialog-form h2 { margin: 0; font-size: 20px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100vw - 32px); box-shadow: 0 8px 30px #0008;
}
.toast.error { border-color: #ff6b6b88; }
