/*
  SbiRadio - Tu Emisora
  Copyright (C) 2026 SbiDev

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

@font-face {
  font-family: "determination";
  src:
    url("../assets/fonts/determination.woff2") format("woff2"),
    url("../assets/fonts/determination.woff") format("woff"),
    url("../assets/fonts/determination.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "park";
  src: url("../assets/fonts/Titania-Regular.ttf") format(truetype);
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  /* COLORS */
  --dark-green: #012d22;
  --midium-green: #55703f;
  --emerald: #396848;
  --almond: #dec4ab;
  --end-bg: #06080f;
  --glow-green: 125 255 168; /* acento luminoso (canales RGB) de cards y footer */
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
  background: transparent;
  list-style: none;
  text-decoration: none;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--emerald);
  outline-offset: 2px;
}

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

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--almond);
}

header {
  display: flex;
  flex-direction: column;
  justify-content: center; /* texto centrado en el alto del header */
  align-items: center;
  background-color: var(--dark-green); /* fallback si la imagen no carga */
  background-image:
    linear-gradient(rgb(1 45 34 / 0.55), rgb(1 45 34 / 0.8)),
    url("../assets/img/disco.webp"); /* velo oscuro: el texto necesita contraste sobre la foto */
  background-size: cover;
  background-position: center;
  padding: clamp(1.5rem, 4vw, 50px) clamp(1rem, 8vw, 150px);
  min-height: clamp(
    240px,
    42dvh,
    400px
  ); /* 400px en desktop; se achica si la pantalla es baja */
  color: var(--almond);

  h1 {
    font-size: clamp(2.25rem, 9vw, 100px);
    font-weight: 400;
    font-family: "park";
    line-height: 1.1;
    overflow-wrap: break-word;
  }

  .subtitle {
    display: block;
    font-size: clamp(1rem, 2.5vw, 24px);
    line-height: 1.4;
  }
}

