:root {
  --bg: #0b0d12;
  --bg-elev: #141824;
  --bg-elev-2: #1c2130;
  --border: #262c3d;
  --text: #e7ebf3;
  --text-dim: #8b93a7;
  --text-faint: #5a6178;
  --accent: #6ea8fe;
  --accent-2: #b892ff;
  --sung: #ffffff;
  --sung-glow: #8ec2ff;
  --danger: #ff6b6b;
  --ok: #46d19e;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(110, 168, 254, 0.10), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(184, 146, 255, 0.08), transparent 55%),
    var(--bg);
  background-attachment: fixed; /* keep gradients anchored, never scroll with content */
  color: var(--text);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  height: 100vh;
  height: 100dvh;
  overflow: hidden; /* app is viewport-locked; only the lyrics list scrolls */
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, 0.75);
  backdrop-filter: blur(10px);
  flex: 0 0 auto; /* fixed header — never scrolls away */
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  font-size: 30px;
  filter: drop-shadow(0 2px 8px rgba(110, 168, 254, 0.4));
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.2px;
}

.tagline {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

.url-form {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 280px;
  max-width: 620px;
}

#url-input {
  flex: 1;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#url-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.18);
}

button {
  font-family: inherit;
  cursor: pointer;
}

#load-btn {
  padding: 11px 22px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0d12;
  font-weight: 700;
  font-size: 14px;
  transition: transform 0.1s, filter 0.15s;
}

#load-btn:hover { filter: brightness(1.08); }
#load-btn:active { transform: translateY(1px); }

/* ---------- Layout ---------- */
.layout {
  flex: 1 1 auto;
  min-height: 0; /* allow children to own the scroll instead of growing the page */
  display: grid;
  grid-template-columns: minmax(340px, 440px) 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.player-panel {
  padding: 16px;
  align-self: start;
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Player ---------- */
.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

#player, #player iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  border: 0;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #10131c, #191d2b);
  color: var(--text-dim);
}

.placeholder.hidden { display: none; }

.placeholder-inner { text-align: center; }
.placeholder-icon {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  font-size: 20px;
  margin-bottom: 10px;
  padding-left: 4px;
}

/* ---------- Song meta ---------- */
.meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.meta-fields label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
}

