:root {
  --bg: #0b0b10;
  --bg-2: #15151d;
  --fg: #f5f5f7;
  --dim: rgba(245, 245, 247, 0.38);
  --faint: rgba(245, 245, 247, 0.16);
  --accent: #1ed760;
  --danger: #ff5c5c;
  --rule: rgba(255, 255, 255, 0.06);
  --glow: rgba(255, 255, 255, 0.18);
  --scrim: rgba(0, 0, 0, 0.5);
  --lyric-scale: 1;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

:root[data-theme="light"] {
  --bg: #f4f4f6;
  --bg-2: #ffffff;
  --fg: #111116;
  --dim: rgba(17, 17, 22, 0.5);
  --faint: rgba(17, 17, 22, 0.2);
  --accent: #1db954;
  --danger: #d93636;
  --rule: rgba(0, 0, 0, 0.08);
  --glow: transparent;
  --scrim: rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 16px) 0 calc(var(--sal) + 16px);
  overflow: hidden;
}

/* Now playing */
.now {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: none;
}
.art {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-2);
  flex: none;
}
.meta { min-width: 0; flex: 1; }
.title, .artist {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title { font-weight: 650; font-size: 17px; }
.artist { color: var(--dim); font-size: 14px; }

.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--dim);
  display: grid;
  place-items: center;
}
.icon-btn:active { background: var(--faint); }
.icon-btn.spin svg { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  flex: none;
  height: 3px;
  margin-top: 12px;
  border-radius: 2px;
  background: var(--faint);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 100%;
  background: var(--fg);
  transform-origin: left;
  transform: scaleX(0);
}

/* Lyrics stage */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(transparent 0, #000 12%, #000 80%, transparent 100%);
  mask-image: linear-gradient(transparent 0, #000 12%, #000 80%, transparent 100%);
}

.lines {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  transition: transform 0.55s cubic-bezier(0.22, 0.8, 0.3, 1);
  will-change: transform;
}

.line {
  margin: 0;
  padding: calc(10px * var(--lyric-scale)) 14px;
  text-align: center;
  text-wrap: balance;
  font-weight: 700;
  font-size: calc(22px * var(--lyric-scale));
  line-height: 1.25;
  color: var(--faint);
  overflow-wrap: anywhere;
  transform: scale(0.92);
  transition: color 0.35s, transform 0.35s, opacity 0.35s;
}
.line.near { color: var(--dim); }
.line.active {
  color: var(--fg);
  transform: scale(1.05);
  text-shadow: 0 0 24px var(--glow);
}
.line.gap { letter-spacing: 0.3em; }

.lines.no-anim, .lines.no-anim .line { transition: none; }

.plain {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 48px 0 calc(var(--sab) + 72px);
  text-align: center;
}
.plain-text {
  white-space: pre-wrap;
  font-size: calc(18px * var(--lyric-scale));
  font-weight: 600;
  line-height: 1.6;
  color: var(--dim);
  overflow-wrap: anywhere;
}
.badge {
  display: inline-block;
  margin-bottom: 16px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--faint);
  color: var(--dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 12px calc(var(--sab) + 40px);
  text-align: center;
}
.status-msg { font-size: 20px; font-weight: 650; }
.status-sub { color: var(--dim); font-size: 15px; max-width: 32ch; }
.status .btn { margin-top: 14px; }

/* Buttons */
.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  font: inherit;
  font-weight: 650;
  color: var(--fg);
  background: var(--bg-2);
  min-height: 44px;
}
.btn.primary { background: var(--accent); color: #04120a; }
.btn.danger { color: var(--danger); }
.btn:active { opacity: 0.8; }

/* Settings sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 10;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  max-height: 85vh;
  overflow-y: auto;
  padding: 10px calc(var(--sar) + 20px) calc(var(--sab) + 20px) calc(var(--sal) + 20px);
  background: var(--bg-2);
  border-radius: 18px 18px 0 0;
  animation: sheet-in 0.25s ease-out;
}
@keyframes sheet-in { from { transform: translateY(100%); } }
.sheet-grip {
  width: 40px;
  height: 5px;
  border-radius: 3px;
  background: var(--faint);
  margin: 0 auto 8px;
}
.sheet h2 { font-size: 18px; margin: 4px 0 16px; }

.row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--rule);
}
.row.toggle { flex-direction: row; align-items: center; justify-content: space-between; }
.row-label { display: flex; justify-content: space-between; font-weight: 600; }
.row-label output { color: var(--dim); font-weight: 500; font-variant-numeric: tabular-nums; }
.hint { color: var(--dim); font-size: 13px; margin: 0; }

input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

.sheet-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.segmented {
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--faint);
}
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 7px 0;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--dim);
}
.segmented input:checked + span { background: var(--bg); color: var(--fg); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.now.idle .art, .now.idle .meta { visibility: hidden; }

/* HUD: mirrored, black, only the current and next line, for windshield reflection */
:root[data-hud] { --bg: #000; --fg: #fff; }
:root[data-hud] .now,
:root[data-hud] .progress { display: none; }
:root[data-hud] .stage { -webkit-mask-image: none; mask-image: none; }
:root[data-hud="v"] .stage { transform: scaleY(-1); }
:root[data-hud="h"] .stage { transform: scaleX(-1); }
:root[data-hud] .line {
  opacity: 0;
  color: #fff;
  font-size: calc(30px * var(--lyric-scale));
  transform: none;
  text-shadow: none;
  transition: opacity 0.3s;
}
:root[data-hud] .line.active { opacity: 1; transform: none; }
:root[data-hud] .line.next { opacity: 0.4; }
:root[data-hud] .plain-text { color: #fff; }

.hud-exit {
  position: fixed;
  top: calc(var(--sat) + 10px);
  right: calc(var(--sar) + 12px);
  z-index: 5;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #555;
  background: #111;
}
