/* ============================================================
 * MELGuessr — charte graphique MEL
 * Rouge MEL #E30613 · Noir #231F20 · Blanc / gris très clair
 * ============================================================ */

:root {
  --mel-red: #e30613;
  --mel-red-dark: #b80510;
  --mel-red-soft: #fdecec;
  --mel-black: #231f20;
  --mel-ink: #1a1a1a;
  --mel-gray: #f5f5f3;
  --mel-gray-2: #e8e8e6;
  --mel-border: #dcdcd9;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(35, 31, 32, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--mel-ink);
  background: var(--mel-gray);
}

#app { height: 100%; }

/* ---------- boutons ---------- */
.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 700;
  padding: 12px 28px;
  min-height: 44px; /* cible tactile confortable (iOS HIG / Material 48dp) */
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--mel-red);
  color: #fff;
  box-shadow: 0 6px 18px rgba(227, 6, 19, 0.35);
}
.btn.primary:hover { background: var(--mel-red-dark); }
.btn.primary:disabled {
  background: var(--mel-gray-2);
  color: #9a9a96;
  cursor: not-allowed;
  box-shadow: none;
}
.btn.ghost {
  background: transparent;
  color: var(--mel-ink);
  border: 2px solid var(--mel-black);
}
.btn.ghost:hover { background: var(--mel-black); color: #fff; }
.btn.big { font-size: 18px; padding: 14px 34px; }

.linklike {
  background: none;
  border: none;
  color: var(--mel-red);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 0 4px;
}

/* ---------- écrans "page" (accueil, final, classement) ---------- */
.screen.home {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(227, 6, 19, 0.06), transparent),
    var(--mel-gray);
}

.home-card {
  width: min(560px, 100%);
  background: #fff;
  border: 1px solid var(--mel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 36px 30px;
  text-align: center;
}
.home-card.wide { width: min(680px, 100%); }

.home-logo {
  width: 220px;
  height: auto;
  margin-bottom: 6px;
}

.game-title {
  margin: 6px 0 4px;
  font-size: 44px;
  letter-spacing: -1px;
  color: var(--mel-black);
}
.game-title::first-letter { color: var(--mel-red); }

.tagline {
  margin: 4px 0 18px;
  color: #55524f;
  font-size: 17px;
  line-height: 1.45;
}

/* pseudo */
.pseudo-box { margin: 8px 0 4px; }
.pseudo-box label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #55524f;
  margin-bottom: 6px;
}
.pseudo-box input {
  width: 100%;
  max-width: 320px;
  font-size: 18px;
  padding: 12px 16px;
  border: 2px solid var(--mel-border);
  border-radius: 10px;
  text-align: center;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s ease;
}
.pseudo-box input:focus { border-color: var(--mel-red); }
.pseudo-box .hint { font-size: 13px; color: #8a8783; margin: 6px 0 0; }
.pseudo-line { font-size: 17px; margin: 4px 0; }
.pseudo-line strong { color: var(--mel-red); }

.record-line {
  margin: 10px 0 18px;
  font-size: 15px;
  color: #55524f;
}

.home-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 6px;
}

.attributions {
  font-size: 12.5px;
  color: #8a8783;
  text-align: center;
}

