:root {
  --bg: #fff7ee;
  --ink: #3a2e39;
  --ink-soft: #8a7a85;
  --accent: #ff6b35;
  --accent-2: #ffa245;
  --accent-grad: linear-gradient(135deg, #ff6b35, #ffa245);
  --card: #ffffff;
  --line: #f0e2d2;
  --shadow: 0 12px 40px rgba(255, 107, 53, 0.12);
  --radius: 24px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  overflow-x: hidden;
}

.icon {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.blob {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  z-index: -1;
  pointer-events: none;
}
.blob-1 { width: 480px; height: 480px; background: #ffd9a8; top: -160px; right: -120px; }
.blob-2 { width: 420px; height: 420px; background: #ffc4b0; bottom: -140px; left: -140px; }

header { text-align: center; padding: 36px 20px 8px; }

h1 {
  font-family: "Fredoka", sans-serif;
  font-size: clamp(2rem, 5vw, 2.9rem);
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.version-badge {
  font-family: "Fredoka", sans-serif;
  font-size: 0.52em;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: var(--accent-grad);
  padding: 0.32em 0.55em 0.28em;
  border-radius: 0.45em;
  box-shadow: 0 5px 14px rgba(255, 107, 53, 0.4);
  transform: rotate(6deg) translateY(-0.35em);
  letter-spacing: 0.02em;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 26%;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 6px 18px rgba(255, 107, 53, 0.35);
}
.logo .icon { width: 0.85em; height: 0.85em; }

.tagline { color: var(--ink-soft); font-size: 1.15rem; margin: 8px 0 0; font-weight: 600; }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px clamp(20px, 3vw, 32px) 28px;
}

h2 {
  font-family: "Fredoka", sans-serif;
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.35);
}

.search-row { display: flex; gap: 12px; flex-wrap: wrap; }
.search-row input { flex: 1 1 260px; }

input[type="search"], input[type="url"] {
  width: 100%;
  padding: 15px 20px;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--ink);
  background: #fffdf9;
  border: 2px solid var(--line);
  border-radius: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255, 107, 53, 0.15); }

input.flash { animation: flash 0.9s ease; }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 rgba(255, 107, 53, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(255, 107, 53, 0); }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: "Fredoka", sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.6; cursor: wait; }

.btn-primary {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 6px 18px rgba(255, 107, 53, 0.35);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(255, 107, 53, 0.4); }

.btn-go {
  width: 100%;
  margin-top: 20px;
  padding: 18px;
  font-size: 1.3rem;
  background: var(--accent-grad);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255, 107, 53, 0.4);
}
.btn-go:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(255, 107, 53, 0.45); }

.btn-ghost {
  width: 100%;
  margin-top: 12px;
  background: transparent;
  color: var(--ink-soft);
  border: 2px solid var(--line);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.hint { color: var(--ink-soft); margin: 14px 0 0; font-weight: 600; }
.hint.error { color: #d64545; }

.field-label { display: block; font-weight: 700; margin-bottom: 10px; }
.field-label small { font-weight: 600; color: var(--ink-soft); }

#results-placeholder {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink-soft);
  font-weight: 600;
  opacity: 0.7;
}
#results-placeholder .icon { width: 44px; height: 44px; stroke-width: 1.6; }
#results-placeholder p { margin: 0; }

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  /* max-content : sinon les lignes se compressent pour tenir dans la hauteur
     contrainte du conteneur (min-size 0 à cause d'overflow:hidden sur .result) */
  grid-auto-rows: max-content;
  gap: 16px;
  margin-top: 20px;
}

.result {
  display: flex;
  flex-direction: column;
  background: #fffdf9;
  border: 2px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font-family: inherit;
  color: inherit;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  position: relative;
}
.result:hover { transform: translateY(-4px); box-shadow: 0 10px 26px rgba(58, 46, 57, 0.14); }
.result.selected { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(255, 107, 53, 0.2); }
.result.selected::after {
  content: "✓ Choisie";
  position: absolute;
  top: 10px;
  left: 10px;
  background: var(--accent-grad);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: 999px;
}

/* Hauteur fixe (pas d'aspect-ratio ni de padding %) : leur contribution à la
   hauteur intrinsèque des lignes de grille est nulle, ce qui écrase les cartes. */
