/* ==========================================================================
   Capa de teléfono (< 768px). Única fuente de verdad del layout móvil:
   cabecera compacta, contenido con scroll propio, mini reproductor y
   barra de pestañas fija. Se carga después de la hoja de la página.
   ========================================================================== */

@media (max-width: 767px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
  }

  body {
    -webkit-tap-highlight-color: transparent;
  }

  #app {
    width: 100%;
    max-width: 100%;
    min-width: 0 !important;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  #principal {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto;
    min-height: 0;
    height: auto !important;
    width: 100%;
    margin: 0 !important;
    padding: 0 !important;
    gap: 0 !important;
    border-radius: 0 !important;
  }

  /* --- Cabecera: sólo la marca, el resto de la barra no existe aquí --- */
  #latNav {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 0 0 auto;
    width: 100% !important;
    max-width: none !important;
    height: 56px !important;
    padding: 0 14px !important;
    margin: 0 !important;
    background: transparent !important;
    border: 0 !important;
  }

  #latNav > a:first-child {
    display: flex !important;
    flex: 0 0 auto;
    width: auto !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #latNav > a:first-child img {
    width: 104px !important;
    max-width: 104px !important;
    height: auto !important;
  }

  #latNav > ul,
  #latNav #underList,
  #latNav hr,
  #latNav #getAppLink {
    display: none !important;
  }

  /* El selector de idioma cabe entre la marca y el perfil. */
  #latNav .lang-toggle {
    flex: 0 0 auto;
    align-self: center;
    height: 30px;
    margin: 0 !important;
    padding: 0 9px;
    gap: 4px;
    font-size: 0.62rem;
  }

  #latNav .lang-toggle svg {
    width: 12px;
    height: 12px;
  }

  /* El perfil vive en la cabecera, junto al logo. */
  #latNav .profile-card {
    flex: 0 1 auto;
    width: auto;
    margin: 0 0 0 auto;
    padding: 0;
    gap: 8px;
    border: 0;
  }

  #latNav .profile-avatar {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
  }

  #latNav .profile-avatar svg {
    width: 16px;
    height: 16px;
  }

  #latNav .profile-name {
    max-width: 104px;
    font-size: 0.74rem;
  }

  #latNav .profile-tag {
    display: none;
  }

  /* --- El contenido es el único contenedor con scroll --- */
  #feed {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: 100% !important;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  #feed::-webkit-scrollbar {
    width: 0;
    height: 0;
  }

  #main {
    padding: 0 14px 28px !important;
    margin: 0 !important;
  }

  #main .greeting {
    margin-bottom: 16px;
    font-size: 1.5rem;
  }

  /* --- Avatar flotante arriba a la derecha --- */
  #topNav {
    position: absolute !important;
    top: 6px;
    right: 10px;
    left: auto;
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    width: auto;
    height: auto;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: 0 !important;
    z-index: 30;
  }

  /* En Home el perfil ya está en la cabecera: nada de avatar flotante. */
  body.home-page #topNav {
    display: none !important;
  }

  #arrowMenu {
    display: none !important;
  }

  #btnTopNav {
    display: flex !important;
    margin: 0 !important;
  }

  #user_bttn {
    display: flex !important;
    margin: 0 !important;
  }

  #user_bttn #dropdownMenuButton1 {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 0;
    color: transparent;
    background: rgba(0, 0, 0, 0.55);
    border: 0;
    border-radius: 50%;
  }

  #user_bttn #dropdownMenuButton1::after {
    display: none !important;
  }

  #user_bttn .imgUsuario {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    margin: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16) !important;
  }

  #user_bttn .imgUsuario svg {
    width: 15px;
    height: 15px;
    fill: #fff;
  }

  /* --- Saludo y tarjetas recientes --- */
  #greeting {
    margin: 4px 0 14px !important;
    font-size: 1.6rem !important;
    line-height: 1.15;
    letter-spacing: -0.02em;
  }

  #playlistsRecentes {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    height: auto !important;
    margin: 0 0 22px !important;
    padding: 0 !important;
    overflow: visible !important;
    list-style: none;
  }

  #feedHeader #playlistsRecentes li {
    position: relative;
    display: flex;
    align-items: center;
    width: 100% !important;
    min-width: 0;
    height: 56px;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.09);
  }

  #feedHeader #playlistsRecentes li img {
    position: absolute;
    top: 0;
    left: 0;
    width: 56px !important;
    height: 56px !important;
    flex: 0 0 56px;
    object-fit: cover;
    border-radius: 0;
  }

  #feedHeader #playlistsRecentes li span {
    position: relative;
    display: -webkit-box;
    overflow: hidden;
    margin: 0 !important;
    padding: 0 10px 0 64px;
    font-size: 0.8rem !important;
    font-weight: 700 !important;
    line-height: 1.25;
    white-space: normal;
    text-overflow: clip;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  #feedHeader #playlistsRecentes li span small {
    display: none;
  }

  #feedHeader #playlistsRecentes li button.btn {
    display: none !important;
  }

  /* --- Estanterías --- */
  #main .feedPlaylist {
    max-width: none !important;
    margin: 0 !important;
    border: 0 !important;
  }

  #main .feedPlaylist h4 {
    margin: 0 0 12px !important;
    font-size: 1.3rem !important;
    letter-spacing: -0.01em;
  }

  #main .feedPlaylist h4 a {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
  }

  #main .feedPlaylist .see-all,
  #main .feedPlaylist > br {
    display: none !important;
  }

  #main .feedPlaylist .playlists {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 10px;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 0 0 20px !important;
    padding: 0 !important;
    list-style: none;
  }

  #main .feedPlaylist .playlists li {
    position: relative;
    width: 100% !important;
    min-width: 0;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
  }

  #main .feedPlaylist .playlists li img,
  #main .feedPlaylist .playlists li img.image-hun {
    display: block;
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 6px;
  }

  #main .feedPlaylist .playlists li span {
    display: -webkit-box !important;
    overflow: hidden;
    margin: 8px 0 0 !important;
    font-size: 0.86rem !important;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.01em;
    white-space: normal;
    text-overflow: clip;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  #main .feedPlaylist .playlists li p {
    display: -webkit-box !important;
    overflow: hidden;
    margin: 2px 0 0 !important;
    color: #a7a7a7;
    font-size: 0.76rem !important;
    line-height: 1.3;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  #main .feedPlaylist .playlists li p br {
    display: none;
  }

  #main .feedPlaylist .playlists li button.btn {
    display: none !important;
  }

  /* --- Pie: mini reproductor sobre la barra de pestañas --- */
  #footer {
    flex: 0 0 auto;
    width: 100%;
    margin: 0 !important;
    background: #121212;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: env(safe-area-inset-bottom);
  }

  #audioBar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto;
    gap: 0;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #121212 !important;
    border: 0 !important;
  }

  #audioBar #musicaPlay {
    grid-column: 1;
    grid-row: 1;
    width: auto !important;
    min-width: 0;
    margin: 0 !important;
    padding: 8px 0 4px 12px;
  }

  #audioBar #musicaPlay .now-playing {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  #audioBar #musicaPlay .now-playing img {
    width: 40px !important;
    height: 40px !important;
    flex: 0 0 40px !important;
    border-radius: 4px;
  }

  #audioBar #musicaPlay .now-meta {
    min-width: 0;
  }

  #audioBar #musicaPlay .now-title {
    font-size: 0.8rem !important;
    font-weight: 600;
  }

  #audioBar #musicaPlay .now-artist {
    font-size: 0.68rem !important;
  }

  /* Sin canción de verdad no hay mini reproductor: solo quedan las pestañas. */
  #footer:not(.is-ready) #musicaPlay,
  #footer:not(.is-ready) #miniPlay,
  #footer:not(.is-ready) #barraMini {
    display: none !important;
  }

  #miniPlay {
    grid-column: 2;
    grid-row: 1;
    align-self: center;
    justify-self: end;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin: 0 12px 0 0;
    padding: 0;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: 0;
    border-radius: 50%;
    transition: background-color 0.15s ease, transform 0.1s ease;
    touch-action: manipulation;
  }

  #miniPlay:active {
    background: rgba(255, 255, 255, 0.18);
    transform: scale(0.92);
  }

  #miniPlay svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
  }

  /* --- Seek: fila propia entre la canción y las pestañas --- */
  #barraMini {
    display: none !important;
    grid-column: 1 / -1;
    grid-row: 2;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 0 12px 4px;
    color: #a7a7a7;
    font-size: 0.6rem;
    font-variant-numeric: tabular-nums;
    line-height: 1;
  }

  /* Aparece con la primera canción: en reposo el pie queda como antes. */
  #barraMini.is-ready {
    display: flex !important;
  }

  #barraMini small {
    flex: 0 0 auto;
    min-width: 26px;
    color: inherit;
    font-size: inherit;
  }

  #barraMini .mini-total {
    text-align: right;
  }

  #barraMini input[type="range"] {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 28px;
    margin: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
  }

  #barraMini input[type="range"]:disabled {
    cursor: default;
    opacity: 0.5;
  }

  /* Firefox */
  #barraMini input[type="range"]::-moz-range-track {
    height: 3px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.24);
  }

  #barraMini input[type="range"]::-moz-range-progress {
    height: 3px;
    border-radius: 99px;
    background: #fff;
  }

  #barraMini input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    transform: scale(0);
    transition: transform 0.12s ease, background-color 0.12s ease;
  }

  #barraMini input[type="range"]:active::-moz-range-thumb,
  #barraMini input[type="range"]:focus-visible::-moz-range-thumb {
    background: #1ed760;
    transform: scale(1);
  }

  /* WebKit / Blink */
  #barraMini input[type="range"]::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: 99px;
    background: linear-gradient(to right, #fff var(--seek, 0%), rgba(255, 255, 255, 0.24) var(--seek, 0%));
  }

  #barraMini input[type="range"]::-webkit-slider-thumb {
    width: 12px;
    height: 12px;
    margin-top: -4.5px;
    border: 0;
    border-radius: 50%;
    background: #1ed760;
    transform: scale(0);
    transition: transform 0.12s ease;
    -webkit-appearance: none;
    appearance: none;
  }

  #barraMini input[type="range"]:active::-webkit-slider-thumb,
  #barraMini input[type="range"]:focus-visible::-webkit-slider-thumb {
    transform: scale(1);
  }

  #botomIcon {
    display: block !important;
    grid-column: 1 / -1;
    grid-row: 3;
  }

  #botomIcon ul.nav {
    display: flex !important;
    flex-direction: row !important;
    align-items: stretch;
    gap: 0;
    margin: 0 !important;
    padding: 0 4px 6px !important;
    list-style: none;
  }

  #botomIcon ul.nav > li,
  #botomIcon ul.nav > li.nav-item {
    flex: 1 1 0;
    min-width: 0;
  }

  #botomIcon .nav-link {
    display: flex !important;
    flex-direction: column !important;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 52px;
    margin: 0 !important;
    padding: 8px 2px !important;
    color: #a7a7a7 !important;
    font-size: 0.64rem !important;
    line-height: 1;
    white-space: nowrap;
    border-radius: 8px;
  }

  #botomIcon .nav-link.ativo {
    color: #fff !important;
  }

  #botomIcon .nav-link svg {
    width: 23px;
    height: 23px;
    margin: 0 !important;
    fill: currentColor;
  }

  /* La barra de escritorio y el botón flotante no existen en el teléfono. */
  #caixaCentral,
  #configAudio,
  #mobiPlay {
    display: none !important;
  }
}

