/* ===================== DESKTOP (default) ===================== */
.app {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--player-h);
  grid-template-areas: "sidebar main" "player player";
}

.sidebar { grid-area: sidebar; display: flex; flex-direction: column; gap: 28px; padding: 24px 14px; border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar .brand { padding: 0 10px; }
.sidebar__links { display: flex; flex-direction: column; gap: 4px; }
.sidebar__item { display: flex; align-items: center; gap: 14px; height: 46px; padding: 0 14px; border-radius: 12px; color: var(--text-2); font-weight: 500; transition: background .15s, color .15s; }
.sidebar__item:hover { background: var(--hover); color: var(--text); }
.sidebar__item[aria-current="page"] { background: var(--bg-elev-2); color: var(--text); }
.sidebar__item[aria-current="page"] .icon { color: var(--accent); }

.main-col { grid-area: main; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { flex: none; display: flex; align-items: center; gap: 16px; height: var(--topbar-h); padding: 0 32px; }
.topbar__brand, .topbar__search-btn { display: none; }
.searchbox--top { width: min(560px, 100%); }
.view { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 32px 32px; outline: none; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .18) transparent; }
.view-section { max-width: 980px; }
.page-title { font-size: 28px; letter-spacing: -.02em; margin-bottom: 18px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head .page-title { margin: 0; }
.page-count { color: var(--text-3); font-weight: 400; }
.search-mobile { display: none; }

.queue-panel { display: none; }

.player-bar {
  grid-area: player;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 2fr) minmax(0, 1fr);
  align-items: center; gap: 24px; padding: 0 24px;
  border-top: 1px solid var(--line); background: var(--bg-elev);
}
.player-bar__left { min-width: 0; }
.player-bar__center { display: flex; flex-direction: column; align-items: center; gap: 0; width: 100%; max-width: 640px; justify-self: center; }
.player-bar__right { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.player-bar .transport { gap: 10px; }
.player-bar .play-btn { width: 46px; height: 46px; }

/* expanded player (desktop): covers the content area; the sidebar and the player bar stay usable */
.expanded {
  --ex-hue: 260;
  position: fixed; z-index: 26; left: var(--sidebar-w); right: 0; top: 0; bottom: var(--player-h);
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; padding: 32px clamp(24px, 4vw, 56px);
  background: radial-gradient(90% 70% at 30% 0%, hsl(var(--ex-hue) 55% 34% / .55), transparent 70%), var(--bg);
  overflow: auto; animation: ex-in .22s var(--ease);
}
.expanded[hidden] { display: none; }
@keyframes ex-in { from { opacity: 0; transform: translateY(16px); } }
.expanded__media { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; min-width: 0; }
.expanded__stage { position: relative; width: min(100%, 60vh, 560px); aspect-ratio: 1; }
.expanded__art { width: 100%; height: 100%; border-radius: var(--radius); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.expanded.show-video .expanded__stage { width: min(100%, 78vh * 1.7778, 920px); aspect-ratio: 16 / 9; }
.expanded.show-video .expanded__art { display: none; }
.expanded.show-video .expanded__video-slot { display: block; width: 100%; height: 100%; border-radius: var(--radius); background: rgba(255, 255, 255, .04); }
.expanded .track-text--large { max-width: 640px; }
.expanded__queue { display: none; min-width: 0; }
.expanded__queue h2 { font-size: 16px; margin: 4px 8px 10px; }
@media (min-width: 1100px) {
  .expanded { grid-template-columns: minmax(0, 1fr) 340px; }
  .expanded__queue { display: block; overflow-y: auto; }
}

/* mobile-only chrome is hidden on desktop */
.mini-player, .bottom-nav, .nowplaying { display: none; }

/* queue side panel on wide screens */
@media (min-width: 1200px) {
  .app { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--panel-w); grid-template-areas: "sidebar main panel" "player player player"; }
  .app.panel-closed { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-areas: "sidebar main" "player player"; }
  .queue-panel { grid-area: panel; display: flex; flex-direction: column; min-height: 0; padding: 20px 12px; border-left: 1px solid var(--line); overflow-y: auto; }
  .app.panel-closed .queue-panel { display: none; }
  .queue-panel__head { padding: 4px 8px 12px; }
  .queue-panel__head h2 { font-size: 16px; }
}

/* ===================== MOBILE ===================== */
@media (max-width: 899px) {
  .app { display: block; position: relative; }
  .sidebar, .player-bar, .queue-panel, .expanded { display: none !important; }
  .main-col { height: 100%; }

  .topbar {
    justify-content: space-between;
    height: calc(var(--topbar-h) - 8px + var(--sat));
    padding: var(--sat) calc(16px + var(--sar)) 0 calc(16px + var(--sal));
  }
  .topbar__brand { display: flex; }
  .topbar__search-btn { display: inline-grid; }
  .searchbox--top { display: none; }

  .view { padding: 4px calc(16px + var(--sar)) calc(var(--nav-h) + var(--sab) + 28px) calc(16px + var(--sal)); }
  .app.has-track .view { padding-bottom: calc(var(--mini-h) + var(--nav-h) + var(--sab) + 36px); }
  .page-title { font-size: 24px; margin-bottom: 14px; }
  .search-mobile { display: block; margin-bottom: 8px; }
  .hero { padding: 22px; }

  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--nav-h) + var(--sab)); padding: 0 var(--sar) var(--sab) var(--sal);
    background: rgba(17, 17, 22, .94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
  }
  .bottom-nav__item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 44px; color: var(--text-3); font-size: 11px; font-weight: 600; }
  .bottom-nav__item[aria-current="page"] { color: var(--text); }
  .bottom-nav__item[aria-current="page"] .icon { color: var(--accent); }

  .app.has-track .mini-player {
    display: flex; align-items: center; gap: 2px;
    position: fixed; z-index: 31;
    left: calc(8px + var(--sal)); right: calc(8px + var(--sar));
    bottom: calc(var(--nav-h) + var(--sab) + 8px);
    height: var(--mini-h); padding-right: 6px; overflow: hidden;
    background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  }
  .mini__open { flex: 1; min-width: 0; height: 100%; padding: 0 0 0 10px; border: 0; background: transparent; text-align: left; }
  .mini-player .track-info { gap: 12px; }
  .mini-player .track-info__art { width: 44px; }
  .mini__progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255, 255, 255, .1); }
  .mini__progress-bar { display: block; height: 100%; width: 0; background: var(--accent); }
  .transport--mini { gap: 0; }
  .transport--mini .play-btn { width: 44px; height: 44px; background: transparent; color: var(--text); }
  .transport--mini .spinner { border-color: rgba(255, 255, 255, .25); border-top-color: var(--text); }

  .toaster { bottom: calc(var(--nav-h) + var(--mini-h) + var(--sab) + 24px); }

  /* full-screen now-playing sheet */
  .nowplaying {
    --np-hue: 260;
    display: flex; flex-direction: column;
    position: fixed; inset: 0; z-index: 60; overflow: hidden;
    padding: var(--sat) calc(20px + var(--sar)) calc(16px + var(--sab)) calc(20px + var(--sal));
    background:
      radial-gradient(120% 60% at 50% 0%, hsl(var(--np-hue) 55% 38% / .5), transparent 70%),
      var(--bg);
    transform: translateY(100%); visibility: hidden;
    transition: transform .35s var(--ease), visibility 0s .35s;
    overscroll-behavior: contain;
  }
  .nowplaying.is-open { transform: none; visibility: visible; transition: transform .35s var(--ease); }

  .np__header { flex: none; display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; height: 56px; touch-action: none; }
  .np__tabs { justify-self: center; display: inline-flex; padding: 2px; border-radius: 999px; background: rgba(255, 255, 255, .08); }
  .np__tab { min-height: 44px; padding: 0 16px; border: 0; border-radius: 999px; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 600; touch-action: manipulation; }
  .np__tab[aria-selected="true"] { background: rgba(255, 255, 255, .16); color: var(--text); }

  .np__body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; justify-content: center; gap: 18px; width: 100%; max-width: 480px; margin: 0 auto; }
  .np__body[hidden], .np__queue[hidden] { display: none; }
  .np__art-wrap { display: grid; place-items: center; touch-action: none; }
  .np__art { width: min(100%, 42vh); border-radius: var(--radius); box-shadow: 0 24px 60px rgba(0, 0, 0, .55); -webkit-touch-callout: none; user-select: none; }
  .nowplaying .play-btn { width: 72px; height: 72px; }
  .nowplaying .transport--full { gap: 12px; justify-content: space-between; }

  .np__queue { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; max-width: 560px; margin: 0 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .np__queue-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px; }
  .np__queue-head h2 { font-size: 17px; }
  .np__queue-empty { padding: 32px 8px; text-align: center; color: var(--text-3); }
  .np__queue-empty[hidden], .np__queue .queue-list[hidden] { display: none; }

  /* hide the bottom bars while the on-screen keyboard is up (Android resizes the viewport) */
  .kbd-open .bottom-nav, .kbd-open .mini-player { display: none; }
}

