:root {
  --bg: #f4efe8;
  --bg-2: #ebe3d8;
  --text: #1c140f;
  --muted: #6d6258;
  --card: rgba(255, 255, 255, 0.72);
  --card-solid: #fffdf9;
  --line: rgba(28, 20, 15, 0.1);
  --accent: #eb0000;
  --accent-2: #ff5a3c;
  --shadow: 0 24px 60px rgba(60, 24, 12, 0.12);
  --radius: 28px;
  --font: "Outfit", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html[data-theme="dark"] {
  --bg: #07080c;
  --bg-2: #10131b;
  --text: #f6f1ea;
  --muted: #b7aea4;
  --card: rgba(18, 20, 28, 0.62);
  --card-solid: #141821;
  --line: rgba(255, 255, 255, 0.1);
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
}

button, input { font-family: inherit; }

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(900px 520px at 15% 10%, color-mix(in srgb, var(--accent) 42%, transparent), transparent 60%),
    var(--art, none) center / cover no-repeat,
    var(--bg);
  filter: blur(42px) saturate(1.25);
  transform: scale(1.12);
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 600ms ease;
}

html[data-theme="light"] .ambient { opacity: 0.28; filter: blur(54px) saturate(1.05); }

.ambient__wash {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 30%, transparent), color-mix(in srgb, var(--bg) 78%, transparent) 42%, var(--bg));
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: calc(14px + var(--safe-t)) 12px calc(18px + var(--safe-b));
  min-height: 100dvh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-sizing: border-box;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 2px;
  width: 100%;
  min-width: 0;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }

.header__actions { display: flex; gap: 8px; flex: 0 0 auto; }

.brand__logo {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  cursor: pointer;
  background: var(--card-solid);
}

.brand__text { min-width: 0; overflow: hidden; }

.brand__title {
  font-family: var(--display);
  font-weight: 680;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand__sub {
  color: var(--muted);
  font-size: 0.86rem;
  min-height: 1.2em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 220ms ease, transform 220ms ease;
}
.brand__sub.is-out { opacity: 0; transform: translateY(-6px); }
.brand__sub.is-in { opacity: 0; transform: translateY(6px); }

.header-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--text) 8%, var(--card-solid));
  backdrop-filter: blur(16px);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  flex: 0 0 auto;
}
.header-icon::before {
  content: "";
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
#theme-btn { --icon: url("./assets/icons/sun.svg"); }
html[data-theme="dark"] #theme-btn { --icon: url("./assets/icons/moon.svg"); }
#header-wa { --icon: url("./assets/icons/whatsapp.svg"); color: #fff; }
.header-icon[hidden] { display: none; }

.channel-bar { display: none !important; }

.grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
}

.card {
  background: rgba(255, 255, 255, 0.78);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.2);
  -webkit-backdrop-filter: blur(22px) saturate(1.2);
}

.player {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 18px 16px 14px;
  position: relative;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}
.player > audio {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.player__art { width: min(100%, 300px); margin: 4px auto 0; }

.cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}

.cover-ring {
  position: absolute;
  inset: -10px;
  border-radius: 36px;
  background: conic-gradient(from 120deg, var(--accent), transparent 40%, var(--accent-2), transparent 75%, var(--accent));
  opacity: 0.35;
  filter: blur(8px);
  animation: spin 14s linear infinite;
}
html[data-live="1"] .cover-ring { opacity: 0.85; animation-duration: 6s; }

@keyframes spin { to { transform: rotate(1turn); } }

#cover {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 30px;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 18px 40px rgba(0,0,0,0.28);
  background: #111;
  display: block;
}

.cover-toggle {
  position: absolute;
  z-index: 2;
  inset: 0;
  border: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,0.45));
  border-radius: 30px;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 12px;
}
.cover-toggle__bubble {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(10,10,12,0.55);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.28);
  backdrop-filter: blur(8px);
}
.cover-toggle[data-state="play"] .cover-toggle__bubble {
  background: var(--accent);
  border-color: transparent;
}
.cover-toggle__icon {
  width: 20px;
  height: 20px;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.cover-toggle[data-state="play"] .cover-toggle__icon,
.cover-toggle:not([data-state="stop"]) .cover-toggle__icon { --icon: url("./assets/icons/play.svg"); }
.cover-toggle[data-state="stop"] .cover-toggle__icon { --icon: url("./assets/icons/stop.svg"); }
.cover-toggle__text { display: none; }

.eq {
  position: absolute;
  z-index: 3;
  left: 14px;
  bottom: 16px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 22px;
  opacity: 0;
  transition: opacity 200ms ease;
}
html[data-live="1"] .eq { opacity: 1; }
.eq span {
  width: 4px;
  height: 6px;
  border-radius: 99px;
  background: #fff;
  transform-origin: bottom;
}
html[data-live="1"] .eq span { animation: bar 0.9s ease-in-out infinite; }
.eq span:nth-child(2) { animation-delay: 0.12s; }
.eq span:nth-child(3) { animation-delay: 0.24s; }
.eq span:nth-child(4) { animation-delay: 0.05s; }
.eq span:nth-child(5) { animation-delay: 0.3s; }
@keyframes bar {
  0%, 100% { height: 5px; }
  50% { height: 20px; }
}

.cover-fade { display: none !important; }

.player__meta { padding: 16px 2px 0; min-width: 0; max-width: 100%; }

.nowplaying { text-align: center; }

.nowplaying__row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 680;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent);
}
html[data-live="1"] .live-dot { animation: pulse 1.6s ease-out infinite; }
@keyframes pulse {
  70% { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.nowplaying__artist {
  font-family: var(--display);
  font-size: clamp(1.7rem, 4.6vw, 2.7rem);
  font-weight: 680;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin-top: 8px;
  overflow-wrap: anywhere;
}

.nowplaying__title {
  margin-top: 6px;
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 520;
}

.controls {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card-solid) 80%, transparent);
  color: var(--text);
  border-radius: 999px;
  min-height: 48px;
  padding: 0 16px;
  font-weight: 680;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  flex: 0 0 auto;
  min-width: 112px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  border: 0;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 40%, transparent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.92rem;
}
.btn-primary[data-state="stop"] {
  background: color-mix(in srgb, var(--text) 88%, #000);
  box-shadow: none;
}

.vol {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 48px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card-solid) 55%, transparent);
}
.vol__mark {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  background: var(--text);
  opacity: 0.75;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M4 9v6h4l5 4V5L8 9H4zm11.5 3a4.5 4.5 0 0 0-2.5-4.03v8.06A4.5 4.5 0 0 0 15.5 12z'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M4 9v6h4l5 4V5L8 9H4zm11.5 3a4.5 4.5 0 0 0-2.5-4.03v8.06A4.5 4.5 0 0 0 15.5 12z'/></svg>") center / contain no-repeat;
}
#vol {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--text) 18%, transparent);
  outline: none;
}
#vol::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--card-solid);
  cursor: pointer;
}
#vol::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--card-solid);
  cursor: pointer;
}

