/* ============================================================
   STEMS APP
   ============================================================ */

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

:root {
  --bg:       #0d0d14;
  --bg2:      #13131e;
  --surface:  rgba(255,255,255,0.05);
  --border:   rgba(255,255,255,0.1);
  --text:     #e0e0ee;
  --dim:      rgba(224,224,238,0.45);
  --accent:   #00dcb4;
  --accent2:  #6450dc;
  --danger:   #ff3350;
  --font:     'Inter', 'Helvetica Neue', Arial, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

#app {
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* ============================================================
   NAV
   ============================================================ */
.nav {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(13,13,20,0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 28px;
}

.nav-links a,
.nav-back {
  color: var(--dim);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.04em;
  transition: color 0.2s;
}

.nav-links a:hover,
.nav-links a.active,
.nav-back:hover {
  color: var(--text);
}

.nav-song-info {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0; /* allow text truncation */
}

.nav-thumb-wrap {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  display: block;
}

.nav-thumb {
  width: 30px;
  height: 30px;
  object-fit: cover;
  display: block;
  transition: opacity 0.2s;
}

.nav-song-title {
  font-size: 13px;
  color: var(--dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   INDEX PAGE
   ============================================================ */
.index-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.index-main {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 48px;
}

.songs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.song-card {
  display: block;
  text-decoration: none;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg2);
  border: 1px solid var(--border);
  aspect-ratio: 3 / 4;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.song-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--card-color, #0d1a2e);
  opacity: 0.55;
}

@media (hover: hover) {
  .song-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(0,0,0,0.55);
    border-color: var(--accent);
  }
}

.song-card-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px;
}

.song-card-id {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.song-card-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.song-card-artist {
  font-size: 12px;
  color: var(--dim);
}

.song-card-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 32px;
  opacity: 0;
  transition: opacity 0.2s;
}

@media (hover: hover) {
  .song-card:hover .song-card-play {
    opacity: 1;
  }
}

/* ============================================================
   ABOUT PAGE
   ============================================================ */
.about-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.about-main {
  flex: 1;
  overflow-y: auto;
  padding: 48px 24px 64px;
}

.about-inner {
  max-width: 760px;
  margin: 0 auto;
}

.about-section {
  margin-bottom: 56px;
}

.about-section h1 {
  font-size: 38px;
  font-weight: 300;
  color: var(--text);
  margin-bottom: 16px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.about-section h2 {
  font-size: 20px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 12px;
  letter-spacing: 0.02em;
}

.about-section p {
  color: var(--dim);
  line-height: 1.75;
  font-size: 16px;
  font-weight: 300;
}

.about-img-placeholder {
  width: 100%;
  height: 260px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border);
  font-size: 12px;
  letter-spacing: 0.1em;
}

.credits-list {
  list-style: none;
}

.credits-list li {
  color: var(--dim);
  font-size: 15px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
}

.credits-list li strong {
  color: var(--text);
  min-width: 120px;
  font-weight: 500;
}

/* ============================================================
   PLAYER PAGE
   ============================================================ */
#viz-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  display: block;
}

