:root {
  --red: #EB303A;
  --red-dark: #B8222B;
  --bg: #111215;
  --panel: #1B1D21;
  --panel-2: #25282D;
  --line: #34383F;
  --text: #F2F3F5;
  --muted: #9BA0A8;
  --spotify: #1DB954;
  --radius: 16px;
  --pad-min: 170px;
  color-scheme: dark;
}
body[data-size="s"] { --pad-min: 130px; }
body[data-size="l"] { --pad-min: 230px; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
input, select, textarea { -webkit-user-select: text; user-select: text; font: inherit; }
button { font: inherit; color: inherit; touch-action: manipulation; }
button:focus { outline: none; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
code { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel-2); padding: 2px 6px; border-radius: 6px; -webkit-user-select: all; user-select: all; word-break: break-all; }
h2 { margin: 0 0 12px; font-size: 1.3rem; }
h3 { margin: 20px 0 8px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.warn { color: #FFB4B8; background: #3A1A1C; padding: 10px 12px; border-radius: 10px; }
.spacer { flex: 1; }

.ico { width: 22px; height: 22px; flex: none; }
.ico-s { width: 16px; height: 16px; flex: none; }
.ico-xs { width: 12px; height: 12px; flex: none; }
.ico-l { width: 36px; height: 36px; }
.ico-xl { width: 56px; height: 56px; color: var(--spotify); }

/* ---------- Kopfzeile ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 14px) 10px calc(env(safe-area-inset-left) + 14px);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.logo-wrap { background: #fff; border-radius: 12px; padding: 3px 8px; flex: none; display: flex; }
.logo { height: 38px; width: auto; display: block; }
.tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; padding: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 9px 16px;
  background: var(--panel-2); color: var(--text); font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--red); }
.tab-add { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.tab-spotify .ico-s { color: var(--spotify); }
.tab-spotify.active { background: var(--spotify); color: #08130c; }
.tab-spotify.active .ico-s { color: #fff; }
.tab-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: blink 1s infinite; }
.top-actions { display: flex; gap: 6px; flex: none; }

/* ---------- Buttons allgemein ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 10px 16px; font-weight: 600; cursor: pointer;
  background: var(--panel-2); color: var(--text); text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.small { padding: 7px 11px; font-size: .88rem; border-radius: 10px; }
.btn-ghost { background: var(--panel-2); }
.btn-ghost.on, #btn-edit.on { background: var(--text); color: var(--bg); }
.btn-primary { background: var(--red); color: #fff; }
.btn-danger { background: transparent; color: #FF7A80; border: 1px solid #5A2A2D; }
.btn-spotify { background: var(--spotify); color: #06120a; padding: 14px 26px; border-radius: 999px; font-size: 1.05rem; }
.icon-only { padding: 10px; }

/* ---------- Hauptbereich ---------- */
main { overflow-y: auto; padding: 16px calc(env(safe-area-inset-right) + 16px) 24px calc(env(safe-area-inset-left) + 16px); -webkit-overflow-scrolling: touch; }
.hint { background: #2B2410; color: #F5DB8B; border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: .92rem; }
.empty-state { max-width: 460px; margin: 10vh auto; text-align: center; }
.empty-state p { color: var(--muted); margin-bottom: 20px; }
.card { max-width: 640px; margin: 4vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 24px; }
.card.center { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.card .row input { flex: 1; min-width: 220px; }
.steps { padding-left: 20px; display: grid; gap: 10px; margin: 0 0 16px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--pad-min), 1fr)); gap: 12px; }

/* ---------- Pads ---------- */
.pad {
  --c: #EB303A;
  --p: 0;
  position: relative; overflow: hidden;
  aspect-ratio: 4 / 3; min-height: 96px;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 2px;
  padding: 12px 14px 16px; text-align: left;
  border: 0; border-radius: var(--radius);
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 92%, #fff 8%), color-mix(in srgb, var(--c) 78%, #000 22%));
  color: #fff; cursor: pointer;
  box-shadow: 0 2px 0 rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.12);
  transition: transform .06s ease, filter .15s ease;
}
.pad:active { transform: scale(.965); filter: brightness(1.15); }
.pad-label { font-weight: 800; font-size: 1.12rem; line-height: 1.15; text-shadow: 0 1px 2px rgba(0,0,0,.35); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
body[data-size="l"] .pad-label { font-size: 1.35rem; }
body[data-size="s"] .pad-label { font-size: .98rem; }
.pad-sub { font-size: .8rem; opacity: .75; }
.pad-top { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 700; opacity: .9; }
.pad-top .time { margin-left: auto; font-variant-numeric: tabular-nums; background: rgba(0,0,0,.25); padding: 2px 7px; border-radius: 999px; }
.pad-flag { font-size: .66rem; letter-spacing: .08em; background: rgba(0,0,0,.25); padding: 2px 6px; border-radius: 6px; }
.pad .bar { position: absolute; left: 0; bottom: 0; height: 6px; width: calc(var(--p) * 100%); background: rgba(255,255,255,.95); }
.pad.playing { box-shadow: 0 0 0 4px #fff inset, 0 0 24px color-mix(in srgb, var(--c) 70%, transparent); animation: pulse 1.2s ease-in-out infinite; }
.pad.playing .time { background: #fff; color: #111; }
.pad.stopping { opacity: .6; animation: none; }
.pad.empty { background: var(--panel-2); border: 2px dashed var(--line); box-shadow: none; color: var(--muted); }
.pad-edit { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.45); border-radius: 999px; padding: 6px; display: flex; }
body.editing .pad-top .time { display: none; }
body.editing .pad:not(.pad-add) { outline: 2px dashed rgba(255,255,255,.35); outline-offset: -6px; }
.pad-add { background: transparent; border: 2px dashed var(--line); box-shadow: none; color: var(--muted); align-items: center; justify-content: center; text-align: center; font-weight: 600; }
.pad-add-plus { font-size: 2.2rem; line-height: 1; font-weight: 300; }

@keyframes pulse { 50% { filter: brightness(1.18); } }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Fußzeile ---------- */
.bottom {
  display: flex; align-items: center; gap: 12px;
  padding: 10px calc(env(safe-area-inset-right) + 14px) calc(env(safe-area-inset-bottom) + 10px) calc(env(safe-area-inset-left) + 14px);
  background: var(--panel); border-top: 1px solid var(--line);
}
.now { flex: 1; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.now::-webkit-scrollbar { display: none; }
.now-idle { color: var(--muted); font-size: .9rem; padding-left: 4px; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 8px 14px; background: var(--c); color: #fff; font-weight: 700; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.stopping { opacity: .5; }
.vol { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.vol input { width: 150px; }
.btn-fade { padding: 14px 18px; }
.btn-stop { background: var(--red); color: #fff; padding: 14px 28px; font-size: 1.1rem; font-weight: 900; letter-spacing: .06em; }

input[type="range"] { accent-color: var(--red); height: 28px; }
input[type="checkbox"] { accent-color: var(--red); width: 22px; height: 22px; flex: none; margin: 0; }
input[type="text"], input[type="number"], select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; font-size: 16px;
}
select { width: auto; max-width: 100%; }

/* ---------- Dialog ---------- */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 20px; padding: 0; width: min(520px, 94vw); max-height: 92dvh; }
dialog.wide { width: min(680px, 96vw); }
dialog::backdrop { background: rgba(0,0,0,.65); }
.dlg { display: flex; flex-direction: column; max-height: 92dvh; }
.dlg > h2 { padding: 20px 22px 0; }
.dlg-body { padding: 4px 22px 16px; overflow-y: auto; display: grid; gap: 14px; }
.dlg-body h3:first-child { margin-top: 4px; }
.dlg-actions { display: flex; gap: 8px; padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
.field { display: grid; gap: 6px; }
.field-label { font-size: .85rem; font-weight: 700; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row input[type="range"] { flex: 1; min-width: 160px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check span { padding-top: 1px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 10px; border: 3px solid transparent; cursor: pointer; }
.swatch.on { border-color: #fff; }
.preview-box { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; gap: 14px; }
.time-val { font-variant-numeric: tabular-nums; min-width: 92px; text-align: right; font-weight: 700; }
#preview-pos { font-variant-numeric: tabular-nums; }
.nudges { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Kabine / Spotify ---------- */
.sp-view { max-width: 980px; margin: 0 auto; display: grid; gap: 16px; }
.sp-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sp-dev { display: flex; align-items: center; gap: 8px; }
.sp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.sp-btn {
  --c: var(--spotify);
  position: relative; overflow: hidden; aspect-ratio: 16 / 10;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: flex-start; gap: 6px;
  padding: 16px; border: 0; border-radius: 20px; cursor: pointer; text-align: left; color: #fff;
  background-color: var(--c); background-size: cover; background-position: center;
}
.sp-btn::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 25%, rgba(0,0,0,.75)); }
.sp-btn:not(.has-img)::before { background: linear-gradient(160deg, rgba(255,255,255,.12), rgba(0,0,0,.3)); }
.sp-btn > * { position: relative; }
.sp-btn:active { transform: scale(.97); }
.sp-btn.active { box-shadow: 0 0 0 4px var(--spotify); }
.sp-btn.empty, .sp-btn.add { background: var(--panel-2); border: 2px dashed var(--line); color: var(--muted); justify-content: center; align-items: center; }
.sp-btn.empty::before, .sp-btn.add::before { display: none; }
.sp-btn-name { font-weight: 800; font-size: 1.3rem; line-height: 1.15; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.sp-btn-tags { display: flex; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; background: rgba(0,0,0,.45); padding: 3px 8px; border-radius: 999px; }
.tag.live { background: var(--spotify); color: #06120a; }
.sp-now { display: flex; align-items: center; gap: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 14px; flex-wrap: wrap; }
.sp-cover { width: 84px; height: 84px; border-radius: 12px; object-fit: cover; flex: none; }
.sp-cover.ph { background: var(--panel-2); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.sp-cover.ph .ico-l { color: var(--muted); }
.sp-meta { flex: 1; min-width: 160px; }
.sp-title { font-weight: 800; font-size: 1.15rem; }
.sp-ctrl { display: flex; align-items: center; gap: 10px; }
.round { width: 52px; height: 52px; border-radius: 50%; padding: 0; }
.round.big { width: 66px; height: 66px; background: #fff; color: #111; }
.round.on { color: var(--spotify); }
.sp-vol input { width: 140px; accent-color: var(--spotify); }
.pl-list { display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
.pl-list:empty { display: none; }
.pl-item { display: flex; align-items: center; gap: 10px; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px; cursor: pointer; }
.pl-item.on { border-color: var(--spotify); }
.pl-item img, .pl-ph { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--panel-2); flex: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  background: #fff; color: #111; font-weight: 600; padding: 12px 18px; border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: min(560px, 92vw); z-index: 1000; text-align: center;
}
.toast[hidden] { display: none; }

@media (max-width: 700px) {
  .logo { height: 30px; }
  #btn-edit-label { display: none; }
  .vol input { width: 90px; }
  .btn-fade { display: none; }
  .cols { grid-template-columns: 1fr; }
}
