:root {
  color-scheme: light dark;
  --bg: #f6f5fb;
  --surface: #ffffff;
  --text: #1c1a2b;
  --muted: #6b6880;
  --line: #e4e1f0;
  --accent: #6d4dff;
  --accent-2: #ec4899;
  --shadow: 0 1px 2px rgb(30 20 80 / .06), 0 6px 20px rgb(30 20 80 / .06);

}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13121c;
    --surface: #1d1b2a;
    --text: #efedf8;
    --muted: #9a97b0;
    --line: #2e2b40;
    --accent: #9a84ff;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);

  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

.wrap {
  width: min(100%, 1180px);
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

/* ---------- Kopf ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(14px + env(safe-area-inset-top)) 0 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.logo { border-radius: 10px; display: block; }

h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -.02em;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.count {
  margin-left: auto;
  font-size: .85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Suche ---------- */

.search { position: relative; }

.search input {
  width: 100%;
  height: 52px;
  padding: 0 52px 0 48px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.05rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  -webkit-appearance: none;
}

.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button { display: none; }

.search input:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  width: 20px;
  height: 20px;
  translate: 0 -50%;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.hint, .clear {
  position: absolute;
  right: 10px;
  top: 50%;
  translate: 0 -50%;
}

.hint {
  display: none;
  min-width: 26px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 7px;
  color: var(--muted);
  font: 600 .8rem/1.5 ui-monospace, Consolas, monospace;
  text-align: center;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .search input:placeholder-shown:not(:focus) ~ .hint { display: block; }
}

.clear {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--muted) 16%, transparent);
  cursor: pointer;
}

.clear svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.clear:hover { background: color-mix(in srgb, var(--muted) 28%, transparent); }

/* ---------- Kategorien ---------- */

.chips {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  padding: 7px 16px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}

.chip:hover { color: var(--text); }

.chip[aria-pressed="true"] {
  border-color: transparent;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  color: #fff;
}

/* ---------- Kacheln ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 10px;
  padding-block: 16px calc(96px + env(safe-area-inset-bottom));
}

/* Farbton kommt pro Kachel über --h; die Farben müssen deshalb hier an der
   Kachel berechnet werden und nicht in :root, wo --h noch nicht gesetzt ist. */
.tile {
  --tile-bg: hsl(var(--h) 90% 96%);
  --tile-line: hsl(var(--h) 70% 89%);
  --tile-fill: hsl(var(--h) 85% 86%);
  --tile-text: hsl(var(--h) 45% 20%);
  --tile-icon: hsl(var(--h) 72% 56%);
}

@media (prefers-color-scheme: dark) {
  .tile {
    --tile-bg: hsl(var(--h) 32% 17%);
    --tile-line: hsl(var(--h) 34% 25%);
    --tile-fill: hsl(var(--h) 45% 30%);
    --tile-text: hsl(var(--h) 75% 90%);
    --tile-icon: hsl(var(--h) 70% 62%);
  }
}

.tile {
  --p: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 12px 16px 12px 12px;
  overflow: hidden;
  border: 1.5px solid var(--tile-line);
  border-radius: 18px;
  background: var(--tile-bg);
  color: var(--tile-text);
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .12s, box-shadow .15s, border-color .15s;
}

/* Fortschrittsbalken hinter dem Inhalt */
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--tile-fill);
  transform-origin: left;
  transform: scaleX(var(--p));
  opacity: 0;
}

.tile > * { position: relative; }

.tile-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--tile-icon);
  color: #fff;
  transition: transform .15s;
}

.tile-icon svg { width: 18px; height: 18px; fill: currentColor; }
.tile-icon .i-stop { display: none; }

.tile-label { overflow-wrap: anywhere; }

@media (hover: hover) {
  .tile:hover {
    transform: translateY(-2px);
    border-color: var(--tile-icon);
    box-shadow: 0 8px 20px hsl(var(--h) 60% 40% / .16);
  }
  .tile:hover .tile-icon { transform: scale(1.08); }
}

.tile:active { transform: scale(.975); }

.tile:focus-visible, .chip:focus-visible, .clear:focus-visible,
.reset:focus-visible, .now:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.tile.playing {
  border-color: var(--tile-icon);
  box-shadow: 0 8px 22px hsl(var(--h) 60% 40% / .22);
}

.tile.playing::before { opacity: 1; }
.tile.playing .i-play { display: none; }
.tile.playing .i-stop { display: block; }

.tile.failed { animation: shake .35s; }

@keyframes shake {
  25% { translate: -5px 0; }
  75% { translate: 5px 0; }
}

/* ---------- Leerer Zustand ---------- */

.empty {
  padding: 56px 16px;
  color: var(--muted);
  text-align: center;
}

.empty p { margin: 0 0 6px; }
.empty-title { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.empty q { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }

.reset {
  margin-top: 14px;
  padding: 10px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- „Läuft gerade“ ---------- */

.now {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(92vw, 520px);
  padding: 10px 20px 10px 10px;
  translate: -50% 0;
  border: 0;
  border-radius: 999px;
  background: #1c1a2b;
  color: #fff;
  box-shadow: 0 10px 30px rgb(0 0 0 / .35);
  font-weight: 600;
  cursor: pointer;
  animation: rise .2s ease-out;
}

@media (prefers-color-scheme: dark) {
  .now { background: #f1effa; color: #1c1a2b; }
}

.now-stop {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.now-stop::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #fff;
}

.now-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@keyframes rise {
  from { opacity: 0; translate: -50% 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- PIN-Abfrage ---------- */

.gate { display: none; }

.locked .top, .locked main, .locked .now { display: none; }

.locked .gate {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 14px;
  min-height: 100dvh;
  padding: 24px;
  text-align: center;
}

.gate img { border-radius: 20px; box-shadow: var(--shadow); }
.gate h1 { font-size: 1.9rem; }
.gate label { color: var(--muted); }

.pin {
  width: 8.2em;
  height: 64px;
  padding: 0 0 0 .5em;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: .5em;
  text-align: center;
  outline: none;
  -webkit-text-security: disc;
}

.pin:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}

.pin.wrong { border-color: #e5484d; animation: shake .35s; }

.pin-msg { min-height: 1.4em; margin: 0; color: #e5484d; font-weight: 600; }