/* chargement */
.loading-card { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.loading-text { font-size: 18px; font-weight: 600; margin: 4px 0 0; }
.loading-progress { font-size: 14px; color: #8a8783; margin: 0; }

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 4px solid var(--mel-red-soft);
  border-top-color: var(--mel-red);
  animation: spin 0.9s linear infinite;
}
.spinner.small { width: 28px; height: 28px; border-width: 3px; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg { color: var(--mel-red); font-size: 16px; }

/* final */
.final-card { margin-top: 8px; }
.final-score {
  font-size: 52px;
  font-weight: 800;
  color: var(--mel-black);
  margin: 6px 0;
  letter-spacing: -1px;
}
.final-score span { font-size: 22px; color: #8a8783; font-weight: 600; }
.record-badge {
  display: inline-block;
  background: var(--mel-red);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 5px 14px;
  border-radius: 999px;
  margin: 2px 0 6px;
}
.rank-line { font-size: 17px; color: #55524f; margin: 6px 0 10px; }
.rank-line.ok { color: var(--mel-red); font-weight: 700; }
.rank-line.warn { color: #b8860b; }

.round-breakdown {
  list-style: none;
  margin: 8px auto 16px;
  padding: 0;
  max-width: 300px;
  border: 1px solid var(--mel-border);
  border-radius: 10px;
  overflow: hidden;
}
.round-breakdown li {
  display: flex;
  justify-content: space-between;
  padding: 7px 14px;
  font-size: 14px;
  color: #55524f;
}
.round-breakdown li + li { border-top: 1px solid var(--mel-gray-2); }
.round-breakdown li span:last-child { font-weight: 700; color: var(--mel-ink); }

/* classement */
.leaderboard { margin: 10px 0 16px; }
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
.lb-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #8a8783;
  padding: 8px 10px;
  border-bottom: 2px solid var(--mel-black);
}
.lb-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--mel-gray-2);
}
.lb-table tr.me td {
  background: var(--mel-red-soft);
  font-weight: 700;
}
.lb-table td.rank { width: 40px; color: #8a8783; font-weight: 700; }
.lb-table td.num { font-weight: 700; text-align: right; }
.lb-table td.date { color: #8a8783; font-size: 13px; text-align: right; }
.empty { color: #8a8783; font-size: 15px; line-height: 1.6; }

/* ============================================================
 * ÉCRAN JEU
 * ============================================================ */
.game { position: fixed; inset: 0; background: var(--mel-black); }

.pano-wrap { position: absolute; inset: 0; }
.pano {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: var(--mel-black);
}
/* viewer MapillaryJS : canvas WebGL plein cadre */
.pano .mapillary-viewer,
.pano canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.pano-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(35, 31, 32, 0.88);
  color: #fff;
  font-size: 16px;
  z-index: 5;
}

/* HUD */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.25);
  font-size: 15px;
}
.hud-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 17px;
  color: var(--mel-black);
}
.hud-brand img { width: 30px; height: 30px; }
.hud-round { font-weight: 700; color: var(--mel-red); }
.hud-moves {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--mel-gray);
  border-radius: 999px;
  padding: 4px 12px;
  white-space: nowrap;
}
.hud-moves.empty {
  background: var(--mel-red-soft);
  color: var(--mel-red-dark);
}
.hud-score { font-weight: 700; margin-left: auto; }
.hud-pseudo {
  color: #55524f;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hud-quit {
  border: none;
  background: var(--mel-gray);
  color: var(--mel-ink);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  flex: none;
}
.hud-quit:hover { background: var(--mel-red); color: #fff; }

/* minimap repliable */
.minimap-wrap {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  width: 380px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: width 0.25s ease, height 0.25s ease;
}
.minimap-wrap .guessmap { height: 280px; }
.minimap-actions { padding: 10px; }
.minimap-actions .validate { width: 100%; }

.minimap-wrap:not(.open) {
  width: 56px;
  height: 56px;
  cursor: pointer;
}
.minimap-wrap:not(.open) .guessmap,
.minimap-wrap:not(.open) .minimap-actions { display: none; }

.minimap-toggle {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 21;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: var(--mel-black);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}
.minimap-toggle:hover { background: var(--mel-red); }

/* pin de devinette */
.pin {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--mel-red);
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
.maplibregl-marker { cursor: pointer; }

/* lien "image illisible" */
.skip-link {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 20;
  border: none;
  background: rgba(35, 31, 32, 0.75);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.85;
}
.skip-link:hover { background: var(--mel-red); opacity: 1; }

/* ============================================================
 * ÉCRAN RÉSULTAT DE MANCHE
 * ============================================================ */
.screen.result {
  position: fixed;
  inset: 0;
  display: flex;
  background: var(--mel-gray);
}
.result-map { flex: 1 1 60%; position: relative; }
.result-panel {
  flex: 0 0 380px;
  max-width: 380px;
  background: #fff;
  border-left: 1px solid var(--mel-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 30px 28px;
  text-align: center;
}
.result-kicker {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mel-red);
}
.distance { margin: 4px 0; font-size: 46px; font-weight: 800; letter-spacing: -1px; }
.points { margin: 0; font-size: 20px; font-weight: 700; color: var(--mel-red); }
.total { margin: 6px 0 22px; font-size: 15px; color: #55524f; }

/* ============================================================
 * PHOTO MYSTÈRE — remplissage avec les points
 * ============================================================ */
.photo-card {
  width: 200px;
  margin: 14px auto 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.photo-stack {
  position: relative;
  aspect-ratio: 4 / 5;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--mel-border);
  box-shadow: var(--shadow);
  background: var(--mel-gray-2);
}
.photo-base,
.photo-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* version "vide" : désaturée et assombrie */
.photo-base {
  filter: grayscale(1) brightness(0.42) contrast(0.92);
}
/* version "pleine" : couleur, révélée de bas en haut via --fill */
.photo-fill {
  clip-path: inset(calc(100% - var(--fill, 0%)) 0 0 0);
  transition: clip-path 1.4s cubic-bezier(0.22, 1, 0.36, 1);
}
/* ligne « liquide » au niveau de remplissage */
.photo-line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--fill, 0%);
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--mel-red), transparent);
  box-shadow: 0 0 14px rgba(227, 6, 19, 0.65);
  transition: bottom 1.4s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}
