/* =========================================================================
   Fulgione Radio - stile
   Palette derivata dall'immagine brand: slate profondo + viola -> magenta.
   ========================================================================= */

:root {
  --slate-900: #0e1116;
  --slate-850: #12161e;
  --slate-800: #161b25;
  --slate-700: #1d2430;
  --slate-600: #2a3342;
  --line:      rgba(255, 255, 255, .08);

  --text:      #f2f4f8;
  --muted:     #8a93a3;
  --muted-2:   #5d6675;

  --purple:    #7b2ff7;
  --magenta:   #e0218a;
  --accent:    #b32fc0;
  --grad:      linear-gradient(135deg, var(--purple), var(--magenta));

  --radius:    18px;
  --shadow:    0 24px 60px rgba(0, 0, 0, .55);

  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body:    "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--slate-900);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;   /* iOS: niente ingrandimento testo automatico */
  -webkit-font-smoothing: antialiased;
}

/* ----- sfondo ambient: logo stazione sfocato ----- */
.ambient {
  position: fixed;
  inset: -8%;
  background-size: cover;
  background-position: center;
  filter: blur(60px) saturate(1.3) brightness(.55);
  transform: scale(1.15);
  transition: background-image .6s ease, opacity .6s ease;
  opacity: 0;
  z-index: 0;
}
.ambient.show { opacity: 1; }

.ambient-veil {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 90% at 15% 110%, rgba(224, 33, 138, .28), transparent 60%),
    radial-gradient(110% 80% at 90% -10%, rgba(123, 47, 247, .22), transparent 55%),
    linear-gradient(180deg, rgba(14, 17, 22, .72), rgba(14, 17, 22, .92));
}

/* ----- layout (mobile-first: una colonna, lista con scroll proprio) ----- */
body { overflow: hidden; }     /* la pagina e' fissa: scorre solo la lista */

.app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;              /* iOS 15.4+ */
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    calc(12px + env(safe-area-inset-top))
    clamp(14px, 4.5vw, 18px)
    calc(10px + env(safe-area-inset-bottom));
}

/* ----- header ----- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 6px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  object-fit: cover;
  object-position: top;
  box-shadow: 0 0 0 1px var(--line), 0 8px 22px rgba(0, 0, 0, .5);
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.02rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  line-height: 1;
}
.brand-name span {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub {
  font-size: .64rem;
  letter-spacing: .34em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-top: 4px;
}
.install-btn {
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--slate-800);
  color: var(--text);
  font: 600 .74rem/1 var(--font-body);
  letter-spacing: .04em;
  padding: 9px 13px;
  border-radius: 999px;
  cursor: pointer;
  display: none;
  align-items: center;
  gap: 6px;
  transition: border-color .2s, transform .1s;
}
.install-btn.show { display: inline-flex; }
.install-btn:hover { border-color: var(--accent); }
.install-btn:active { transform: scale(.96); }

/* ----- now playing / disco ----- */
.stage {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(2px, 1.5vh, 10px) 0 4px;
}

.deck {
  position: relative;
  width: clamp(104px, 24vh, 150px);   /* mobile: disco piu' piccolo */
  aspect-ratio: 1;
  margin: 2px 0 4px;
}

/* braccio del giradischi */
.tonearm {
  position: absolute;
  top: -6%;
  right: 2%;
  width: 46%;
  transform-origin: 86% 14%;
  transform: rotate(-32deg);
  transition: transform .55s cubic-bezier(.5, 1.4, .6, 1);
  z-index: 3;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .55));
  pointer-events: none;
}
.deck.playing .tonearm { transform: rotate(0deg); }

/* vinile */
.vinyl {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    repeating-radial-gradient(circle at center,
      #0b0d11 0, #0b0d11 1px, #15181e 2px, #0b0d11 3px),
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .08), transparent 45%),
    #0a0c0f;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .04),
    inset 0 0 40px rgba(0, 0, 0, .8),
    var(--shadow);
  will-change: transform;
  z-index: 1;
}
.vinyl::after { /* riflesso che scorre */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(115deg, transparent 38%,
    rgba(255, 255, 255, .07) 49%, transparent 60%);
  z-index: 2;
}

