/* ============================================================
   Cube Rubik 3D — habillage
   ============================================================ */
:root {
  --fond1: #0b0e1a;
  --fond2: #1a1040;
  --verre: rgba(255, 255, 255, 0.07);
  --verre-fort: rgba(255, 255, 255, 0.12);
  --bord: rgba(255, 255, 255, 0.16);
  --texte: #eef0ff;
  --texte-doux: rgba(238, 240, 255, 0.65);
  --accent1: #7c4dff;
  --accent2: #00e5ff;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--texte);
  background:
    radial-gradient(1200px 800px at 72% -10%, #2c1a60 0%, transparent 60%),
    radial-gradient(1000px 700px at 8% 112%, #00344d 0%, transparent 55%),
    linear-gradient(160deg, var(--fond1), var(--fond2));
  user-select: none;
  -webkit-user-select: none;
}

#scene {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }

#confettis { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* ---------- En-tête ---------- */
#haut {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 16px 22px;
  z-index: 10;
  pointer-events: none;
  animation: descendre .7s ease both;
}
@keyframes descendre { from { transform: translateY(-16px); opacity: 0; } to { transform: none; opacity: 1; } }

#haut h1 { font-size: clamp(19px, 3.2vw, 27px); font-weight: 800; letter-spacing: .3px; text-shadow: 0 2px 14px rgba(0,0,0,.45); }
#haut h1 .degrade {
  background: linear-gradient(90deg, var(--accent1), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

#stats { display: flex; gap: 8px; pointer-events: auto; }
.stat {
  display: flex; align-items: center; gap: 7px;
  background: var(--verre);
  border: 1px solid var(--bord);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 18px rgba(0,0,0,.25);
}
.stat b { font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.stat span { filter: saturate(1.2); }

/* ---------- Fil des derniers coups ---------- */
#fil-historique {
  position: fixed; top: 76px;
  left: 0; right: 0; margin: 0 auto;
  width: max-content; max-width: 92vw;
  display: flex; gap: 5px; overflow: hidden;
  z-index: 9; pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; opacity: .85;
}
#fil-historique .coup {
  background: var(--verre);
  border: 1px solid var(--bord);
  border-radius: 7px;
  padding: 2px 8px;
  white-space: nowrap;
  animation: pop .18s ease;
}
#fil-historique .coup:nth-last-child(1) { border-color: rgba(124, 77, 255, .8); color: #d9c9ff; }

/* ---------- Boutons ---------- */
.btn {
  appearance: none; border: 1px solid var(--bord);
  background: var(--verre);
  color: var(--texte);
  font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 11px 18px; border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 6px 20px rgba(0,0,0,.28);
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
  touch-action: manipulation;
}
.btn:hover { background: var(--verre-fort); transform: translateY(-2px); box-shadow: 0 10px 26px rgba(0,0,0,.35); }
.btn:active { transform: translateY(0) scale(.96); }

.btn.primaire {
  background: linear-gradient(135deg, var(--accent1), #5a2ee0);
  border-color: rgba(255,255,255,.22);
  box-shadow: 0 8px 26px rgba(124, 77, 255, .45);
}
.btn.primaire:hover { box-shadow: 0 12px 32px rgba(124, 77, 255, .6); }

.btn.rond { width: 46px; height: 46px; padding: 0; font-size: 19px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }

#controles {
  position: fixed;
  left: 0; right: 0; margin: 0 auto;
  width: max-content; max-width: 94vw;
  bottom: 58px;
  display: flex; gap: 9px; flex-wrap: wrap; justify-content: center;
  z-index: 10;
  animation: monter .7s .15s ease both;
}
@keyframes monter { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }

#indice {
  position: fixed; bottom: 16px; left: 0; right: 0;
  text-align: center; font-size: 13px; color: var(--texte-doux);
  z-index: 9; pointer-events: none; padding: 0 12px;
}
#indice b { color: var(--texte); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 128px;
  left: 0; right: 0; margin: 0 auto;
  width: max-content; max-width: 92vw;
  background: rgba(20, 24, 44, .92);
  border: 1px solid var(--bord);
  border-radius: 999px;
  padding: 10px 20px; font-size: 15px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity .25s ease, transform .25s ease;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#toast.visible { opacity: 1; transform: translateY(0); }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  background: rgba(5, 8, 20, .62);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  padding: 18px;
}
.modal.ouvert { display: flex; }

