/* Néo-brutalisme : aplats vifs, bordures épaisses, ombres dures décalées. */
:root {
  --bg: #fff4e0;      /* fond de page */
  --text: #111;       /* texte sur le fond */
  --line: #111;       /* bordures, ombres, visualiseur */
  --paper: #fff;      /* cartes neutres */
  --on-color: #111;   /* texte posé sur un aplat coloré */
  --track: #fff4e0;   /* fond des jauges */
  --yellow: #ffd23f;
  --pink: #ff6b9d;
  --cyan: #3de0ff;
  --green: #7dff8a;
  --disabled: #ddd;
  color-scheme: light;
}

/* Mode nuit : uniquement si l'utilisateur l'active avec le bouton (clair par défaut) */
:root[data-theme="dark"] {
  --bg: #16151c;
  --text: #f5efe2;
  --line: #f5efe2;
  --paper: #24232d;
  --track: #16151c;
  --yellow: #f5c518;
  --pink: #ff5c93;
  --cyan: #2fd3f5;
  --green: #5ef070;
  --disabled: #4a4955;
  color-scheme: dark;
}

:root {
  --border: 3px solid var(--line);
  --shadow: 6px 6px 0 var(--line);
  --shadow-sm: 3px 3px 0 var(--line);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden; /* tout tient dans l'écran : pas de scroll de page */
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.app > * { flex-shrink: 0; }

/* En-tête */
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
header h1 {
  margin: 0;
  font-family: "Archivo Black", "Space Grotesk", sans-serif;
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  line-height: 1;
}
header h1 span {
  display: inline-block;
  background: var(--pink);
  color: var(--on-color);
  border: var(--border);
  padding: 0 6px 2px;
  margin-left: 4px;
  transform: rotate(-3deg);
  box-shadow: var(--shadow-sm);
}
.actions { display: flex; gap: 10px; flex-shrink: 0; }
.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--paper);
  color: var(--text);
  border: var(--border);
  box-shadow: var(--shadow-sm);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.icon-btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); }
.icon-btn[hidden] { display: none; }
#install { background: var(--cyan); color: var(--on-color); }

/* Petit écran (≤ 350 px) : titre réduit pour laisser la place aux boutons */
@media (max-width: 350px) {
  header h1 { font-size: 1.25rem; }
  .icon-btn { width: 40px; height: 40px; }
}

