:root {
  --scale: 1;
  --b: min(1vw, 1.7778vh);              /* base unit: 1% of a 16:9 screen width */
  --u: calc(var(--b) * var(--scale));   /* player unit */
  --px: 50;
  --py: 47;
  --fg: 18, 20, 24;
  --accent: 52, 84, 128;
  --glass: 255, 255, 255;
  --glass-a: .44;
  --edge-a: .6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #e9e7e3;
  user-select: none;
  cursor: default;
}

body {
  font-family: "Segoe UI Variable Display", "Segoe UI", "Pretendard", "Apple SD Gothic Neo",
               "Malgun Gothic", "Yu Gothic UI", "Microsoft YaHei UI", sans-serif;
  color: rgb(var(--fg));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#bg, #dust {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#dust { pointer-events: none; transition: opacity 1s; }
body.no-dust #dust { opacity: 0; }

#stage { position: fixed; inset: 0; pointer-events: none; }

/* ───────── Player ───────── */
.rig {
  position: absolute;
  left: calc(var(--px) * 1%);
  top: calc(var(--py) * 1%);
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: calc(1.7 * var(--u));
}
.player {
  position: relative;
  /* 25.8u = cover + vinyl + paddings; the info column grows with the title. */
  width: calc((25.8 + var(--info-w, 16.2)) * var(--u));
  height: calc(14 * var(--u));
  transition: opacity .9s ease, width .7s cubic-bezier(.2, .8, .2, 1);
}
body.hide-idle .player.is-idle { opacity: 0; }

.ambient {
  position: absolute;
  inset: calc(-1.5 * var(--u));
  border-radius: calc(4 * var(--u));
  background-size: cover;
  background-position: center;
  filter: blur(calc(3.2 * var(--u))) saturate(1.7);
  opacity: 0;
  transition: opacity 1.4s ease, background-image 1.4s ease;
}
.player.has-art .ambient { opacity: .42; }

.glass {
  position: absolute;
  inset: 0;
  border-radius: calc(1.7 * var(--u));
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 45%),
    rgba(var(--glass), var(--glass-a));
  -webkit-backdrop-filter: blur(calc(2.2 * var(--u))) saturate(1.5);
  backdrop-filter: blur(calc(2.2 * var(--u))) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, var(--edge-a));
  box-shadow:
    0 calc(1.8 * var(--u)) calc(4.5 * var(--u)) rgba(0, 0, 0, .2),
    0 calc(.3 * var(--u)) calc(.9 * var(--u)) rgba(0, 0, 0, .1),
    inset 0 1px 0 rgba(255, 255, 255, .35);
  transition: background-color 1.2s ease, border-color 1.2s ease;
}
body.no-blur .glass {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  background: rgba(var(--glass), calc(var(--glass-a) + .34));
}

/* ───────── Cover ───────── */
.cover {
  position: absolute;
  left: calc(1.2 * var(--u));
  top: 50%;
  width: calc(15.5 * var(--u));
  height: calc(15.5 * var(--u));
  transform: translateY(-50%);
  border-radius: calc(1.15 * var(--u));
  overflow: hidden;
  z-index: 3;
  background: linear-gradient(145deg, #3a3f4b, #16181d);
  box-shadow:
    0 calc(1.4 * var(--u)) calc(3.2 * var(--u)) rgba(0, 0, 0, .38),
    0 calc(.25 * var(--u)) calc(.7 * var(--u)) rgba(0, 0, 0, .22);
}
.cover-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, .5);
}
.cover-empty svg { width: 34%; height: 34%; }
.cover-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.06);
  transition: opacity .9s ease, transform 1.4s cubic-bezier(.2, .8, .2, 1);
}
.cover-img.show { opacity: 1; transform: scale(1); }
/* A cover that is not square is shown whole ("fit") over a blurred, darkened copy of
   itself, rather than cropped: cropping a small 16:9 thumbnail to a square enlarges it
   almost twice as much and throws half of it away. */
.cover-img.fit { object-fit: contain; }
.cover-fill {
  position: absolute;
  inset: -14%;
  background: center / cover no-repeat;
  filter: blur(calc(.9 * var(--u))) brightness(.7) saturate(1.25);
  opacity: 0;
  transition: opacity .9s ease;
}
.cover-fill.show { opacity: 1; }
.cover-gloss {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 38%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}

