body, html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: #09090b;
  color: #ededed;
  font-family: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#ui-container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 10;
  background: #141416;
  padding: 40px 48px;
  border-radius: 6px;
  border: 1px solid #2a2a2e;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  pointer-events: auto !important;
  width: min(420px, calc(100vw - 32px));
  box-sizing: border-box;
}

body.playing #ui-container {
  opacity: 0;
  visibility: hidden;
}

body.playing #ui-container:hover,
body.playing #ui-container:focus-within {
  opacity: 1;
  visibility: visible;
}

h1 {
  margin: 0 0 8px;
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}

p {
  font-size: 0.95rem;
  color: #b4b4bb;
  margin: 0 0 24px;
}

/* File inputs stay focusable, just not visible */
input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

button, select, label {
  font: inherit;
}

:focus-visible,
label:focus-within {
  outline: 2px solid #ffd166;
  outline-offset: 2px;
}

.load-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.custom-file-upload,
#demo-btn {
  display: inline-block;
  padding: 10px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 4px;
  border: 1px solid #ffd166;
}

.custom-file-upload {
  background: #ffd166;
  color: #1a1400;
}

.custom-file-upload:hover {
  background: #ffdd8a;
}

#demo-btn {
  background: transparent;
  color: #ffd166;
}

#demo-btn:hover {
  background: #2a2412;
}

#status {
  margin-bottom: 20px;
  color: #b4b4bb;
  font-size: 0.85rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

#controls {
  display: flex;
  justify-content: center;
  gap: 8px;
}

#controls button,
#test-audio-btn {
  background: #1f1f23;
  color: #ededed;
  border: 1px solid #3a3a40;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

#controls button:hover,
#test-audio-btn:hover {
  background: #2c2c31;
  border-color: #55555c;
}

#secondary-controls {
  margin-top: 12px;
}

#top-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  left: 16px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  pointer-events: auto;
}

#top-controls button, #top-controls label, #top-controls select {
  background-color: #141416;
  color: #c9c9cf;
  border: 1px solid #2f2f34;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

#top-controls button:hover, #top-controls label:hover, #top-controls select:hover {
  background-color: #222226;
  color: #fff;
  border-color: #4a4a50;
}

#top-controls button.active, #top-controls label.active {
  background-color: #2a2412;
  color: #ffd166;
  border-color: #ffd166;
}

#top-controls select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23c9c9cf' stroke-width='1.5'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  padding-right: 28px;
}

#top-controls select option {
  background: #09090b;
  color: #ededed;
}

/* Club Mode FX */
body.club-mode #visualizer, body.club-mode #webcam-bg, body.club-mode #theme-bg {
  animation: rgb-shift 2s infinite alternate ease-in-out;
  -webkit-animation: rgb-shift 2s infinite alternate ease-in-out;
}

@keyframes rgb-shift {
  0% { filter: drop-shadow(0px 0px 0px rgba(0,0,0,0)) hue-rotate(0deg); -webkit-filter: drop-shadow(0px 0px 0px rgba(0,0,0,0)) hue-rotate(0deg); }
  33% { filter: drop-shadow(5px 0px 10px rgba(255,0,0,0.3)) hue-rotate(45deg); -webkit-filter: drop-shadow(5px 0px 10px rgba(255,0,0,0.3)) hue-rotate(45deg); }
  66% { filter: drop-shadow(-5px 0px 10px rgba(0,255,255,0.3)) hue-rotate(90deg); -webkit-filter: drop-shadow(-5px 0px 10px rgba(0,255,255,0.3)) hue-rotate(90deg); }
  100% { filter: drop-shadow(0px 5px 10px rgba(0,255,0,0.3)) hue-rotate(0deg); -webkit-filter: drop-shadow(0px 5px 10px rgba(0,255,0,0.3)) hue-rotate(0deg); }
}

/* Carnival Effect */
body.effect-carnival #visualizer, body.effect-carnival #webcam-bg, body.effect-carnival #theme-bg {
  animation: carnival-spin 4s infinite linear, rgb-shift 1s infinite alternate ease-in-out;
  -webkit-animation: carnival-spin 4s infinite linear, rgb-shift 1s infinite alternate ease-in-out;
}

@keyframes carnival-spin {
  0% { transform: rotate(0deg) scale(1); -webkit-transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.1); -webkit-transform: rotate(180deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); -webkit-transform: rotate(360deg) scale(1); }
}

/* Trippy Effect */
body.effect-trippy #visualizer, body.effect-trippy #webcam-bg, body.effect-trippy #theme-bg {
  animation: trippy-pulse 2s infinite alternate ease-in-out;
  -webkit-animation: trippy-pulse 2s infinite alternate ease-in-out;
}

@keyframes trippy-pulse {
  0% { transform: scale(1) skew(0deg); filter: hue-rotate(0deg) blur(0px) invert(0%); -webkit-transform: scale(1) skew(0deg); -webkit-filter: hue-rotate(0deg) blur(0px) invert(0%); }
  100% { transform: scale(1.3) skew(15deg); filter: hue-rotate(360deg) blur(4px) invert(20%); -webkit-transform: scale(1.3) skew(15deg); -webkit-filter: hue-rotate(360deg) blur(4px) invert(20%); }
}

/* Matrix Effect */
body.effect-matrix #visualizer, body.effect-matrix #webcam-bg, body.effect-matrix #theme-bg {
  filter: sepia(1) hue-rotate(70deg) saturate(3) contrast(1.5);
  -webkit-filter: sepia(1) hue-rotate(70deg) saturate(3) contrast(1.5);
  animation: matrix-glitch 0.2s infinite;
  -webkit-animation: matrix-glitch 0.2s infinite;
}

@keyframes matrix-glitch {
  0% { transform: translate(0, 0); -webkit-transform: translate(0, 0); }
  20% { transform: translate(-2px, 2px); -webkit-transform: translate(-2px, 2px); }
  40% { transform: translate(-2px, -2px); -webkit-transform: translate(-2px, -2px); }
  60% { transform: translate(2px, 2px); -webkit-transform: translate(2px, 2px); }
  80% { transform: translate(2px, -2px); -webkit-transform: translate(2px, -2px); }
  100% { transform: translate(0, 0); -webkit-transform: translate(0, 0); }
}

#footer {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  font-size: 0.8rem;
  color: #9a9aa2;
  pointer-events: auto;
}

#footer a {
  color: inherit;
  text-underline-offset: 3px;
}

#footer a:hover {
  color: #fff;
}

#theme-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  opacity: 0;
  transition: opacity 1s ease;
}

#webcam-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.5s ease;
  transform: scaleX(-1); /* Mirror the camera */
}

#webcam-bg.active, #theme-bg.active {
  opacity: 0.6; /* Higher opacity so it's clearly visible */
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  body.club-mode #visualizer, body.club-mode #webcam-bg, body.club-mode #theme-bg,
  body[class*="effect-"] #visualizer, body[class*="effect-"] #webcam-bg, body[class*="effect-"] #theme-bg {
    animation: none;
    -webkit-animation: none;
  }
}

@media (max-width: 480px) {
  #top-controls { justify-content: center; }
  #ui-container { padding: 28px 20px; }
}