.thumb-wrap { position: relative; width: 100%; height: 108px; flex-shrink: 0; background: #eee4d6; }
.thumb-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.duration {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(20, 15, 20, 0.85);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 8px;
}

.result-info { padding: 12px 14px 14px; }
.result-title {
  font-weight: 800;
  font-size: 0.98rem;
  line-height: 1.3;
  margin: 0 0 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-channel { color: var(--ink-soft); font-size: 0.9rem; font-weight: 700; margin: 0; }

.format-row { display: flex; gap: 14px; margin-top: 18px; flex-wrap: wrap; }

.format-pill {
  flex: 1 1 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 15px 12px;
  font-family: "Fredoka", sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  background: #fffdf9;
  border: 2px solid var(--line);
  border-radius: 18px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.pill-top { display: inline-flex; align-items: center; gap: 9px; }
.format-pill small { font-family: "Nunito", sans-serif; font-size: 0.85rem; color: var(--ink-soft); font-weight: 700; }
.format-pill:hover { transform: translateY(-2px); }
.format-pill.selected {
  border-color: var(--accent);
  background: #fff1e8;
  box-shadow: 0 0 0 4px rgba(255, 107, 53, 0.15);
}
.format-pill.selected small { color: var(--accent); }

footer {
  text-align: center;
  color: var(--ink-soft);
  font-weight: 700;
  padding: 0 20px 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
footer .heart { color: #e05555; fill: currentColor; stroke: none; }

/* ---------- Overlay de progression ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(46, 26, 18, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fade-in 0.25s ease;
}
.overlay[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  background: var(--card);
  border-radius: 30px;
  padding: 38px 32px 34px;
  width: min(430px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 30px 80px rgba(30, 15, 10, 0.4);
  animation: pop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

@keyframes pop-in {
  from { transform: scale(0.8) translateY(30px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.vinyl-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  margin: 0 auto 16px;
}

.ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 10; }
.ring-fg {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 754;
  stroke-dashoffset: 754;
  transition: stroke-dashoffset 0.5s ease;
}

.ring.indeterminate { animation: ring-spin 1.2s linear infinite; }
.ring.indeterminate .ring-fg { stroke-dashoffset: 565; transition: none; }
@keyframes ring-spin {
  from { transform: rotate(-90deg); }
  to { transform: rotate(270deg); }
}

.vinyl {
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background: repeating-radial-gradient(circle at 50% 50%, #1c1b20 0 2px, #29272e 2px 4px);
  box-shadow: inset 0 0 0 6px #121116, 0 10px 26px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: spin 2.4s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.vinyl-label {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle, #ff8c57, #e8590c);
  background-size: cover;
  background-position: center;
  border: 4px solid #f6f1e7;
  position: relative;
}
.vinyl-label::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f6f1e7;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.percent {
  font-family: "Fredoka", sans-serif;
  font-size: 2.4rem;
  font-weight: 700;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.1;
}

.status-text { font-weight: 800; font-size: 1.1rem; margin-top: 4px; }

.job-title {
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 1.2em;
}

.equalizer {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 7px;
  height: 38px;
  margin-top: 18px;
}
.equalizer span {
  width: 9px;
  height: 100%;
  border-radius: 6px;
  background: var(--accent-grad);
  animation: eq 0.9s ease-in-out infinite;
  transform-origin: bottom;
}
.equalizer span:nth-child(1) { animation-delay: 0s; }
.equalizer span:nth-child(2) { animation-delay: 0.15s; }
.equalizer span:nth-child(3) { animation-delay: 0.3s; }
.equalizer span:nth-child(4) { animation-delay: 0.45s; }
.equalizer span:nth-child(5) { animation-delay: 0.6s; }
.equalizer span:nth-child(6) { animation-delay: 0.75s; }
.equalizer span:nth-child(7) { animation-delay: 0.9s; }
@keyframes eq {
  0%, 100% { transform: scaleY(0.25); }
  50% { transform: scaleY(1); }
}

.big-icon {
  width: 68px;
  height: 68px;
  stroke-width: 2;
  animation: pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.big-icon.success { color: #2eab5c; }
.big-icon.failure { color: #d64545; }

.done-title {
  font-family: "Fredoka", sans-serif;
  font-size: 1.9rem;
  font-weight: 700;
  margin-top: 8px;
}
.done-hint { color: var(--ink-soft); font-weight: 700; margin: 10px 0 0; }

#done-filename { margin-top: 6px; }

.confetti {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  animation: confetti-fall linear forwards;
  pointer-events: none;
}
@keyframes confetti-fall {
  to { transform: translateY(560px) rotate(720deg); opacity: 0.2; }
}

/* ---------- Desktop : tout tient sur un seul écran ----------
   (min-height : sous 620px on laisse la page défiler, sinon le bas
   serait coupé et inaccessible) */

@media (min-width: 960px) and (min-height: 620px) {
  body {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  header { padding: 20px 20px 4px; }
  .tagline { font-size: 1rem; margin-top: 4px; }

  main {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 1200px;
    display: grid;
    grid-template-columns: 1.45fr 1fr;
    align-items: stretch;
    gap: 24px;
    padding: 18px 28px 14px;
  }

  .card {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #download-card { justify-content: flex-start; }

  #results-placeholder { display: flex; }
  #results-placeholder[hidden] { display: none; }

  .results {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 8px;
    align-content: start;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
  }
  .results::-webkit-scrollbar { width: 8px; }
  .results::-webkit-scrollbar-track { background: transparent; }
  .results::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
  .results::-webkit-scrollbar-thumb:hover { background: var(--accent-2); }

  footer { padding: 4px 20px 14px; font-size: 0.9rem; }
}

@media (max-width: 560px) {
  body { font-size: 16.5px; }
  .results { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .vinyl-wrap { width: 210px; height: 210px; }
  .vinyl { inset: 24px; }
}