main {
  display: flex; /* una sola columna: el player se centra solo */
  flex: 0 0 auto; /* no crece: el fondo de oleaje queda pegado al reproductor */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  /* más aire vertical: la banda de oleaje ocupa más alto alrededor del player */
  padding: clamp(2.5rem, 6vw, 5rem) 1.5rem;
  width: 100%;
  background-image: url("../assets/img/bg.webp");
  background-size: cover;
  background-position: center;

  .player-container {
    display: flex;
    flex-direction: column; /* player + indicador del stream, apilados y centrados */
    justify-content: center;
    align-items: center;
    gap: 0.375rem;
    width: 100%;
    max-width: 640px; /* la caja no se estira en pantallas anchas */
    padding: 1.5rem 1.25rem;

    /* caja de madera */
    background-image:
      radial-gradient(circle, rgb(0 0 0 / 0.1), rgb(0 0 0 / 0.2)),
      url("../assets/img/bg-player.webp");
    border-radius: 18px;
    box-shadow:
      inset 0 2px 4px rgb(255 255 255 / 0.25),
      inset 0 -4px 10px rgb(0 0 0 / 0.5),
      0 10px 25px rgb(0 0 0 / 0.45);

    /* placa metálica/crema donde vive el reproductor */
    audio {
      width: 100%;
      max-width: 520px;
      height: 32px;
      zoom: 1.3; /* agranda botones y textos (Chrome, Safari, Firefox 126+) */
      border-radius: 8px;
      border: 4px solid #c9a24a; /* latón */
      box-shadow:
        inset 0 0 8px rgb(0 0 0 / 0.35),
        0 2px 0 rgb(255 255 255 / 0.15);

      /* tiñe iconos y barras hacia marrón/dorado */
      filter: sepia(1) saturate(1.8) hue-rotate(-12deg) contrast(0.95);

      &::-webkit-media-controls-enclosure {
        border-radius: 8px;
        background-color: #ecd9a6;
      }

      &::-webkit-media-controls-panel {
        background-color: #ecd9a6;
        background-image: linear-gradient(
          180deg,
          rgb(255 255 255 / 0.35),
          rgb(0 0 0 / 0.12)
        );
        padding: 0 10px;
      }

      &::-webkit-media-controls-current-time-display,
      &::-webkit-media-controls-time-remaining-display {
        color: #3b2008;
        font-family: "Courier New", monospace;
        font-weight: bold;
        text-shadow: 0 1px 0 rgb(255 255 255 / 0.4);
      }
    }
  }

  .player-container .player-controls {
    display: none;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 520px;
    padding: 0.5rem 0.75rem;
    border: 4px solid #c9a24a;
    border-radius: 8px;
    background-color: #ecd9a6; /* misma placa crema que el panel nativo */
    box-shadow:
      inset 0 0 8px rgb(0 0 0 / 0.35),
      0 2px 0 rgb(255 255 255 / 0.15);

    /* visible solo cuando JS la habilita */
    &:not([hidden]) {
      display: flex;
    }

    .play-toggle {
      display: grid;
      place-items: center;
      flex: 0 0 auto;
      width: 2.75rem;
      height: 2.75rem;
      border-radius: 50%;
      background-color: var(--dark-green);
      color: #ecd9a6;
      cursor: pointer;

      &:hover,
      &:focus-visible {
        background-color: var(--emerald);
      }

      .play-toggle__icon {
        display: block;
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 9px 0 9px 15px;
        border-color: transparent transparent transparent currentColor;
      }

      /* pausa: dos barras en lugar del triángulo */
      &[data-state="playing"] .play-toggle__icon {
        width: 14px;
        height: 18px;
        border: 0;
        background:
          linear-gradient(currentColor, currentColor) left / 5px 100% no-repeat,
          linear-gradient(currentColor, currentColor) right / 5px 100% no-repeat;
      }
    }

    .volume-control {
      display: flex;
      align-items: center;
      flex: 1 1 auto;
      min-width: 0;
      /* más aire respecto al play: evita que el conjunto parezca una barra de tiempo */
      margin-inline-start: 0.75rem;
      gap: 0.4rem;
    }

    .volume-label {
      flex: 0 0 auto;
      color: var(--dark-green);
      font-family: "determination", ui-monospace, "Cascadia Mono", monospace;
      font-size: 0.7rem;
      letter-spacing: 0.12em;
      line-height: 1;
      opacity: 0.75;
    }

    .volume {
      flex: 1 1 auto;
      min-width: 0;
      accent-color: var(--dark-green);
      cursor: pointer;
    }

    .mute-toggle {
      display: grid;
      place-items: center;
      flex: 0 0 auto;
      width: 2.25rem;
      height: 2.25rem;
      border-radius: 50%;
      color: var(--dark-green);
      cursor: pointer;

      &:hover,
      &:focus-visible {
        background-color: rgb(1 45 34 / 0.12);
      }

      .mute-toggle__icon {
        width: 1.35rem;
        height: 1.35rem;
        fill: currentColor;

        .mute-toggle__wave,
        .mute-toggle__slash {
          fill: none;
          stroke: currentColor;
          stroke-width: 2;
          stroke-linecap: round;
        }

        .mute-toggle__slash {
          display: none;
        }
      }

      /* muteado: se ocultan las ondas y aparece la barra tachada */
      &[data-state="muted"] .mute-toggle__icon {
        .mute-toggle__wave {
          display: none;
        }

        .mute-toggle__slash {
          display: block;
        }
      }
    }
  }

  .player-container .stream-status {
    /* display de radio de auto incrustado en la madera: marco oscuro + vidrio */
    order: -1; /* siempre arriba del todo dentro del player */
    display: block;
    width: 100%;
    max-width: 520px;
    min-height: 2.5rem; /* un poco más alto */
    margin: 0 0 1rem; /* separación respecto al reproductor */
    padding: 0.45rem 1rem;
    /* el texto largo se desplaza como en una radio de auto: no agranda la placa */
    overflow: hidden;
    border: 2px solid #14100a;
    border-radius: 6px;
    background-color: #06120c;
    /* vidrio apagado con scanlines tenues */
    background-image: repeating-linear-gradient(
      0deg,
      rgb(255 255 255 / 0.035) 0 1px,
      transparent 1px 3px
    );
    color: #7dffa8;
    font-family: "determination", ui-monospace, "Cascadia Mono", monospace;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    /* el alto de línea completa el min-height: texto centrado en vertical */
    line-height: 1.6rem;
    text-align: center;
    text-transform: uppercase;
    white-space: nowrap;
    text-shadow:
      0 0 6px rgb(125 255 168 / 0.55),
      0 0 14px rgb(125 255 168 / 0.25);
    box-shadow:
      inset 0 0 0 2px #a8843a,
      /* aro latón interior */ inset 0 3px 10px rgb(0 0 0 / 0.85),
      0 2px 4px rgb(0 0 0 / 0.45);

    /* texto del display: se mide y se anima solo si desborda */
    .stream-status__text {
      display: inline-block;
      white-space: nowrap;
    }

    /* sin estado: el vidrio queda encendido pero en reposo */
    .stream-status__text:empty::after {
      content: "STANDBY";
      color: #2f6b4c;
      text-shadow: none;
    }

    /* desplazamiento de ida y vuelta cuando el mensaje no entra */
    &.is-scrolling {
      text-align: left;
    }

    &.is-scrolling .stream-status__text {
      animation: stream-marquee var(--marquee-duration, 8s) linear infinite
        alternate;
    }

    /* punto verde pulsante cuando el stream está al aire */
    &.is-live::before {
      content: "";
      display: inline-block;
      width: 0.45rem;
      height: 0.45rem;
      margin-inline-end: 0.4rem;
      vertical-align: middle;
      border-radius: 50%;
      background-color: #7dffa8;
      box-shadow: 0 0 6px rgb(125 255 168 / 0.8);
      animation: stream-pulse 1.6s ease-in-out infinite;
    }
  }

  /* contador de oyentes: línea discreta bajo el display del stream.
     Reserva su alto siempre (visibility) para que el player no salte
     cuando aparece el primer conteo. */
  .player-container .listeners {
    display: flex;
    align-self: center; /* centrado bajo el reproductor */
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin: 1rem 0 0; /* separación respecto al reproductor */
    visibility: hidden;
    color: #ecd9a6;
    font-family: "determination", ui-monospace, "Cascadia Mono", monospace;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    line-height: 1.2;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgb(0 0 0 / 0.7);

    /* visible solo cuando JS encontró un conteo válido */
    &.is-visible {
      visibility: visible;
    }

    .listeners__value {
      color: #7dffa8;
      text-shadow:
        0 0 6px rgb(125 255 168 / 0.55),
        0 0 14px rgb(125 255 168 / 0.25);
    }
  }
}

