/* =========================================================
   Радио Онлайн — основной файл стилей
   Подход: mobile-first (сначала стили для телефона,
   затем @media для планшетов и компьютеров).
   ========================================================= */

/* ---------- 1. Переменные: меняйте цвета здесь ---------- */
:root {
  --bg: #14161c;          /* фон страницы */
  --surface: #1d2029;     /* фон карточек и плеера */
  --surface-2: #262a35;   /* фон при наведении */
  --border: #2f3441;
  --text: #eef0f5;        /* основной текст */
  --muted: #9aa1b2;       /* второстепенный текст */
  --accent: #ff6b35;      /* акцентный цвет (кнопка Play, активные элементы) */
  --accent-hover: #ff8456;
  --accent-text: #1a0d06; /* текст на акцентном фоне */
  --danger: #ff5c6c;
  --ok: #3ddc84;
  --radius: 14px;
  --tap: 44px;            /* минимальный размер зоны нажатия пальцем */
  --ease: 0.2s ease;
}

/* ---------- 2. Базовые стили ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden; /* защита от горизонтальной прокрутки */
}

img, svg { display: block; max-width: 100%; }
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* Видимая рамка фокуса для управления с клавиатуры */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-text);
  padding: 8px 12px; z-index: 100; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

.muted { color: var(--muted); }

/* ---------- 3. Плеер (шапка) ---------- */
.player {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(29, 32, 41, 0.96);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
@supports (backdrop-filter: blur(8px)) {
  .player { background: rgba(29, 32, 41, 0.85); backdrop-filter: blur(10px); }
}

.player__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 12px;
  display: grid;
  /* телефон: обложка | название | кнопка play */
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "cover info play";
  align-items: center;
  gap: 12px;
}

.logo {
  display: none; /* на телефоне скрываем, чтобы освободить место */
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 18px;
}
.logo svg { color: var(--accent); }
.logo b { color: var(--accent); font-weight: 700; }

.player__cover {
  grid-area: cover;
  width: 48px; height: 48px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
}

.player__info { grid-area: info; min-width: 0; /* важно для обрезки длинного текста */ }

.player__name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player__status {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player__status::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: 1px;
  background: var(--muted);
}

/* Цвет индикатора статуса для каждого состояния плеера */
.player[data-state="loading"] .player__status::before { background: #ffc94d; animation: pulse 1s infinite; }
.player[data-state="playing"] .player__status::before { background: var(--ok); }
.player[data-state="paused"]  .player__status::before { background: var(--muted); }
.player[data-state="error"]   .player__status        { color: var(--danger); }
.player[data-state="error"]   .player__status::before { background: var(--danger); }

/* Кнопка Play/Pause */
.btn-play {
  grid-area: play;
  position: relative;
  width: 56px; height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  transition: background var(--ease), transform var(--ease), opacity var(--ease);
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.35);
}
.btn-play:hover:not(:disabled) { background: var(--accent-hover); }
.btn-play:active:not(:disabled) { transform: scale(0.94); }
.btn-play:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.btn-play svg { grid-area: 1 / 1; }
.btn-play .i-pause,
.btn-play .spinner { display: none; }

/* Показываем нужную иконку в зависимости от состояния */
.player[data-state="playing"] .btn-play .i-play  { display: none; }
.player[data-state="playing"] .btn-play .i-pause { display: block; }
.player[data-state="loading"] .btn-play .i-play  { display: none; }
.player[data-state="loading"] .btn-play .spinner { display: block; }

.spinner {
  grid-area: 1 / 1;
  width: 26px; height: 26px;
  border: 3px solid rgba(26, 13, 6, 0.25);
  border-top-color: var(--accent-text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Громкость: на телефоне скрыта (громкость регулируется кнопками
   телефона; iOS вообще не позволяет менять громкость из JS) */
.volume { display: none; align-items: center; gap: 6px; }

.btn-icon {
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%;
  background: transparent;
  display: grid; place-items: center;
  color: var(--muted);
  transition: color var(--ease), background var(--ease);
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); }
.btn-icon .i-mute { display: none; }
.volume.is-muted .i-vol  { display: none; }
.volume.is-muted .i-mute { display: block; color: var(--danger); }

/* Ползунок громкости */
.volume__range {
  -webkit-appearance: none;
  appearance: none;
  width: 110px; height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--accent) var(--fill, 80%), var(--border) var(--fill, 80%));
  cursor: pointer;
}
.volume__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.volume__range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 0;
}