/* ───────── Vinyl ───────── */
.vinyl {
  position: absolute;
  top: 50%;
  left: calc(2.7 * var(--u));
  width: calc(14 * var(--u));
  height: calc(14 * var(--u));
  margin-top: calc(-7 * var(--u));
  z-index: 2;
  border-radius: 50%;
  transform: translateX(0);
  transition: transform 1.3s cubic-bezier(.2, .8, .2, 1);
  box-shadow: 0 calc(.8 * var(--u)) calc(2 * var(--u)) rgba(0, 0, 0, .35);
}
.player.has-track .vinyl { transform: translateX(calc(1.6 * var(--u))); }
.player.is-playing .vinyl { transform: translateX(calc(5.5 * var(--u))); }

.vinyl-disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 19.5%, rgba(255, 255, 255, .1) 19.8% 20.2%, transparent 20.5%),
    repeating-radial-gradient(circle, #09090b 0 .7%, #1b1b20 1% 1.3%, #09090b 1.6%);
  animation: spin 7s linear infinite;
  animation-play-state: paused;
}
.player.is-playing .vinyl-disc { animation-play-state: running; }
@keyframes spin { to { transform: rotate(360deg); } }

.vinyl-label {
  position: absolute;
  inset: 31%;
  border-radius: 50%;
  background: #2b2e36 center / cover no-repeat;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12), 0 0 0 calc(.12 * var(--u)) rgba(0, 0, 0, .5);
}
.vinyl-hole {
  position: absolute;
  inset: 47.6%;
  border-radius: 50%;
  background: #0b0b0d;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .25);
}
.vinyl-sheen {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 35deg,
    transparent 0 6%, rgba(255, 255, 255, .2) 11%, transparent 17% 50%,
    rgba(255, 255, 255, .14) 58%, transparent 66% 100%);
  mix-blend-mode: screen;
}

/* ───────── Info ───────── */
.info {
  position: absolute;
  left: calc(23.9 * var(--u));
  right: calc(1.9 * var(--u));
  top: calc(1.35 * var(--u));
  bottom: calc(1.3 * var(--u));
  display: flex;
  flex-direction: column;
  min-width: 0;
  z-index: 4;
}

.status {
  display: flex;
  align-items: center;
  gap: calc(.5 * var(--u));
  font-size: calc(.6 * var(--u));
  font-weight: 650;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: rgba(var(--fg), .6);
}
.pulse { display: inline-flex; align-items: flex-end; gap: calc(.1 * var(--u)); height: calc(.62 * var(--u)); }
.pulse i {
  width: calc(.11 * var(--u));
  height: 100%;
  border-radius: 1px;
  background: rgb(var(--accent));
  transform-origin: bottom;
  transform: scaleY(.3);
}
.player.is-playing .pulse i { animation: pulse 1s ease-in-out infinite; }
.player.is-playing .pulse i:nth-child(2) { animation-delay: -.35s; }
.player.is-playing .pulse i:nth-child(3) { animation-delay: -.7s; }
@keyframes pulse { 0%, 100% { transform: scaleY(.3); } 50% { transform: scaleY(1); } }

.status, .timeline, #spectrum { flex-shrink: 0; }

.meta {
  margin-top: calc(.7 * var(--u));
  min-width: 0;
  min-height: 0;
  flex-shrink: 1;
  overflow: hidden;      /* the meta block gives way; the spectrum never gets pushed out */
  transition: opacity .35s ease, transform .35s ease;
}
.meta.swap { opacity: 0; transform: translateY(calc(.35 * var(--u))); }

#title {
  margin: 0;
  font-size: calc(1.85 * var(--u));
  font-weight: 650;
  line-height: 1.16;
  letter-spacing: -.012em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Room for descenders (g, y, p): the clipping box would otherwise cut them off.
     The negative margin gives the space back, so nothing below moves. */
  padding-bottom: .16em;
  margin-bottom: -.16em;
}
/* Titles wider than the widest card wrap to two smaller lines. */
.player.title-long #title {
  font-size: calc(1.5 * var(--u));
  white-space: normal;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow-wrap: anywhere;
}
.player.is-idle #title { font-weight: 500; font-size: calc(1.35 * var(--u)); color: rgba(var(--fg), .7); }

