:root {
  --bg: #0a0a0a;
  --bg-card: #161616;
  --bg-card-hover: #1f1f1f;
  --red: #e0222b;
  --red-glow: #ff3b44;
  --white: #f5f5f5;
  --muted: #8a8a8a;
  --border: #2a2a2a;

  /* Нижний безопасный отступ: Telegram не отдаёт env(safe-area-inset-bottom)
     в своём WebView, но с Bot API 8.0 даёт собственные переменные. Берём максимум. */
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --tabbar-h: 54px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  /* внутри Telegram реальная видимая высота — только эта переменная,
     иначе низ приложения уезжает под системную панель */
  height: var(--tg-viewport-stable-height, 100dvh);
  background:
    radial-gradient(ellipse 500px 300px at 15% -5%, rgba(224,34,43,0.16), transparent 60%),
    radial-gradient(ellipse 400px 260px at 100% 10%, rgba(224,34,43,0.08), transparent 60%),
    var(--bg);
}

/* --- Иконка (наушники + мик) --- */
.hs-band { stroke: var(--white); stroke-width: 9; }
.hs-pad { fill: var(--red); }
.hs-mic-arc { stroke: var(--red-glow); stroke-width: 3.4; }

/* --- Векторные иконки (общий класс, цвет наследуется от родителя) --- */
.ic {
  display: block;
  width: 20px;
  height: 20px;
  color: inherit;
  flex-shrink: 0;
  pointer-events: none; /* клик всегда ловит кнопка, а не svg */
}
.ic-14 { width: 14px; height: 14px; }
.ic-16 { width: 16px; height: 16px; }
.ic-18 { width: 18px; height: 18px; }
.ic-20 { width: 20px; height: 20px; }
.ic-22 { width: 22px; height: 22px; }
.ic-26 { width: 26px; height: 26px; }
.ic-28 { width: 28px; height: 28px; }
.ic-accent { color: var(--red-glow); filter: drop-shadow(0 0 6px rgba(255,59,68,0.5)); }

/* Кнопки с иконкой — центрируем содержимое */
button { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }

/* --- Topbar --- */
.topbar {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 9px; }
.logo-icon {
  width: 26px; height: 26px;
  filter: drop-shadow(0 0 6px rgba(255,59,68,0.65));
}
.logo-text {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.3px;
  text-shadow: 0 0 12px rgba(224, 34, 43, 0.5);
}

/* --- Screens --- */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 30px;
  animation: screenIn 0.22s ease;
}
.screen.active { display: block; }
.screen.has-player { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 78px); }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 2px 12px;
}
.screen-title { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.back-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--white);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font-size: 16px;
}

/* --- Search --- */
.search-bar { margin-bottom: 10px; }
.search-bar input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--white);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.search-bar input:focus { border-color: var(--red); }
.search-bar input::placeholder { color: var(--muted); }

/* --- Lists --- */
.list { display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.list-item:active { background: var(--bg-card-hover); transform: scale(0.99); }

.list-item-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: radial-gradient(circle at 30% 30%, #2a0a0c, #120404);
  border: 1px solid var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--red-glow);
  flex-shrink: 0;
}

.list-item-body { flex: 1; min-width: 0; }
.list-item-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item-fav, .list-item-download {
  background: none;
  border: none;
  color: var(--muted);
  flex-shrink: 0;
  padding: 4px;
  transition: color 0.15s;
}
.list-item-download { overflow: visible; }
.list-item-download:disabled { opacity: 0.5; }
.list-item-fav.active { color: var(--red-glow); filter: drop-shadow(0 0 6px var(--red-glow)); }

.dl-bounce {
  color: var(--red-glow) !important;
  filter: drop-shadow(0 0 6px var(--red-glow));
  animation: dlArrowLoop 0.45s ease-in-out 2;
}
@keyframes dlArrowLoop {
  0%   { transform: translateY(-5px); opacity: 0.4; }
  60%  { transform: translateY(4px); opacity: 1; }
  100% { transform: translateY(-5px); opacity: 0.4; }
}

