/* ==========================================================================
   CHAOS: The Internet's Most Beautiful Sound Playground
   Vanilla CSS - Hand-drawn, Chalkboard/Sticker Pack Aesthetic (v2)
   ========================================================================== */

/* Font & Core Resets */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: #000000;
  color: #e5e5e5;
  font-family: 'Short Stack', 'Gochi Hand', cursive, sans-serif;
  overflow-x: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Wobbly Hand-Drawn Utility Borders */
.hand-border {
  border: 2px solid #e5e5e5;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}

/* App Container Layout */
#app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 10px 15px 80px 15px; /* bottom padding for master volume footer */
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* ==========================================================================
   Header & Chaos Meter
   ========================================================================== */

.chaos-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 10px 20px 10px;
  border-bottom: 2px dashed #333;
  margin-bottom: 15px;
}

.logo-area {
  display: flex;
  flex-direction: column;
}

.logo-title {
  font-family: 'Schoolbell', 'Patrick Hand', cursive, sans-serif;
  font-size: 2.8rem;
  font-weight: bold;
  letter-spacing: 2px;
  color: #ffffff;
  display: inline-block;
  transform: rotate(-2deg);
  animation: logo-float 4s ease-in-out infinite alternate;
}

.logo-subtitle {
  font-size: 0.95rem;
  color: #888;
  margin-top: 2px;
}

/* Chaos Meter */
.chaos-meter-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 320px;
  text-align: center;
}

.meter-label {
  font-size: 0.8rem;
  letter-spacing: 1px;
  color: #888;
  margin-bottom: 5px;
  font-family: 'Schoolbell', cursive, sans-serif;
}

.chaos-meter-track {
  width: 100%;
  height: 24px;
  background-color: #222;
  border: 2px solid #e5e5e5;
  border-radius: 20px 8px 18px 10px / 12px 20px 10px 18px;
  overflow: hidden;
  position: relative;
}

#chaos-meter-fill {
  height: 100%;
  width: 0%;
  background: #4caf50; /* starts green */
  transition: width 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), background-color 0.4s ease;
  border-radius: 10px;
}

#chaos-meter-text {
  font-size: 0.9rem;
  margin-top: 4px;
  font-weight: bold;
  font-family: 'Schoolbell', cursive, sans-serif;
}

/* Wiggle levels depending on chaos */
.wiggle-low {
  animation: wiggle-low-anim 3s ease-in-out infinite;
}

.wiggle-medium {
  animation: wiggle-medium-anim 1.2s ease-in-out infinite;
}

.wiggle-high {
  animation: wiggle-high-anim 0.6s ease-in-out infinite;
}

.wiggle-max {
  animation: wiggle-max-anim 0.15s linear infinite;
  box-shadow: 0 0 10px rgba(255, 0, 0, 0.3);
}

/* ==========================================================================
   Main Playground Layout
   ========================================================================== */

.playground-layout {
  display: flex;
  flex: 1;
  min-height: 0; /* allows flex scrolling child */
}

/* Sound Grid Section */
.sound-library-section {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
}

/* Custom Scrollbar for Hand-drawn feel */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #1a1a1a;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: #444;
  border: 1px solid #121212;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #666;
}

.sound-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 20px;
  padding: 5px;
}

/* Sound Sticker Cards */
.sound-card {
  background-color: #1e1e1e;
  border: 2px solid #333;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  padding: 12px 10px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  cursor: pointer;
  height: 185px; /* Rigid height to prevent growing/shifting surrounding cards */
  width: 100%;
  user-select: none;
  transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
              border-color 0.25s ease, 
              box-shadow 0.25s ease,
              opacity 0.25s ease;
}

/* Card states */
.sound-card:hover {
  border-color: #666;
}

.sound-card.playing {
  border-color: #ffffff;
  background-color: #242424;
  box-shadow: 0px 0px 12px rgba(255, 255, 255, 0.15);
}

.sound-card.paused {
  opacity: 0.65;
  border-color: #555;
  background-color: #1a1a1a;
  box-shadow: none;
}

/* Mascot Icon */
.sound-card .mascot-icon-container {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
  margin-bottom: auto;
  pointer-events: none;
}

.sound-card .mascot-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: grayscale(100%);
  opacity: 0.5;
  transition: filter 0.25s ease, opacity 0.25s ease, transform 0.2s ease;
}

.sound-card.playing .mascot-icon,
.sound-card.paused .mascot-icon {
  filter: grayscale(0%);
  opacity: 1;
}

