:root {
  --fg: #fff;
  --fg-dim: rgba(255, 255, 255, .72);
  --glass: rgba(18, 18, 18, .55);
  --glass-hi: rgba(255, 255, 255, .12);
  --accent: #1ed760;
  --card: #181818;
  --card-line: #2a2a2a;
  --fade: 600ms;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--fg); overflow: hidden; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
body.idle-ui { cursor: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* ---------- Art ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; background: #000; }
#backdrop {
  position: absolute; inset: -8%;
  background: center / cover no-repeat;
  filter: blur(48px) saturate(1.3) brightness(.55);
  opacity: 0; transition: opacity 1.5s ease;
}
body.fit #backdrop { opacity: 1; }
.layer {
  position: absolute; inset: 0;
  background: center / cover no-repeat;
  opacity: 0;
  will-change: transform, opacity;
  backface-visibility: hidden;
}
body.fit .layer { background-size: contain; }
/* Gentle darkening at top and bottom so text and controls stay readable */
#shade {
  position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0,0,0,.45), transparent 22%),
    linear-gradient(to top, rgba(0,0,0,.6), transparent 30%);
  opacity: 0; transition: opacity var(--fade) ease;
}
body.show-ui #shade, body.show-info #shade { opacity: 1; }

/* ---------- Fading UI ---------- */
.ui { transition: opacity var(--fade) ease, transform var(--fade) ease; }
body:not(.show-ui) #bar, body:not(.show-ui) #menu { opacity: 0; pointer-events: none; transform: translateY(8px); }

#info {
  position: fixed; left: max(20px, env(safe-area-inset-left)); top: max(16px, env(safe-area-inset-top));
  max-width: min(70vw, 720px);
  text-shadow: 0 1px 8px rgba(0,0,0,.7);
  opacity: 0; pointer-events: none;
}
body.show-info #info { opacity: 1; }
#title { font-weight: 650; font-size: clamp(15px, 1.6vw, 22px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#artist { color: var(--fg-dim); font-size: clamp(13px, 1.2vw, 17px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Control bar ---------- */
#bar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(960px, calc(100vw - 32px));
  padding: 10px 16px 12px;
  background: var(--glass);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--glass-hi);
  border-radius: 18px;
}
body:not(.show-ui) #bar { transform: translateX(-50%) translateY(8px); }

#progress { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
#progress span { min-width: 36px; text-align: center; }
#track { position: relative; flex: 1; height: 18px; cursor: pointer; }
#track::before { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.25); }
#fill { position: absolute; left: 0; top: 7px; height: 4px; border-radius: 2px; background: var(--fg); width: 0; }
#knob { position: absolute; top: 3px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: var(--fg); left: 0; opacity: 0; transition: opacity .15s; }
#track:hover #fill, body.seeking #fill { background: var(--accent); }
#track:hover #knob, body.seeking #knob { opacity: 1; }
body.no-control #track { cursor: default; }
body.no-control #track:hover #fill { background: var(--fg); }
body.no-control #track:hover #knob { opacity: 0; }

#buttons { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-top: 6px; gap: 8px; }
.group { display: flex; align-items: center; gap: 6px; }
.group.right { justify-content: flex-end; }
.icon { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; display: grid; place-items: center; cursor: pointer; padding: 0; }
.icon svg { width: 22px; height: 22px; fill: currentColor; }
.icon:hover { background: rgba(255,255,255,.1); }
.icon.big { width: 52px; height: 52px; background: var(--fg); color: #000; }
.icon.big svg { width: 28px; height: 28px; }
.icon.big:hover { background: #fff; transform: scale(1.05); }
.icon:disabled, .ctl.off { opacity: .35; cursor: not-allowed; }
.icon:focus-visible, .pill:focus-visible, .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pill { border: 1px solid var(--glass-hi); background: rgba(255,255,255,.06); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; min-width: 64px; }
.pill:hover { background: rgba(255,255,255,.14); }
body.show-info #bInfo { color: var(--accent); }

#vol { display: flex; align-items: center; gap: 6px; }
#vol svg { width: 20px; height: 20px; fill: var(--fg-dim); }
#volume { width: 110px; accent-color: var(--fg); cursor: pointer; }
#note { margin-top: 6px; font-size: 12px; color: var(--fg-dim); text-align: center; }

/* Narrow screens (phones): stack the side groups, keep the transport controls central */
@media (max-width: 640px) {
  #buttons { grid-template-columns: 1fr; }
  .group.left, .group.right { justify-content: center; }
  .group.mid { justify-content: center; order: -1; }
  #volume { width: 90px; }
}

/* ---------- Menu ---------- */
#menu {
  position: fixed; right: max(16px, calc(50vw - 480px)); bottom: 150px;
  min-width: 220px; padding: 6px;
  background: rgba(24,24,24,.92); border: 1px solid var(--glass-hi); border-radius: 12px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
#menuWho { padding: 8px 12px; font-size: 12px; color: var(--fg-dim); border-bottom: 1px solid var(--glass-hi); margin-bottom: 4px; }
.row { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.row:hover { background: rgba(255,255,255,.1); }

/* ---------- Idle ---------- */
#idle { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; }
.idle-box { text-align: center; padding: 24px 32px; background: rgba(0,0,0,.45); border-radius: 16px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.idle-title { font-size: 22px; font-weight: 650; }
.idle-sub { color: var(--fg-dim); margin-top: 4px; }

/* ---------- Setup ---------- */
#setup { position: fixed; inset: 0; overflow: auto; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(ellipse at top, #1d3b2a, #000 70%); user-select: text; -webkit-user-select: text; }
.card { width: min(640px, 100%); background: var(--card); border: 1px solid var(--card-line); border-radius: 16px; padding: 28px; }
.card h1 { margin: 0 0 6px; font-size: 24px; }
.card .lead { color: var(--fg-dim); margin-top: 0; }
.card ol { padding-left: 20px; }
.card li { margin: 8px 0; }
.card a { color: var(--accent); }
.copyrow, .inrow { display: flex; gap: 8px; margin-top: 6px; align-items: stretch; }
.copyrow code { flex: 1; min-width: 0; overflow-wrap: anywhere; background: #000; border: 1px solid var(--card-line); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.card button { border: 0; border-radius: 999px; padding: 8px 16px; font-weight: 600; cursor: pointer; background: var(--accent); color: #000; white-space: nowrap; }
.copyrow button { background: #333; color: #fff; }
.inrow input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--card-line); background: #000; color: #fff; font: 14px ui-monospace, Consolas, monospace; }
.small { font-size: 13px; color: var(--fg-dim); }
.err { color: #ff6b6b; }
@media (max-width: 520px) { .inrow { flex-direction: column; } .card { padding: 20px; } }

@media (prefers-reduced-motion: reduce) {
  .ui, #shade, #backdrop { transition: none; }
}