/* etichetta centrale = logo stazione */
.label {
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  background: var(--grad);
  background-size: cover;
  background-position: center;
  box-shadow:
    0 0 0 4px #0a0c0f,
    0 0 0 5px rgba(255, 255, 255, .06),
    inset 0 0 18px rgba(0, 0, 0, .45);
  display: grid;
  place-items: center;
  overflow: hidden;
  z-index: 2;
}
.label::after { /* foro centrale */
  content: "";
  width: 9%;
  height: 9%;
  border-radius: 50%;
  background: #05060a;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, .9);
}
.label-fallback {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

.np-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.05rem, 4.6vw, 1.32rem);
  text-align: center;
  margin: 6px 0 2px;
  max-width: 90%;
  line-height: 1.18;
}
.np-group {
  font-size: .72rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
  min-height: 1em;
}
.np-status {
  font-size: .72rem;
  color: var(--muted);
  margin-top: 4px;
  min-height: 1em;
  display: flex;
  align-items: center;
  gap: 7px;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-2);
}
.np-status.live .dot { background: #2ecc71; box-shadow: 0 0 8px #2ecc71; }
.np-status.buffering .dot { background: #f1c40f; animation: pulse 1s infinite; }
.np-status.error .dot { background: var(--magenta); }

@keyframes pulse { 50% { opacity: .35; } }

/* ----- controlli ----- */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin: clamp(6px, 1.4vh, 12px) 0 4px;
}
.ctrl {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 6px;
  border-radius: 50%;
  transition: transform .12s, color .2s;
}
.ctrl:hover { color: var(--accent); }
.ctrl:active { transform: scale(.9); }
.ctrl svg { width: 26px; height: 26px; fill: currentColor; }

.play {
  width: clamp(58px, 16vw, 72px);
  height: clamp(58px, 16vw, 72px);
  border-radius: 50%;
  background: var(--grad);
  box-shadow: 0 12px 30px rgba(224, 33, 138, .35);
}
.play svg { width: 30px; height: 30px; fill: #fff; }
.play:hover { color: #fff; }

.volume-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 78%;
  max-width: 300px;
  margin: 8px auto 2px;
}
.volume-row svg { width: 17px; height: 17px; fill: var(--muted); flex: none; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--slate-600);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(179, 47, 192, .25);
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border: none; border-radius: 50%;
  background: #fff; cursor: pointer;
}

/* ----- lista stazioni ----- */
.stations-wrap {
  flex: 1;
  min-height: 0;            /* indispensabile: permette lo scroll interno */
  display: flex;
  flex-direction: column;
  margin-top: 6px;
}
.list-head {
  flex: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 6px 2px 8px;
}
.list-head h2 {
  font: 600 .76rem/1 var(--font-body);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.list-head .count { font-size: .72rem; color: var(--muted-2); }

/* ----- ricerca ----- */
.search {
  flex: none;
  position: relative;
  margin: 0 2px 10px;
}
.search svg {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  fill: var(--muted);
  pointer-events: none;
}
.search input {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 14px 11px 39px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--slate-800);
  color: var(--text);
  font: 500 .9rem var(--font-body);
  outline: none;
  transition: border-color .2s, background .2s;
}
.search input::placeholder { color: var(--muted-2); }
.search input:focus {
  border-color: var(--accent);
  background: var(--slate-700);
}
.search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  height: 14px;
  width: 14px;
  background:
    linear-gradient(45deg, transparent 45%, var(--muted) 45%, var(--muted) 55%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, var(--muted) 45%, var(--muted) 55%, transparent 55%);
  cursor: pointer;
}

.stations {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;   /* scroll inerziale su iOS */
  overscroll-behavior: contain;
  margin: 0 -4px;
  padding: 0 4px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--slate-600) transparent;
}
.stations::-webkit-scrollbar { width: 6px; }
.stations::-webkit-scrollbar-thumb { background: var(--slate-600); border-radius: 99px; }