.list-item.playing {
  border-color: var(--red);
  background: linear-gradient(90deg, rgba(224,34,43,0.10), var(--bg-card) 60%);
  box-shadow: 0 0 0 1px var(--red), 0 0 16px rgba(224, 34, 43, 0.2);
}
.list-item.playing .list-item-icon {
  border-color: var(--red-glow);
  box-shadow: 0 0 10px rgba(255,59,68,0.5);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* --- Мини-эквалайзер (в списке / мини-плеере) --- */
.eq-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  flex-shrink: 0;
}
.eq-bars span {
  width: 3px;
  background: var(--red-glow);
  border-radius: 2px;
  height: 30%;
  animation: eqBounce 0.9s ease-in-out infinite;
  animation-play-state: paused;
  box-shadow: 0 0 4px var(--red-glow);
}
.eq-bars.playing span { animation-play-state: running; }
.eq-bars span:nth-child(1) { animation-delay: 0s; }
.eq-bars span:nth-child(2) { animation-delay: 0.15s; }
.eq-bars span:nth-child(3) { animation-delay: 0.3s; }
.eq-bars span:nth-child(4) { animation-delay: 0.45s; }
@keyframes eqBounce {
  0%, 100% { height: 25%; }
  50% { height: 100%; }
}

/* --- Мини-плеер (нижний бар) --- */
.player-bar {
  position: fixed;
  left: 8px; right: 8px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
  /* стеклянная полупрозрачная плашка */
  background: linear-gradient(135deg, rgba(48,26,28,0.28), rgba(16,13,13,0.22));
  -webkit-backdrop-filter: blur(26px) saturate(170%);
  backdrop-filter: blur(26px) saturate(170%);
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 18px;
  z-index: 10;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.07);
  cursor: pointer;
  transition: transform 0.15s;
}
/* если backdrop-filter не поддерживается — не оставляем «дырявый» фон */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .player-bar { background: linear-gradient(135deg, #1a1414, #0f0d0d); }
}
.player-bar:active { transform: scale(0.99); }
.player-bar.hidden { display: none; }

.player-bar-progress { height: 2px; background: rgba(255,255,255,0.12); }
.player-bar-progress-fill { height: 100%; width: 0%; background: var(--red); box-shadow: 0 0 6px var(--red-glow); transition: width 0.2s linear; }

.player-bar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
}

.mini-art {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: radial-gradient(circle at 30% 30%, rgba(60,12,16,0.75), rgba(18,4,4,0.7));
  border: 1px solid rgba(224,34,43,0.65);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.mini-art-img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: inherit;
  -webkit-mask-image: radial-gradient(circle closest-side, #000 68%, rgba(0,0,0,0.5) 88%, transparent 100%);
  mask-image: radial-gradient(circle closest-side, #000 68%, rgba(0,0,0,0.5) 88%, transparent 100%);
}

.player-info { flex: 1; min-width: 0; }
.player-surah { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-reciter { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mini-playpause {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--red-glow), var(--red));
  border: none;
  color: var(--white);
  box-shadow: 0 0 14px rgba(224,34,43,0.55);
  flex-shrink: 0;
  padding: 0;
}
/* у «play» визуальный центр смещён влево — компенсируем */
.mini-playpause .ic[data-icon="play"] { transform: translateX(1px); }

/* --- Полноэкранный "Сейчас играет" --- */
.now-playing {
  position: fixed;
  inset: 0;
  /* полупрозрачное «стекло» поверх приложения */
  background:
    radial-gradient(ellipse 700px 500px at 50% 0%, rgba(224,34,43,0.20), transparent 55%),
    rgba(10,8,8,0.72);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  backdrop-filter: blur(28px) saturate(140%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 10px 20px calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}
.now-playing.open { transform: translateY(0); }
.now-playing.hidden { display: none; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .now-playing { background: radial-gradient(ellipse 700px 500px at 50% 0%, rgba(224,34,43,0.18), transparent 55%), #0a0808; }
}

.np-glow {
  position: absolute;
  top: -80px; left: 50%;
  transform: translateX(-50%);
  width: 320px; height: 320px;
  background: radial-gradient(circle, rgba(224,34,43,0.35), transparent 70%);
  filter: blur(10px);
  pointer-events: none;
}

.np-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 4px;
  position: relative;
  z-index: 1;
}
.np-collapse-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--white);
  font-size: 20px;
  line-height: 1;
}
.np-header-title {
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--muted);
  font-weight: 600;
}

