/* ─── Cosmic Visualizer Styles ──────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000000;
  font-family: 'Inter', -apple-system, sans-serif;
  color: #e0e0f0;
}

/* ─── CRT Background Frame ─────────────────────────────────── */
#crt-frame {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
  overflow: hidden;
}

#crt-bg-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  user-select: none;
  /* Scale up 115% from center, then shift left 100px and down 100px */
  transform-origin: center center;
  transform: scale(1.15) translateX(-20px);
}

/* ─── Canvas Container — clipped to CRT screen area ─────────── */
/*
 * The CRT main screen occupies roughly:
 *   Left: 26.5%  Right: 82%  Top: 4%  Bottom: 82%
 * of the background image. We position the canvas to match.
 */
#canvas-container {
  position: fixed;
  z-index: 1;
  overflow: hidden;
  /* Subtle rounded corners matching CRT glass curvature */
  border-radius: 8px;
  /* Inner shadow to blend canvas into CRT bezel */
  box-shadow: inset 0 0 40px 15px rgba(0, 0, 0, 0.6);
  /* Default fallback — JS will override for precise fit */
  left: 25%;
  top: 4%;
  width: 55%;
  height: 75%;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ─── UI Overlay — positioned over the CRT screen area ─────── */
.ui-overlay {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  padding: 10px 16px;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  /* Default fallback — JS will position to match canvas */
  bottom: 20%;
  left: 25%;
  width: 55%;
}

.ui-overlay::-webkit-scrollbar {
  display: none;
}

.ui-overlay > .ui-panel {
  flex-shrink: 0;
}

.ui-overlay > .now-playing {
  flex-shrink: 0;
  align-self: flex-start;
}