.station {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--slate-800);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 9px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  color: var(--text);
  transition: border-color .18s, background .18s, transform .08s;
}
.station:hover { border-color: var(--slate-600); background: var(--slate-700); }
.station:active { transform: scale(.99); }
.station.active {
  border-color: transparent;
  background:
    linear-gradient(var(--slate-800), var(--slate-800)) padding-box,
    var(--grad) border-box;
  border: 1px solid transparent;
}
.station-logo {
  width: 42px; height: 42px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--slate-600);
  flex: none;
}
.station-logo.placeholder {
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  background: var(--grad);
  color: #fff;
}
.station-meta { min-width: 0; flex: 1; }
.station-name {
  font-weight: 600; font-size: .92rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.station-group {
  font-size: .68rem; color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.station .eq {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  flex: none;
}
.station.active .eq { display: flex; }
.station .eq i {
  width: 3px; background: var(--accent); border-radius: 2px;
  animation: eq 1s ease-in-out infinite;
}
.station .eq i:nth-child(2) { animation-delay: .2s; }
.station .eq i:nth-child(3) { animation-delay: .4s; }
@keyframes eq {
  0%, 100% { height: 5px; } 50% { height: 16px; }
}

/* stati lista */
.state-msg {
  text-align: center;
  color: var(--muted);
  font-size: .86rem;
  padding: 30px 16px;
}
.state-msg button {
  margin-top: 12px;
  background: var(--grad);
  color: #fff; border: none;
  padding: 9px 18px; border-radius: 999px;
  font: 600 .8rem var(--font-body); cursor: pointer;
}

/* skeleton di caricamento */
.skel {
  height: 60px; border-radius: 13px; margin-bottom: 8px;
  background: linear-gradient(90deg, var(--slate-800) 25%, var(--slate-700) 50%, var(--slate-800) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* focus visibile */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* preferenza riduzione movimento */
@media (prefers-reduced-motion: reduce) {
  .vinyl, .station .eq i, .skel, .np-status.buffering .dot { animation: none !important; }
  .tonearm { transition: none; }
  .ambient { transition: opacity .2s; }
}

/* schermi bassi (mobile landscape corto): disco ancora piu' piccolo */
@media (max-height: 560px) and (max-width: 699px) {
  .deck { width: clamp(96px, 26vh, 150px); }
  .stage { padding-top: 0; }
  .controls { margin: 8px 0 2px; }
}

/* ======================= DESKTOP / TABLET: due colonne ====================
   Player a sinistra, elenco canali a destra con scroll proprio.            */
@media (min-width: 700px) {
  body { overflow: hidden; }

  .app {
    max-width: 1080px;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-columns: 1fr minmax(340px, 440px);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "top  top"
      "stage list";
    column-gap: clamp(24px, 4vw, 56px);
    row-gap: 8px;
    padding: clamp(18px, 3vh, 30px) clamp(20px, 4vw, 40px);
  }

  .topbar { grid-area: top; }

  /* pannello sinistro: player centrato verticalmente */
  .stage {
    grid-area: stage;
    align-self: center;
    justify-self: center;
    width: 100%;
    max-width: 460px;
    padding: 0;
  }
  .deck { width: clamp(220px, 22vw, 300px); }
  .np-name { font-size: clamp(1.3rem, 2vw, 1.7rem); }

  /* pannello destro: lista dentro una superficie "vetro" coordinata */
  .stations-wrap {
    grid-area: list;
    min-height: 0;
    margin-top: 0;
    background: linear-gradient(180deg,
      rgba(27, 33, 44, .58), rgba(16, 19, 26, .58));
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 22px;
    padding: 18px 8px 10px 18px;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, .05),
      0 24px 60px rgba(0, 0, 0, .45);
    -webkit-backdrop-filter: blur(20px) saturate(1.25);
    backdrop-filter: blur(20px) saturate(1.25);
  }
  .list-head { margin: 0 8px 14px 2px; }
  .stations { padding-right: 10px; }

  /* righe integrate nel pannello, non blocchi staccati */
  .station {
    background: rgba(255, 255, 255, .025);
    border-color: rgba(255, 255, 255, .055);
    border-radius: 14px;
  }
  .station:hover {
    background: rgba(255, 255, 255, .06);
    border-color: rgba(255, 255, 255, .1);
  }
  .station.active {
    background:
      linear-gradient(rgba(123, 47, 247, .14), rgba(224, 33, 138, .14)) padding-box,
      var(--grad) border-box;
    border: 1px solid transparent;
  }
}

/* desktop largo: disco piu' generoso */
@media (min-width: 1100px) {
  .deck { width: clamp(260px, 18vw, 320px); }
}