.np-art-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  min-height: 0;
}
.np-art {
  width: min(62vw, 260px);
  height: min(62vw, 260px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #241010, #0c0505 70%);
  border: 1px solid rgba(224,34,43,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 0 50px rgba(224,34,43,0.25), inset 0 0 30px rgba(0,0,0,0.6);
}
/* Круговой эквалайзер внутри обложки */
.np-viz {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  pointer-events: none;
}
/* Обложка канала по центру круга. Не вращается — стоит статично.
   Края растворяются в фоне маской, чтобы не было резкого обреза. */
.np-art-img {
  position: relative;
  z-index: 1;
  width: 62%;
  height: 62%;
  border-radius: 50%;
  object-fit: cover;
  animation: none;
  -webkit-mask-image: radial-gradient(circle closest-side, #000 55%, rgba(0,0,0,0.75) 76%, rgba(0,0,0,0.25) 91%, transparent 100%);
  mask-image: radial-gradient(circle closest-side, #000 55%, rgba(0,0,0,0.75) 76%, rgba(0,0,0,0.25) 91%, transparent 100%);
}
.np-art-ring {
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1.5px solid var(--red-glow);
  opacity: 0.55;
  animation: ringPulse 2.4s ease-in-out infinite;
}
@keyframes ringPulse {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.06); opacity: 0.15; }
}

.np-meta { text-align: center; padding: 18px 0 8px; position: relative; z-index: 1; }
.np-surah { font-size: 19px; font-weight: 700; text-shadow: 0 0 16px rgba(224,34,43,0.35); }
.np-reciter { font-size: 13px; color: var(--muted); margin-top: 4px; }

.np-progress { padding: 10px 2px 4px; position: relative; z-index: 1; }
.np-progress input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
}
.np-progress input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
}
.np-times { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

.np-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 14px 0 2px;
  position: relative;
  z-index: 1;
}
.np-controls-side {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 34px;
  padding: 4px 0 6px;
  position: relative;
  z-index: 1;
}
.np-side-btn {
  background: none; border: none;
  color: var(--muted);
  padding: 6px;
  transition: color 0.15s;
}
.np-side-btn:disabled { opacity: 0.5; }
.np-side-btn.active { color: var(--red-glow); filter: drop-shadow(0 0 8px var(--red-glow)); }
.np-main-btn {
  background: none; border: none;
  color: var(--white);
  padding: 6px;
}
.np-main-btn:active { opacity: 0.6; }
.np-play-btn {
  width: 62px; height: 62px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--red-glow), var(--red));
  border: none;
  color: var(--white);
  padding: 0;
  box-shadow: 0 0 26px rgba(224,34,43,0.55);
}
.np-play-btn .ic[data-icon="play"] { transform: translateX(2px); }

/* --- Tabbar --- */
.tabbar {
  display: flex;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(13,13,13,0.72);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  flex-shrink: 0;
  padding-bottom: var(--safe-bottom);
  position: relative;
  z-index: 5;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px 0 10px;
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.15s;
}
.tab-btn .tab-icon { color: inherit; }
.tab-btn.active { color: var(--red-glow); }
.tab-btn.active .tab-icon { filter: drop-shadow(0 0 7px rgba(255,59,68,0.6)); }
