*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d1a;
  --surface: #16162a;
  --surface2: #1e1e38;
  --accent: #7c6bff;
  --accent2: #ff6bbb;
  --text: #e8e8f0;
  --muted: #7878a0;
  --active-lyric: #ffffff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(24px, env(safe-area-inset-top))
           max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom))
           max(16px, env(safe-area-inset-left));
  gap: 16px;
}

h1 {
  font-size: 1.6rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 16px;
  padding: 20px 24px;
  width: 100%;
}

.card h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}
.field label { font-size: 0.8rem; color: var(--muted); }
.field input {
  background: var(--surface2);
  border: 1px solid #2e2e50;
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus { border-color: var(--accent); }
.field select {
  background: var(--surface2);
  border: 1px solid #2e2e50;
  border-radius: 8px;
  color: var(--text);
  padding: 8px 36px 8px 12px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237878a0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.field select:focus { border-color: var(--accent); }
.field select option { background: var(--surface); }

#playBtn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 50px;
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 28px;
  flex: 1;
  transition: opacity 0.2s, transform 0.1s;
}
#playBtn:hover { opacity: 0.9; transform: scale(1.02); }
#playBtn:disabled { opacity: 0.4; cursor: default; transform: none; }

.play-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

/* Volume button + popup */
.vol-wrap {
  position: relative;
}
#volBtn {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 50px;
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 10px 14px;
  line-height: 1;
  transition: opacity 0.2s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
#volBtn:hover { opacity: 0.9; transform: scale(1.02); }
.vol-popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 12px;
  padding: 14px 10px;
  z-index: 100;
  align-items: center;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
/* Bridge the gap between button and popup so hover isn't lost */
.vol-popup::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 14px;
}
.vol-wrap:hover .vol-popup,
.vol-wrap.open .vol-popup { display: flex; }
.vol-popup input[type=range] {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 28px;
  height: 100px;
  accent-color: var(--accent);
  cursor: pointer;
}
.vol-popup .vol-pct {
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type=range] {
  accent-color: var(--accent);
  cursor: pointer;
}

/* 5-col grid: [label 82px] [−26px] [slider 1fr] [+26px] [value 52px] */
.sliders-grid {
  display: grid;
  grid-template-columns: 82px 26px 1fr 26px 52px;
  row-gap: 10px;
  column-gap: 6px;
  align-items: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 14px;
}
.sliders-grid input[type=range] {
  width: 100%;
  min-width: 0;
}
.offset-btn {
  background: var(--surface2);
  border: 1px solid #2e2e50;
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
  width: 26px;
  text-align: center;
  transition: background 0.15s;
  touch-action: manipulation;
}
.offset-btn:hover { background: var(--accent); border-color: var(--accent); }
.offset-value {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.now-playing-inner {
  display: flex;
  align-items: center;
  gap: 16px;
}
.album-art {
  width: 80px; height: 80px;
  border-radius: 10px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  flex-shrink: 0;
  overflow: hidden;
}
.album-art img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }
.track-details { flex: 1; }
.track-title { font-size: 1.05rem; font-weight: 700; }
.track-artist { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.progress-wrap {
  margin-top: 14px;
}
.progress-times {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 5px;
  font-variant-numeric: tabular-nums;
}
.progress-track {
  position: relative;
  height: 6px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: visible;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  box-shadow: 0 0 8px color-mix(in srgb, var(--accent) 60%, transparent);
  transition: width 0.4s linear;
  position: relative;
  max-width: 100%;
}
.progress-thumb {
  position: absolute;
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent),
              0 0 10px color-mix(in srgb, var(--accent2) 60%, transparent);
  animation: pulse-thumb 2s ease-in-out infinite;
}
@keyframes pulse-thumb {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 40%, transparent),
                         0 0 10px color-mix(in srgb, var(--accent2) 60%, transparent); }
  50%       { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 25%, transparent),
                         0 0 18px color-mix(in srgb, var(--accent2) 80%, transparent); }
}
.progress-thumb.hidden { display: none; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 0.85rem;
  color: var(--muted);
}
.toggle-row input[type=checkbox] { display: none; }
.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--surface2);
  border-radius: 99px;
  flex-shrink: 0;
  transition: background 0.2s;
  margin-left: auto;
}
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s, background 0.2s;
}
.toggle-row input:checked + .toggle-track { background: var(--accent); }
.toggle-row input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
  background: #fff;
}
#lyricsSyncControls.disabled { opacity: 0.35; pointer-events: none; }
.duration-info {
  font-size: 0.72rem;
  margin-top: 6px;
  padding: 5px 10px;
  border-radius: 7px;
  background: rgba(255, 200, 80, 0.06);
  border: 1px solid rgba(255, 200, 80, 0.18);
  color: #f0c040;
}
.duration-info.ok {
  background: rgba(100, 220, 130, 0.06);
  border-color: rgba(100, 220, 130, 0.2);
  color: #64dc82;
}
.spinner {
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#lyricsContainer {
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 8px 0;
}
#lyricsContainer::-webkit-scrollbar { width: 4px; }
#lyricsContainer::-webkit-scrollbar-track { background: transparent; }
#lyricsContainer::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }

