:root {
  --bg: #0d0f14;
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.62);
  --faint: rgba(255, 255, 255, 0.12);
  --accent: #dba960;
  --live: #e2453c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

#backdrop {
  position: fixed;
  inset: -60px;
  background: var(--bg) center / cover no-repeat;
  filter: blur(48px) saturate(1.3) brightness(0.45);
  transform: scale(1.1);
  transition: background-image 1s ease;
  z-index: 0;
}
#backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(13, 15, 20, 0.2), rgba(13, 15, 20, 0.85));
}

#player {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
}

header.top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--muted);
}
header.top h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg);
}

.status { display: flex; align-items: center; gap: 10px; }

#live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--faint);
  color: var(--muted);
}
#live .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
#live.on { background: var(--live); color: #fff; }
#player[data-state="playing"] #live.on .dot { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* ---- cover ---- */
.stage {
  position: relative;
  width: min(78vw, 340px);
  aspect-ratio: 1;
  margin: 36px 0 28px;
}
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 22%;
  background: var(--faint);
}
/* Cover is a squircle (most art is square).
   COVER_RADIUS in player.js must match this border-radius. */
#cover {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 22%;
  object-fit: cover;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
#cover.show { opacity: 1; transform: scale(1); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- title ---- */
.now { text-align: center; width: 100%; min-height: 64px; }
#song {
  margin: 0;
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
#artist {
  margin: 6px 0 0;
  font-size: 17px;
  color: var(--accent);
  overflow-wrap: anywhere;
}

/* ---- visualizer ---- */
.stage, .viz-wrap { cursor: pointer; -webkit-tap-highlight-color: transparent; }
/* Ring visualizer canvas: extends 12% past the cover on every side
   (RING_SCALE in player.js must match: 1 + 2 * 0.12). */
#ring {
  position: absolute;
  inset: -12%;
  width: 124%;
  height: 124%;
  z-index: 1;
}
.viz-wrap {
  position: relative;
  width: 100%;
  margin: 18px 0 10px;
}
#viz {
  width: 100%;
  height: 90px;
  display: block;
}
#vizlabel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
  opacity: 0;
}
#vizlabel.show { animation: vizlabel 1.4s ease forwards; }
@keyframes vizlabel {
  0% { opacity: 0; }
  12%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- controls ---- */
.controls {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 18px;
}

#play {
  flex: none;
  width: 72px; height: 72px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #1a1408;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(219, 169, 96, 0.35);
  transition: transform 0.15s ease, filter 0.15s ease;
}
#play:hover { filter: brightness(1.08); }
#play:active { transform: scale(0.95); }
#play:focus-visible, #mute:focus-visible, #volume:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}
#play svg { width: 30px; height: 30px; fill: currentColor; }
#play .i-pause, #play .i-load { display: none; }
#player[data-state="playing"] #play .i-play { display: none; }
#player[data-state="playing"] #play .i-pause { display: block; }
#player[data-state="loading"] #play .i-play { display: none; }
#player[data-state="loading"] #play .i-load { display: block; animation: spin 0.9s linear infinite; }

.vol {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
#mute {
  flex: none;
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
#mute:hover { color: var(--fg); background: var(--faint); }
#mute svg { width: 22px; height: 22px; fill: currentColor; }
#mute .i-muted { display: none; }
#player[data-muted="1"] #mute .i-vol { display: none; }
#player[data-muted="1"] #mute .i-muted { display: block; }

#volume {
  --fill: 10%;
  flex: 1;
  min-width: 0;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
#volume::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--fg) var(--fill), var(--faint) var(--fill));
}
#volume::-moz-range-track { height: 4px; border-radius: 2px; background: var(--faint); }
#volume::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--fg); }
#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--fg);
  border: 0;
}
#volume::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--fg); border: 0; }
#player[data-muted="1"] #volume { opacity: 0.5; }

/* ---- equaliser ---- */
#eqbtn {
  flex: none;
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}
#eqbtn:hover, #eqbtn[aria-expanded="true"] { color: var(--fg); background: var(--faint); }
#eqbtn svg { width: 22px; height: 22px; fill: currentColor; }
#eqbtn:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }

#eq {
  width: 100%;
  margin-top: 16px;
  padding: 10px 16px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--faint);
}
#eq[hidden] { display: none; }
.eq-row {
  display: grid;
  grid-template-columns: 56px 1fr 52px;
  align-items: center;
  gap: 12px;
}
.eq-row label { font-size: 14px; color: var(--muted); }
.eq-row output {
  font-size: 13px;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
/* Fill runs from the centre (0 dB) to the thumb. */
.eq-row input {
  --lo: 50%; --hi: 50%;
  width: 100%;
  min-width: 0;
  height: 32px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.eq-row input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--faint) var(--lo), var(--accent) var(--lo), var(--accent) var(--hi), var(--faint) var(--hi));
}
.eq-row input::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--faint) var(--lo), var(--accent) var(--lo), var(--accent) var(--hi), var(--faint) var(--hi));
}
.eq-row input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--fg);
  border: 0;
}
.eq-row input::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--fg); border: 0; }
.eq-row input:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
.eq-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 6px;
}
.eq-note { display: none; flex: 1; font-size: 12px; color: var(--muted); }
#eqreset {
  border: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--faint);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
#eqreset:hover { background: rgba(255, 255, 255, 0.2); }
#eqreset:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
#player[data-eq="off"] .eq-row, #player[data-eq="off"] #eqreset { opacity: 0.4; pointer-events: none; }
#player[data-eq="off"] .eq-note { display: block; }

/* ---- recent ---- */
.recent {
  width: 100%;
  margin-top: 36px;
}
.recent h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
#recent { list-style: none; margin: 0; padding: 0; }
#recent li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--faint);
}
#recent img {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--faint);
}
.r-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.r-song, .r-artist { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-song { font-size: 15px; }
.r-artist { font-size: 13px; color: var(--muted); }
#recent time { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- toasts: install prompt (bottom) and update prompt (top) ---- */
.toast {
  position: fixed;
  left: 50%;
  z-index: 10;
  width: min(528px, calc(100% - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px 12px 12px;
  border-radius: 16px;
  background: rgba(24, 27, 35, 0.92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--faint);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
#install.show, #update.show { transform: translate(-50%, 0); opacity: 1; }
#install {
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translate(-50%, calc(100% + 40px));
}
#update {
  top: max(16px, env(safe-area-inset-top));
  z-index: 11;
  padding-left: 16px;
  transform: translate(-50%, calc(-100% - 40px));
}
#install img { flex: none; width: 44px; height: 44px; border-radius: 10px; }
.in-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.in-text strong { font-size: 15px; }
.in-text span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.in-text b { color: var(--fg); font-weight: 600; }
.in-text svg { width: 16px; height: 16px; fill: var(--accent); vertical-align: -3px; }
.toast button { border: 0; cursor: pointer; font: inherit; }
.in-go {
  flex: none;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1408;
  font-weight: 700 !important;
  font-size: 14px !important;
}
.in-go:hover { filter: brightness(1.08); }
.in-x {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px !important;
  line-height: 1;
}
.in-x:hover { color: var(--fg); background: var(--faint); }
.toast button:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  #player[data-state="playing"] #live.on .dot { animation: none; }
  .toast { transition: opacity 0.2s ease; }
}

@media (min-height: 900px) {
  .stage { margin-top: 56px; }
}
