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

:root {
  --bg:           #0c0c14;
  --surface:      #13131e;
  --card:         #1a1a28;
  --card-hover:   #21213200;
  --border:       rgba(255,255,255,0.07);
  --accent:       #7c5cfc;
  --accent-light: #a48cff;
  --accent-glow:  rgba(124,92,252,0.35);
  --warm:         #ff6b6b;
  --green:        #4cde80;
  --text:         #eeeef8;
  --text-muted:   #7878a0;
  --text-dim:     #444460;
  --radius-sm:    8px;
  --radius:       14px;
  --radius-lg:    20px;
  --shadow:       0 8px 32px rgba(0,0,0,0.5);
  --shadow-accent:0 0 24px var(--accent-glow);
  --font-mono:    'JetBrains Mono', 'Fira Mono', monospace;
  --transition:   0.18s ease;
}

/* Prevent flex/grid from overriding the HTML hidden attribute */
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(12,12,20,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: none;
}
@media (min-width: 600px) { .logo-tagline { display: block; } }

/* ── Toolbar ─────────────────────────────────────────── */
.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.toolbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap input[type="search"] {
  width: 100%;
  padding: 8px 12px 8px 34px;
}

.bpm-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.bpm-filter label,
.sort-wrap label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.bpm-filter input {
  width: 64px;
  text-align: center;
  padding: 8px 6px;
}

.range-sep { color: var(--text-muted); }

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Inputs & Selects ────────────────────────────────── */
input[type="text"],
input[type="number"],
input[type="url"],
input[type="search"],
select,
textarea {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 9px 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder,
textarea::placeholder { color: var(--text-dim); }

select { cursor: pointer; }

textarea { resize: vertical; }

input[type="number"] {
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }

/* Safari adds a built-in search icon that shifts placeholder text */
input[type="search"] { -webkit-appearance: none; appearance: none; }
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-light); box-shadow: var(--shadow-accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--card); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.btn-danger {
  background: transparent;
  color: var(--warm);
  border: 1px solid rgba(255,107,107,0.3);
  margin-left: auto;
}
.btn-danger:hover { background: rgba(255,107,107,0.1); }

.btn-danger-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-danger-ghost:hover { color: var(--warm); border-color: rgba(255,107,107,0.4); background: rgba(255,107,107,0.08); }

.btn-tap {
  background: rgba(124,92,252,0.15);
  color: var(--accent-light);
  border: 1px solid rgba(124,92,252,0.3);
  padding: 9px 16px;
}
.btn-tap:hover { background: rgba(124,92,252,0.25); }
.btn-tap.tapping {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-accent);
  animation: tapPulse 0.1s ease;
}

@keyframes tapPulse {
  0% { transform: scale(1); }
  50% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

.btn-metro {
  background: var(--accent);
  color: #fff;
  padding: 12px 28px;
  font-size: 1rem;
  border-radius: var(--radius);
  width: 100%;
  max-width: 240px;
}
.btn-metro:hover { background: var(--accent-light); box-shadow: var(--shadow-accent); }
.btn-metro.playing {
  background: rgba(255,107,107,0.9);
}
.btn-metro.playing:hover { background: var(--warm); }

/* ── Header actions ──────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-lib-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Main / Song Grid ────────────────────────────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.song-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

/* ── Tempo Groups ────────────────────────────────────── */
.song-grid.grouped {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.tempo-section-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.tempo-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.tempo-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tempo-range {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.tempo-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

/* ── Song Card ───────────────────────────────────────── */
.song-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}

.song-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-glow) 0%, transparent 60%);
  opacity: 0;
  transition: opacity var(--transition);
  pointer-events: none;
}

.song-card:hover {
  border-color: rgba(124,92,252,0.4);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transform: translateY(-2px);
}

.song-card:hover::before { opacity: 1; }

.card-bpm-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
  border-radius: 99px;
  padding: 3px 12px 3px 10px;
  width: fit-content;
}

.card-bpm-value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
}

.card-bpm-unit {
  font-size: 0.65rem;
  font-weight: 600;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-info { flex: 1; }

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 3px;
  color: var(--text);
}

.card-artist {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-has-video {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-dim);
}
.card-has-video svg { width: 12px; height: 12px; }
.card-has-video.linked { color: var(--green); }

.card-play-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.song-card:hover .card-play-hint { color: var(--accent-light); }

/* ── Empty State ─────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  opacity: 0.3;
}

.empty-state h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.empty-state p {
  font-size: 0.9rem;
  max-width: 340px;
}

/* ── Modal Backdrop ──────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

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

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  transition: color var(--transition), background var(--transition);
}
.modal-close svg { width: 20px; height: 20px; }
.modal-close:hover { color: var(--text); background: var(--card); }

/* ── Player Modal ─────────────────────────────────────  */
.player-modal { max-width: 780px; }