/* ── Secciones informativas ───────────────────────────────────────
   Viven fuera de <main> a propósito: así no heredan el fondo del
   reproductor y cada una puede recibir su propio fondo más adelante. */
.info {
  display: flex;
  flex: 1 0 auto; /* absorbe el alto libre: el footer queda al fondo */
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  width: 100%;
  /* fondo de vinilo detrás de las cards; el velo oscuro mantiene el foco
     en el contenido y evita que la foto compita con las tarjetas */
  background-color: var(--end-bg); /* respaldo si la imagen no carga */
  background-image:
    linear-gradient(rgb(6 8 15 / 0.35), rgb(6 8 15 / 0.65)),
    url("../assets/img/bg-disco2.webp");
  background-size: cover;
  background-position: center;
  /* aire arriba y abajo: las cards respiran respecto al reproductor y al footer */
  padding: clamp(3.5rem, 8vw, 6rem) 1.5rem clamp(3rem, 6vw, 4.5rem);

  /* Card vintage de papel envejecido sobre verde profundo: a propósito no
     repite la placa crema con aro de latón del reproductor. */
  .panel {
    width: 100%;
    max-width: 640px;
    padding: 1.5rem 1.5rem 1.6rem;
    /* marco de latón, en sintonía con el aro del reproductor */
    border: 3px solid #c9a24a;
    border-radius: 4px;
    background-color: #0d3a2c;
    background-image:
      radial-gradient(rgb(236 217 166 / 0.05) 1px, transparent 1px),
      linear-gradient(180deg, rgb(255 255 255 / 0.05), transparent 60%);
    background-size:
      6px 6px,
      100% 100%;
    color: #e6d7b4;
    box-shadow:
      /* doble filete interior: separa el contenido del marco */
      inset 0 0 0 5px #0d3a2c,
      inset 0 0 0 6px rgb(236 217 166 / 0.28),
      0 14px 30px rgb(0 0 0 / 0.28);

    h2 {
      margin: 0 0 0.75rem;
      font-family: "park", Georgia, "Times New Roman", serif;
      font-size: clamp(1.5rem, 3.5vw, 1.9rem);
      font-weight: 400;
      line-height: 1.15;
      color: #f4e8ca;

      /* filete corto bajo el título */
      &::after {
        content: "";
        display: block;
        width: 2.75rem;
        height: 1px;
        margin-top: 0.6rem;
        background-color: rgb(236 217 166 / 0.45);
      }
    }

    p {
      margin: 0 0 0.9rem;
      /* lectura cómoda: párrafos de las cards a 18px con interlineado amplio */
      font-size: 1.125rem;
      line-height: 1.65;
    }

    /* los enlaces dentro del texto se distinguen; los botones no */
    p a {
      color: #f7ecd2;
      text-decoration: underline;
      text-decoration-color: rgb(236 217 166 / 0.45);
      text-underline-offset: 2px;

      &:hover,
      &:focus-visible {
        text-decoration-color: currentColor;
      }
    }

    .tags {
      display: flex;
      flex-wrap: wrap;
      justify-content: center; /* etiquetas centradas dentro de la card */
      gap: 0.4rem;
      margin: 1rem 0 0;
      padding: 0;

      li {
        padding: 0.22rem 0.55rem;
        border: 1px solid rgb(236 217 166 / 0.35);
        border-radius: 2px;
        color: #d9c8a3;
        font-family: "determination", ui-monospace, "Cascadia Mono", monospace;
        font-size: 0.65rem;
        letter-spacing: 0.1em;
        line-height: 1.3;
        text-transform: uppercase;
      }
    }

    .listen-actions {
      display: flex;
      flex-wrap: wrap;
      justify-content: center; /* botones centrados dentro de la card */
      gap: 0.5rem;
      /* más aire arriba: la card no queda con la mitad inferior vacía */
      margin: 2rem 0 0;
    }

    .chip {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-height: 2.5rem;
      padding: 0.45rem 1rem;
      border: 1px solid rgb(1 45 34 / 0.55);
      border-radius: 2px;
      background-color: #e6d7b4;
      color: #0b2f24;
      font-family: "determination", ui-monospace, "Cascadia Mono", monospace;
      font-size: 0.72rem;
      letter-spacing: 0.09em;
      line-height: 1.2;
      text-align: center;
      text-decoration: none;
      text-transform: uppercase;
      cursor: pointer;
      box-shadow: 0 2px 0 rgb(0 0 0 / 0.25);
      transition:
        transform 0.12s ease,
        background-color 0.12s ease,
        box-shadow 0.12s ease;

      &:hover,
      &:focus-visible {
        background-color: #f4e8ca;
        box-shadow: 0 3px 0 rgb(0 0 0 / 0.25);
        transform: translateY(-1px);
      }

      &:active {
        box-shadow: 0 1px 0 rgb(0 0 0 / 0.25);
        transform: translateY(0);
      }
    }

    .chip--button {
      appearance: none;
    }

    /* `display` del chip pisaría el [hidden] del navegador: el botón debe
       permanecer oculto hasta que JS confirme que puede compartir. */
    .chip--button[hidden] {
      display: none;
    }

    .share-status {
      min-height: 1.2rem; /* reserva el alto: el texto no hace saltar la card */
      margin: 0.6rem 0 0;
      color: #cdbc98;
      font-family: "determination", ui-monospace, "Cascadia Mono", monospace;
      font-size: 0.68rem;
      letter-spacing: 0.09em;
      line-height: 1.2;
      text-transform: uppercase;
    }
  }
}

