:root {
  /* Karaoke stage palette: plum surfaces, magenta + gold marquee accents,
     red lyric fill. Page background stays #000 = transparent on the
     additive MRBD display. */
  --bg-primary: #000000;
  --surface: #190c20;
  --surface-2: #241132;
  --surface-3: #321845;
  --text-primary: #ffffff;
  --text-dim: #cbb9d8;
  --text-muted: #8d78a0;
  --pink: #ff2e88;
  --pink-deep: #a2246c;
  --purple: #7a2fc0;
  --gold: #ffc531;
  --gold-dim: #b98a1e;
  --red-fill: #ff3d3d;
  --danger: #ff4466;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 600px;
  height: 600px;
  overflow: hidden;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.hidden { display: none; }

/* --- Header: marquee strip --- */
.header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 2px solid var(--pink-deep);
  gap: 12px;
  flex-shrink: 0;
}
.header h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  flex: 1;
  background: linear-gradient(90deg, var(--gold), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-icon { font-size: 24px; }
.header-meta {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.back-btn {
  background: transparent;
  color: var(--gold);
  font-size: 22px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}
.back-btn:focus, .back-btn.focused {
  outline: none;
  border-color: var(--gold);
  background: var(--surface-2);
}

/* --- Content Area --- */
.content {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-label {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--gold);
  margin-top: 6px;
}

.hint {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  padding: 12px;
}

/* --- Focus (D-pad): solid stage-light highlight, no glow --- */
.focusable {
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  border: 2px solid transparent;
  cursor: pointer;
  min-height: 44px;
}
.focusable:focus { outline: none; }

/* --- Song list items --- */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.list-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
  text-align: left;
  gap: 14px;
  flex-shrink: 0;
}
.list-item:focus, .list-item.focused {
  background: linear-gradient(120deg, var(--pink-deep) 0%, var(--purple) 100%);
  border-color: var(--pink);
  transform: translateX(4px);
}
.list-item:focus .list-item-meta,
.list-item.focused .list-item-meta { color: var(--text-dim); }
.list-item-icon {
  font-size: 24px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-3);
  border-radius: 50%;
}
.list-item:focus .list-item-icon,
.list-item.focused .list-item-icon { background: rgba(0, 0, 0, 0.3); }
.list-item-content { flex: 1; min-width: 0; }
.list-item-title {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Player: the stage --- */
.player-header { gap: 16px; }
.player-title-block { flex: 1; min-width: 0; }
.player-song {
  font-size: 18px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-artist {
  font-size: 13px;
  color: var(--gold);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 24px;
  position: relative;
  overflow: hidden;
  /* Faint spotlight falling on the lyrics */
  background: radial-gradient(ellipse 65% 55% at 50% 42%,
              rgba(122, 47, 192, 0.18) 0%, transparent 70%);
}

.lyrics-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.lyric-line {
  width: 100%;
  line-height: 1.3;
  overflow: hidden;
  /* Single row per line — long lines are split at load time so the
     karaoke wipe never fills two rows at once */
  white-space: nowrap;
}
.lyric-line.prev {
  font-size: 18px;
  color: var(--text-muted);
  min-height: 24px;
}
.lyric-line.current {
  position: relative;
  font-size: 32px;
  font-weight: 800;
  color: var(--text-primary);
  min-height: 78px;
}
.lyric-line.next {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-dim);
  min-height: 26px;
}
.lyric-line.next2 {
  font-size: 18px;
  color: var(--text-muted);
  min-height: 24px;
}

/* Karaoke wipe: sung words turn red over the white line */
.line-base { display: block; }
.line-fill {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  color: var(--red-fill);
  clip-path: inset(0 100% 0 0);
  pointer-events: none;
}

.countdown {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  font-weight: 800;
  color: #1a0c20;
  background: var(--gold);
  padding: 8px 22px;
  border-radius: var(--radius-lg);
}

.player-footer {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  background: var(--surface);
  border-top: 2px solid var(--pink-deep);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.player-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.control-hint {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.control-hint.accent { color: var(--gold); font-weight: 700; }

/* --- D-pad Keyboard --- */
.search-content { gap: 14px; }

.query-display {
  min-height: 56px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 2px solid var(--surface-3);
  border-radius: var(--radius-md);
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  overflow: hidden;
  white-space: nowrap;
}
.query-text { color: var(--text-primary); }
.query-placeholder { color: var(--text-muted); font-weight: 400; }
.query-caret {
  display: inline-block;
  width: 3px;
  height: 24px;
  margin-left: 2px;
  background: var(--gold);
  flex-shrink: 0;
}

.kbd {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.kbd-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.kbd-key {
  flex: 1;
  max-width: 52px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.kbd-key.kbd-wide { max-width: 118px; flex: 2; font-size: 16px; }
.kbd-key.kbd-space { max-width: 200px; flex: 4; font-size: 15px; }
.kbd-key.targeted {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a0c20;
  font-weight: 800;
}

.search-results { flex: 1; }

/* Home: the whole content column scrolls, not the individual lists */
#library-list, #featured-list {
  flex-shrink: 0;
  overflow-y: visible;
}

/* --- Loading --- */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  flex: 1;
}
.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface-3);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  font-size: 16px;
  color: var(--text-muted);
}

/* --- Errors --- */
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
}
.error-icon { font-size: 48px; }
.error-message {
  font-size: 16px;
  color: var(--text-dim);
  max-width: 400px;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--surface-3);
  color: var(--text-primary);
  font-weight: 600;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  border: 2px solid var(--gold);
  transition: transform 0.3s ease;
  z-index: 100;
  pointer-events: none;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--pink); }

/* --- Progress Bar --- */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--pink), var(--gold));
  border-radius: 4px;
}

/* --- Utility --- */
.hidden { display: none !important; }
