:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #14161f;
  --muted: #5d6377;
  --border: #e2e5ee;
  --accent: #e5484d;
  --accent-2: #ff7a59;
  --shadow: 0 1px 2px rgba(20, 22, 31, 0.06), 0 6px 18px rgba(20, 22, 31, 0.07);
  --radius: 14px;
  --player-h: 84px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #232736;
    --text: #eef0f6;
    --muted: #9aa1b5;
    --border: #2a2f3d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 22px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  padding-bottom: calc(var(--player-h) + 24px);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- горна лента ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.search { position: relative; flex: 1; max-width: 520px; margin-left: auto; }
.search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---------- навигация и филтри ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 24px; }

.tabs, .chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tabs { padding: 18px 0 10px; }

.tabs button, .chip, .ghost-btn, .more {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tabs button:hover, .chip:hover, .ghost-btn:hover, .more:hover { border-color: var(--muted); }
.tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.filters { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.chips { flex: 1; min-width: 0; }
.chip { padding: 6px 13px; font-size: 13px; font-weight: 500; color: var(--muted); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

select {
  flex: none;
  max-width: 220px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
}

.list-head { display: flex; align-items: baseline; gap: 12px; margin: 22px 0 14px; flex-wrap: wrap; }
.list-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.count { color: var(--muted); font-size: 14px; }
.ghost-btn { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; font-size: 13px; }

.status { text-align: center; color: var(--muted); padding: 32px 16px; }
.status.error { color: var(--accent); }

/* ---------- карти на станции ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card.is-current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.art {
  position: relative;
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 11px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--surface-2);
}
.art img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.art-fallback { font-weight: 800; font-size: 17px; color: var(--muted); display: grid; place-items: center; }

.eq {
  position: absolute;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  padding-bottom: 16px;
  background: rgba(0, 0, 0, 0.5);
}
.card.is-current .eq { display: flex; }
.eq i { width: 4px; height: 6px; border-radius: 2px; background: #fff; }
body[data-player-state="playing"] .card.is-current .eq i { animation: eq 0.9s ease-in-out infinite alternate; }
body[data-player-state="playing"] .card.is-current .eq i:nth-child(2) { animation-delay: -0.3s; }
body[data-player-state="playing"] .card.is-current .eq i:nth-child(3) { animation-delay: -0.6s; }
@keyframes eq { from { height: 4px; } to { height: 24px; } }

.meta { flex: 1; min-width: 0; }
.meta h3 { margin: 0 0 2px; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta p { margin: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; height: 20px; margin-top: 6px; overflow: hidden; }
.tags span { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

.fav, .icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 50%;
  transition: color 0.15s, background 0.15s, transform 0.1s;
}
.fav { align-self: flex-start; width: 34px; height: 34px; }
.fav:hover, .icon-btn:hover { background: var(--surface-2); color: var(--text); }
.fav:active, .icon-btn:active { transform: scale(0.9); }
.fav.on, .fav-btn.on { color: var(--accent); }
.fav.on svg, .fav-btn.on svg { fill: currentColor; }

.card.skeleton { cursor: default; pointer-events: none; }
.card.skeleton .art, .card.skeleton b {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.card.skeleton b { display: block; height: 12px; border-radius: 6px; margin: 6px 0; }
.card.skeleton b:last-child { width: 60%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.more { display: block; margin: 28px auto 0; padding: 10px 28px; }
.more:disabled { opacity: 0.5; cursor: wait; }

/* ---------- плейър ---------- */
.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  height: var(--player-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.08);
}

.np { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.np .art { width: 54px; height: 54px; }
.np-meta { min-width: 0; }
.np-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player[data-state="error"] .np-sub { color: var(--accent); }

.controls { display: flex; align-items: center; gap: 10px; }
.icon-btn { width: 40px; height: 40px; }

.play {
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 0.1s, opacity 0.15s;
}
.play:hover:not(:disabled) { transform: scale(1.05); }
.play:active:not(:disabled) { transform: scale(0.95); }
.play:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
.play svg { grid-area: 1 / 1; }
.play .i-stop, .play .i-spin { display: none; }
.player[data-state="playing"] .i-play, .player[data-state="loading"] .i-play { display: none; }
.player[data-state="playing"] .i-stop { display: block; }
.player[data-state="loading"] .i-spin { display: block; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.volume { display: flex; align-items: center; gap: 6px; flex: 1; max-width: 220px; justify-content: flex-end; }
.icon-btn .i-mute, .icon-btn.muted .i-vol { display: none; }
.icon-btn.muted .i-mute { display: block; }

input[type="range"] {
  --fill: 80%;
  flex: 1;
  max-width: 150px;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--border) var(--fill));
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}

/* ---------- инсталиране ---------- */
.install-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.install-dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 28px 24px 24px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.install-dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); }
.install-dialog h2 { margin: 12px 0 8px; font-size: 21px; }
.dialog-icon { border-radius: 16px; }
.dialog-close { position: absolute; top: 10px; right: 10px; margin: 0; }
.dialog-close button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 15px; }
.lead { color: var(--muted); margin: 0 0 16px; }
.steps { text-align: left; margin: 16px 0 0; padding-left: 22px; display: grid; gap: 10px; }
.steps li { padding-left: 4px; }
.inline-ico { vertical-align: -3px; color: #0a84ff; }
.note { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 14px; }
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 20px;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
#apkSize { font-weight: 400; opacity: 0.85; }
.link-btn { margin-top: 16px; border: 0; background: none; color: var(--muted); text-decoration: underline; font-size: 14px; }
.url-box { margin: 0 0 16px; padding: 12px; border-radius: 10px; background: var(--surface-2); font-weight: 700; word-break: break-all; user-select: all; }

/* ---------- iPhone: изрез и долна лента в режим „приложение“ ---------- */
.topbar { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
.player { height: calc(var(--player-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
body { padding-bottom: calc(var(--player-h) + env(safe-area-inset-bottom) + 24px); }

/* ---------- мобилни ---------- */
@media (max-width: 720px) {
  :root { --player-h: 76px; }
  .topbar { padding: max(10px, env(safe-area-inset-top)) 16px 10px; gap: 10px; }
  .install-btn { padding: 8px 10px; }
  .install-btn span { display: none; }
  .brand-name { display: none; }
  .wrap { padding: 0 16px; }
  .filters { flex-direction: column; align-items: stretch; }
  select { max-width: none; }
  .grid { grid-template-columns: 1fr; }
  .player { padding: 0 16px; gap: 12px; }
  .volume { display: none; }
  .list-head h1 { font-size: 20px; }
}

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