/* ===================== TABLET PORTRAIT (600-899px) ===================== */
@media (min-width: 600px) and (max-width: 899px) {
  .app.has-track .mini-player { left: 8px; right: 8px; max-width: 720px; margin-inline: auto; }
  .np__body { max-width: 560px; gap: 22px; }
  .np__art { width: min(100%, 48vh); }
  .view-section { max-width: 720px; margin-inline: auto; }
  .np__queue { max-width: 640px; }
}

/* ===================== PHONE LANDSCAPE (short and wide) ===================== */
@media (max-width: 899px) and (orientation: landscape) and (max-height: 520px) {
  :root { --nav-h: 48px; --mini-h: 56px; --topbar-h: 56px; }
  .bottom-nav__item { flex-direction: row; gap: 8px; font-size: 12px; }
  .bottom-nav__item .icon { width: 22px !important; height: 22px !important; }
  .view { padding-bottom: calc(var(--nav-h) + var(--sab) + 16px); }
  .app.has-track .view { padding-bottom: calc(var(--mini-h) + var(--nav-h) + var(--sab) + 24px); }
  .app.has-track .mini-player { max-width: 640px; margin-inline: auto; }

  .nowplaying { padding-top: max(var(--sat), 4px); padding-bottom: calc(8px + var(--sab)); }
  .np__header { height: 44px; }
  .np__body {
    max-width: none; display: grid; grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto auto; align-content: center; column-gap: 32px; row-gap: 10px;
  }
  .np__art-wrap { grid-row: 1 / 4; grid-column: 1; }
  .np__art { width: min(64vh, 38vw); }
  .np__body > :not(.np__art-wrap) { grid-column: 2; }
  .nowplaying .track-text--large { text-align: left; }
  .nowplaying .track-text--large .track-text__title { font-size: 20px; }
  .nowplaying .play-btn { width: 60px; height: 60px; }
  .toaster { bottom: calc(var(--nav-h) + var(--mini-h) + var(--sab) + 12px); }
}
