* { box-sizing: border-box; }

:root {
  --bg: #f2f0ea;
  --bg-elev: #f8f6f1;
  --bg-elev-2: #ece7db;
  --border: #ded8c9;
  --text: #2b2a26;
  --text-dim: #6f6a5c;
  --accent: #4f8cff;
  --accent-hover: #6ea0ff;
  --danger: #ff5c5c;
  --radius: 10px;
  --topbar-h: 64px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Top bar / logo ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo-holder {
  display: flex;
  align-items: center;
  height: 100%;
  flex-shrink: 0;
}

.logo-holder img {
  max-height: 70px;
  max-width: 150px;
  object-fit: contain;
}

.logo-fallback {
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 14px;
  color: var(--text-dim);
}

.now-playing {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.np-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.np-folder {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Player shell ---------- */
.player-shell {
  flex-shrink: 0;
  background: var(--bg);
}

.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}

.video-wrap video,
.video-wrap .audio-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

.video-wrap .audio-art[hidden] {
  display: none;
}

.video-wrap:fullscreen,
.video-wrap:-webkit-full-screen {
  aspect-ratio: unset;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-wrap:fullscreen video,
.video-wrap:-webkit-full-screen video {
  position: static;
  inset: auto;
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

audio#audioEl {
  display: none;
}

/* ---------- Controls (above content, per spec: controls sit above player row) ---------- */
.controls {
  padding: 14px 16px 16px;
}

.controls-seek {
  display: flex;
  align-items: center;
}

.controls-seek .seek {
  width: 100%;
  flex: none;
}

.controls-times {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
}

.controls-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.btn {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: #e2ddcf;
  border-color: #cfc9b8;
}

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

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  flex-shrink: 0;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Belt-and-suspenders: the HTML `hidden` attribute already hides the
   inactive icon (iconPause/iconPlay, iconVolMute/iconVolHigh,
   iconFsEnter/iconFsExit) via the browser's default [hidden]{display:none}
   rule, and nothing in this file overrides that. This rule just guarantees
   it stays hidden even if some other stylesheet on the page sets its own
   `svg { display: ... }` rule that would otherwise fight it. */
.btn-icon svg[hidden] {
  display: none !important;
}

/* Transport row (shuffle / prev / play / next / repeat): plain icon-only
   buttons on a transparent background, matching the reference layout. */
.controls-buttons .btn-icon {
  background: transparent;
  border: none;
  color: var(--text-dim);
}

.controls-buttons .btn-icon:hover {
  background: var(--bg-elev-2);
}

.controls-buttons .btn-play {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent);
}

.controls-buttons .btn-play:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent-hover);
}

.btn-play svg {
  width: 26px;
  height: 26px;
}

.time-current,
.time-duration {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-dim);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  height: 20px;
}

.seek {
  --progress: 0%;
  flex: 1 1 120px;
  min-width: 80px;
}

.seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right,
    var(--accent) 0%, var(--accent) var(--progress),
    var(--border) var(--progress), var(--border) 100%);
}

.seek::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.seek::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -6px;
  border: none;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
}

.speed-group {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.speed-label {
  display: none;
}

.speed-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 20px;
  height: 40px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-align-last: center;
}

.speed-select:hover {
  background: var(--bg-elev-2);
}

/* ---------- Playlist area ---------- */
.playlist-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 12px 12px;
  background: var(--bg);
  color: var(--text);
  -webkit-overflow-scrolling: touch;
}

.playlist-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding-bottom: 8px;
  z-index: 5;
  transform: translateZ(0);
  will-change: transform;
}

.search-box {
  flex: 1 1 200px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 1px;
  font-size: 14px;
  min-width: 0;
}

.search-box::placeholder {
  color: var(--text-dim);
}

.filter-group {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.filter-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.folders {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.folder {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
}

.folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}

.folder-header:hover {
  background: var(--bg-elev-2);
}

.folder-name {
  font-weight: 600;
  font-size: 14px;
}

.folder-meta {
  font-size: 12px;
  color: var(--text-dim);
}

.folder-caret {
  transition: transform 0.15s ease;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-left: 8px;
}

.folder.collapsed .folder-caret {
  transform: rotate(-90deg);
}

.folder-items {
  border-top: 1px solid var(--border);
}

.folder.collapsed .folder-items {
  display: none;
}

.track {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.track:last-child {
  border-bottom: none;
}

.track:hover {
  background: var(--bg-elev-2);
}

.track.active {
  background: rgba(79, 140, 255, 0.15);
}

.track-type-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-dim);
}

.track.active .track-type-icon {
  color: var(--accent);
}

.track-title {
  flex: 1;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track.active .track-title {
  color: var(--accent);
  font-weight: 600;
}

.track-playing-indicator {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: none;
  color: var(--accent);
}

.track.active .track-playing-indicator {
  display: inline-flex;
}

.state-msg {
  text-align: center;
  color: var(--text-dim);
  padding: 30px 10px;
  font-size: 14px;
}

.state-error {
  color: var(--danger);
}

/* ---------- Responsive ---------- */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 1fr 2fr;
    grid-template-rows: var(--topbar-h) 1fr;
    column-gap: 20px;
  }

  .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .playlist-area {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
    padding: 26px 24px 20px;
  }

  .player-shell {
    grid-column: 2;
    grid-row: 2;
    height: 100%;
    overflow-y: auto;
    border-bottom: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 8px;
    gap: 10px;
  }

  .logo-holder img {
    max-height: 50px;
    max-width: 110px;
  }

  .np-title { font-size: 13px; }
  .np-folder { font-size: 11px; }

  .controls-buttons {
    gap: 8px;
  }
}