/* Message temporaire, en bas au-dessus du bouton Écouter (position calculée en JS).
   Toucher ou glisser sur le côté / vers le bas pour le fermer. */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 120px;
  max-width: 448px;
  margin: 0 auto;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper);
  color: var(--text);
  border: var(--border);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.4;
  touch-action: none;           /* le glissement est géré par l'appli */
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.toast > span { flex: 1; }
.toast[hidden] { display: none; }
.toast.show { animation: toast-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes toast-in { from { transform: translateY(40px); opacity: 0; } }
.toast-action {
  flex-shrink: 0;
  padding: 6px 12px;
  font: 700 0.85rem "Space Grotesk", sans-serif;
  text-transform: uppercase;
  background: var(--yellow);
  color: var(--on-color);
  border: 3px solid var(--line);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.toast-action:active { transform: translate(3px, 3px); box-shadow: none; }
@media (prefers-reduced-motion: reduce) { .toast, .toast.show { transition: none; animation: none; } }

/* Pile de cartes : direct au-dessus, analyses passées derrière (glisser ou toucher).
   Seule la carte du dessus occupe de la place : celles du fond (et celles qui partent ou
   arrivent) s'alignent sur elle et passent sous le classement. */
.stack {
  position: relative;
  isolation: isolate;           /* toute la pile reste sous le classement */
  outline: none;
  touch-action: pan-y;          /* le glissement horizontal est géré par l'appli */
  user-select: none;
  -webkit-user-select: none;
}
.stack.has-history { cursor: grab; }
.stack.has-history:active { cursor: grabbing; }
.stack > .card {
  position: relative; /* pour que z-index ordonne aussi la carte du dessus */
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.3s;
}
.stack > .card:not([data-depth="0"]), .stack > .card.leaving, .stack > .card.incoming {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.card[data-depth="1"] { transform: translate(5px, 9px) rotate(2deg); box-shadow: var(--shadow-sm); }
.card[data-depth="2"] { transform: translate(-4px, 15px) rotate(-2deg); box-shadow: var(--shadow-sm); }
.card.leaving { z-index: 9 !important; pointer-events: none; }
.stack:focus-visible .card[data-depth="0"] { outline: 3px dashed var(--line); outline-offset: 5px; }
@media (prefers-reduced-motion: reduce) { .stack > .card { transition: none; } }

.card-top { display: flex; align-items: flex-start; gap: 8px; }
.card-top .family { margin-right: auto; }
.del {
  flex-shrink: 0;
  width: 30px;
  height: 26px;
  padding: 0;
  font: 700 1rem/1 "Space Grotesk", sans-serif;
  background: #fff;
  color: var(--on-color);
  border: 3px solid var(--on-color);
  cursor: pointer;
}
.del:active { transform: translate(2px, 2px); }
.result.past { background: var(--card-bg); }

/* Carte du résultat principal */
.result {
  background: var(--yellow);
  color: var(--on-color);
  border: var(--border);
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
}
.family {
  display: inline-block;
  margin: 0;
  min-height: 1.7em;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.family:not(:empty) {
  background: #fff;
  border: 3px solid var(--on-color);
  padding: 2px 8px;
}
.style {
  margin: 8px 0 10px;
  font-family: "Archivo Black", "Space Grotesk", sans-serif;
  font-size: clamp(1.7rem, 9vw, 2.6rem);
  line-height: 1.02;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  /* deux lignes max pour garder une hauteur stable */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.about { margin: 0 0 12px; font-size: 0.88rem; font-weight: 500; line-height: 1.4; }
.about[hidden] { display: none; }
.status {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  min-height: 1.2em;
  border-top: 3px solid var(--on-color);
  padding-top: 8px;
}

.progress { height: 14px; background: #fff; border: 3px solid var(--on-color); margin-top: 10px; }
.progress div { height: 100%; width: 0; background: var(--pink); transition: width 0.2s; }
.progress.hidden { display: none; }

/* Classement : une seule carte, lignes compactes. Prend la place restante
   et défile en interne seulement si l'écran est vraiment petit. */
.ranking {
  position: relative;
  z-index: 1; /* au-dessus des cartes du fond de la pile */
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  background: var(--paper);
  border: var(--border);
  box-shadow: var(--shadow-sm);
}
.ranking:empty { display: none; }
.ranking li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: baseline;
  padding: 7px 12px 9px;
}
.ranking li + li { border-top: 2px solid var(--line); }
.ranking .name { font-weight: 700; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking .name small {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-left: 8px;
  padding: 0 4px;
  border: 2px solid var(--line);
  vertical-align: 2px;
}
.ranking .pct { font-weight: 700; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.ranking .bar { grid-column: 1 / -1; height: 10px; background: var(--track); border: 2px solid var(--line); }
.ranking .bar div { height: 100%; background: var(--cyan); transition: width 0.6s ease; }
.ranking li:first-child .bar div { background: var(--pink); }

/* Visualiseur : poussé vers le bas, au-dessus du bouton */
#viz {
  width: 100%;
  height: 56px;
  display: block;
  margin-top: auto;
  color: var(--line);
  background: var(--paper);
  border: var(--border);
  box-shadow: var(--shadow-sm);
}
#viz[hidden] { display: none; }
#viz[hidden] + .listen { margin-top: auto; }

/* Bouton principal */
.listen {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 16px;
  background: var(--green);
  color: var(--on-color);
  border: var(--border);
  box-shadow: var(--shadow);
  font-family: "Archivo Black", "Space Grotesk", sans-serif;
  font-size: 1.2rem;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}
.listen:active:not(:disabled) { transform: translate(6px, 6px); box-shadow: 0 0 0 var(--line); }
.listen:disabled { background: var(--disabled); cursor: default; }
.listen .dot { width: 14px; height: 14px; background: var(--on-color); }
.listen[aria-pressed="true"] { background: var(--pink); }
.listen[aria-pressed="true"] .dot { animation: pulse 1s steps(2) infinite; }

@keyframes pulse { 50% { background: #fff; } }

footer { font-size: 0.7rem; font-weight: 500; line-height: 1.4; opacity: 0.8; }
footer a { color: inherit; font-weight: 700; }