.artist, .album {
  margin: 0;
  padding-bottom: .1em;
  margin-bottom: -.1em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.artist {
  margin-top: calc(.45 * var(--u));
  font-size: calc(1 * var(--u));
  font-weight: 550;
  color: rgba(var(--fg), .84);
}
.album {
  margin-top: calc(.15 * var(--u));
  font-size: calc(.8 * var(--u));
  font-weight: 450;
  color: rgba(var(--fg), .55);
}

.spacer { flex: 1; }

#titleMeasure {
  position: absolute;
  left: -9999px;
  top: 0;
  visibility: hidden;
  white-space: nowrap;
  font-size: calc(1.85 * var(--u));
  font-weight: 650;
  letter-spacing: -.012em;
}

.timeline {
  display: flex;
  align-items: center;
  gap: calc(.6 * var(--u));
  font-size: calc(.6 * var(--u));
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  color: rgba(var(--fg), .62);
  transition: opacity .6s ease;
}
.timeline .bar {
  flex: 1;
  height: calc(.17 * var(--u));
  min-height: 2px;
  border-radius: 99px;
  background: rgba(var(--fg), .15);
  overflow: hidden;
}
.timeline .fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: rgb(var(--accent));
  transform-origin: left;
  transform: scaleX(0);
}
.player.no-timeline .timeline { opacity: 0; }
body.hide-timeline .timeline { display: none; }

#spectrum {
  display: block;
  width: 100%;
  height: calc(1.8 * var(--u));
  margin-top: calc(.6 * var(--u));
}
body.hide-spectrum #spectrum { display: none; }

/* ───────── Analyzer ───────── */
.analyzer {
  position: relative;
  /* Take the card's width and never widen the rig: changing digits in the readouts
     must not shift the layout. */
  width: 0;
  min-width: 100%;
  overflow: hidden;
  border-radius: calc(1.7 * var(--u));
  max-height: calc(17 * var(--u));
  transition: opacity .6s ease, max-height .8s cubic-bezier(.3, .7, .2, 1), margin-top .8s cubic-bezier(.3, .7, .2, 1);
}
.analyzer canvas { min-width: 0; max-width: 100%; }
/* Collapsed rather than display:none so turning the panel on or off animates.
   The negative margin cancels the rig's gap. */
body.hide-analyzer .analyzer {
  max-height: 0;
  opacity: 0;
  margin-top: calc(-1.7 * var(--u));
}
body.hide-idle .player.is-idle + .analyzer { opacity: 0; }

.an-body {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) calc(12.5 * var(--u));
  gap: calc(1.9 * var(--u));
  padding: calc(1.1 * var(--u)) calc(1.6 * var(--u)) calc(1.2 * var(--u));
}
.an-main { min-width: 0; }
.an-head, .an-label, .an-row > span, .an-stats span, .an-bpm span {
  font-size: calc(.5 * var(--u));
  font-weight: 650;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: rgba(var(--fg), .5);
}
.an-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: calc(.4 * var(--u));
}
.an-head2 { margin-top: calc(.7 * var(--u)); }
#anSpectrum { display: block; width: 100%; height: calc(4.8 * var(--u)); }
#anGram, #anLoud {
  display: block;
  width: 100%;
  height: calc(1.7 * var(--u));
  border-radius: calc(.3 * var(--u));
  background: rgba(var(--fg), .06);
}

.an-side { display: flex; flex-direction: column; justify-content: space-between; min-width: 0; }
.an-tempo { display: flex; align-items: flex-start; justify-content: space-between; }
.an-bpm { display: flex; align-items: baseline; gap: calc(.4 * var(--u)); }
.an-bpm b {
  font-size: calc(2.3 * var(--u));
  font-weight: 300;
  line-height: .9;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
  text-align: right;
}
/* Beat position in the bar: four dots, the first one marks the strongest beat. */
.an-bpm { position: relative; }
.an-beats { align-self: center; display: flex; align-items: center; gap: calc(.28 * var(--u)); margin-right: calc(.2 * var(--u)); }
.an-beats i {
  width: calc(.38 * var(--u));
  height: calc(.38 * var(--u));
  border-radius: 50%;
  background: rgb(var(--accent));
  opacity: .15;
}
.an-beats i:first-child { width: calc(.5 * var(--u)); height: calc(.5 * var(--u)); }
/* Tempo confidence: how steady the estimate has been. */
.an-conf {
  position: absolute;
  right: 0;
  bottom: calc(-.5 * var(--u));
  width: calc(5.2 * var(--u));
  height: calc(.14 * var(--u));
  min-height: 2px;
  border-radius: 99px;
  background: rgba(var(--fg), .13);
  overflow: hidden;
}
.an-conf > div { width: 100%; height: 100%; background: rgb(var(--accent)); transform-origin: right; transform: scaleX(0); transition: transform .6s ease; }
#anBpm { transition: opacity .6s ease; }

