/**
 * base.css - Gemeinsame Styles für Music Faces
 * Kinderfreundlich, verspielt, animiert
 */

/* =========================================================================
   CSS Custom Properties (Defaults - werden von Themes überschrieben)
   ========================================================================= */

:root {
  /* Farben */
  --color-primary: #8b5cf6;
  --color-secondary: #ec4899;
  --color-background: #1a1a2e;
  --color-surface: #16213e;
  --color-surface-hover: #1e2a4a;
  --color-text: #ffffff;
  --color-text-muted: #94a3b8;
  --color-accent-1: #4ade80;
  --color-accent-2: #fbbf24;
  --color-accent-3: #38bdf8;
  --color-danger: #ef4444;
  --color-success: #22c55e;
  --color-panel-header: var(--color-text);  /* Fuer lesbaren Kontrast */

  /* Grid/Sequencer Farben */
  --color-grid-line: rgba(139, 92, 246, 0.6);
  --color-playhead: rgba(139, 92, 246, 0.25);
  --color-cell-occupied: rgba(251, 191, 36, 0.5);
  --color-cell-active: rgba(34, 197, 94, 0.6);
  --color-marker: #22c55e;
  --color-marker-corner: #fbbf24;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-full: 9999px;

  /* Schatten */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px var(--color-primary);

  /* Abstände */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Animationen */
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-snap: cubic-bezier(0.2, 0, 0, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-md: 16px;
  --font-size-lg: 20px;
  --font-size-xl: 28px;
  --font-size-2xl: 36px;
}

/* =========================================================================
   Reset & Base
   ========================================================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  color: var(--color-text);
  background: var(--color-background);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: 44px;  /* Touch-optimiert: min. 44px fuer Tablets */
  min-width: 44px;
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    transform var(--duration-fast) var(--ease-bounce),
    box-shadow var(--duration-fast) var(--ease-smooth),
    background var(--duration-fast) var(--ease-smooth);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  transform: scale(1.05);
  background: var(--color-surface-hover);
}

.btn:active {
  transform: scale(0.95);
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Button Varianten */
.btn-primary {
  background: var(--color-primary);
  box-shadow: var(--shadow-sm), 0 0 20px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
  background: var(--color-primary);
  box-shadow: var(--shadow-md), 0 0 30px rgba(139, 92, 246, 0.5);
}

.btn-success {
  background: var(--color-success);
  box-shadow: var(--shadow-sm), 0 0 20px rgba(34, 197, 94, 0.3);
}

.btn-danger {
  background: var(--color-danger);
}

/* Große runde Buttons (für Kinder) */
.btn-round {
  width: 60px;
  height: 60px;
  padding: 0;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xl);
}

.btn-round-lg {
  width: 80px;
  height: 80px;
  font-size: var(--font-size-2xl);
}

/* Icon Buttons */
.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-full);
}

/* Play Button spezial */
.btn-play {
  width: 64px;
  height: 64px;
  padding: 0;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  box-shadow: var(--shadow-md), var(--shadow-glow);
  font-size: var(--font-size-xl);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-play span {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-play svg {
  width: 28px;
  height: 28px;
}

.btn-play:hover {
  box-shadow: var(--shadow-lg), 0 0 40px var(--color-primary);
}

.btn-play.playing {
  background: var(--color-success);
  box-shadow: var(--shadow-md), 0 0 30px var(--color-success);
  position: relative;
}

/* GPU-optimierte Glow-Animation mit Pseudo-Element statt box-shadow */
.btn-play.playing::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: inherit;
  background: radial-gradient(circle, var(--color-success) 0%, transparent 70%);
  opacity: 0.4;
  animation: pulse-glow-optimized 2s ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}

/* =========================================================================
   Panels & Cards
   ========================================================================= */

.panel {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
}

.panel-header {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-panel-header);
  margin-bottom: var(--space-md);
}

.card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  box-shadow: var(--shadow-lg);
  transition: transform var(--duration-normal) var(--ease-bounce);
}

.card:hover {
  transform: translateY(-4px);
}

/* =========================================================================
   Form Controls
   ========================================================================= */

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
.input,
.select {
  padding: var(--space-sm) var(--space-md);
  font-family: inherit;
  font-size: var(--font-size-md);
  color: var(--color-text);
  background: var(--color-surface);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
.input:focus,
.select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3);
}

select {
  cursor: pointer;
}

