/*******************************************************
 * 161HZ Audiocast – Barrierefreies Design
 * WCAG 2.1 AAA konform
 * MIT Lizenz Maik Matthes 161HZ.DE
 *******************************************************/

/* ===== CSS Custom Properties ===== */
:root {
  /* Farben – Kontrastverhältnis mind. 7:1 (AAA) */
  --color-bg: #0d0d0d;
  --color-surface: #1a1a1a;
  --color-surface-hover: #252525;
  --color-border: #444;
  --color-text: #f0f0f0;
  --color-text-muted: #b0b0b0;
  --color-accent: #4fc3f7;
  --color-accent-hover: #81d4fa;
  --color-play: #66bb6a;
  --color-play-hover: #81c784;
  --color-stop: #ef5350;
  --color-stop-hover: #e57373;
  --color-mute: #ffa726;
  --color-mute-hover: #ffb74d;
  --color-muted-active: #e53935;
  --color-focus: #90caf9;
  --color-link: #81d4fa;
  --color-link-hover: #b3e5fc;

  /* Schrift */
  --font-base: 1.125rem;   /* 18px – besser lesbar */
  --font-scale: 1;
  --line-height: 1.6;
  --font-family: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Abstände */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* Radien */
  --radius: 0.5rem;
  --radius-lg: 0.75rem;

  /* Min. Touch-Target (WCAG 2.5.8 AAA) */
  --touch-min: 44px;

  /* Fokus */
  --focus-width: 3px;
  --focus-offset: 3px;
}

/* ===== High-Contrast-Modus ===== */
.high-contrast {
  --color-bg: #000;
  --color-surface: #111;
  --color-surface-hover: #222;
  --color-border: #fff;
  --color-text: #fff;
  --color-text-muted: #ddd;
  --color-accent: #ffff00;
  --color-accent-hover: #ffff66;
  --color-play: #00ff00;
  --color-play-hover: #66ff66;
  --color-stop: #ff0000;
  --color-stop-hover: #ff6666;
  --color-mute: #ffff00;
  --color-mute-hover: #ffff66;
  --color-muted-active: #ff0000;
  --color-focus: #ffff00;
  --color-link: #ffff00;
  --color-link-hover: #ffff99;
}

/* ===== Reset & Basis ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: calc(var(--font-base) * var(--font-scale));
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  font-family: var(--font-family);
  line-height: var(--line-height);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ===== Fokus-Stile (immer sichtbar) ===== */
:focus-visible {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
  border-radius: 2px;
}

/* ===== Skip-Link ===== */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  background: var(--color-accent);
  color: #000;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  z-index: 1000;
  text-decoration: none;
}

.skip-link:focus {
  top: var(--space-md);
}

/* ===== Header ===== */
header {
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  padding: var(--space-lg) var(--space-xl);
  text-align: center;
}

header h1 {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--color-accent);
}

/* ===== Toolbar (Accessibility-Controls) ===== */
.accessibility-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.accessibility-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  padding: var(--space-xs) var(--space-md);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface-hover);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.accessibility-controls button:hover {
  background: var(--color-border);
  border-color: var(--color-accent);
}

.accessibility-controls button:active {
  transform: scale(0.97);
}

.accessibility-controls button[aria-pressed="true"] {
  background: var(--color-accent);
  color: #000;
  border-color: var(--color-accent);
}

/* ===== Intro ===== */
.intro-text {
  max-width: 48rem;
  margin: var(--space-xl) auto;
  padding: 0 var(--space-lg);
  text-align: center;
}

.intro-text p {
  font-size: 1.05rem;
  color: var(--color-text-muted);
  line-height: var(--line-height);
}

/* ===== Main ===== */
main {
  flex: 1;
  padding: var(--space-md) var(--space-lg);
  max-width: 72rem;
  margin: 0 auto;
  width: 100%;
}

/* ===== Gruppen-Header ===== */
.desc-header {
  font-size: clamp(1.15rem, 3vw, 1.5rem);
  font-weight: 700;
  color: var(--color-accent);
  margin: var(--space-xl) 0 var(--space-md);
  padding-bottom: var(--space-xs);
  border-bottom: 2px solid var(--color-border);
}

/* ===== Kanal-Grid ===== */
.row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

/* ===== Audio-Player ===== */
.player {
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md) var(--space-lg);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-md);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.player:hover {
  border-color: var(--color-accent);
}

.player.is-playing {
  border-color: var(--color-play);
  box-shadow: 0 0 0 1px var(--color-play), 0 0 16px rgba(102, 187, 106, 0.12);
}

/* --- Großer runder Play/Stop-Button --- */
.player-play {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  border: 2px solid var(--color-play);
  background: transparent;
  color: var(--color-play);
  font-size: 1.5rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
  line-height: 1;
  padding: 0;
  font-family: inherit;
}

.player-play:hover {
  background: var(--color-play);
  color: #000;
}

.player-play:active {
  transform: scale(0.92);
}

.player-play[data-state="stop"] {
  border-color: var(--color-stop);
  color: var(--color-stop);
}

.player-play[data-state="stop"]:hover {
  background: var(--color-stop);
  color: #fff;
}

/* --- Player Body (Mitte) --- */
.player-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.player-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
}