.sound-card.playing .mascot-icon {
  transform: scale(1.05);
}

/* Name */
.sound-card .sound-name {
  font-size: 0.95rem;
  font-weight: bold;
  color: #888;
  font-family: 'Short Stack', cursive, sans-serif;
  transition: color 0.25s ease;
  pointer-events: none;
}

.sound-card.playing .sound-name,
.sound-card.paused .sound-name {
  color: #ffffff;
}

/* Remove button X */
.remove-card-btn {
  position: absolute;
  top: 8px;
  right: 12px;
  background: transparent;
  border: none;
  color: #888;
  font-size: 1.1rem;
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, color 0.2s ease, background 0.2s ease;
}

/* Only show X when active (playing/paused) OR on hover */
.sound-card:hover .remove-card-btn,
.sound-card.playing .remove-card-btn,
.sound-card.paused .remove-card-btn {
  opacity: 1;
  pointer-events: auto;
}

.remove-card-btn:hover {
  color: #ff5252;
  background-color: #2c2c2c;
}

/* Slider Area inside Sound Card */
.card-slider-container {
  width: 90%;
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.sound-card.playing .card-slider-container,
.sound-card.paused .card-slider-container {
  opacity: 1;
  pointer-events: auto;
}

.volume-percentage-text {
  font-size: 0.75rem;
  font-family: 'Schoolbell', cursive, sans-serif;
  color: #999;
  width: 26px;
  text-align: right;
}

/* Mini indicator light on active card */
.sound-card::after {
  content: '';
  position: absolute;
  top: 10px;
  left: 14px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: transparent;
  transition: background-color 0.25s ease;
}

.sound-card.playing::after {
  background-color: #00e676; /* Green dot when playing */
  box-shadow: 0 0 4px #00e676;
}

.sound-card.paused::after {
  background-color: #ff9800; /* Orange dot when paused */
  box-shadow: 0 0 4px #ff9800;
}

/* ==========================================================================
   Hand Drawn Sliders
   ========================================================================== */

.hand-slider {
  -webkit-appearance: none;
  width: 100%;
  background: transparent;
  cursor: pointer;
  height: 24px;
}

.hand-slider:focus {
  outline: none;
}

/* Webkit (Chrome, Safari, Edge) Sliders */
.hand-slider::-webkit-slider-runnable-track {
  width: 100%;
  height: 8px;
  background: #333;
  border: 2px solid #e5e5e5;
  border-radius: 100px 10px 80px 15px / 12px 80px 10px 100px;
  transition: height 0.15s ease;
}

.hand-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 18px;
  width: 18px;
  border: 2px solid #e5e5e5;
  background: #ffffff;
  border-radius: 50%;
  margin-top: -7px; /* centres the thumb */
  transition: transform 0.15s ease, width 0.15s ease, height 0.15s ease;
  box-shadow: 2px 2px 0px #000;
  animation: thumb-breathe 2s ease-in-out infinite;
}

/* Hover/active thickness scaling */
.hand-slider:active::-webkit-slider-runnable-track {
  height: 10px;
}

.hand-slider:active::-webkit-slider-thumb {
  transform: scale(1.25);
  background: #00e676;
}

/* Firefox Sliders */
.hand-slider::-moz-range-track {
  width: 100%;
  height: 8px;
  background: #333;
  border: 2px solid #e5e5e5;
  border-radius: 100px 10px 80px 15px / 12px 80px 10px 100px;
}

.hand-slider::-moz-range-thumb {
  height: 18px;
  width: 18px;
  border: 2px solid #e5e5e5;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 2px 2px 0px #000;
  transition: transform 0.15s ease;
  animation: thumb-breathe 2s ease-in-out infinite;
}

.hand-slider:active::-moz-range-thumb {
  transform: scale(1.25);
  background: #00e676;
}

/* ==========================================================================
   Presets Section
   ========================================================================== */

