:root {
  --bg: #000;
  --fg: #fff;
  --muted: rgba(255, 255, 255, .55);
  --surface: rgba(255, 255, 255, .08);
  --border: rgba(255, 255, 255, .18);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* Muss vor allen Layout-Regeln stehen: sonst überschreibt z. B.
   `.sheet { display: flex }` das hidden-Attribut, und das Overlay liegt
   unsichtbar über der Seite und schluckt alle Klicks. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* Kein Overscroll-Bounce, kein Doppeltipp-Zoom beim schnellen Drücken */
  overscroll-behavior-y: contain;
  touch-action: manipulation;
}

/* ---------- Kopfbereich ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  background: rgba(0, 0, 0, .82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

#search {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  font-size: 16px; /* <16px löst auf iOS Auto-Zoom aus */
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  appearance: none;
}

#search::placeholder { color: var(--muted); }
#search:focus-visible,
.chip:focus-visible,
.icon-btn:focus-visible,
.tile:focus-visible,
.sheet-btn:focus-visible {
  outline: 2px solid #4da3ff;
  outline-offset: 2px;
}

.icon-btn {
  flex: none;
  width: 46px;
  height: 46px;
  font-size: 22px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}

.icon-btn:active { transform: scale(.94); }

.filters { display: flex; gap: 6px; }

.chip {
  padding: 7px 13px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.chip.is-active {
  color: #000;
  background: var(--fg);
  border-color: var(--fg);
  font-weight: 600;
}

.vol {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

.vol input {
  width: 92px;
  accent-color: #fff;
}

#vol-out {
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Raster ---------- */

main {
  padding: 14px 12px calc(var(--safe-b) + 90px);
}

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

.tile {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  color: var(--fg);
  border: 2px solid rgba(255, 255, 255, .2);
  box-shadow: 0 3px 6px rgba(0, 0, 0, .35);
  cursor: pointer;
  /* Langes Drücken soll unser Menü öffnen, nicht das des Browsers */
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .1s ease;
}

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

.tile.is-playing {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .35), 0 3px 6px rgba(0, 0, 0, .35);
}

.tile .emoji {
  font-size: 34px;
  line-height: 1;
  /* Emoji sollen ihre eigenen Farben behalten */
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .4));
}

.tile .label {
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  line-height: 1.15;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}

.tile .star {
  position: absolute;
  top: 5px;
  right: 7px;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}

.empty {
  margin-top: 40px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Stopp ---------- */

.stop {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 18px);
  transform: translateX(-50%);
  padding: 12px 26px;
  font-size: 15px;
  font-weight: 600;
  color: #000;
  background: #fff;
  border: none;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
  cursor: pointer;
  z-index: 20;
}

/* ---------- Aktionsmenü ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(var(--safe-b) + 16px);
  background: rgba(0, 0, 0, .6);
  backdrop-filter: blur(3px);
}

.sheet-card {
  width: min(420px, 100%);
  padding: 16px;
  background: #1c1c1e;
  border: 1px solid var(--border);
  border-radius: 18px;
  display: grid;
  gap: 8px;
}

.sheet-card h2 {
  margin: 2px 0 8px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
}

.sheet-btn {
  padding: 14px;
  font-size: 16px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
}

.sheet-btn:active { transform: scale(.98); }
.sheet-btn.subtle { background: none; color: var(--muted); }

/* ---------- Hinweis-Einblendung ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 80px);
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(90vw, 380px);
  padding: 11px 18px;
  font-size: 14px;
  text-align: center;
  color: #000;
  background: #fff;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
}

@media (prefers-reduced-motion: reduce) {
  .tile, .sheet-btn { transition: none; }
  .tile:active, .icon-btn:active, .sheet-btn:active { transform: none; }
}