label {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Range Slider */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease-bounce);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.slider::-webkit-slider-thumb:active {
  transform: scale(0.9);
}

/* =========================================================================
   Labels & Text
   ========================================================================= */

.label {
  font-size: var(--font-size-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
}

.value {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--color-text);
}

.value-lg {
  font-size: var(--font-size-xl);
}

/* =========================================================================
   Theme Switcher
   ========================================================================= */

.theme-switcher {
  position: relative;
}

.theme-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 160px;
  z-index: 100;
}

.theme-menu .btn {
  justify-content: flex-start;
  width: 100%;
  padding: var(--space-sm) var(--space-md);
}

.theme-menu .btn:hover {
  transform: none;
  background: var(--color-surface-hover);
}

/* =========================================================================
   Transport Controls
   ========================================================================= */

.transport {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-md) var(--space-xl);
  background: rgba(0, 0, 0, 0.9);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(10px);
}

.transport-control {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.transport-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* =========================================================================
   Overlays & Modals
   ========================================================================= */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}

/* Audio Init Overlay */
.audio-init {
  position: fixed;
  inset: 0;
  background: var(--color-background);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  z-index: 2000;
}

.audio-init-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-lg);
}

.audio-init-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  padding: 0;
  background: var(--color-surface);
  color: var(--color-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform var(--duration-fast) var(--ease-bounce), box-shadow var(--duration-fast);
}

.audio-init-btn svg {
  width: 40px;
  height: 40px;
}

.audio-init-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-lg), 0 0 40px var(--color-primary-glow, rgba(255, 107, 107, 0.4));
}

.audio-init-btn:active {
  transform: scale(0.95);
}

.audio-init-text {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text);
}

.audio-init-hint {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  max-width: 280px;
  text-align: center;
  line-height: 1.4;
}

.audio-init.hidden {
  display: none;
}

/* Detector Loading Overlay */
.detector-loading {
  position: fixed;
  inset: 0;
  background: var(--color-background);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  z-index: 1999;
}

.detector-loading-animation {
  display: flex;
  gap: var(--space-md);
}

.loading-note {
  color: var(--color, var(--color-primary));
  animation: bounce-note 0.6s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.loading-note svg {
  width: 32px;
  height: 32px;
}

@keyframes bounce-note {
  0%, 100% {
    transform: translateY(0) scale(1);
    opacity: 0.6;
  }
  50% {
    transform: translateY(-16px) scale(1.2);
    opacity: 1;
  }
}

.detector-loading-text {
  font-size: var(--font-size-lg);
  color: var(--color-text-muted);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* =========================================================================
   Hint Bar
   ========================================================================= */

.hint {
  display: flex;
  gap: var(--space-lg);
  padding: var(--space-sm) var(--space-lg);
  background: rgba(0, 0, 0, 0.8);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.hint kbd {
  display: inline-block;
  padding: 2px 8px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--font-size-xs);
  margin-right: var(--space-xs);
}

/* =========================================================================
   Animations
   ========================================================================= */

@keyframes wiggle {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Legacy: box-shadow Animation (nur fuer Elemente ohne ::after) */
@keyframes pulse-glow {
  0%, 100% { box-shadow: var(--shadow-md), 0 0 20px var(--color-success); }
  50% { box-shadow: var(--shadow-md), 0 0 40px var(--color-success); }
}

/* GPU-optimiert: opacity + scale Animation (viel performanter auf Mobile) */
@keyframes pulse-glow-optimized {
  0%, 100% {
    opacity: 0.3;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.15);
  }
}

@keyframes pop-in {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slide-up {
  0% { transform: translateY(20px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes confetti {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-100px) rotate(720deg); opacity: 0; }
}

@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

/* Animation Utilities */
.animate-wiggle { animation: wiggle 0.5s ease-in-out; }
.animate-bounce { animation: bounce 0.5s ease-in-out; }
.animate-pop { animation: pop-in 0.3s var(--ease-bounce); }
.animate-slide-up { animation: slide-up 0.3s var(--ease-smooth); }

/* =========================================================================
   Utilities
   ========================================================================= */

.hidden { display: none !important; }
.invisible { visibility: hidden; }
.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;
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }

/* =========================================================================
   Transitions (for Alpine x-transition)
   ========================================================================= */

.fade-enter-active,
.fade-leave-active {
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

[x-cloak] { display: none !important; }