.presets-shelf {
  margin-top: 15px;
  border-top: 2px dashed #333;
  padding-top: 15px;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.presets-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.presets-title {
  font-family: 'Schoolbell', cursive, sans-serif;
  font-size: 1.2rem;
  letter-spacing: 1px;
}

.presets-carousel-container {
  overflow-x: auto;
  padding: 5px 0 15px 0;
  width: 100%;
}

.presets-carousel {
  display: flex;
  gap: 15px;
  width: max-content;
}

/* Preset Cards */
.preset-card {
  width: 180px;
  background-color: #1e1e1e;
  border: 2px solid #333;
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.preset-card:hover {
  border-color: #e5e5e5;
  transform: translateY(-4px) rotate(-1deg);
  box-shadow: 4px 4px 0px #000000;
}

.preset-cover-wrapper {
  width: 100%;
  height: 95px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid #222;
  margin-bottom: 8px;
  background-color: #111;
  pointer-events: none;
}

.preset-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.preset-card:hover .preset-cover {
  transform: scale(1.05);
}

.preset-title-text {
  font-size: 0.9rem;
  font-weight: bold;
  text-align: center;
  font-family: 'Short Stack', cursive, sans-serif;
  color: #e5e5e5;
  pointer-events: none;
}

/* Badge for newly unlocked secrets */
.preset-secret-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  background-color: #ea80fc;
  color: #000;
  font-size: 0.7rem;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1.5px solid #fff;
  transform: rotate(-8deg);
  font-family: 'Schoolbell', cursive, sans-serif;
  animation: heartbeat 1.5s infinite;
  pointer-events: none;
}

/* ==========================================================================
   Master Volume Footer
   ========================================================================== */

.master-volume-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background-color: #000000;
  border-top: 2px solid #e5e5e5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  z-index: 100;
}

.master-volume-container {
  display: flex;
  align-items: center;
  gap: 15px;
  width: 100%;
  max-width: 600px;
}

.volume-icon {
  font-size: 1.3rem;
  user-select: none;
}

#master-volume-text {
  font-size: 1rem;
  font-weight: bold;
  font-family: 'Schoolbell', cursive, sans-serif;
  width: 45px;
  text-align: right;
}

/* ==========================================================================
   Buttons (Cute, Hand-drawn look)
   ========================================================================== */

.icon-btn-hand {
  background: #1e1e1e;
  border: 2px solid #e5e5e5;
  border-radius: 50%;
  color: #e5e5e5;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
  box-shadow: 2px 2px 0px #000;
}

.icon-btn-hand:hover {
  transform: scale(1.1) rotate(5deg);
  background: #333;
}

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

.text-btn-hand {
  background: transparent;
  border: 2px solid #e5e5e5;
  border-radius: 12px 4px 10px 6px / 6px 10px 4px 12px;
  color: #e5e5e5;
  padding: 4px 12px;
  font-family: 'Schoolbell', cursive, sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  box-shadow: 2px 2px 0px #000;
}

.text-btn-hand:hover {
  transform: translateY(-2px) rotate(1deg);
  background: #252525;
}

.text-btn-hand:active {
  transform: translateY(1px);
}

.action-btn-hand {
  background: #2a2a2a;
  border: 2px solid #ff5252;
  border-radius: 8px 12px 7px 10px / 10px 7px 12px 8px;
  color: #ff5252;
  padding: 8px 16px;
  font-family: 'Schoolbell', cursive, sans-serif;
  font-weight: bold;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  box-shadow: 3px 3px 0px #000;
}

.action-btn-hand:hover {
  transform: translateY(-2px) scale(1.02);
  background: #ff5252;
  color: #000;
}

/* ==========================================================================
   Modals (Settings)
   ========================================================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  display: none !important;
}

.modal-content-hand {
  background-color: #1e1e1e;
  border: 3px solid #e5e5e5;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  width: 90%;
  max-width: 450px;
  padding: 25px;
  box-shadow: 8px 8px 0px #000000;
  animation: modal-enter 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px dashed #333;
  padding-bottom: 12px;
  margin-bottom: 20px;
}

.modal-header h2 {
  font-family: 'Schoolbell', cursive, sans-serif;
  font-size: 1.6rem;
  color: #fff;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #00e676;
}

.settings-help {
  font-size: 0.8rem;
  color: #777;
}

.about-section {
  border-top: 2px dashed #2a2a2a;
  padding-top: 15px;
  margin-top: 5px;
}

.about-section h3 {
  font-family: 'Schoolbell', cursive, sans-serif;
  font-size: 1rem;
  color: #fff;
  margin-bottom: 6px;
}

.about-section p {
  font-size: 0.85rem;
  color: #888;
  line-height: 1.4;
  margin-bottom: 8px;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */

.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  width: 90%;
  max-width: 400px;
  pointer-events: none;
}

.toast-hand {
  pointer-events: auto;
  background-color: #ea80fc;
  color: #000000;
  border: 2px solid #ffffff;
  border-radius: 12px 18px 14px 16px / 16px 14px 18px 12px;
  padding: 12px 20px;
  font-family: 'Schoolbell', cursive, sans-serif;
  font-weight: bold;
  box-shadow: 4px 4px 0px #000;
  text-align: center;
  animation: toast-enter 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.25),
             toast-exit 0.3s cubic-bezier(0.6, -0.28, 0.735, 0.045) 3.7s forwards;
}