/* Overload lamp at the end of the L / R meters. */
.an-over {
  width: calc(.32 * var(--u));
  height: calc(.32 * var(--u));
  min-width: 3px;
  min-height: 3px;
  border-radius: 50%;
  background: rgba(var(--fg), .16);
  transition: background .5s ease, box-shadow .5s ease;
}
.an-over.on { background: #ff4d3d; box-shadow: 0 0 calc(.5 * var(--u)) rgba(255, 77, 61, .8); transition-duration: 0s; }
/* Rows without a lamp keep the same meter length. */
.an-row:not(:has(.an-over))::after { content: ""; width: calc(.32 * var(--u)); min-width: 3px; }

/* Tonal balance curve */
.an-tone { grid-column: 1 / -1; gap: calc(.2 * var(--u)) !important; }
#anTone { display: block; width: 100%; height: calc(1.25 * var(--u)); }
.an-tone-cap { display: flex; flex-direction: row !important; justify-content: space-between; }

.an-meters { display: grid; gap: calc(.42 * var(--u)); }
.an-row { display: flex; align-items: center; gap: calc(.6 * var(--u)); }
.an-row > span { width: calc(1.9 * var(--u)); letter-spacing: .12em; }
.an-meter {
  position: relative;
  flex: 1;
  height: calc(.32 * var(--u));
  min-height: 3px;
  border-radius: 99px;
  background: rgba(var(--fg), .13);
  overflow: hidden;
}
.an-meter > div {
  width: 100%;
  height: 100%;
  background: rgba(var(--fg), .78);
  transform-origin: left;
  transform: scaleX(0);
}
.an-meter > i {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 100%;
  background: rgb(var(--accent));
}
.an-bal::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(var(--fg), .35);
}
.an-bal > i { width: calc(.5 * var(--u)); margin-left: calc(-.25 * var(--u)); border-radius: 99px; left: 50%; }

.an-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: calc(.75 * var(--u)) calc(.3 * var(--u)); }
.an-stats div { display: flex; flex-direction: column; gap: calc(.1 * var(--u)); }
.an-stats b {
  font-size: calc(1 * var(--u));
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.an-stats span { letter-spacing: .1em; font-size: calc(.45 * var(--u)); }

/* ───────── Lyrics ───────── */
#lyrics {
  --ls: 1;
  --halo: 255, 255, 255;
  position: fixed;
  left: 50%;
  top: calc(var(--ly, 84) * 1%);
  transform: translate(-50%, -50%);
  width: calc(72 * var(--b));
  max-width: 88vw;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .7s ease;
}
#lyrics.on { opacity: 1; }
body.hide-lyrics #lyrics { display: none; }
#lyCur {
  font-size: calc(2.1 * var(--b) * var(--ls));
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -.005em;
  /* Karaoke sweep: --p is the sung fraction of the line (set from JS). */
  --p: 0%;
  color: transparent;
  background: linear-gradient(90deg, rgb(var(--fg)) var(--p), rgba(var(--fg), .42) calc(var(--p) + 3%));
  -webkit-background-clip: text;
  background-clip: text;
  /* drop-shadow, not text-shadow: a text-shadow would paint over the clipped fill. */
  filter: drop-shadow(0 0 calc(.3 * var(--b)) rgba(var(--halo), .85)) drop-shadow(0 0 calc(1.1 * var(--b)) rgba(var(--halo), .7));
  transition: opacity .28s ease, transform .28s ease;
}
#lyCur.swap { opacity: 0; transform: translateY(calc(.5 * var(--b))); }
#lyNext {
  margin-top: calc(.55 * var(--b));
  font-size: calc(1.15 * var(--b) * var(--ls));
  font-weight: 500;
  color: rgba(var(--fg), .55);
  text-shadow: 0 0 calc(1 * var(--b)) rgba(var(--halo), .9);
  min-height: 1.3em;
}