/* ---------- 4. Навигация ---------- */
.nav {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px 8px;
  overflow-x: auto;              /* если не влезает — скроллится только меню, не страница */
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.nav::-webkit-scrollbar { display: none; }

.nav__link {
  flex: 0 0 auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 15px;
  transition: color var(--ease), background var(--ease);
}
.nav__link:hover { color: var(--text); background: var(--surface-2); }
.nav__link.is-active { color: var(--accent-text); background: var(--accent); }

.badge {
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  display: inline-grid; place-items: center;
}
.nav__link.is-active .badge { background: rgba(0,0,0,.2); color: var(--accent-text); }

/* Переключатель «Экономия трафика» */
.eco {
  flex: 0 0 auto;
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 38px; padding: 0 8px;
  font-size: 14px; color: var(--muted);
  cursor: pointer; user-select: none;
}
/* position: relative — чтобы скрытый чекбокс не «вылезал» за меню и не создавал горизонтальную прокрутку */
.eco { position: relative; }
.eco input { position: absolute; left: 0; top: 0; opacity: 0; width: 1px; height: 1px; margin: 0; }
.eco__switch {
  position: relative;
  width: 36px; height: 20px;
  border-radius: 999px;
  background: var(--border);
  transition: background var(--ease);
}
.eco__switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff;
  transition: transform var(--ease);
}
.eco input:checked + .eco__switch { background: var(--accent); }
.eco input:checked + .eco__switch::after { transform: translateX(16px); }
.eco input:focus-visible + .eco__switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 5. Основной контент ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 12px 32px;
}
.main:focus { outline: none; }

.view__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.view__title { font-size: 22px; line-height: 1.25; margin: 4px 0 14px; }

/* Поиск и фильтры */
.toolbar { display: grid; gap: 12px; margin-bottom: 10px; }

.search {
  position: relative;
  display: flex; align-items: center;
}
.search svg { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  height: 48px;
  padding: 0 14px 0 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px; /* 16px — чтобы iOS не увеличивал страницу при фокусе */
  transition: border-color var(--ease);
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); }

.genres {
  display: flex;
  gap: 8px;
  overflow-x: auto;   /* на телефоне жанры листаются пальцем по горизонтали */
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.genres::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.result-info { margin: 4px 0 12px; font-size: 14px; color: var(--muted); min-height: 21px; }

/* ---------- 6. Сетка и карточки станций ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)); /* телефон: 2 колонки */
  gap: 10px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  min-width: 0;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
  animation: fadeIn 0.3s ease both;
}
.card:hover { background: var(--surface-2); }

/* Вся карточка кликабельна через эту кнопку */
.card__main {
  display: flex; flex-direction: column; gap: 10px;
  padding: 0; border: 0; background: none;
  text-align: left; min-width: 0;
}
.card__main::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); } /* растягиваем зону клика */

.card__logo-wrap { position: relative; }
.card__logo {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-2);
}
/* Иконка «играет» поверх логотипа */
.card__overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity var(--ease);
}
.card__overlay span {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
}
.card:hover .card__overlay { opacity: 1; }

.card__name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
  padding-right: 34px; /* место под сердечко */
}
.card__genre { font-size: 13px; color: var(--muted); }

/* Кнопка «В избранное» */
.card__fav {
  position: absolute;
  right: 6px; bottom: 6px;
  z-index: 2; /* поверх растянутой зоны клика */
  width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid; place-items: center;
  transition: color var(--ease), background var(--ease), transform var(--ease);
}
.card__fav:hover { color: var(--text); background: rgba(255,255,255,.06); }
.card__fav:active { transform: scale(0.88); }
.card__fav[aria-pressed="true"] { color: var(--danger); }
.card__fav[aria-pressed="true"] path { fill: currentColor; }

/* Активная карточка (сейчас играет) */
.card.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.card.is-active .card__overlay { opacity: 1; }
.card.is-active .card__genre { color: var(--accent); }

