/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-glow: rgba(233, 69, 96, 0.3);
  --text-primary: #eaeaea;
  --text-secondary: #a0a0b0;
  --text-muted: #6a6a7a;
  --success: #2ecc71;
  --warning: #f39c12;
  --border: #2a2a4a;
  --radius: 10px;
  --transition: 0.2s ease;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* === Header === */
header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo-icon {
  font-size: 2rem;
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #ff9a76);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

nav {
  display: flex;
  gap: 0.5rem;
}

.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
}

.tab-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

/* === Main === */
main {
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

h2 {
  font-size: 1.4rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

h3 {
  font-size: 1rem;
  margin-bottom: 0.6rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* === Buttons === */
.btn {
  border: none;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: #1a4a8a;
}

.btn-record {
  background: var(--accent);
  color: white;
  font-size: 1rem;
  padding: 0.8rem 2rem;
}

.btn-record:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-record.recording {
  background: #c0392b;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233, 69, 96, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(233, 69, 96, 0); }
}

.record-dot {
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
  display: inline-block;
}

.btn-record.recording .record-dot {
  background: #ff0000;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.btn-stop {
  background: #555;
  color: white;
}

.btn-stop:hover:not(:disabled) {
  background: #777;
}

.btn-danger {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-danger:hover {
  background: var(--accent);
  color: white;
}

.btn-download {
  background: transparent;
  color: var(--success);
  border: 1px solid var(--success);
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-download:hover {
  background: var(--success);
  color: white;
}

.btn-spotify {
  background: #1db954;
  color: white;
  white-space: nowrap;
}

.btn-spotify:hover:not(:disabled) {
  background: #1ed760;
  box-shadow: 0 0 15px rgba(29, 185, 84, 0.4);
}

.spotify-input-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.spotify-input-group input {
  flex: 1;
  font-size: 1rem;
  padding: 0.8rem 1rem;
}

.hint-text {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 0.8rem;
}

/* === Spotify Search Results === */
.spotify-results {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.spotify-result-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(42, 42, 74, 0.5);
}

.spotify-result-item:last-child {
  border-bottom: none;
}

.spotify-result-item:hover {
  background: rgba(29, 185, 84, 0.1);
}

.spotify-result-item img {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

.spotify-result-info {
  flex: 1;
  min-width: 0;
}

.spotify-result-info .track-name {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spotify-result-info .track-artist {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spotify-result-item .result-load-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--transition);
}

.spotify-result-item .result-load-btn:hover {
  background: var(--accent-hover);
}

.results-loading {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
}

/* === Inputs === */
input[type="text"], textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  width: 100%;
  transition: border-color var(--transition);
  font-family: inherit;
}

input[type="text"]:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.url-input-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.url-input-group input {
  flex: 1;
}

/* === Timer & Status === */
.timer {
  font-family: 'Courier New', monospace;
  font-size: 1.2rem;
  color: var(--text-secondary);
  min-width: 60px;
}

.status-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* === Sing Along Layout === */
.sing-along-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

.player-section, .visualization-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#spotify-player-container {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 152px;
  position: relative;
}

#spotify-player {
  width: 100%;
  min-height: 152px;
  border: none;
  border-radius: var(--radius);
}

/* === Preview Player === */
.preview-player {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
}

.preview-artwork {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.preview-info {
  flex: 1;
  min-width: 0;
}

.preview-track-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-artist-name {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-player audio {
  width: 100%;
  max-width: 250px;
  height: 36px;
  flex-shrink: 0;
}

.player-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.player-placeholder.hidden {
  display: none;
}

.placeholder-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.sing-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* === Pitch Panel === */
.pitch-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.current-note {
  font-size: 2.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-family: 'Courier New', monospace;
  min-height: 3.5rem;
}

canvas {
  width: 100%;
  height: auto;
  background: var(--bg-primary);
  border-radius: 6px;
  display: block;
}

/* === Lyrics Panel === */
.lyrics-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  flex: 1;
}

.lyrics-panel textarea {
  height: 150px;
  resize: vertical;
}

.lyrics-scroll {
  height: 200px;
  overflow-y: auto;
  font-size: 1.2rem;
  line-height: 2;
  padding: 1rem;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.lyrics-scroll .lyrics-line {
  transition: all 0.3s ease;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.lyrics-scroll .lyrics-line.active {
  color: var(--accent);
  font-weight: 600;
  background: rgba(233, 69, 96, 0.1);
  transform: scale(1.02);
}

/* === Practice Layout === */
.practice-layout {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 2rem;
  align-items: start;
}

.practice-controls {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.practice-buttons {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.practice-pitch {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.playback-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.playback-section audio {
  width: 100%;
  margin: 0.5rem 0;
}

.playback-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* === Recordings List === */
.recordings-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.badge {
  background: var(--accent);
  color: white;
  padding: 0.2rem 0.7rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.recordings-list {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.recording-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: border-color var(--transition);
}

.recording-card:hover {
  border-color: var(--accent);
}

.recording-info {
  flex: 1;
}

.recording-info h4 {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
}

.recording-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 1rem;
}

.recording-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.recording-actions audio {
  height: 32px;
  max-width: 250px;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.modal-content label {
  display: block;
  color: var(--text-secondary);
  margin: 1rem 0 0.5rem;
  font-size: 0.85rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  justify-content: flex-end;
}

/* === Responsive === */
@media (max-width: 900px) {
  .sing-along-layout,
  .practice-layout {
    grid-template-columns: 1fr;
  }

  header {
    flex-direction: column;
    align-items: flex-start;
  }

  nav {
    width: 100%;
    overflow-x: auto;
  }

  main {
    padding: 1rem;
  }
}

@media (max-width: 600px) {
  .tab-btn {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
  }

  .preview-player {
    flex-wrap: wrap;
  }

  .preview-player audio {
    max-width: none;
    width: 100%;
  }

  .recording-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .recording-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .recording-actions audio {
    width: 100%;
    max-width: none;
  }
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