.meta-fields input {
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.meta-fields input:focus {
  border-color: var(--accent);
}

.meta-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.btn-secondary {
  flex: 1;
  text-align: center;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}

.btn-secondary:hover {
  border-color: var(--accent);
  background: #232a3d;
}

.file-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.match-row {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
}

.match-row.hidden { display: none; }

#match-select {
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

/* ---------- Controls ---------- */
.controls {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.offset-control {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.offset-label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

.offset-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-nudge {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  min-width: 44px;
}

.btn-nudge:hover { border-color: var(--accent); }

.offset-value {
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  text-decoration: underline;
}
.btn-link:hover { color: var(--text); }

.btn-calibrate {
  margin-top: 14px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, color 0.15s;
}
.btn-calibrate:hover { border-color: var(--accent); }
.btn-calibrate.armed {
  border-color: var(--accent);
  background: rgba(110, 168, 254, 0.14);
  color: var(--accent);
  animation: cal-pulse 1.15s ease-in-out infinite;
}
@keyframes cal-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(110, 168, 254, 0.4); }
  50% { box-shadow: 0 0 0 7px rgba(110, 168, 254, 0); }
}

/* While arming a calibration, lyric lines become tap targets */
.lyrics.calibrating { cursor: crosshair; }
.lyrics.calibrating .lyric-line:not(.interlude):hover {
  color: var(--accent);
  background: rgba(110, 168, 254, 0.10);
  opacity: 1;
}

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ---------- Lyrics ---------- */
.lyrics-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

.lyrics-tabs {
  display: flex;
  gap: 6px;
  padding: 16px 20px 0;
  flex: 0 0 auto;
}
.lyrics-tabs.hidden { display: none; }

.lyrics-tabs .tab {
  padding: 8px 16px;
  border-radius: 9px 9px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, color 0.15s;
}
.lyrics-tabs .tab:hover { color: var(--text); }
.lyrics-tabs .tab.active {
  background: var(--bg-elev-2);
  color: var(--text);
  border-color: var(--border);
}
.lyrics-tabs .tab.hidden { display: none; }
.lyrics-tabs .tab.pending {
  color: var(--text-faint);
  cursor: default;
}
.lyrics-tabs .tab .tab-spinner {
  width: 11px;
  height: 11px;
  border: 2px solid var(--text-faint);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.lyrics-tabs .tab .src-lang {
  font-weight: 500;
  color: var(--text-faint);
  font-size: 11px;
}

.lyrics-status {
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  min-height: 20px;
  flex: 0 0 auto;
}

.lyrics-status.error { color: var(--danger); }
.lyrics-status.ok { color: var(--ok); }
.lyrics-status .spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--text-faint);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 7px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.lyrics {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* Small top pad (active line rides near the top early, then centres as the
     song builds); large bottom pad so the final lines can still reach centre. */
  padding: 11vh 40px 46vh;
  scroll-padding-top: 11vh;
  scroll-behavior: smooth;
  outline: none;
  /* Fade the top/bottom edges so lines ease in/out instead of butting against
     the status bar or the footer. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 8%, #000 90%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 8%, #000 90%, transparent 100%);
}

.lyrics::-webkit-scrollbar { width: 10px; }
.lyrics::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

.lyric-line {
  font-size: 26px;
  line-height: 1.35;
  font-weight: 700;
  color: var(--text-faint);
  margin: 0 0 18px;
  padding: 4px 8px;
  border-radius: 8px;
  transition: color 0.25s ease, opacity 0.25s ease, transform 0.25s ease, filter 0.25s ease;
  cursor: pointer;
  opacity: 0.55;
  transform-origin: left center;
  will-change: transform, opacity;
}

.lyric-line:hover { color: var(--text-dim); }

.lyric-line.past {
  color: var(--text-dim);
  opacity: 0.5;
}

.lyric-line.active {
  opacity: 1;
  transform: scale(1.03);
  color: var(--sung);
  filter: drop-shadow(0 2px 18px rgba(142, 194, 255, 0.28));
}

/* Karaoke sweep: a fill layer clipped to the text */
.lyric-line.active .fill,
.lyric-line .word.active .wfill {
  background: linear-gradient(90deg, var(--sung-glow), var(--sung));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lyric-line .base { color: inherit; }

/* Line-mode sweep uses a clipped overlay */
.lyric-line.sweep {
  position: relative;
}
.lyric-line .sweep-base { color: var(--text-dim); }
.lyric-line .sweep-fill {
  position: absolute;
  inset: 4px 8px;
  color: var(--sung);
  overflow: hidden;
  white-space: nowrap;
  width: 0%;
  pointer-events: none;
  filter: drop-shadow(0 0 12px rgba(142, 194, 255, 0.35));
}

/* Word-mode */
.lyric-line .word {
  color: var(--text-faint);
  transition: color 0.12s linear;
}
.lyric-line.active .word { color: var(--text-dim); }
.lyric-line .word.sung { color: var(--sung); }
.lyric-line .word.active {
  color: var(--sung);
  text-shadow: 0 0 16px rgba(142, 194, 255, 0.45);
}

/* Instrumental / intro interlude — a single compact indicator instead of dead space */
.lyric-line.interlude {
  cursor: pointer;
  margin: 0 0 18px;
  transform: none;
  filter: none;
}
.lyric-line.interlude .instrumental {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 26px;
  line-height: 1;
  color: var(--text-faint);
  transition: color 0.25s ease, transform 0.25s ease;
}
.lyric-line.interlude.active {
  opacity: 1;
  transform: none;
}
.lyric-line.interlude.active .instrumental {
  color: var(--accent);
  transform: scale(1.06);
  filter: drop-shadow(0 2px 16px rgba(110, 168, 254, 0.35));
}
.lyric-line.interlude.active .dot {
  animation: bob 1.15s ease-in-out infinite;
}
.lyric-line.interlude .dot:nth-child(2) { animation-delay: 0.18s; }
.lyric-line.interlude .dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes bob {
  0%, 100% { opacity: 0.4; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-5px); }
}

.plain-note {
  margin: 0 0 20px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.25);
  color: #ffb3b3;
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Footer ---------- */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  flex-wrap: wrap;
}
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto; /* let the whole page scroll when stacked */
  }
  .topbar {
    position: sticky;
    top: 0;
  }
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    overflow: visible;
  }
  .player-panel {
    align-self: stretch;
    max-height: none;
    overflow: visible;
  }
  .lyrics-panel {
    height: 72vh;
    height: 72dvh;
  }
  .lyrics { padding: 32vh 24px; }
  .lyric-line { font-size: 22px; }
}