/* «Эквалайзер» — анимированные полоски на играющей станции */
.eq { display: none; gap: 3px; align-items: flex-end; height: 18px; }
.eq i { width: 4px; background: var(--accent-text); border-radius: 2px; animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -0.3s; }
.eq i:nth-child(3) { animation-delay: -0.6s; }
.card.is-active.is-playing .eq { display: flex; }
.card.is-active.is-playing .card__overlay .i-play-sm { display: none; }

/* Пустые состояния */
.empty {
  text-align: center;
  padding: 40px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty__icon { font-size: 40px; line-height: 1; margin-bottom: 8px; color: var(--muted); }
.empty__title { font-size: 18px; font-weight: 700; margin: 0 0 6px; }
.empty__text { color: var(--muted); margin: 0 auto 16px; max-width: 420px; }

/* Кнопки общего назначения */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap);
  padding: 0 18px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 600; text-decoration: none;
  transition: background var(--ease);
}
.btn:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 7. Страница «О радио» ---------- */
.about { max-width: 720px; }
.about h2 { font-size: 18px; margin: 28px 0 10px; }
.about__lead { font-size: 17px; }
.about__now {
  display: flex; gap: 14px; align-items: center;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
}
.about__now img { width: 64px; height: 64px; border-radius: 10px; flex: 0 0 auto; }
.about__now p { margin: 0; }
.about__now .about__now-name { font-weight: 700; font-size: 17px; }
.contacts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.contacts li { word-break: break-word; }
.contacts span { color: var(--muted); }

/* ---------- 8. Подвал, уведомления ---------- */
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.toast {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: #3a1d22;
  border: 1px solid var(--danger);
  color: #ffe3e6;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: fadeIn 0.25s ease both;
}

.noscript { text-align: center; padding: 20px; color: var(--danger); }

/* ---------- 9. Режим «Экономия трафика» ----------
   Класс .eco-mode добавляется к <body> из script.js.
   Скрываем логотипы, эффекты размытия и анимации. */
.eco-mode .card__logo-wrap,
.eco-mode .player__cover,
.eco-mode .about__now img { display: none; }
.eco-mode .player { backdrop-filter: none; background: var(--surface); }
.eco-mode .btn-play { box-shadow: none; }
.eco-mode .grid { grid-template-columns: 1fr; gap: 6px; }
.eco-mode .card { flex-direction: row; align-items: center; padding: 10px 12px; animation: none; }
.eco-mode .card__main { gap: 2px; }
.eco-mode .card__name { -webkit-line-clamp: 1; }
.eco-mode .card__fav { top: 50%; bottom: auto; transform: translateY(-50%); }
.eco-mode *, .eco-mode *::before, .eco-mode *::after { transition: none !important; }
.eco-mode .eq i { animation: none; }

/* ---------- 10. Анимации ---------- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes pulse  { 50% { opacity: 0.3; } }
@keyframes eq     { 0%, 100% { height: 4px; } 50% { height: 18px; } }

/* Уважаем системную настройку «Уменьшить движение» */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 11. Адаптивность ---------- */

/* Большие телефоны / маленькие планшеты */
@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .eco-mode .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Планшеты */
@media (min-width: 768px) {
  .player__inner {
    grid-template-columns: auto auto 1fr auto auto;
    grid-template-areas: "logo cover info play volume";
    gap: 16px;
    padding: 12px 20px;
  }
  .logo { display: flex; grid-area: logo; margin-right: 8px; }
  .volume { display: flex; grid-area: volume; }
  .nav { padding: 0 16px 10px; }
  .main { padding: 24px 20px 40px; }
  .view__title { font-size: 28px; }
  .toolbar { grid-template-columns: minmax(240px, 340px) 1fr; align-items: center; }
  .genres { flex-wrap: wrap; overflow: visible; }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
  .eco-mode .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card { padding: 14px; }
}

/* Компьютеры */
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .player__cover { width: 52px; height: 52px; }
  .btn-play { width: 60px; height: 60px; }
}

@media (min-width: 1200px) {
  .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* На сенсорных экранах нет «наведения» — не показываем оверлей постоянно */
@media (hover: none) {
  .card:hover { background: var(--surface); }
  .card:hover .card__overlay { opacity: 0; }
  .card.is-active .card__overlay { opacity: 1; }
}