/* Pantallas muy estrechas: la marca y el nombre caben sin apretarse. */
@media (max-width: 380px) {
  #latNav {
    gap: 8px;
    padding: 0 10px !important;
  }

  #latNav > a:first-child img {
    width: 92px !important;
    max-width: 92px !important;
  }

  #latNav .profile-name {
    max-width: 84px;
  }
}

/* ==========================================================================
   Página de búsqueda: la barra superior se convierte en el buscador.
   ========================================================================== */

@media (max-width: 767px) {
  /* La marca y el perfil también se ven en Search. */
  body.search-page #latNav {
    display: flex !important;
    height: 52px !important;
  }

  body.search-page #principal {
    background: #121212 !important;
  }

  body.search-page #feed {
    background: #121212;
  }

  body.search-page #topNav {
    position: sticky !important;
    top: 0;
    right: 0;
    left: 0;
    display: flex !important;
    align-items: center;
    width: 100%;
    height: auto;
    padding: 8px 12px !important;
    background: rgba(18, 18, 18, 0.92) !important;
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    z-index: 40;
  }

  body.search-page #arrowMenu {
    display: flex !important;
    align-items: center;
    width: 100% !important;
  }

  body.search-page #arrowMenu > a,
  body.search-page #arrowMenu > button {
    display: none !important;
  }

  body.search-page #arrowMenu .div--hun {
    width: 100% !important;
    float: none !important;
  }

  body.search-page #arrowMenu .form--hun {
    width: 100% !important;
    float: none !important;
  }

  body.search-page #arrowMenu .form--hun input {
    width: 100% !important;
    height: 44px !important;
    padding: 0 14px 0 40px !important;
    color: #000 !important;
    background-color: #fff !important;
    border-radius: 6px;
    font-size: 0.95rem !important;
  }

  body.search-page #btnTopNav {
    display: none !important;
  }

  body.search-page #main {
    padding: 8px 14px 28px !important;
  }
}

/* ==========================================================================
   Tablet (768–1100px): estanterías en rejilla real, sin alturas fijas que
   recorten las tarjetas.
   ========================================================================== */

@media (min-width: 768px) and (max-width: 1100px) {
  #main .feedPlaylist .playlists {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px 14px;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  #main .feedPlaylist .playlists li {
    width: 100% !important;
    margin: 0 !important;
    padding: 12px !important;
  }

  #main .feedPlaylist .playlists li img {
    margin-bottom: 12px;
  }

  #main .feedPlaylist .playlists li button.btn {
    display: none !important;
  }
}

@media (min-width: 768px) and (max-width: 1100px) {
  #main .feedPlaylist .playlists li span {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  #main .feedPlaylist .playlists li p {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}
