:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0d1017);
  --bg-soft: #111722;
  --surface: var(--tg-theme-secondary-bg-color, #171c26);
  --surface-2: #202736;
  --surface-3: #2a3345;
  --text: var(--tg-theme-text-color, #f4f6fb);
  --muted: var(--tg-theme-hint-color, #9ba6b8);
  --accent: var(--tg-theme-button-color, #42c7bd);
  --accent-strong: #2fb3aa;
  --accent-soft: rgba(66, 199, 189, 0.16);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --danger: #ff9d9d;
  --shadow: rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

html { overflow-x: hidden; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 92% -12%, rgba(75, 145, 255, 0.12), transparent 34%),
    radial-gradient(circle at -10% 42%, rgba(138, 75, 255, 0.08), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.solid { fill: currentColor; stroke: none; }
.icon-star { fill: transparent; }

.app-shell {
  width: min(760px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 18px 16px 150px;
}

.hero {
  position: relative;
  isolation: isolate;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(75, 145, 255, 0.26), rgba(138, 75, 255, 0.16)),
    var(--surface);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.24), inset 0 1px rgba(255, 255, 255, 0.03);
}
.hero::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 170px;
  height: 170px;
  right: -70px;
  top: -95px;
  border-radius: 50%;
  background: rgba(116, 151, 255, 0.14);
  filter: blur(2px);
}

.eyebrow { margin: 0 0 5px; color: #9ec3ff; font-size: 11px; font-weight: 800; letter-spacing: 0.15em; }
h1 { margin: 0; font-size: clamp(28px, 7vw, 42px); }
.subtitle { margin: 7px 0 0; color: var(--muted); }
.hero-icon {
  width: 54px;
  height: 54px;
  color: #dbe8ff;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, .35));
}

.filters, .content { min-width: 0; margin-top: 18px; }
.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.02);
}
input { min-width: 0; padding: 13px 14px; }
select { padding: 10px 12px; }
input::placeholder { color: var(--muted); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 0 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
}
.search-button:active { transform: translateY(1px); }
.search-button .icon { width: 18px; height: 18px; }

.select-row { margin-top: 12px; }
.select-row label {
  display: grid;
  grid-template-columns: auto minmax(140px, 220px);
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

.chips-shell {
  position: relative;
  min-width: 0;
  margin-top: 8px;
}
.chips {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 7px 4px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}
.chips::-webkit-scrollbar { height: 4px; }
.chips::-webkit-scrollbar-track { background: transparent; }
.chips::-webkit-scrollbar-thumb { border-radius: 999px; background: var(--accent); }
.chip {
  position: relative;
  z-index: 1;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  scroll-snap-align: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text);
  white-space: nowrap;
  user-select: none;
  transition: border-color .16s ease, background .16s ease, color .16s ease, transform .12s ease;
}
.chip:hover { border-color: var(--line-strong); background: var(--surface-2); }
.chip:active { transform: scale(.97); }
.chip .icon { width: 17px; height: 17px; }
.chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
}
.chip[data-view="favorites"].active .icon-star { fill: currentColor; }


.section-title { display: flex; justify-content: space-between; align-items: baseline; }
h2 { margin: 0 0 10px; font-size: 21px; }
#result-count, .status { color: var(--muted); font-size: 14px; }
.status { padding: 24px 4px; text-align: center; }
.status.error { color: var(--danger); }

.station-list { display: grid; gap: 10px; }
.station {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 6px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}
.station:hover { border-color: var(--line-strong); }
.station.playing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 10px 28px rgba(0, 0, 0, 0.12); }
.station-main {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
  border: 0;
  border-radius: 13px;
  padding: 5px;
  background: transparent;
  color: inherit;
  text-align: left;
}
.station-main:active { transform: scale(.99); }
.station-logo {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  object-fit: cover;
  background: var(--surface-2);
}
.station-copy { min-width: 0; }
.station-name { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 750; }
.station-meta { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-top: 5px; color: var(--muted); font-size: 12px; }
.play-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
}
.play-icon .icon { width: 18px; height: 18px; }
.station.playing .play-icon { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }

.favorite-button {
  align-self: center;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
}
.favorite-button:hover { border-color: var(--line-strong); color: var(--text); }
.favorite-button .icon { width: 22px; height: 22px; }
.favorite-button.active,
.favorite-player.active { color: #ffd45c; }
.favorite-button.active .icon-star,
.favorite-player.active .icon-star { fill: currentColor; }

.player {
  position: fixed;
  z-index: 10;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: block;
  width: min(736px, calc(100% - 24px));
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(19, 24, 34, .96);
  box-shadow: 0 18px 50px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(18px);
}
.player.hidden { display: none; }
.player-main {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 9px;
}
.player img { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; background: var(--surface-2); }
.player-copy { min-width: 0; }
.player-copy strong, .player-copy span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.player-copy span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.round-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
}
.round-button:active { transform: scale(.96); }
.round-button .icon { width: 19px; height: 19px; }
.round-button.secondary { border-color: var(--line); background: var(--surface-2); color: var(--text); }
.favorite-player { border-color: var(--line); background: var(--surface-2); color: var(--muted); }
.favorite-player .icon { width: 21px; height: 21px; }

.volume-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding: 0 4px 2px;
  color: var(--muted);
  font-size: 12px;
}
.volume-row > .icon { width: 20px; height: 20px; color: var(--accent); }
.volume-row input[type="range"] {
  width: 100%;
  height: 5px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  accent-color: var(--accent);
  background: var(--surface-2);
}
.volume-row output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

@media (max-width: 430px) {
  .app-shell { padding: 14px 10px 166px; }
  .hero { padding: 17px; }
  .hero-icon { width: 45px; height: 45px; }
  .search-button { padding: 0 14px; }
  .player-main { grid-template-columns: 42px minmax(0, 1fr) auto auto auto; gap: 6px; }
  .player-main img { width: 42px; height: 42px; }
  .player-main .round-button { width: 35px; height: 35px; }
  .favorite-button { width: 38px; height: 38px; }
}

@media (max-width: 350px) {
  .search-button span { display: none; }
  .search-button { width: 48px; padding: 0; }
  .select-row label { grid-template-columns: 1fr; gap: 6px; }
  .station-main { grid-template-columns: 46px minmax(0, 1fr) auto; gap: 8px; }
  .station-logo { width: 46px; height: 46px; }
}