/* ==========================================================================
   Floating Particles Effect
   ========================================================================== */

.particle {
  position: absolute;
  pointer-events: none;
  font-size: 0.75rem;
  z-index: 10;
  animation: particle-rise 1.5s ease-out forwards;
}

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

/* Logo float */
@keyframes logo-float {
  0% { transform: translateY(0px) rotate(-2deg); }
  100% { transform: translateY(-3px) rotate(0deg); }
}

/* Breathing Volume Knob */
@keyframes thumb-breathe {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Toast animations */
@keyframes toast-enter {
  0% { transform: translateY(-50px) scale(0.8); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes toast-exit {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-50px) scale(0.8); opacity: 0; }
}

/* Modal enter */
@keyframes modal-enter {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Particle rising up and fading */
@keyframes particle-rise {
  0% {
    transform: translateY(0) scale(0.5);
    opacity: 1;
  }
  100% {
    transform: translateY(-80px) translateX(var(--drift, 10px)) scale(1.2);
    opacity: 0;
  }
}

/* Chaos wiggles */
@keyframes wiggle-low-anim {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-1px) rotate(0.3deg); }
}

@keyframes wiggle-medium-anim {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-1px, 0.5px) rotate(-0.5deg); }
  75% { transform: translate(1px, -0.5px) rotate(0.5deg); }
}

@keyframes wiggle-high-anim {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  20% { transform: translate(-2px, 1px) rotate(-1.2deg); }
  40% { transform: translate(1.5px, -1.5px) rotate(1deg); }
  60% { transform: translate(-1.5px, -1px) rotate(-0.8deg); }
  80% { transform: translate(2px, 1.5px) rotate(1.2deg); }
}

@keyframes wiggle-max-anim {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  10% { transform: translate(-4px, 2px) rotate(-2.5deg); }
  20% { transform: translate(3px, -3px) rotate(2.2deg); }
  30% { transform: translate(-2px, -2px) rotate(-2deg); }
  40% { transform: translate(4px, 3px) rotate(2.5deg); }
  50% { transform: translate(-3px, 1px) rotate(-2.2deg); }
  60% { transform: translate(2px, -2px) rotate(2deg); }
  70% { transform: translate(-4px, 3px) rotate(-2.5deg); }
  80% { transform: translate(3px, -1px) rotate(2.2deg); }
  90% { transform: translate(-2px, 2px) rotate(-2deg); }
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1) rotate(-8deg); }
  50% { transform: scale(1.1) rotate(-8deg); }
}

/* ==========================================================================
   Responsive Rules
   ========================================================================== */

/* Tablet & Smaller Layouts */
@media (max-width: 900px) {
  body {
    height: auto;
    overflow-y: auto;
  }
  
  #app-container {
    height: auto;
    padding-bottom: 90px;
  }
  
  .playground-layout {
    height: auto;
  }
  
  .sound-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  
  .chaos-header {
    flex-direction: column;
    gap: 15px;
    align-items: center;
    text-align: center;
  }
  
  .chaos-meter-container {
    width: 100%;
    max-width: 400px;
  }
}

/* Mobile Screens */
@media (max-width: 600px) {
  .sound-grid {
    grid-template-columns: repeat(2, 1fr); /* Strict 2 columns */
  }
  
  .logo-title {
    font-size: 2.2rem;
  }
  
  .presets-carousel-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Accessibility: Reduce Motion */
body.reduce-motion .logo-title,
body.reduce-motion .preset-card,
body.reduce-motion .preset-cover,
body.reduce-motion .playing-badge,
body.reduce-motion .now-playing-card,
body.reduce-motion .modal-content-hand,
body.reduce-motion .toast-hand,
body.reduce-motion #chaos-meter-fill {
  animation: none !important;
  transition: none !important;
}

body.reduce-motion .hand-slider::-webkit-slider-thumb {
  animation: none !important;
}
body.reduce-motion .hand-slider::-moz-range-thumb {
  animation: none !important;
}

body.reduce-motion .wiggle-low,
body.reduce-motion .wiggle-medium,
body.reduce-motion .wiggle-high,
body.reduce-motion .wiggle-max {
  animation: none !important;
}

body.reduce-motion .particle {
  display: none !important;
}