@keyframes stream-pulse {
  50% {
    opacity: 0.3;
  }
}

@keyframes stream-marquee {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(var(--marquee-distance, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  /* sin animación: el mensaje largo se recorta con puntos suspensivos */
  .player-container .stream-status .stream-status__text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .player-container .stream-status.is-live::before {
    animation: none;
  }
}

.end {
  background-color: var(--end-bg);
  display: flex;
  flex-flow: column nowrap;
  align-items: center;
  justify-content: center;
  padding: clamp(1.5rem, 3vw, 25px) clamp(1rem, 8vw, 150px);
  transition: background-color 0.25s ease;
  /* resplandor que sube desde el borde superior del footer */
  box-shadow:
    0 -2px 10px rgb(var(--glow-green) / 0.35),
    0 -14px 40px rgb(var(--glow-green) / 0.22);

  .end-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap; /* si no entra en una fila, centra el texto bajo la imagen */
    gap: 10px;

    img {
      display: block;
      width: 160px;
      height: auto; /* respeta la proporción intrínseca 640x512 del logo */
      max-width: 100%;
      image-rendering: pixelated;
    }

    .end-title {
      font-family: determination;
      font-size: clamp(1.75rem, 5vw, 40px);
      color: #fafafa;
      text-align: center;
    }
  }

  .memerandum {
    margin: 30px 0px;
    color: #fafafa;

    a {
      color: inherit;
      text-decoration: underline;
      text-underline-offset: 2px;

      &:hover,
      &:focus-visible {
        opacity: 0.7;
      }
    }
  }
}

/* ── RESPONSIVE ───────────────────────────────────────────── */

/* Pantallas grandes: las dos cards informativas comparten la fila.
   El padding centra el contenido a 1360px sin recortar el fondo de vinilo,
   que sigue cubriendo todo el ancho de la sección. */
@media (min-width: 981px) {
  .info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch; /* las dos cards toman el mismo alto */
    padding-inline: max(1.5rem, calc((100% - 1360px) / 2));
  }

  .info .panel {
    max-width: none;
  }
}