.ui-panel {
  pointer-events: auto;
  background: rgba(5, 5, 16, 0.25);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.title {
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(192, 208, 255, 0.3);
}

/* ─── Audio Controls ────────────────────────────────────────── */
.audio-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.audio-btn {
  background: rgba(220, 40, 40, 0.05);
  border: 1px solid rgba(220, 40, 40, 0.12);
  color: rgba(240, 70, 70, 0.45);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.05em;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.audio-btn svg {
  flex-shrink: 0;
}

.audio-btn:hover {
  background: rgba(220, 40, 40, 0.1);
  border-color: rgba(220, 40, 40, 0.25);
}

.audio-btn.active {
  background: rgba(220, 40, 40, 0.1);
  border-color: rgba(220, 40, 40, 0.3);
  color: rgba(238, 68, 68, 0.5);
}

.spotify-btn {
  background: rgba(30, 215, 96, 0.05);
  border-color: rgba(30, 215, 96, 0.15);
  color: rgba(30, 215, 96, 0.45);
  text-decoration: none;
}

.spotify-btn:hover {
  background: rgba(30, 215, 96, 0.1);
  border-color: rgba(30, 215, 96, 0.3);
  color: rgba(30, 215, 96, 0.7);
}

.audio-btn--secondary {
  background: rgba(192, 208, 255, 0.06);
  border-color: rgba(192, 208, 255, 0.15);
  color: rgba(192, 208, 255, 0.6);
}

.audio-btn--secondary:hover {
  background: rgba(192, 208, 255, 0.1);
  border-color: rgba(192, 208, 255, 0.3);
  color: rgba(192, 208, 255, 0.85);
}

.audio-btn--secondary.active {
  background: rgba(100, 180, 255, 0.15);
  border-color: rgba(100, 180, 255, 0.5);
  color: rgba(150, 200, 255, 0.9);
}

/* ─── Drop Overlay ─────────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-overlay.visible {
  display: flex;
}

.drop-message {
  font-size: 20px;
  font-weight: 300;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(240, 70, 70, 0.8);
  border: 2px dashed rgba(220, 40, 40, 0.4);
  border-radius: 16px;
  padding: 48px 72px;
  animation: dropPulse 1.5s ease infinite;
}

@keyframes dropPulse {
  0%, 100% { border-color: rgba(220, 40, 40, 0.4); }
  50%      { border-color: rgba(220, 40, 40, 0.8); }
}

/* ─── Now Playing Bar ──────────────────────────────────────── */
.now-playing {
  pointer-events: auto;
  background: rgba(5, 5, 16, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 320px;
  max-width: 550px;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.now-playing.hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.play-pause-btn {
  background: rgba(220, 40, 40, 0.08);
  border: 1px solid rgba(220, 40, 40, 0.15);
  color: rgba(240, 70, 70, 0.45);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s ease;
}

.play-pause-btn:hover {
  background: rgba(220, 40, 40, 0.12);
  border-color: rgba(220, 40, 40, 0.3);
}

.track-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.track-name {
  font-size: 12px;
  font-weight: 400;
  color: rgba(255, 170, 170, 0.42);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  max-width: 140px;
}

.progress-wrapper {
  flex: 1;
  min-width: 60px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.progress-bar-container {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  /* Larger touch target */
  padding: 8px 0;
  margin: -8px 0;
  background-clip: content-box;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(204, 34, 34, 0.45), rgba(238, 68, 68, 0.45));
  border-radius: 2px;
  transition: width 0.1s linear;
}

.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: rgba(192, 208, 255, 0.18);
}

.volume-slider {
  width: 60px;
  accent-color: #DD3333;
  flex-shrink: 0;
  cursor: pointer;
}

/* ─── Reference Overlay (Dev) ───────────────────────────────── */
.ref-overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  display: none;
}

.ref-overlay.visible {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
}

.ref-overlay img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ref-controls {
  position: fixed;
  bottom: 60px;
  right: 24px;
  z-index: 15;
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(5, 5, 16, 0.6);
  backdrop-filter: blur(8px);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
}

.ref-controls input[type="range"] {
  width: 100px;
  accent-color: #DD3333;
}

/* ─── Footer ────────────────────────────────────────────────── */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 12px 24px;
  text-align: center;
}

.site-footer a {
  font-size: 11px;
  color: rgba(192, 208, 255, 0.25);
  text-decoration: none;
  letter-spacing: 0.05em;
  transition: color 0.3s ease;
}

.site-footer a:hover {
  color: rgba(192, 208, 255, 0.5);
}

/* ─── Stems / MIDI Panel ────────────────────────────────────── */
.stems-panel {
  pointer-events: auto;
  background: rgba(5, 5, 16, 0.6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 14px 16px;
  width: 100%;
  max-width: 520px;
  flex-shrink: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.stems-panel.hidden {
  display: none;
}

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

.stems-panel-title {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(192, 208, 255, 0.5);
}

.stems-panel-close {
  background: none;
  border: none;
  color: rgba(192, 208, 255, 0.35);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.2s;
}

.stems-panel-close:hover {
  color: rgba(255, 255, 255, 0.7);
}

/* ─── Stem Slots Grid ───────────────────────────────────────── */
.stems-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.stem-slot {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.3s;
}

.stem-slot.loaded {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Color-coded assignments */
.stem-slot[data-assignment="ring"] {
  border-color: rgba(220, 40, 40, 0.35);
}
.stem-slot[data-assignment="spikes"] {
  border-color: rgba(255, 90, 50, 0.35);
}
.stem-slot[data-assignment="waves"] {
  border-color: rgba(170, 119, 187, 0.35);
}
.stem-slot[data-assignment="atmosphere"] {
  border-color: rgba(100, 160, 255, 0.35);
}

.stem-slot-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stem-slot-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(192, 208, 255, 0.4);
}

.stem-remove-btn {
  background: none;
  border: none;
  color: rgba(255, 100, 100, 0.5);
  font-size: 16px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.2s;
}

.stem-remove-btn:hover {
  color: rgba(255, 100, 100, 0.9);
}

.stem-remove-btn.hidden {
  display: none;
}

.stem-drop-zone {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.stem-filename {
  font-size: 11px;
  color: rgba(192, 208, 255, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.stem-filename.active {
  color: rgba(255, 210, 170, 0.8);
}

.stem-upload-btn {
  background: rgba(220, 40, 40, 0.08);
  border: 1px solid rgba(220, 40, 40, 0.2);
  color: rgba(240, 70, 70, 0.8);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.stem-upload-btn:hover {
  background: rgba(220, 40, 40, 0.18);
  border-color: rgba(220, 40, 40, 0.45);
}

.stem-assignment {
  background: rgba(5, 5, 16, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(192, 208, 255, 0.7);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  padding: 4px 6px;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
  appearance: auto;
}

.stem-assignment:focus {
  outline: 1px solid rgba(220, 40, 40, 0.4);
  outline-offset: 1px;
}

/* ─── Stem Playback Controls ────────────────────────────────── */
.stem-playback {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.stem-playback.hidden {
  display: none;
}

.stem-progress-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* ─── MIDI Section ──────────────────────────────────────────── */
.midi-section {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 10px;
  margin-top: 4px;
}

.midi-header {
  margin-bottom: 8px;
}

.midi-title {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(192, 208, 255, 0.4);
}

.midi-upload-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.midi-channel-map {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.midi-channel-map.hidden {
  display: none;
}

.midi-map-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.midi-map-row label {
  font-size: 10px;
  color: rgba(192, 208, 255, 0.45);
  white-space: nowrap;
  min-width: 32px;
}

.midi-ch-assign {
  background: rgba(5, 5, 16, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(192, 208, 255, 0.7);
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  padding: 3px 5px;
  border-radius: 5px;
  cursor: pointer;
  flex: 1;
  appearance: auto;
}

.midi-note-label {
  font-size: 9px;
  color: rgba(192, 208, 255, 0.3);
  white-space: nowrap;
  letter-spacing: 0.03em;
}

/* ─── Loading State ─────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

body {
  animation: fadeIn 1.5s ease;
}

/* ─── Fullscreen Enter Button (top-right of canvas) ────── */
.fs-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  background: rgba(5, 5, 16, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.25);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.fs-btn:hover {
  background: rgba(5, 5, 16, 0.4);
  color: rgba(255, 255, 255, 0.5);
  border-color: rgba(255, 255, 255, 0.12);
}

/* ─── Fullscreen Transport Bar ─────────────────────────── */
.fs-transport {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(5, 5, 16, 0.25);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 10px 16px;
  align-items: center;
  gap: 12px;
  max-width: 600px;
  width: calc(100vw - 48px);
  pointer-events: auto;
}

body.fullviz .fs-transport {
  display: flex;
}

body.fullviz .fs-btn {
  display: none;
}

.fs-transport-btn {
  background: rgba(220, 40, 40, 0.08);
  border: 1px solid rgba(220, 40, 40, 0.15);
  color: rgba(240, 70, 70, 0.45);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.25s ease;
}

.fs-transport-btn:hover {
  background: rgba(220, 40, 40, 0.15);
  border-color: rgba(220, 40, 40, 0.3);
}

#fs-exit {
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.3);
}

#fs-exit:hover {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.5);
}

.fs-track-name {
  font-size: 11px;
  font-weight: 400;
  color: rgba(255, 170, 170, 0.35);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  max-width: 120px;
}

.fs-progress-wrap {
  flex: 1;
  min-width: 60px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fs-progress-container {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  padding: 8px 0;
  margin: -8px 0;
  background-clip: content-box;
}

.fs-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(204, 34, 34, 0.45), rgba(238, 68, 68, 0.45));
  border-radius: 2px;
  transition: width 0.1s linear;
}

.fs-time {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  color: rgba(192, 208, 255, 0.15);
}

.fs-spotify {
  padding: 6px 8px;
  flex-shrink: 0;
}

/* ─── Fullscreen Viz Mode ──────────────────────────────── */
body.fullviz #crt-frame { display: none; }
body.fullviz .ui-overlay { display: none; }

body.fullviz #canvas-container {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  z-index: 1 !important;
}

/* ─── Mobile adjustments ───────────────────────────────── */
@media (max-width: 768px) {
  .ui-overlay {
    padding: 6px 8px;
  }

  .ui-panel {
    padding: 8px 12px;
    gap: 8px;
  }

  .title {
    font-size: 11px;
  }

  .audio-btn {
    font-size: 10px;
    padding: 6px 10px;
  }
}