.photo-card figcaption {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
}
.photo-hint {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-size: 11px;
  color: #55524f;
}
.photo-pct {
  font-weight: 800;
  font-size: 15px;
  color: var(--mel-red);
  font-variant-numeric: tabular-nums;
}
.photo-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--mel-ink);
}
.photo-credit {
  font-size: 11px;
  color: #8a8783;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--mel-black);
  color: #fff;
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  box-shadow: var(--shadow);
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- animation "shake" ---------- */
.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ============================================================
 * RESPONSIVE
 * ============================================================ */
@media (max-width: 720px) {
  .game-title { font-size: 34px; }
  .home-card { padding: 26px 20px; }
  .home-logo { width: 170px; }

  .minimap-wrap { width: min(300px, calc(100vw - 32px)); }
  .minimap-wrap .guessmap { height: 220px; }

  .hud { gap: 10px; font-size: 13px; }
  .hud-brand span { display: none; }
  .hud-pseudo { display: none; }
  .hud-moves { padding: 3px 9px; font-size: 12px; }
  .hud-quit { width: 40px; height: 40px; font-size: 16px; }
  .minimap-toggle { width: 40px; height: 40px; font-size: 19px; }
  .skip-link { padding: 10px 16px; font-size: 14px; }

  .screen.result { flex-direction: column; }
  /* mobile : la carte prend moins de place pour que le panneau (distance,
     photo, bouton) tienne dans l'écran ; overflow-y de sécurité si ça déborde */
  .result-map { flex: 1 1 auto; min-height: 45%; }
  .photo-card { width: 120px; margin: 8px auto 10px; }
  .result-panel {
    flex: 0 0 auto;
    max-width: none;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--mel-border);
    padding: 16px 18px;
    overflow-y: auto;
  }
  .distance { font-size: 34px; }
}

/* ============================================================
 * Feedback modal (bugs & suggestions) — pattern Ravito adapté MEL
 * ============================================================ */
.feedback-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(35, 31, 32, 0.55);
  padding: 20px;
}
.feedback-dialog {
  position: relative;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 440px;
  padding: 26px 24px 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.feedback-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: var(--mel-gray);
  color: var(--mel-ink);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}
.feedback-close:hover { background: var(--mel-red); color: #fff; }
.feedback-title {
  margin: 0 0 18px;
  font-size: 20px;
  color: var(--mel-black);
}
.feedback-form-group { margin-bottom: 14px; }
.feedback-label {
  display: block;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--mel-black);
}
.feedback-optional { font-weight: 400; color: #8a8783; }
.feedback-select,
.feedback-textarea,
.feedback-input {
  width: 100%;
  border: 1px solid var(--mel-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 15px;
  color: var(--mel-ink);
  background: var(--mel-gray);
}
.feedback-textarea { resize: vertical; min-height: 96px; }
.feedback-select:focus,
.feedback-textarea:focus,
.feedback-input:focus {
  outline: 2px solid var(--mel-red);
  outline-offset: -1px;
  background: #fff;
}
.feedback-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 4px;
}
.feedback-status { font-size: 13px; }
.feedback-status.success { color: #1a7f37; }
.feedback-status.error { color: var(--mel-red); }

/* bouton 💬 dans le HUD de jeu (même famille que .hud-quit) */
.hud-feedback {
  border: none;
  background: var(--mel-gray);
  color: var(--mel-ink);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  flex: none;
}
.hud-feedback:hover { background: var(--mel-red); color: #fff; }

/* petit lien discret sous les actions des écrans home/final */
.feedback-link {
  margin-top: 18px;
  background: none;
  border: none;
  color: #8a8783;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  padding: 8px;
}
.feedback-link:hover { color: var(--mel-red); }

@media (max-width: 640px) {
  .hud-feedback { width: 40px; height: 40px; font-size: 16px; }
  .feedback-dialog { padding: 22px 18px 16px; }
}

/* watchdog écran de chargement (API Mapillary lente) */
.loading-slow { margin-top: 18px; }
.loading-slow p {
  color: #8a8783;
  font-size: 14px;
  margin: 0 0 12px;
}

/* échec total du panorama d'une manche */
.pano-fail-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