/* Desktop amplio: reduce escalas antes del layout de tablet */
@media (max-width: 1280px) {
  header {
    padding-inline: clamp(1.5rem, 5vw, 80px);
  }

  header h1 {
    font-size: clamp(2.25rem, 7.5vw, 88px);
  }

  header .subtitle {
    font-size: clamp(1rem, 1.8vw, 20px);
  }

  .end {
    padding-inline: clamp(1.5rem, 5vw, 80px);
  }
}

/* Tablet y móvil grande: todo en una columna */
@media (max-width: 980px) {
  header {
    padding-inline: 1rem;
    padding-block: clamp(
      3rem,
      8dvh,
      8rem
    ); /* el header respira con el viewport y absorbe parte del aire del layout en una columna */
  }

  main {
    padding: clamp(2rem, 6vw, 3.25rem) 1rem; /* el gutter ahora lo aporta main, no el player */
    gap: 1.25rem;
  }

  main .player-container {
    width: 100%;
    margin: 0;
  }

  .end .end-logo {
    flex-direction: column;
    text-align: center;
  }

  .end .memerandum {
    text-align: center;
  }
}

/* El zoom del audio desborda la caja del reproductor en anchos intermedios */
@media (max-width: 760px) {
  main .player-container audio {
    height: 40px;
    zoom: 1;
  }
}

/* Móvil */
@media (max-width: 680px) {
  header {
    padding-inline: 1rem; /* el padding-block hereda del clamp 980px: el header sigue respirando en móvil */
  }

  main {
    gap: 1.25rem;
  }

  main .player-container {
    margin: 0;
    padding: 1rem;
  }

  .info {
    padding: 2.75rem 1rem 1.75rem;
  }

  .info .panel {
    padding: 1rem;
  }

  .info .panel .chip {
    flex: 1 1 auto; /* los botones ocupan el ancho disponible al envolverse */
  }

  .end .end-logo {
    gap: 6px;
  }

  .end .end-logo img {
    width: 120px;
  }

  .end .memerandum {
    margin: 20px 0 0;
    font-size: 0.9375rem;
    line-height: 1.55;
  }
}

/* Móvil pequeño */
@media (max-width: 400px) {
  header {
    padding-inline: 0.75rem;
  }

  main {
    padding-inline: 0.75rem;
  }

  main .player-container {
    padding: 0.75rem;
  }

  .info {
    padding: 2.25rem 0.75rem 1.5rem;
  }

  .info .panel {
    padding: 0.75rem;
  }

  .end {
    padding-inline: 0.75rem;
  }

  .end .end-title {
    font-size: 1.5rem;
  }

  .end .memerandum {
    font-size: 0.875rem;
  }
}
