/*
 * Media player — brand chrome. The legacy red/pink (#e94560) toolbar
 * accent is replaced with brand violet so the player matches Heyming OS.
 * Native <video> / <audio> controls keep their UA chrome (they're not
 * stylable cross-browser anyway).
 */

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

body {
  font-family: var(--font-ui);
  background: linear-gradient(
    135deg,
    var(--surface-1) 0%,
    var(--surface-2) 50%,
    var(--surface-0) 100%
  );
  color: var(--text-1);
  height: 100vh;
  overflow: hidden;
}

#player-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 90px;
  background: linear-gradient(to bottom, var(--surface-2), var(--surface-1));
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--hairline-strong);
  margin: 0 4px;
}

.toolbar-spacer {
  flex: 1;
}

#toolbar button {
  background: var(--surface-1);
  border: 1px solid var(--hairline-strong);
  color: var(--text-1);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

#toolbar button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-primary) 30%, transparent);
  border-color: var(--accent-primary);
}

#toolbar button:active:not(:disabled) {
  transform: scale(0.95);
}

#toolbar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#toolbar button.active {
  background: color-mix(in srgb, var(--accent-primary) 40%, transparent);
  border-color: var(--accent-primary);
}

#playback-speed {
  background: var(--surface-1);
  border: 1px solid var(--hairline-strong);
  color: var(--text-1);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

#playback-speed:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#playback-speed option {
  background: var(--surface-1);
  color: var(--text-1);
}

#time-display {
  font-size: 13px;
  color: var(--text-2);
  font-family: var(--font-mono);
  padding: 0 8px;
}

/* Drop zone */
#drop-zone {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  border: 3px dashed var(--hairline-strong);
  border-radius: 16px;
  margin: 20px;
  transition: all 0.3s ease;
}

#drop-zone.active {
  display: flex;
}

#drop-zone.drag-over {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
}

.drop-content {
  text-align: center;
  padding: 40px;
}

.drop-content .icon {
  font-size: 80px;
  display: block;
  margin-bottom: 20px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

.drop-content h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 12px;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-primary-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.drop-content p {
  color: var(--text-2);
  font-size: 16px;
  margin-bottom: 8px;
}

.drop-content .formats {
  font-size: 12px;
  color: var(--text-3);
}

/* Media wrapper */
#media-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--pure-black);
  min-height: 0;
  position: relative;
}

#media-wrapper.hidden {
  display: none;
}

#media {
  flex: 1;
  width: 100%;
  object-fit: contain;
  background: var(--pure-black);
  min-height: 0;
}

/* Show native controls at bottom when playing audio */
#media-wrapper.audio-mode #media {
  position: absolute;
  bottom: 40px;
  left: 0;
  right: 0;
  width: 100%;
  height: 54px;
  background: transparent;
}

/* YouTube container */
#youtube-container {
  flex: 1;
  width: 100%;
  display: none;
  background: var(--pure-black);
}

#youtube-container.visible {
  display: flex;
}

#youtube-player {
  width: 100%;
  height: 100%;
}

/* Hide native video when showing YouTube */
#media-wrapper.youtube-mode #media,
#media-wrapper.midi-mode #media {
  display: none;
}

#media-info {
  height: 32px;
  background: linear-gradient(to right, var(--surface-1), var(--surface-2));
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-top: 1px solid var(--hairline);
  flex-shrink: 0;
}

#media-name {
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Audio visualization */
#audio-visual {
  flex: 1;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    135deg,
    var(--surface-1) 0%,
    var(--accent-primary-bg) 50%,
    var(--surface-2) 100%
  );
  /* The visualizer is the main event here, so the surrounding chrome gives
   * back space on short viewports instead of pushing the canvas out. */
  padding: clamp(12px, 3vh, 40px);
  padding-bottom: clamp(40px, 6vh, 80px);
  overflow-y: auto;
}

#audio-visual.visible {
  display: flex;
}

.album-art {
  font-size: clamp(44px, 9vh, 120px);
  margin-bottom: clamp(8px, 2vh, 30px);
  flex-shrink: 0;
  animation: float 3s ease-in-out infinite;
}

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

.audio-info {
  text-align: center;
  margin-bottom: clamp(10px, 2vh, 30px);
  flex-shrink: 0;
}

#audio-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-1);
}

#audio-artist {
  font-size: 16px;
  color: var(--text-2);
}

.viz-panel {
  width: 100%;
  max-width: min(100%, 900px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Frequency spectrum + oscilloscope canvas.
 * Click cycles the style; drag the corner to resize. */
.visualizer {
  position: relative;
  cursor: pointer;
  width: 100%;
  height: clamp(200px, 50vh, 620px);
  min-width: 220px;
  min-height: 80px;
  max-width: 100%;
  max-height: 80vh;
  margin: 0 auto;
  resize: both;
  overflow: hidden;
  border-radius: 8px;
}

#viz-canvas {
  width: 100%;
  height: 100%;
  /* Always-dark slab so frequency bars (brand accent + white) stay
   * readable. Do not use --text-1 — it flips near-white in dark mode. */
  background: var(--pure-black);
  display: block;
}

.viz-label {
  position: absolute;
  top: 8px;
  left: 10px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #fff;
  background: rgb(0 0 0 / 55%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.viz-label.visible {
  opacity: 1;
}

.midi-seek-row {
  display: none;
  width: 100%;
  max-width: 400px;
  margin-top: clamp(10px, 2vh, 24px);
  flex-shrink: 0;
}

#media-wrapper.midi-mode .midi-seek-row {
  display: block;
}

#midi-seek {
  width: 100%;
  height: 28px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent-primary);
}

#midi-seek:disabled {
  cursor: default;
  opacity: 0.5;
}

.midi-channels {
  display: none;
  width: 100%;
  max-width: 520px;
  margin-top: clamp(8px, 1.5vh, 16px);
  text-align: left;
  flex-shrink: 0;
}

#media-wrapper.midi-mode .midi-channels {
  display: block;
}

.midi-channels-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin-bottom: 8px;
}

#midi-channel-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.midi-ch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.midi-ch-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-1);
}

.midi-ch-row button {
  flex-shrink: 0;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border, #ccc);
  background: var(--surface-1, #fff);
  color: var(--text-1);
  cursor: pointer;
}

.midi-ch-row button.active {
  background: var(--accent-primary, #1a73e8);
  color: #fff;
  border-color: transparent;
}

.midi-ch-row.muted .midi-ch-name {
  opacity: 0.45;
}

/* Loading state */
#media-wrapper.loading::after {
  content: '⏳ Loading...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 24px;
  color: var(--text-1);
  z-index: 10;
}

/* Error overlay */
.media-error-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--scrim-strong);
  color: var(--danger);
  font-size: 20px;
  font-weight: 500;
  z-index: 20;
  text-align: center;
  padding: 40px;
}

/* Narrow viewports: wrap the toolbar and drop secondary labels/time so the
 * chrome fits without horizontal document scroll (e.g. 320px phones). */
@media (max-width: 640px) {
  #player-container {
    max-width: 100%;
  }

  #toolbar {
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    gap: 4px;
    row-gap: 6px;
    padding: 8px 8px 8px 100px;
  }

  .toolbar-divider,
  .toolbar-spacer {
    display: none;
  }

  #toolbar button {
    padding: 6px 8px;
  }

  .btn-label {
    display: none;
  }

  #time-display {
    display: none;
  }

  #drop-zone {
    margin: 12px;
  }

  .drop-content {
    padding: 20px 12px;
  }

  .drop-content .formats {
    white-space: normal;
    padding: 0 4px;
  }
}