/* ───────── Clock ───────── */
#clock {
  /* --cx / --cy: 0..1 across the screen (1, 1 = bottom right, the original place).
     The element is shifted by the same fraction of its own size, so it always stays
     inside the margins whatever its size. */
  --cx: 1;
  --cy: 1;
  --cs: 1;
  --mx: calc(3.2 * var(--b));
  --my: calc(4.6 * var(--b));
  position: fixed;
  left: calc(var(--mx) + (100% - 2 * var(--mx)) * var(--cx));
  top: calc(var(--my) + (100% - 2 * var(--my)) * var(--cy));
  transform: translate(calc(-100% * var(--cx)), calc(-100% * var(--cy)));
  text-align: right;
  white-space: nowrap;
  color: rgba(var(--fg), .8);
  pointer-events: none;
  transition: opacity .8s ease, color 1.2s ease;
}
body.hide-clock #clock { opacity: 0; }
#clockDate {
  font-size: calc(1.05 * var(--b) * var(--cs));
  font-weight: 550;
  letter-spacing: .04em;
  opacity: .75;
}
#clockTime {
  font-size: calc(4.8 * var(--b) * var(--cs));
  font-weight: 250;
  line-height: 1.05;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

/* ───────── Custom background image ───────── */
#bgImage {
  --dim: .25;
  --blur: 0px;
  position: fixed;
  /* Blurring fades the edges to transparent: overshoot the screen so that stays outside. */
  inset: calc(var(--blur) * -2);
  background: center / cover no-repeat;
  filter: blur(var(--blur));
  opacity: 0;
  transition: opacity .8s ease;
  pointer-events: none;
}
#bgImage::after { content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, var(--dim)); }
body.has-bgimage #bgImage { opacity: 1; }
/* Over a photo the album palette says nothing about what is behind the text:
   lyrics and clock go white with a dark halo, which reads on a dimmed image. */
body.has-bgimage #lyrics { --fg: 246, 247, 250; --halo: 0, 0, 0 !important; }
body.has-bgimage:not(.clock-glass) #clock { --fg: 246, 247, 250; text-shadow: 0 0 calc(1.2 * var(--b)) rgba(0, 0, 0, .55); }

body.hide-paused .player.is-paused { opacity: 0; }
body.hide-paused .player.is-paused + .analyzer { opacity: 0; }

/* ───────── Clock options ───────── */
#clock.align-left { text-align: left; }
#clock.align-center { text-align: center; }
body.clock-glass #clock {
  padding: calc(1.1 * var(--b) * var(--cs)) calc(1.7 * var(--b) * var(--cs));
  border-radius: calc(1.6 * var(--b) * var(--cs));
  background: rgba(var(--glass), var(--glass-a, .46));
  -webkit-backdrop-filter: blur(calc(2.2 * var(--b))) saturate(1.5);
  backdrop-filter: blur(calc(2.2 * var(--b))) saturate(1.5);
  box-shadow: 0 calc(1.2 * var(--b)) calc(3.5 * var(--b)) rgba(0, 0, 0, .18), inset 0 0 0 1px rgba(255, 255, 255, var(--edge-a, .3));
}
body.clock-glass.no-blur #clock { -webkit-backdrop-filter: none; backdrop-filter: none; }
#clock[data-font="condensed"] { font-family: "Bahnschrift", "Segoe UI", sans-serif; font-stretch: 80%; }
#clock[data-font="mono"] { font-family: "Cascadia Mono", "Consolas", "Courier New", monospace; }
#clock[data-font="mono"] #clockTime { letter-spacing: -.06em; }
#clock[data-font="serif"] { font-family: "Georgia", "Cambria", "Times New Roman", serif; }
#clock[data-font="rounded"] { font-family: "Segoe UI Variable Display", "Segoe UI", sans-serif; }
#clock[data-font="rounded"] #clockTime { font-weight: 600; }