.status {
  min-height: 1.2em;
  margin-top: 8px;
  text-align: center;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 520;
}
.status:empty { display: none; }

.channel-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  min-width: 0;
  max-width: 100%;
}
.channel-row::-webkit-scrollbar { display: none; }
.channel-row[style*="display: none"],
.channel-row[style*="display:none"] { display: none !important; }

.channel-tile,
.channel-chip {
  flex: 0 0 auto;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card-solid) 70%, transparent);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  font-size: 0.86rem;
  font-weight: 680;
}
.channel-tile:hover,
.channel-chip:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }

.recent {
  display: flex;
  flex-direction: column;
  min-height: 280px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
.card__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 16px 16px 10px;
}
.card__title-row { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card__title {
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}
.card__link {
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 50%, transparent);
}
.card__meta { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }

.recent__controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 0 16px 12px;
  min-width: 0;
}
#recent-search {
  width: 100%;
  min-width: 0;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  color: var(--text);
  padding: 0 12px;
  font-size: 1rem;
}
#refresh-btn { flex: 0 0 auto; }

.recent__list {
  overflow: auto;
  padding: 0 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 52vh;
  -webkit-overflow-scrolling: touch;
}

.row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 12px;
  align-items: center;
  padding: 8px;
  border-radius: 16px;
}
.row:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.row img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 12px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
}
.row__time {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 680;
  letter-spacing: 0.04em;
}
.row__artist { font-weight: 680; line-height: 1.2; }
.row__title { color: var(--muted); font-size: 0.92rem; line-height: 1.25; }
.empty { padding: 16px; color: var(--muted); }

.desktop-extra { overflow: hidden; min-height: 140px; }
.desktop-extra__inner,
.desktop-extra__link { width: 100%; height: 100%; min-height: 140px; }
.desktop-extra__img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  display: block;
}

.ad-slot:empty { display: none; }
.footer { padding: 4px 6px 8px; color: var(--muted); font-size: 0.82rem; }
.footer__about { margin: 0 0 6px; line-height: 1.45; }
.footer__about a { color: var(--text); }
.footer__hint { opacity: 0.8; }
.mono { font-family: ui-monospace, monospace; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .cover-ring, .eq span, .live-dot, .brand__sub { animation: none !important; transition: none !important; }
}

@media (min-width: 960px) {
  body { overflow: hidden; }
  .app {
    height: 100dvh;
    padding-top: calc(18px + var(--safe-t));
    padding-bottom: calc(12px + var(--safe-b));
  }
  .grid,
  .grid.grid--with-extra {
    flex: 1;
    display: grid !important;
    grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
    grid-template-areas:
      "player recent"
      "extra recent";
    grid-template-rows: minmax(0, 1fr) 190px;
    gap: 16px;
    min-height: 0;
    height: auto;
  }
  .player {
    grid-area: player;
    height: 100%;
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    align-items: center;
    gap: 28px;
    padding: 28px;
    text-align: left;
  }
  .player__art { width: 100%; margin: 0; }
  .player__meta { padding: 0; }
  .nowplaying, .status { text-align: left; }
  .nowplaying__row { justify-content: flex-start; }
  .nowplaying__artist { font-size: clamp(2rem, 3vw, 3rem); }
  .recent { grid-area: recent; height: 100%; min-height: 0; }
  .desktop-extra { grid-area: extra; display: block; }
  .desktop-extra__img { height: 100%; }
  .recent__list { max-height: none; flex: 1; min-height: 0; }
}

@media (max-width: 959px) {
  .player {
    position: sticky;
    top: 0;
    z-index: 4;
    padding-top: 12px;
    order: 1;
  }
  .recent { order: 2; }
  .desktop-extra { order: 3; }
  .player__art { width: min(42vw, 168px); }
  .nowplaying__artist { font-size: 1.45rem; }
  .desktop-extra__img { height: 150px; }
  .recent__list { max-height: none; }
  .card__header { flex-wrap: wrap; }
  .card__meta { margin-left: auto; }
  .recent__controls { align-items: center; }
  #recent-search { min-width: 0; width: 1%; }
}

@media (max-width: 420px) {
  .app { width: min(100% - 16px, 1180px); }
  .brand__title { font-size: 1.05rem; }
  .player__art { width: min(100%, 240px); }
  .controls { flex-wrap: wrap; }
  .btn-primary, .vol { width: 100%; }
}