.player-page {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.player-page .nav,
.player-page .player-bottom {
  pointer-events: all;
}

.player-bottom {
  padding: 16px 20px;
  /* Safe-area inset for notched phones */
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Loading */
.player-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.loading-label {
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 16px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.loading-tracks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  width: 300px;
}

.loading-track {
  font-size: 11px;
  color: var(--dim);
  padding: 4px 10px;
  background: var(--surface);
  border-radius: 4px;
  text-align: left;
}

.loading-track span {
  color: var(--accent);
  float: right;
}

/* Transport bar */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: rgba(13,13,20,0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.btn-play {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  border: none;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}

.btn-play:hover {
  background: #00ffce;
  transform: scale(1.06);
}

.progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--surface);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.progress-bar:hover {
  height: 6px;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  pointer-events: none;
}

.time-display {
  font-size: 11px;
  color: var(--dim);
  min-width: 36px;
  font-variant-numeric: tabular-nums;
}

/* Rack outer wrapper — animates the whole rack in/out */
.rack-wrap {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.35s ease;
}

.rack-wrap.collapsed {
  grid-template-rows: 0fr;
}

.rack-wrap.collapsed .player-rack {
  /* delay hiding content until after collapse animation */
  transition: opacity 0.15s ease 0.15s;
  opacity: 0;
}

/* Rack panel */
.player-rack {
  min-height: 0;      /* required for grid collapse */
  overflow: hidden;   /* clips content and border during animation */
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  padding: 18px 16px 14px;
  background: rgba(13,13,20,0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Toggle button — last item inside .controls-bar */
.rack-toggle {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

@media (hover: hover) {
  .rack-toggle:hover {
    background: rgba(0,220,180,0.12);
  }
}

/* Stem sliders */
.stem-sliders {
  display: flex;
  gap: 4px;
  align-items: flex-end;
}

.stem-channel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 56px;
}

.stem-name {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stem-controls {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
}

.stem-meter {
  border-radius: 3px;
  background: rgba(0,0,0,0.4);
  display: block;
  flex-shrink: 0;
}

.stem-slider-wrap {
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Vertical range — widest browser support */
.stem-slider {
  writing-mode: vertical-lr;
  direction: rtl;
  -webkit-appearance: slider-vertical;
  appearance: slider-vertical;
  width: 32px;
  height: 140px;
  cursor: pointer;
  accent-color: var(--accent);
  touch-action: none; /* prevent page scroll while sliding */
}

.stem-vol {
  font-size: 10px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* Sample buttons — 6 rows × 2 cols */
.sample-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  align-self: center;
  padding: 0 6px;
}

.sample-btn {
  width: 100px;
  height: 34px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--dim);
  font-size: 10px;
  font-family: var(--font);
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s, transform 0.06s;
}

/* Buttons: fast tap response, no callout */
.sample-btn,
.btn-play {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .sample-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    color: var(--text);
    border-color: rgba(255,255,255,0.25);
  }
}

.sample-btn.flash {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  transform: scale(0.94);
}

.sample-btn:disabled {
  opacity: 0.18;
  cursor: default;
}

/* VU meters */
.vu-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-left: 4px;
}

.vu-bars {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  justify-content: center;
}

.vu-canvas {
  border-radius: 3px;
  background: rgba(0,0,0,0.35);
  display: block;
}

.vu-labels {
  display: flex;
  gap: 5px;
}

.vu-labels span {
  font-size: 10px;
  color: var(--dim);
  width: 20px;
  text-align: center;
  margin-top: 10px;
}

/* Player error */
.player-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--danger);
  font-size: 14px;
  pointer-events: none;
}

/* ============================================================
   RESPONSIVE — MOBILE (≤ 700px)
   ============================================================ */
@media (max-width: 700px) {

  /* Nav */
  .nav {
    padding: 10px 16px;
  }
  .nav-brand { font-size: 15px; }
  .nav-links { gap: 18px; }

  /* Index grid — 2 columns minimum, then auto-fill */
  .songs-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }
  .index-main { padding: 20px 14px 40px; }

  /* About */
  .about-main { padding: 28px 16px 48px; }
  .about-section h1 { font-size: 28px; }

  /* Player bottom: scrollable so all controls are reachable */
  .player-bottom {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: calc(100svh - 52px);
    /* fallback for browsers without svh */
    max-height: calc(100vh - 52px);
    padding: 10px 12px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  /* Transport bar: slightly smaller */
  .controls-bar { padding: 8px 12px; gap: 10px; }
  .btn-play { width: 36px; height: 36px; font-size: 13px; }
  .progress-bar { height: 5px; }
  .progress-bar:hover { height: 5px; } /* don't expand on touch */

  /* Rack: wrap so samples fall below stems+VU */
  .player-rack {
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 14px 12px;
  }

  /* Stems row fills available width */
  .stem-sliders {
    flex: 1;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 2px;
  }

  .stem-channel { width: 44px; }

  /* Shorter sliders — save vertical space */
  .stem-slider-wrap { height: 110px; }
  .stem-slider      { height: 100px; }

  /* Scale stem-meter canvas visually (drawing still uses attribute height) */
  .stem-meter { height: 100px; }

  /* VU section stays on same row as sliders, sits right of them */
  .vu-section {
    flex-shrink: 0;
    padding-left: 0;
    display: inline-grid;
    margin-top: 20px;
  }
  /* Shorter VU bars on mobile */
  .vu-canvas { height: 100px !important; }

  /* Samples: push to second row, full rack width, 4-col grid */
  .sample-grid {
    flex: 0 0 100%;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    padding: 0;
    display: inline-grid;
    margin-top: 10px;
  }

  /* Bigger touch targets for sample buttons */
  .sample-btn {
    width: 100%;
    height: 40px;
    font-size: 11px;
  }
}

/* Extra-small (portrait phone, ≤ 400px) */
@media (max-width: 400px) {
  .sample-grid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(4, 1fr);
  }
  .stem-channel { width: 40px; }
}
