/* Pure black base: pixels are off on the OLED panel. */
:root {
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.62);
  --faint: rgba(255, 255, 255, 0.18);
  --accent: #1ed760;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Views set display:flex/grid, which would override the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: #000;
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  /* Disable the browser's double-tap zoom so our double tap (mode cycle) works. */
  touch-action: manipulation;
}

/* Hide the pointer after a few idle seconds (desktop, TV remotes). */
body.cursor-idle, body.cursor-idle * { cursor: none !important; }

/* ---------- background modes (cycled by double tap) ---------- */
#backdrop {
  position: fixed;
  inset: -10%;
  background-size: cover;
  background-position: center;
  filter: blur(60px) saturate(1.4) brightness(0.45);
  opacity: 0;
  transition: opacity 0.8s ease;
  z-index: 0;
  pointer-events: none;
}
/* Only the blur mode shows the album-art backdrop. */
body:not(.mode-blur) #backdrop { display: none; }
#backdrop.on { opacity: 1; }

body.mode-grey { --accent: rgba(255, 255, 255, 0.85); }
body.mode-grey #art { filter: grayscale(1); }

/* ---------- setup / login panels ---------- */
.panel {
  position: relative;
  z-index: 1;
  max-width: 420px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 24px 16px;
}
.panel h1 { font-size: 28px; font-weight: 700; }
.panel p { color: var(--muted); line-height: 1.45; }
.panel .hint { font-size: 14px; }
.panel code {
  color: var(--fg);
  word-break: break-all;
  user-select: all;
}
.panel input {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--faint);
  background: #111;
  color: var(--fg);
  font: inherit;
}
.panel button {
  padding: 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #000;
  font: inherit;
  font-weight: 700;
}
.panel button.link {
  background: none;
  color: var(--muted);
  font-weight: 400;
}

/* ---------- player ---------- */
#player {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.art-wrap {
  position: relative;
  width: min(84vw, 52vh);
  aspect-ratio: 1;
  flex-shrink: 0;
}
#art, #art-empty {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 14px;
}
#art {
  object-fit: cover;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.5s ease;
}
#art.on { opacity: 1; }
#art-empty {
  display: grid;
  place-items: center;
  font-size: 96px;
  color: var(--faint);
  background: #0a0a0a;
}

.meta {
  width: min(84vw, 520px);
  text-align: center;
}
.status {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  min-height: 1.2em;
  margin-bottom: 8px;
}
.status.paused { color: var(--muted); }
#title {
  font-size: clamp(22px, 6vw, 34px);
  font-weight: 700;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#artist {
  margin-top: 6px;
  font-size: clamp(16px, 4.4vw, 20px);
  font-weight: 500;
  color: var(--muted);
}
#album {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  opacity: 0.8;
}
#artist, #album {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress { margin-top: 24px; }
.bar {
  height: 4px;
  border-radius: 2px;
  background: var(--faint);
  overflow: hidden;
}
#bar-fill {
  height: 100%;
  width: 0;
  background: var(--fg);
  border-radius: 2px;
}
.times {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.device {
  margin-top: 18px;
  font-size: 13px;
  color: var(--accent);
  min-height: 1.2em;
}

/* ---------- lyrics view (long press) ---------- */
.lyrics {
  position: relative;   /* so line offsetTop is measured from the panel */
  margin-top: 16px;
  height: 38vh;
  overflow-y: auto;
  scrollbar-width: none;
  /* Fade lines out towards the top and bottom edges. */
  -webkit-mask-image: linear-gradient(transparent, #000 22%, #000 78%, transparent);
  mask-image: linear-gradient(transparent, #000 22%, #000 78%, transparent);
  padding: 16vh 0;
}
.lyrics::-webkit-scrollbar { display: none; }
.lyric, .lyrics-msg {
  font-size: clamp(18px, 4.6vw, 26px);
  font-weight: 700;
  line-height: 1.35;
  padding: 6px 0;
  color: var(--faint);
  transition: color 0.3s ease, transform 0.3s ease;
  transform-origin: left center;
}
.lyric.active { color: var(--fg); }
.lyric.plain { color: var(--muted); font-weight: 500; font-size: 18px; }
.lyrics-msg { color: var(--muted); font-weight: 500; }

/* In lyrics view, compact the header and drop album/progress/device. */
body.lyrics-on #status,
body.lyrics-on #album,
body.lyrics-on .progress,
body.lyrics-on #device { display: none; }
body.lyrics-on #title { font-size: clamp(18px, 4.4vw, 24px); -webkit-line-clamp: 1; }
body.lyrics-on #artist { font-size: 15px; margin-top: 2px; }
body.lyrics-on .art-wrap { width: min(44vw, 30vh); }
body.lyrics-on #player { gap: 20px; }

/* Landscape: art left, text right */
@media (orientation: landscape) {
  #player { flex-direction: row; gap: 48px; }
  .art-wrap { width: min(70vh, 44vw); }
  .meta { text-align: left; width: min(44vw, 520px); }
  .lyrics { height: 62vh; padding: 26vh 0; }
  body.lyrics-on .art-wrap { width: min(60vh, 34vw); }
  body.lyrics-on .meta { width: min(52vw, 640px); }
}
@media (orientation: portrait) {
  .lyric, .lyrics-msg { transform-origin: center; }
}

/* Big screens (TV, desktop): scale everything with the viewport instead of
   the phone-sized pixel caps above. Phones in landscape (~750x360) stay as is. */
@media (orientation: landscape) and (min-width: 1000px) and (min-height: 560px) {
  #player { gap: 6vw; padding: 5vh 6vw; }
  .art-wrap { width: min(70vh, 42vw); }
  .meta { width: 46vw; }
  #art, #art-empty { border-radius: 1.6vh; }

  .status { font-size: 1.7vh; margin-bottom: 1.4vh; }
  #title { font-size: 6vh; }
  #artist { font-size: 3.4vh; margin-top: 1vh; }
  #album { font-size: 2.4vh; margin-top: 0.6vh; }
  .progress { margin-top: 4.5vh; }
  .bar { height: 0.5vh; border-radius: 0.25vh; }
  .times { font-size: 1.9vh; margin-top: 1.2vh; }
  .device { font-size: 2vh; margin-top: 3vh; }

  .lyrics { height: 68vh; padding: 30vh 0; margin-top: 2.5vh; }
  .lyric, .lyrics-msg { font-size: 4.8vh; line-height: 1.3; padding: 1vh 0; }
  .lyric.plain { font-size: 3vh; }

  body.lyrics-on #player { gap: 5vw; }
  body.lyrics-on .art-wrap { width: min(56vh, 30vw); }
  body.lyrics-on .meta { width: 56vw; }
  body.lyrics-on #title { font-size: 4vh; }
  body.lyrics-on #artist { font-size: 2.6vh; margin-top: 0.4vh; }

  #toast { font-size: 2vh; padding: 1.2vh 2.4vh; bottom: 4vh; }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 2;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: #222;
  color: var(--fg);
  font-size: 14px;
}