.carte {
  position: relative;
  width: 100%; max-width: 600px; max-height: 86vh; overflow-y: auto;
  background: linear-gradient(165deg, rgba(30, 34, 62, .96), rgba(16, 18, 38, .96));
  border: 1px solid var(--bord);
  border-radius: 22px;
  padding: 28px 30px;
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  animation: carte .28s cubic-bezier(.34, 1.56, .64, 1) both;
}
@keyframes carte { from { transform: scale(.88) translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.carte h2 { font-size: 23px; margin-bottom: 14px; }
.carte section { margin: 16px 0; }
.carte h3 { font-size: 16px; margin-bottom: 7px; color: #cdbaff; }
.carte ul { list-style: none; }
.carte li { padding: 3px 0; color: var(--texte-doux); }
.carte li b, .carte p b { color: var(--texte); }
.carte p { color: var(--texte-doux); line-height: 1.65; font-size: 14.5px; }
.carte code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: rgba(124, 77, 255, .18);
  border: 1px solid rgba(124, 77, 255, .35);
  border-radius: 6px; padding: 1px 7px; font-size: 13px; color: #e4daff;
}
.carte .note { font-size: 13px; margin-top: 8px; }
.fermer {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--bord); background: var(--verre); color: var(--texte);
  font-size: 15px; cursor: pointer;
  transition: transform .12s ease, background .15s ease;
}
.fermer:hover { transform: rotate(90deg); background: var(--verre-fort); }

.notation { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; }
.puce { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; vertical-align: -1px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.p-u { background: #ffffff; } .p-d { background: #ffd500; }
.p-l { background: #ff5800; } .p-r { background: #b71234; }
.p-f { background: #009b48; } .p-b { background: #0046ad; }

/* ---------- Victoire ---------- */
.carte.victoire { text-align: center; max-width: 430px; }
.grosse-emoji { font-size: 64px; animation: bondir .7s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes bondir { from { transform: scale(0) rotate(-30deg); } to { transform: none; } }
.carte.victoire h2 { margin-bottom: 10px; }
.badge-record {
  display: none; margin: 0 auto 12px; width: fit-content;
  background: linear-gradient(135deg, #f7b733, #fc4a1a);
  border-radius: 999px; padding: 6px 18px;
  font-weight: 800; font-size: 15px;
  box-shadow: 0 6px 22px rgba(252, 138, 26, .45);
  animation: pop .4s .3s cubic-bezier(.34, 1.56, .64, 1) both;
}
.grille-victoire { display: flex; justify-content: center; gap: 12px; margin: 18px 0 22px; flex-wrap: wrap; }
.grille-victoire > div {
  display: flex; flex-direction: column; gap: 3px;
  background: var(--verre); border: 1px solid var(--bord);
  border-radius: 14px; padding: 12px 22px; min-width: 104px;
}
.grille-victoire .etq { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--texte-doux); }
.grille-victoire b { font-size: 21px; font-variant-numeric: tabular-nums; }
.rangee-boutons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  #haut { padding: 12px 14px; }
  .stat { padding: 6px 11px; font-size: 13px; }
  .stat b { min-width: 44px; }
  #controles { bottom: 52px; gap: 6px; }
  .btn { font-size: 13px; padding: 9px 11px; }
  .btn.rond { width: 40px; height: 40px; font-size: 16px; }
  #indice { font-size: 11.5px; bottom: 12px; }
  #fil-historique { top: 102px; font-size: 11.5px; }
  #toast { bottom: auto; top: 138px; }
  .carte { padding: 22px 20px; }
  .notation { grid-template-columns: 1fr; }
}
