/* ---- Base / theme ---- */
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --border: #334155;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.topbar-extra { color: var(--muted); font-size: 0.9rem; }

.topbar { flex-wrap: wrap; }
.topbar-nav { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.nav-link {
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid transparent;
  font-size: 0.9rem;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); border-color: var(--border); }
.nav-link.active { background: var(--panel-2); color: var(--text); }

.topbar-user { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: block; }
.role-badge {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  text-transform: capitalize;
  white-space: nowrap;
}
.role-badge.manager { background: #1e3a5f; color: #93c5fd; }
.role-badge.admin { background: #4a1d6e; color: #d8b4fe; }

.app { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.loading { color: var(--muted); }
.error {
  background: #7f1d1d; color: #fecaca; padding: 1rem;
  border-radius: var(--radius); white-space: pre-wrap;
}

/* ---- Song list ---- */
.search {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  margin-bottom: 1rem;
}
.song-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}
@media (min-width: 700px) {
  .song-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1000px) {
  .song-grid { grid-template-columns: repeat(3, 1fr); }
}
.song-card {
  display: block;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color 0.15s, transform 0.05s;
}
.song-card:hover { border-color: var(--accent); }
.song-card:active { transform: scale(0.99); }
.song-card h3 { margin: 0 0 0.4rem; }
.song-card .chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  font-size: 0.72rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.chip.missing { background: #7f1d1d; color: #fecaca; }

/* Incomplete songs */
.song-card.broken { border-color: #b45309; }
.badge-broken {
  margin-left: 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fbbf24;
  vertical-align: middle;
}
.banner-broken {
  background: #78350f;
  color: #fde68a;
  border: 1px solid #b45309;
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.9rem;
}

/* ---- Practice (split) view ---- */
.practice-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.practice-head h2 { margin: 0; }
.back { color: var(--muted); }

.split {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr; /* mobile: stacked, notes on top */
}
@media (min-width: 900px) {
  .split { grid-template-columns: 3fr 2fr; align-items: start; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-title {
  padding: 0.6rem 0.9rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

/* Notes viewer */
.notes-viewer { height: 60vh; min-height: 320px; }
@media (min-width: 900px) {
  .notes-viewer { height: calc(100vh - 220px); }
}

/* View toggle (PDF vs. Score) */
.view-toggle {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
}
.view-btn {
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
}
.view-btn.active {
  background: var(--accent-strong);
  color: #04212f;
  border-color: var(--accent);
  font-weight: 700;
}
.view-btn:hover { border-color: var(--accent); }

/* View content */
.view-content {
  width: 100%;
  height: 100%;
  overflow: auto;
}
.notes-image {
  max-width: 100%;
  height: auto;
  display: block;
}

.notes-viewer iframe,
.notes-viewer img {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #fff;
  object-fit: contain;
}
.notes-missing { padding: 1.5rem; color: var(--muted); }

/* PDF rendered by PDF.js: a scrollable column of page canvases */
.notes-viewer.pdf { overflow-y: auto; background: #0b1220; }
.pdf-scroll {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
}
.pdf-page {
  max-width: 100%;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}

/* Right panel inner padding */
.controls { padding: 0.9rem; }

/* Voice selector */
.voices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}
.voice-btn {
  padding: 0.7rem;
  font-size: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.voice-btn:hover { border-color: var(--accent); }
.voice-btn.active {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #04212f;
  font-weight: 700;
}
.voice-btn.full { grid-column: 1 / -1; }
.voice-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Score (OSMD) prototype */
.score-box {
  background: #fff;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 0.5rem;
  overflow-x: auto;
  min-height: 200px;
}

/* Player */
.player audio { width: 100%; margin: 0.5rem 0; }
.now-playing { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.25rem; }

.tools { margin-top: 0.75rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.tool-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}
.tool-row label { color: var(--muted); min-width: 4.5rem; }
.tool-row input[type="range"] { flex: 1; min-width: 120px; }
.btn {
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.on { background: var(--accent-strong); color: #04212f; border-color: var(--accent); font-weight: 700; }
.speed-val { min-width: 3rem; text-align: right; color: var(--text); }
.hint { color: var(--muted); font-size: 0.82rem; margin: 0.25rem 0 0; }

/* ---- Auth / gate screens ---- */
.auth-card {
  max-width: 420px;
  margin: 10vh auto 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
}
.auth-card h2 { margin-top: 0; }
.btn.primary {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #04212f;
  font-weight: 700;
}
.btn.danger { background: #7f1d1d; border-color: #b91c1c; color: #fecaca; }
.btn.btn-small { padding: 0.25rem 0.6rem; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.google-btn { font-size: 1rem; padding: 0.7rem 1.4rem; }

/* ---- Forms (add/edit song, people) ---- */
.form-card {
  max-width: 720px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.field { margin-bottom: 0.9rem; }
.field label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.25rem; }
.field input,
.add-person input,
.form-card select {
  padding: 0.55rem 0.7rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.field input { width: 100%; max-width: 420px; }
.form-actions { display: flex; align-items: center; gap: 0.8rem; margin: 0.8rem 0; flex-wrap: wrap; }

.file-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.file-label { min-width: 11rem; color: var(--text); font-size: 0.92rem; }
.file-label .req { color: #fbbf24; }
.file-row input[type="file"] { color: var(--muted); font-size: 0.85rem; max-width: 100%; }
.file-current { font-size: 0.85rem; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-current.none { color: var(--muted); }

/* Upload progress */
.upload-box { margin-top: 0.8rem; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.upload-status { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.45rem; }
.upload-label { min-width: 11rem; font-size: 0.85rem; color: var(--muted); }
.progress {
  flex: 1;
  height: 6px;
  min-width: 80px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress > div { height: 100%; width: 0%; background: var(--accent-strong); transition: width 0.15s; }
.upload-status.failed .upload-label { color: #fecaca; }

.danger-zone { margin-top: 1.2rem; border-top: 1px solid #7f1d1d; padding-top: 0.9rem; }

/* ---- People ---- */
.add-person { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.add-person input { flex: 1; min-width: 220px; }
.people-list { margin-top: 1rem; }
.person-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.person-email { flex: 1; min-width: 180px; word-break: break-all; }
.edit-link { font-size: 0.9rem; }
