/* Additive styles for the YT→MP3 page.
   Base reset, variables, typography, nav, and .container come from /style.css. */

:root {
  /* Map app variable names to the site's existing variables */
  --bg:         var(--background);
  --text:       var(--text-color);
  --muted:      var(--medium-gray);
  --blue-hover: var(--button-hover-bg);
  /* New variables not in the site stylesheet */
  --surface:    #ffffff;
  --surface2:   #E8F2FF;
  --border:     #C2D3FA;
  --success:    #22c55e;
  --error:      #e53e3e;
  --radius:     8px;
}

/* Make body a flex column so the footer stays pinned */
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Step nav ─────────────────────────────────────────────────────────────── */
.steps {
  border-bottom: 1px solid var(--border-color);
  background: var(--bg);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
.steps::-webkit-scrollbar { display: none; }

/* Inner wrapper aligns step items to the site's content width */
.steps-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  cursor: default;
}
.step-item.active { color: var(--text); border-bottom-color: var(--blue); }
.step-item.done   { color: var(--success); cursor: pointer; }
.step-item.done:hover { color: #16a34a; background: rgba(34,197,94,0.07); }

.step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}
.step-item.active .step-num { background: var(--blue); color: #fff; }
.step-item.done   .step-num { background: var(--success); color: #fff; }

/* ── Main content area ────────────────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 32px 20px 0;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  min-height: 0;
}

.step-panel { display: none; }
.step-panel.active { display: block; }

/* Step 3 fills all remaining viewport height so dl-bar anchors above footer */
#p3.step-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding-bottom: 0;
}

/* ── App buttons (distinct from site .button class) ──────────────────────── */
.btn {
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: var(--blue-hover); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

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

.btn-green { background: var(--success); }
.btn-green:hover:not(:disabled) { background: #16a34a; }

/* ── Loading / error ─────────────────────────────────────────────────────── */
.loading {
  display: none;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  margin-top: 18px;
  justify-content: center;
  font-size: 0.88rem;
}
.loading.active { display: flex; }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  background: rgba(229,62,62,0.08);
  border: 1px solid rgba(229,62,62,0.35);
  color: var(--error);
  padding: 11px 14px;
  border-radius: var(--radius);
  margin-top: 14px;
  font-size: 0.88rem;
  display: none;
  text-align: left;
}
.error-box.active { display: block; }

/* ── Step 1: URL input ───────────────────────────────────────────────────── */
.url-wrap {
  max-width: 580px;
  margin: 64px auto 0;
  text-align: center;
}
.url-wrap h2 {
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin-bottom: 6px;
  color: var(--dark-blue);
}
.url-wrap .sub { color: var(--muted); font-size: 0.95rem; margin-bottom: 28px; }
.input-row { display: flex; gap: 8px; }
.input-row input {
  flex: 1;
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 0;
  font-family: inherit;
}
.input-row input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(64,92,255,0.12);
}
.input-row input::placeholder { color: var(--muted); }

/* ── Step 2: YouTube matching progress ───────────────────────────────────── */
.match-wrap { max-width: 640px; margin: 0 auto; padding-top: 8px; }
.match-wrap h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 5px;
  color: var(--dark-blue);
}
.match-sub { color: var(--muted); font-size: 0.88rem; margin-bottom: 28px; }

.bar-track {
  background: var(--border);
  border-radius: 100px;
  height: 7px;
  overflow: hidden;
  margin-bottom: 8px;
}
.bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 100px;
  transition: width 0.4s ease;
}
.bar-label { text-align: right; font-size: 0.8rem; color: var(--muted); margin-bottom: 22px; }

.match-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 460px;
  overflow-y: auto;
  padding-right: 4px;
}
.match-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 0.83rem;
  box-shadow: 0 1px 3px rgba(19,27,114,0.06);
}
.match-art {
  width: 36px;
  height: 36px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface2);
}
.match-info { flex: 1; overflow: hidden; }
.match-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.match-artist { font-size: 0.74rem; color: var(--muted); }
.match-status {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--border);
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}
.match-status.ok   { background: rgba(34,197,94,0.15); color: var(--success); }
.match-status.miss { background: rgba(229,62,62,0.12); color: var(--error); }
.match-status.spin { background: transparent; }
.match-status.spin::after {
  content: "";
  display: block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.add-url-link {
  color: var(--blue);
  cursor: pointer;
  font-size: 0.72rem;
  text-decoration: underline;
  margin-left: 5px;
  display: none;
}
.add-url-link:hover { color: var(--blue-hover); }
.add-url-link.visible { display: inline; }

.manual-url-row { display: none; align-items: center; gap: 5px; margin-top: 6px; }
.manual-url-row.visible { display: flex; }

.manual-url-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border-color);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  outline: none;
  min-width: 0;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
.manual-url-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(64,92,255,0.12);
}
.manual-url-input::placeholder { color: var(--muted); }

.manual-url-apply {
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.manual-url-apply:hover { background: var(--blue-hover); }

.proceed-row { margin-top: 20px; display: flex; align-items: center; gap: 12px; }

/* ── Step 3: Video selection ─────────────────────────────────────────────── */
.sel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  flex-shrink: 0;
}
.sel-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--dark-blue);
}
.sel-header .sub { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar input[type="search"] {
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 7px 11px;
  border-radius: var(--radius);
  font-size: 0.82rem;
  outline: none;
  width: 180px;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
.toolbar input[type="search"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(64,92,255,0.12);
}
.toolbar input[type="search"]::placeholder { color: var(--muted); }
.toolbar .btn { padding: 7px 12px; font-size: 0.8rem; }

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-bottom: 8px;
}
.video-card {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(19,27,114,0.08);
  transition: border-color 0.18s, transform 0.15s, box-shadow 0.15s;
  user-select: none;
}
.video-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(19,27,114,0.14); }
.video-card.selected { border-color: var(--blue); }
.video-card.hidden { display: none; }