.player-artist {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.player-body {
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (min-width: 680px) {
  .player-body {
    flex-direction: row;
    align-items: flex-start;
  }
}

.youtube-container {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#youtube-player-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 */
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}

#youtube-player-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.no-video-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 180px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
}

.no-video-msg svg { width: 48px; height: 48px; }
.no-video-msg p { font-size: 0.85rem; }

/* ── Metronome Panel ─────────────────────────────────── */
.metronome-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 8px 0;
  min-width: 200px;
}

.bpm-readout {
  display: flex;
  align-items: center;
  gap: 12px;
}

.bpm-adj {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
  user-select: none;
}
.bpm-adj:hover { background: var(--card-hover); border-color: var(--accent); color: var(--accent-light); }

.bpm-number-wrap {
  text-align: center;
  min-width: 90px;
}

.bpm-number {
  display: block;
  font-family: var(--font-mono);
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-light);
  letter-spacing: -0.03em;
}

.bpm-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Beat Visualizer */
.beat-visualizer {
  position: relative;
  width: 80px;
  height: 80px;
}

.beat-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.05s ease, box-shadow 0.05s ease;
}

.beat-ring.pulse {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow), inset 0 0 20px var(--accent-glow);
}

.beat-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.05s ease, transform 0.05s ease, box-shadow 0.05s ease;
}

.beat-ring.pulse .beat-dot {
  background: var(--accent-light);
  transform: scale(1.15);
  box-shadow: 0 0 12px var(--accent-glow);
}

.bpm-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  min-height: 1.2em;
}

/* ── Edit Modal ──────────────────────────────────────── */
.edit-modal { max-width: 600px; }

.edit-modal form {
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 140px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.req { color: var(--warm); }

.field-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.bpm-group { max-width: 120px; min-width: 80px; }
.tap-group { max-width: 140px; }
.lookup-group { max-width: 140px; }

.lookup-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  font-size: 0.8rem;
}

/* Tap feedback — always occupies space so the Tap button never moves */
.tap-feedback {
  background: rgba(124,92,252,0.08);
  border: 1px solid rgba(124,92,252,0.25);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.tap-feedback.active {
  opacity: 1;
  pointer-events: auto;
}

.tap-bpm-display {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.tap-bpm-display span:first-child {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent-light);
}

.tap-bpm-display span:last-child {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tap-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  flex: 1;
}

/* Input row */
.input-row {
  display: flex;
  gap: 8px;
}

.input-row input { flex: 1; }

/* YouTube preview inside form */
.yt-preview {
  background: #000;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.yt-preview-video {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
}
.yt-preview-video iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.yt-preview .btn { margin: 8px; align-self: flex-start; }

/* Form actions */
.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-top: 4px;
}

/* ── Standalone Metronome Modal ──────────────────────── */
.sa-metro-modal { max-width: 420px; }

.sa-metro-body {
  padding: 24px 28px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Tap feedback panel is always visible in the standalone metro so the
   button never shifts position and "Use this BPM" stays reachable */
#sa-tap-feedback {
  opacity: 1;
  pointer-events: auto;
  width: 100%;
}

.sa-space-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: -4px;
}

/* ── Footer ──────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 24px;
  font-size: 0.78rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--text-muted);
  text-decoration: none;
}
footer a:hover { color: var(--accent-light); }

/* ── Media info note ─────────────────────────────────── */
.media-info {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.45;
}
.media-info svg { width: 13px; height: 13px; flex-shrink: 0; margin-top: 1px; }
.media-info strong { color: var(--text-muted); font-weight: 600; }

/* ── Spotify embed ───────────────────────────────────── */
#spotify-player-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
}
#spotify-player-wrap iframe {
  display: block;
  width: 100%;
  border: none;
}

/* ── Media open links ────────────────────────────────── */
.media-open-links {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 8px;
}

.media-open-link {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-decoration: none;
  transition: color var(--transition);
}
.media-open-link:hover { color: var(--accent-light); }

/* ── Copy-link button ────────────────────────────────── */
.btn-copy-link {
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 0.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  border-radius: 6px;
  font-family: inherit;
  transition: color var(--transition), background var(--transition);
}
.btn-copy-link svg { width: 13px; height: 13px; }
.btn-copy-link:hover { color: var(--accent-light); background: rgba(124,92,252,0.1); }
.btn-copy-link.copied { color: var(--green); }

/* ── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 99px;
  box-shadow: var(--shadow);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