.player-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-listeners {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Equalizer-Bars --- */
.player-eq {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 24px;
  padding: 2px 0;
}

.player-eq span {
  display: block;
  width: 4px;
  border-radius: 2px;
  background: var(--color-border);
  height: 4px;
  transition: background 0.2s ease;
}

/* Ruhezustand: statische niedrige Bars */
.player-eq span:nth-child(1) { height: 6px; }
.player-eq span:nth-child(2) { height: 10px; }
.player-eq span:nth-child(3) { height: 8px; }
.player-eq span:nth-child(4) { height: 14px; }
.player-eq span:nth-child(5) { height: 6px; }
.player-eq span:nth-child(6) { height: 10px; }
.player-eq span:nth-child(7) { height: 8px; }
.player-eq span:nth-child(8) { height: 12px; }
.player-eq span:nth-child(9) { height: 6px; }
.player-eq span:nth-child(10) { height: 10px; }
.player-eq span:nth-child(11) { height: 14px; }
.player-eq span:nth-child(12) { height: 8px; }

/* Animierte Bars wenn aktiv */
.player.is-playing .player-eq span {
  background: var(--color-play);
  animation: eq-bounce 0.8s ease-in-out infinite alternate;
}

.player.is-playing .player-eq span:nth-child(1)  { animation-delay: 0s; }
.player.is-playing .player-eq span:nth-child(2)  { animation-delay: 0.1s; }
.player.is-playing .player-eq span:nth-child(3)  { animation-delay: 0.15s; }
.player.is-playing .player-eq span:nth-child(4)  { animation-delay: 0.05s; }
.player.is-playing .player-eq span:nth-child(5)  { animation-delay: 0.2s; }
.player.is-playing .player-eq span:nth-child(6)  { animation-delay: 0.08s; }
.player.is-playing .player-eq span:nth-child(7)  { animation-delay: 0.18s; }
.player.is-playing .player-eq span:nth-child(8)  { animation-delay: 0.03s; }
.player.is-playing .player-eq span:nth-child(9)  { animation-delay: 0.12s; }
.player.is-playing .player-eq span:nth-child(10) { animation-delay: 0.22s; }
.player.is-playing .player-eq span:nth-child(11) { animation-delay: 0.07s; }
.player.is-playing .player-eq span:nth-child(12) { animation-delay: 0.16s; }

.player.is-playing.is-muted .player-eq span {
  background: var(--color-muted-active);
  animation-play-state: paused;
}

@keyframes eq-bounce {
  0%   { height: 4px; }
  100% { height: 22px; }
}

/* Verbinde-Zustand: pulsierende Bars */
.player.is-connecting .player-eq span {
  background: var(--color-accent);
  animation: eq-pulse 1.2s ease-in-out infinite;
}

@keyframes eq-pulse {
  0%, 100% { opacity: 0.3; height: 4px; }
  50%      { opacity: 1;   height: 12px; }
}

/* --- Mute-Button (rechts) --- */
.player-mute {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.15rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  padding: 0;
  font-family: inherit;
}

.player-mute:hover {
  border-color: var(--color-mute);
  color: var(--color-text);
}

.player-mute[aria-pressed="true"] {
  background: var(--color-muted-active);
  border-color: var(--color-muted-active);
  color: #fff;
}

.player-mute[hidden] {
  display: none;
}

/* ===== Status-Anzeige (visuell) ===== */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.02em;
}

.status-indicator::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
  flex-shrink: 0;
}

.status-indicator[data-status="playing"]::before {
  background: var(--color-play);
  box-shadow: 0 0 6px var(--color-play);
}

.status-indicator[data-status="connecting"]::before {
  background: var(--color-accent);
  animation: status-pulse 1s ease-in-out infinite;
}

.status-indicator[data-status="stopped"]::before {
  background: var(--color-text-muted);
}

.status-indicator[data-status="muted"]::before {
  background: var(--color-muted-active);
}

@keyframes status-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

button {
  font-family: inherit;
}

/* ===== Live-Region (Screenreader-Feedback) ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Footer ===== */
footer {
  background: var(--color-surface);
  border-top: 2px solid var(--color-border);
  text-align: center;
  padding: var(--space-lg) var(--space-md);
  margin-top: auto;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

footer a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
}

footer a:hover {
  color: var(--color-link-hover);
}

footer p {
  margin-top: var(--space-sm);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  :root {
    --space-lg: 1rem;
    --space-xl: 1.5rem;
  }

  header {
    padding: var(--space-md);
  }

  main {
    padding: var(--space-sm) var(--space-md);
  }

  .row {
    grid-template-columns: 1fr;
  }

  .player {
    grid-template-columns: auto 1fr auto;
    padding: var(--space-sm) var(--space-md);
    gap: var(--space-sm);
  }

  .player-play {
    width: 48px;
    height: 48px;
    min-width: 48px;
    font-size: 1.25rem;
  }

  .player-mute {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }
}

/* ===== Forced Colors (Windows High Contrast) ===== */
@media (forced-colors: active) {
  .player-play,
  .player-mute,
  .accessibility-controls button {
    border: 2px solid ButtonText;
  }

  .player {
    border: 2px solid CanvasText;
  }

  .status-indicator::before,
  .player-eq span {
    forced-color-adjust: none;
  }
}

/* ===== Print ===== */
@media print {
  .accessibility-controls,
  .skip-link,
  .player-play,
  .player-mute,
  .player-eq,
  audio {
    display: none !important;
  }

  body {
    color: #000;
    background: #fff;
  }
}