.v-thumb {
  position: relative;
  padding-bottom: 56.25%;
  background: var(--surface2);
  overflow: hidden;
}
.v-thumb img, .v-thumb .art-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preview-overlay {
  position: absolute;
  inset: 0;
  background: rgba(19,27,114,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.18s;
}
.v-thumb:hover .preview-overlay { opacity: 1; }

.preview-btn {
  background: rgba(255,255,255,0.9);
  color: var(--dark-blue);
  border: none;
  padding: 7px 13px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
}
.preview-btn:hover { background: var(--blue); color: #fff; }

.check-badge {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 22px;
  height: 22px;
  background: var(--blue);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.video-card.selected .check-badge { opacity: 1; transform: scale(1); }

.dur-badge {
  position: absolute;
  bottom: 5px;
  right: 5px;
  background: rgba(19,27,114,0.78);
  color: #fff;
  font-size: 0.68rem;
  padding: 2px 5px;
  border-radius: 4px;
  pointer-events: none;
}
.v-info { padding: 9px 11px 11px; }
.v-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 3px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.v-channel { font-size: 0.72rem; color: var(--muted); }

.video-card.no-match { opacity: 0.6; cursor: default; }
.video-card.no-match:hover { transform: none; box-shadow: 0 2px 6px rgba(19,27,114,0.08); }
.no-match-badge {
  position: absolute;
  inset: 0;
  background: rgba(211,231,255,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--error);
  font-weight: 600;
  pointer-events: none;
}

/* ── Card action buttons (retry / edit URL) ──────────────────────────────── */
.card-actions {
  display: flex;
  gap: 6px;
  padding: 6px 8px 8px;
  justify-content: flex-end;
}
.card-retry-btn,
.card-edit-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.card-retry-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
.card-edit-btn:hover  { background: var(--surface2); border-color: var(--blue); }
.card-retry-btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }

/* ── Card URL input row ───────────────────────────────────────────────────── */
.card-url-row {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 0 8px 8px;
}
.card-url-row.visible { display: flex; }
.card-url-input {
  flex: 1;
  min-width: 0;
  font-size: 0.75rem;
  padding: 5px 8px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.card-url-input:focus { border-color: var(--blue); }
.card-url-input.input-error { border-color: var(--error); }
.card-url-apply,
.card-url-cancel {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background 0.15s;
}
.card-url-apply:hover  { background: var(--blue); color: #fff; border-color: var(--blue); }
.card-url-cancel:hover { background: var(--error); color: #fff; border-color: var(--error); }

/* ── Retry-failed flash ───────────────────────────────────────────────────── */
@keyframes retry-flash {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 3px var(--error); }
}
.video-card.retry-failed { animation: retry-flash 0.5s ease; }

/* ── Download bar (step 3) — anchored at the bottom of the step panel ────── */
.dl-bar {
  flex-shrink: 0;
  background: rgba(211,231,255,0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-color);
  padding: 12px 24px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  /* break out of main's 20px side padding to go edge-to-edge */
  margin: 0 -20px;
}
.dl-bar.visible { display: flex; }
.dl-bar-left { font-size: 0.88rem; color: var(--muted); }
.dl-bar-left strong { color: var(--text); }

/* ── Step 4: Download progress ───────────────────────────────────────────── */
.progress-wrap { max-width: 680px; margin: 0 auto; padding-top: 8px; }
.progress-wrap h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 5px;
  color: var(--dark-blue);
}
.progress-sub { color: var(--muted); font-size: 0.88rem; margin-bottom: 28px; }

.songs-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}
.song-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 0.85rem;
  box-shadow: 0 1px 3px rgba(19,27,114,0.06);
}
.song-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--border);
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}
.song-icon.ok    { background: rgba(34,197,94,0.15); color: var(--success); }
.song-icon.error { background: rgba(229,62,62,0.12); color: var(--error); }
.song-icon.spin  { background: transparent; }
.song-icon.spin::before {
  content: "";
  display: block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.song-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

/* ── Step 5: Done ────────────────────────────────────────────────────────── */
.done-wrap { max-width: 520px; margin: 40px auto 0; text-align: center; }
.done-icon {
  width: 76px;
  height: 76px;
  background: rgba(34,197,94,0.12);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  margin: 0 auto 22px;
}
.done-wrap h2 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 7px;
  color: var(--dark-blue);
}
.done-wrap .sub { color: var(--muted); font-size: 0.92rem; margin-bottom: 30px; }
.done-note { font-size: 0.76rem; color: var(--muted); margin-top: 14px; line-height: 1.6; }
.done-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* ── Preview modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(19,27,114,0.6);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal-box {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
  max-width: 820px;
  box-shadow: 0 20px 60px rgba(19,27,114,0.25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.modal-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal-yt-link {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  text-decoration: none;
  padding: 3px 8px;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.modal-yt-link:hover {
  color: var(--dark-blue);
  border-color: var(--blue);
  background: var(--surface2);
  text-decoration: none;
}
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 3px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}
.modal-close:hover { color: var(--text); }
.modal-frame { position: relative; padding-bottom: 56.25%; background: var(--surface2); }
.modal-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  main { padding: 24px 14px 0; }
  .dl-bar { margin: 0 -14px; }
  .url-wrap { margin-top: 40px; }
  .url-wrap h2 { font-size: 1.5rem; }
  .input-row { flex-direction: column; }
  .video-grid { grid-template-columns: 1fr 1fr; }
  .sel-header { flex-direction: column; }
}
@media (max-width: 380px) {
  .video-grid { grid-template-columns: 1fr; }
}
