/* ==========================================================================
   styles.css — основные стили для радио-приложения
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light dark; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur-base) var(--ease), color var(--dur-base) var(--ease);
}

h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   ПЕРЕКЛЮЧАТЕЛЬ ТЕМЫ
   ========================================================================== */
.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  background: var(--bg-surface);
  border: var(--border-w) solid var(--border-default);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-base) var(--ease), background-color var(--dur-base) var(--ease);
}
.theme-toggle:hover { border-color: var(--border-strong); }
.theme-toggle__track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--gray-200);
  border-radius: 999px;
  transition: background-color var(--dur-base) var(--ease);
}
[data-theme="dark"] .theme-toggle__track { background: var(--gray-700); }
.theme-toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--pure-black);
  transition: transform var(--dur-base) var(--ease), background-color var(--dur-base) var(--ease);
}
[data-theme="dark"] .theme-toggle__thumb {
  transform: translateX(16px);
  background: var(--pure-white);
}
.theme-toggle__label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: left;
}

/* ==========================================================================
   СТРАНИЦА / BENTO-СЕТКА
   ========================================================================== */
.page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 88px 24px 48px;
}
.bento {
  width: 100%;
  max-width: var(--container-max);
  display: grid;
  grid-template-columns: 1.1fr 1.5fr 0.9fr;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "brand now stats"
    "brand now stats"
    "history history history";
  gap: var(--gap);
}
.tile {
  background: var(--bg-surface);
  border: var(--border-w) solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-base) var(--ease), background-color var(--dur-base) var(--ease), box-shadow var(--dur-base) var(--ease);
}

/* ==========================================================================
   ПЛИТКА БРЕНДА
   ========================================================================== */
.tile--brand {
  grid-area: brand;
  padding: 34px 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--bg-inverse);
  color: var(--text-on-inverse);
  border-color: var(--bg-inverse);
}
.brand-mark {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--border-w) solid var(--text-on-inverse);
  border-radius: var(--radius-sm);
  color: var(--text-on-inverse);
}
.brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.brand-tagline {
  font-size: var(--fs-md);
  color: color-mix(in srgb, var(--text-on-inverse) 70%, transparent);
  line-height: 1.45;
}
.feature-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  border-top: var(--border-w) solid color-mix(in srgb, var(--text-on-inverse) 20%, transparent);
}
.feature-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-sm);
  color: color-mix(in srgb, var(--text-on-inverse) 85%, transparent);
}
.feature-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* ==========================================================================
   ПЛИТКА ТЕКУЩЕГО ТРЕКА + ПЛЕЕР
   ========================================================================== */
.tile--now-playing {
  grid-area: now;
  padding: 24px 28px;
  display: flex;
  align-items: center;
}
.now-playing__inner {
  display: flex;
  gap: 28px;
  width: 100%;
  align-items: center;
}
.now-playing__art {
  flex-shrink: 0;
  width: 130px;
  height: 130px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--gray-200);
}
.now-playing__art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.now-playing__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.now-playing__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.track-label {
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}
.track-artist {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
}
.track-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-primary);
}
.track-album {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.track-progress {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border-default);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: var(--accent-bg);
  width: 0%;
  transition: width 0.2s linear;
}
.progress-time {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--text-tertiary);
}

/* Аудиоплеер */
.audio-player {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}
.play-btn {
  background: var(--accent-bg);
  color: var(--accent-text);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), transform 0.2s;
}
.play-btn:hover {
  background: var(--accent-bg-hover);
  transform: scale(1.05);
}
.play-btn:active {
  transform: scale(0.95);
}
#audio-element {
  display: none;
}

/* ==========================================================================
   ПЛИТКА СТАТИСТИКИ
   ========================================================================== */
.tile--stats {
  grid-area: stats;
  padding: 24px 26px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  justify-content: center;
}
.stats-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stats-label {
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
}
.stats-value {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
}
.stats-next {
  font-weight: 400;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

/* ==========================================================================
   ПЛИТКА ИСТОРИИ
   ========================================================================== */
.tile--history {
  grid-area: history;
  padding: 24px 28px;
}
.history-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.history-item:last-child { border-bottom: none; }
.history-item .history-art {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--gray-200);
  flex-shrink: 0;
}
.history-item .history-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.history-item .history-artist {
  font-weight: 500;
  color: var(--text-primary);
}
.history-item .history-title {
  font-weight: 400;
  color: var(--text-secondary);
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

/* ==========================================================================
   СКЕЛЕТОНЫ (шиммеры) — только при первой загрузке
   ========================================================================== */
.skeleton {
  background: var(--skeleton-bg);
  border-radius: 4px;
  background-image: linear-gradient(
    90deg,
    var(--skeleton-bg) 25%,
    var(--skeleton-shimmer) 50%,
    var(--skeleton-bg) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton--art {
  width: 130px;
  height: 130px;
  border-radius: var(--radius-sm);
}
.skeleton--text {
  height: 1.2em;
  width: 80%;
  margin: 4px 0;
}
.skeleton--text:nth-child(2) { width: 60%; }
.skeleton--progress {
  height: 4px;
  width: 100%;
  margin-top: 8px;
}
.skeleton--stats {
  height: 60px;
  width: 100%;
  margin-top: 8px;
}
.skeleton--history-item {
  height: 32px;
  width: 100%;
  border-radius: 4px;
  margin: 4px 0;
}

/* Скрываем реальный контент, пока грузится впервые */
[data-loaded="false"] .now-playing__info > *:not(.skeleton),
[data-loaded="false"] .now-playing__art img,
[data-loaded="false"] .stats-item,
[data-loaded="false"] .history-list .history-item:not(.skeleton) {
  display: none;
}
[data-loaded="false"] .skeleton { display: block; }
[data-loaded="true"] .skeleton { display: none; }

/* ==========================================================================
   ОШИБКА ЗАГРУЗКИ
   ========================================================================== */
.error-message {
  grid-column: 1 / -1;
  padding: 40px 20px;
  text-align: center;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
}
.error-message .error-icon {
  font-size: 2rem;
  color: var(--text-tertiary);
  margin-bottom: 12px;
}
.error-message .error-text {
  font-size: var(--fs-md);
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.error-message .btn-retry {
  background: var(--accent-bg);
  color: var(--accent-text);
  border: none;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.error-message .btn-retry:hover {
  background: var(--accent-bg-hover);
}

/* ==========================================================================
   АДАПТИВНОСТЬ
   ========================================================================== */
@media (max-width: 980px) {
  .bento {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "brand brand"
      "now stats"
      "history history";
  }
  .tile--brand { padding: 30px 24px; }
  .now-playing__art { width: 100px; height: 100px; }
}

@media (max-width: 620px) {
  .page { padding: 80px 12px 24px; }
  .bento {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "now"
      "stats"
      "history";
    gap: 14px;
  }
  .tile--brand { padding: 24px 18px; }
  .tile--now-playing { padding: 18px; }
  .now-playing__inner { flex-direction: column; align-items: flex-start; gap: 16px; }
  .now-playing__art { width: 100%; height: auto; aspect-ratio: 1/1; max-width: 200px; align-self: center; }
  .tile--stats { padding: 20px; }
  .tile--history { padding: 18px; }
  .theme-toggle { top: 12px; right: 12px; }
  .theme-toggle__label { display: none; }
  .theme-toggle { padding: 6px; }
}