.lyric-line {
  text-align: center;
  padding: 8px 20px;
  font-size: 1.2rem;
  line-height: 1.6;
  color: var(--muted);
  border-radius: 8px;
  transition: color 0.3s, font-size 0.2s, font-weight 0.2s;
  cursor: default;
}
.lyric-line.active {
  color: var(--active-lyric);
  font-size: 1.45rem;
  font-weight: 700;
  background: rgba(124, 107, 255, 0.08);
}
.lyric-line.near {
  color: #b0b0d0;
  font-size: 1.3rem;
}

.lyrics-placeholder {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 30px 0;
}
.plain-lyrics {
  white-space: pre-wrap;
  font-family: inherit;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.8;
}

.lyrics-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.lyrics-header h2 { margin-bottom: 0; }
.lyrics-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 2px 9px;
  border-radius: 99px;
  text-transform: uppercase;
}
.lyrics-badge.synced {
  background: rgba(100, 220, 130, 0.12);
  color: #64dc82;
  border: 1px solid rgba(100, 220, 130, 0.3);
}
.lyrics-badge.plain {
  background: rgba(120, 120, 160, 0.12);
  color: var(--muted);
  border: 1px solid rgba(120, 120, 160, 0.25);
}
.lyrics-badge.synced-off {
  background: rgba(120, 120, 160, 0.08);
  color: var(--muted);
  border: 1px solid rgba(120, 120, 160, 0.18);
  opacity: 0.6;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#historyCard .history-list::-webkit-scrollbar { width: 4px; }
#historyCard .history-list::-webkit-scrollbar-track { background: transparent; }
#historyCard .history-list::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
}
.history-art {
  width: 44px; height: 44px;
  border-radius: 7px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
  overflow: hidden;
}
.history-art img { width: 100%; height: 100%; object-fit: cover; border-radius: 7px; }
.history-info { flex: 1; min-width: 0; }
.history-title  { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-artist { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-time   { font-size: 0.72rem; color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }

details > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
details > summary::before { content: '▶'; font-size: 0.7rem; transition: transform 0.2s; }
details[open] > summary::before { transform: rotate(90deg); }
details .card { margin-top: 12px; }

/* ── Merged station + now-playing card ── */
.merged-station-track {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}
.station-side {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding-left: 16px;
  border-left: 1px solid var(--surface2);
}
.station-logo {
  max-width: 90px;
  max-height: 48px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 6px;
}
.station-logo-fallback {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--surface2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}
.station-display-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.track-side {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

/* ── Two-column layout ── */
#layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
  width: 100%;
  max-width: 1280px;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}
#lyricsCol {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}
#lyricsCol .lyrics-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#lyricsCol .lyrics-card #lyricsContainer {
  flex: 1;
  min-height: 0;
}
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}
#historyCard {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
#historyCard .history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
@media (max-width: 780px) {
  body { height: auto; overflow: auto; padding-bottom: 40px; }
  #layout { grid-template-columns: 1fr; flex: none; }
  #lyricsCol .lyrics-card { height: auto; }
  #lyricsCol #lyricsContainer { max-height: 60vh; }
  #historyCard { flex: none; }
}

/* ── Update banner ── */
#updateBanner {
  display: none;
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 50px;
  padding: 10px 16px 10px 20px;
  gap: 12px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  z-index: 200;
  white-space: nowrap;
}
#updateBanner.visible { display: flex; }
#updateBanner button {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none;
  border-radius: 50px;
  color: #fff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 16px;
  transition: opacity 0.2s;
}
#updateBanner button:hover { opacity: 0.85; }

/* ── Version footer ── */
#appVersion {
  font-size: 0.68rem;
  color: var(--muted);
  opacity: 0.4;
  text-align: center;
  padding: 4px 0 max(8px, env(safe-area-inset-bottom));
  letter-spacing: 0.3px;
  flex-shrink: 0;
  user-select: none;
}

/* ── Debug log panel (toggle via footer tap) ── */
#debugPanel {
  display: none;
  background: #0a0a12;
  border-top: 1px solid #333;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
#debugPanel.visible { display: block; }
#debugLog {
  font-family: monospace;
  font-size: 10px;
  color: #0f0;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
#debugLog .err { color: #f66; }
#debugClear {
  margin-top: 6px;
  font-size: 10px;
  padding: 2px 8px;
  background: #222;
  color: #aaa;
  border: 1px solid #444;
  border-radius: 3px;
  cursor: pointer;
}
