/* 2048 — identite visuelle.
   lf-shell.js pose l'habillage commun ; on le repeint ici, ecran par ecran
   (data-screen="home|pause|help|over|board"). Le jeu, lui, possede sa scene :
   bandeau, plateau, aide. */
:root {
  --nuit: #120d26;
  --nuit-2: #1d1640;
  --encre: #f4f1ff;
  --brume: #a99fd6;
  --or: #ffb547;
  --rose: #f15bb5;
  --cyan: #2fd3e0;
  --verre: rgba(32, 24, 66, 0.72);
  --trait: rgba(190, 170, 255, 0.18);

  /* le shell lit ces variables */
  --lf-bg: transparent;
  --lf-panel: var(--verre);
  --lf-ink: var(--encre);
  --lf-mute: var(--brume);
  --lf-accent: var(--or);
  --lf-accent-ink: #1b0f05;
  --lf-line: var(--trait);
  --lf-radius: 22px;

  --gap: clamp(7px, 2.2vmin, 13px);
  --taille: min(92vw, calc(100dvh - 235px), 500px);
  --police: 'Fredoka', 'Nunito', system-ui, sans-serif;
}

html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  background:
    radial-gradient(ellipse 80% 60% at 15% 0%, rgba(241, 91, 181, 0.22), transparent 60%),
    radial-gradient(ellipse 70% 60% at 100% 100%, rgba(47, 211, 224, 0.16), transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 10%, rgba(255, 181, 71, 0.14), transparent 60%),
    linear-gradient(160deg, var(--nuit-2), var(--nuit) 60%);
  background-attachment: fixed;
}
/* une aurore qui respire, tres lentement, derriere tout */
body::before {
  content: '';
  position: fixed;
  inset: -20%;
  background:
    radial-gradient(circle at 30% 40%, rgba(155, 93, 229, 0.20), transparent 35%),
    radial-gradient(circle at 70% 60%, rgba(241, 91, 181, 0.14), transparent 35%);
  animation: aurore 18s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes aurore {
  from { transform: translate3d(-4%, -2%, 0) rotate(0deg); }
  to   { transform: translate3d(4%, 3%, 0) rotate(8deg); }
}

/* ---------- habillage du shell ------------------------------------------ */
.lf-shell { font-family: var(--police); background: transparent; }
.lf-bar {
  border-bottom: 0;
  padding: 12px 16px;
  gap: 10px;
}
.lf-bar a, .lf-btn {
  font-family: var(--police);
  font-weight: 500;
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--trait);
  transition: transform .15s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.lf-bar a:hover, .lf-btn:hover {
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 181, 71, 0.6);
  transform: translateY(-1px);
}
.lf-btn:focus-visible, .lf-bar a:focus-visible { outline: 3px solid var(--or); outline-offset: 2px; }
.lf-title {
  font-size: 1.35rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--or), var(--rose));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lf-scores { gap: 8px; }
.lf-scores > div {
  min-width: 64px;
  padding: 6px 12px 5px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--trait);
  text-align: center;
}
.lf-scores b { font-size: 1.2rem; font-weight: 700; }
.lf-scores span { font-size: .62rem; color: var(--brume); }

.lf-veil { background: rgba(12, 8, 28, 0.62); backdrop-filter: blur(6px); }
.lf-card {
  background: linear-gradient(160deg, rgba(48, 36, 96, 0.88), rgba(24, 18, 52, 0.92));
  border: 1px solid var(--trait);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: 26px 22px;
}
.lf-card h2 { font-weight: 700; font-size: 1.9rem; letter-spacing: -0.01em; }
.lf-card p { color: var(--brume); }
.lf-row { gap: 10px; }
.lf-btn { padding: 10px 18px; font-size: 1rem; }
.lf-btn.primary {
  background: linear-gradient(135deg, var(--or), var(--rose));
  color: #fff;
  border: 0;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(80, 20, 40, 0.35);
  box-shadow: 0 10px 28px rgba(241, 91, 181, 0.35);
}
.lf-btn.primary:hover { box-shadow: 0 14px 34px rgba(241, 91, 181, 0.5); }
.lf-btn.lf-daily {
  background: linear-gradient(135deg, rgba(47, 211, 224, 0.28), rgba(155, 93, 229, 0.28));
  border-color: rgba(47, 211, 224, 0.55);
  font-weight: 600;
}
.lf-eyebrow { color: var(--or) !important; font-weight: 600; }
.lf-note a { color: var(--or); }

/* -- accueil : pas de carte, une affiche */
.lf-veil:has(.lf-card[data-screen="home"]) { background: transparent; backdrop-filter: none; }
.lf-card[data-screen="home"] {
  background: transparent;
  border: 0;
  box-shadow: none;
  max-width: 400px;
}
.lf-card[data-screen="home"] h2 {
  font-size: clamp(3.6rem, 16vw, 5.2rem);
  line-height: 1;
  margin: 2px 0 10px;
  background: linear-gradient(100deg, var(--or) 0%, #ffe08a 25%, var(--rose) 50%, var(--cyan) 75%, var(--or) 100%);
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: miroite 7s linear infinite;
  filter: drop-shadow(0 6px 24px rgba(241, 91, 181, 0.35));
}
@keyframes miroite { to { background-position: -300% 0; } }
.lf-card[data-screen="home"] > p:not(.lf-eyebrow):not(.lf-note) { font-size: 1.05rem; color: #d6cff5; }
.lf-card[data-screen="home"] .lf-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.lf-card[data-screen="home"] .lf-btn.primary,
.lf-card[data-screen="home"] .lf-btn.lf-daily { grid-column: 1 / -1; }
.lf-card[data-screen="home"] .lf-btn.primary { min-height: 58px; font-size: 1.25rem; }
.lf-card[data-screen="home"] .lf-row > :last-child:nth-child(even) { grid-column: 1 / -1; }

/* -- ecran de commandes */
.lf-help li { color: #ddd6fb; font-size: .95rem; }
.lf-keys kbd {
  font-family: var(--police);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  border-color: rgba(190, 170, 255, 0.35);
  color: var(--encre);
}

/* ---------- la scene de jeu ---------------------------------------------- */
.scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: var(--taille);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.scene.tire { cursor: grabbing; }

.hud { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.puce {
  font-size: .8rem;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--trait);
  color: #d6cff5;
  font-variant-numeric: tabular-nums;
}
.puce-mode { color: var(--or); border-color: rgba(255, 181, 71, 0.45); }

.plateau {
  position: relative;
  width: var(--taille);
  aspect-ratio: 1;
  padding: var(--gap);
  box-sizing: border-box;
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(58, 44, 118, 0.78), rgba(28, 20, 60, 0.9));
  border: 1px solid rgba(190, 170, 255, 0.22);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  outline: none;
  cursor: grab;
}
.plateau:focus-visible { box-shadow: 0 0 0 2px rgba(255, 181, 71, 0.45), 0 24px 60px rgba(0, 0, 0, 0.45); }
.fond {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  height: 100%;
}
.creux {
  border-radius: 14px;
  background: rgba(10, 6, 30, 0.38);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
}
.calque { position: absolute; inset: var(--gap); }

/* une tuile : la div glisse (transform), le span rebondit (animation) */
.tuile {
  --r: 0; --c: 0;
  position: absolute;
  top: 0; left: 0;
  width: calc((100% - 3 * var(--gap)) / 4);
  height: calc((100% - 3 * var(--gap)) / 4);
  transform: translate(calc(var(--c) * (100% + var(--gap))), calc(var(--r) * (100% + var(--gap))));
  transition: transform 115ms cubic-bezier(.2, .75, .3, 1);
  z-index: 1;
}
.tuile > span {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  overflow: hidden;
  font: 700 calc(var(--taille) * 0.115)/1 var(--police);
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 2px 6px rgba(20, 0, 40, 0.35);
  background: var(--fond-tuile);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28), inset 0 -4px 0 rgba(0, 0, 0, 0.14);
}
/* reflet vitre */
.tuile > span::before {
  content: '';
  position: absolute;
  inset: 0 0 52% 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0));
  border-radius: 14px 14px 40% 40%;
  pointer-events: none;
}
.tuile.d3 > span { font-size: calc(var(--taille) * 0.092); }
.tuile.d4 > span { font-size: calc(var(--taille) * 0.074); }
.tuile.d5 > span { font-size: calc(var(--taille) * 0.06); }

/* les paliers : de la nuit vers l'or, on voit sa progression sans lire */
.v2    { --fond-tuile: linear-gradient(145deg, #4a4f86, #3a3d6c); }
.v4    { --fond-tuile: linear-gradient(145deg, #5b5fb8, #4a4c98); }
.v8    { --fond-tuile: linear-gradient(145deg, #7d63f0, #6249d1); }
.v16   { --fond-tuile: linear-gradient(145deg, #a86cf0, #8a4fd8); }
.v32   { --fond-tuile: linear-gradient(145deg, #dc6be3, #b84cc6); }
.v64   { --fond-tuile: linear-gradient(145deg, #ff6fb0, #e04a93); }
.v128  { --fond-tuile: linear-gradient(145deg, #ff8a7a, #f0625c); }
.v256  { --fond-tuile: linear-gradient(145deg, #ffa24f, #f27f2e); }
.v512  { --fond-tuile: linear-gradient(145deg, #ffcd4f, #f5a623); }
.v1024 { --fond-tuile: linear-gradient(145deg, #f3f06b, #c9e04a); }
.v2048 { --fond-tuile: linear-gradient(120deg, #ffcf5a, #ff7ab8, #6ee7f0, #ffcf5a); }
.v4096 { --fond-tuile: linear-gradient(145deg, #35f0d0, #12b8e8); }
.vmax  { --fond-tuile: linear-gradient(145deg, #ffffff, #c9c3ff); }
.v512 > span, .v1024 > span, .vmax > span { color: #3b1d05; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4); }
.v128 > span, .v256 > span { box-shadow: 0 0 18px rgba(255, 140, 90, 0.45), 0 6px 14px rgba(0, 0, 0, 0.28), inset 0 -4px 0 rgba(0, 0, 0, 0.14); }
.v512 > span, .v1024 > span { box-shadow: 0 0 26px rgba(255, 210, 80, 0.55), 0 6px 14px rgba(0, 0, 0, 0.28), inset 0 -4px 0 rgba(0, 0, 0, 0.12); }
.v2048 > span, .brille > span {
  background-size: 300% 300%;
  animation: irise 4s ease-in-out infinite;
  box-shadow: 0 0 34px rgba(255, 140, 200, 0.7), 0 0 60px rgba(110, 231, 240, 0.35);
}
@keyframes irise {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* apparition, fusion, eclat */
.nouvelle > span { animation: apparait 190ms cubic-bezier(.3, 1.4, .5, 1) 70ms backwards; }
@keyframes apparait { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.fusion { z-index: 2; }
.fusion > span { animation: fusionne 210ms cubic-bezier(.3, 1.5, .5, 1); }
@keyframes fusionne { 0% { transform: scale(1); } 45% { transform: scale(1.2); } 100% { transform: scale(1); } }
.v2048.fusion > span { animation: fusionne 260ms cubic-bezier(.3, 1.5, .5, 1), irise 4s ease-in-out infinite; }
.eclat::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 18px;
  border: 3px solid rgba(255, 220, 140, 0.9);
  animation: onde 420ms ease-out forwards;
  pointer-events: none;
}
@keyframes onde { from { transform: scale(.85); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }

/* coup impossible : le plateau bute */
.bute-left  { animation: bute-left 180ms ease; }
.bute-right { animation: bute-right 180ms ease; }
.bute-up    { animation: bute-up 180ms ease; }
.bute-down  { animation: bute-down 180ms ease; }
@keyframes bute-left  { 40% { transform: translateX(-7px); } }
@keyframes bute-right { 40% { transform: translateX(7px); } }
@keyframes bute-up    { 40% { transform: translateY(-7px); } }
@keyframes bute-down  { 40% { transform: translateY(7px); } }

.plateau.fige .calque { filter: saturate(.55) brightness(.8); transition: filter .5s ease; }

/* +points qui s'envolent */
.gain { position: absolute; left: 0; right: 0; top: -6px; height: 0; pointer-events: none; z-index: 5; }
.envol {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, 0);
  font-weight: 700;
  font-size: 1.25rem;
  color: #fff;
  text-shadow: 0 2px 10px rgba(241, 91, 181, 0.8);
  animation: envol 850ms ease-out forwards;
}
.envol.gros { font-size: 1.7rem; color: #ffe08a; text-shadow: 0 2px 14px rgba(255, 181, 71, 0.9); }
@keyframes envol {
  from { transform: translate(-50%, 6px) scale(.8); opacity: 0; }
  20%  { opacity: 1; transform: translate(-50%, -6px) scale(1.05); }
  to   { transform: translate(-50%, -46px) scale(1); opacity: 0; }
}

/* 2048 atteint */
.victoire {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  border-radius: 24px;
  background: radial-gradient(circle, rgba(40, 20, 80, 0.82), rgba(18, 13, 38, 0.6));
  animation: entre 300ms ease-out;
  pointer-events: none;
  overflow: hidden;
}
.victoire.part { opacity: 0; transition: opacity .5s ease; }
.victoire strong {
  font-size: calc(var(--taille) * 0.2);
  line-height: 1;
  background: linear-gradient(100deg, var(--or), #ffe08a, var(--rose), var(--cyan), var(--or));
  background-size: 300% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: miroite 3s linear infinite, rebond 600ms cubic-bezier(.3, 1.6, .5, 1);
}
.victoire span { color: #efe9ff; font-size: 1rem; padding: 0 20px; }
@keyframes entre { from { opacity: 0; } }
@keyframes rebond { from { transform: scale(.3); } }
.confetti {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  background: hsl(var(--h), 90%, 65%);
  animation: confetti 1.6s cubic-bezier(.2, .7, .4, 1) var(--d) forwards;
  opacity: 0;
}
@keyframes confetti {
  0% { transform: translate(-50%, -50%) rotate(0); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--x) * var(--taille) * .55), calc(var(--taille) * .5)) rotate(540deg); opacity: 0; }
}

/* premiere partie : le geste montre une fois */
.coach {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 14%;
  border-radius: 24px;
  background: linear-gradient(180deg, transparent 35%, rgba(18, 13, 38, 0.8));
  pointer-events: none;
  transition: opacity .35s ease;
}
.coach.part { opacity: 0; }
.coach p { margin: 10px 24px 0; text-align: center; color: #fff; font-weight: 500; }
.coach-main {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.18), 0 6px 18px rgba(0, 0, 0, 0.4);
  animation: geste 1.8s ease-in-out infinite;
}
@keyframes geste {
  0%   { transform: translateX(-70px); opacity: 0; }
  20%  { opacity: 1; }
  70%  { transform: translateX(70px); opacity: 1; }
  100% { transform: translateX(70px); opacity: 0; }
}

/* l'aide sous la grille : le doigt sur mobile, le clavier ailleurs */
.aide { margin: 2px 0 0; font-size: .82rem; color: var(--brume); text-align: center; }
.aide kbd {
  font: 600 .74rem/1 var(--police);
  display: inline-block;
  min-width: 1.5em;
  padding: 3px 5px;
  margin: 0 1px;
  border-radius: 5px;
  border: 1px solid var(--trait);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--encre);
}
.aide-doigt { display: none; }
@media (hover: none) and (pointer: coarse) {
  .aide-doigt { display: inline; }
  .aide-clavier { display: none; }
}

/* ---------- accueil : la mini-grille -------------------------------------- */
.mini {
  --taille: 176px;
  --gap: 6px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  width: var(--taille);
  aspect-ratio: 1;
  padding: var(--gap);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(58, 44, 118, 0.85), rgba(28, 20, 60, 0.92));
  border: 1px solid rgba(190, 170, 255, 0.25);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4), 0 0 60px rgba(155, 93, 229, 0.25);
  transform: rotate(-6deg);
  animation: flotte 6s ease-in-out infinite;
}
@keyframes flotte {
  0%, 100% { transform: rotate(-6deg) translateY(0); }
  50% { transform: rotate(-4deg) translateY(-6px); }
}
.mini-creux { position: relative; border-radius: 8px; background: rgba(10, 6, 30, 0.38); aspect-ratio: 1; }
.mini .tuile { position: absolute; inset: 0; width: auto; height: auto; transform: none; transition: none; }
.mini .tuile > span { border-radius: 8px; font-size: calc(var(--taille) * 0.12); }
.mini .tuile.d3 > span { font-size: calc(var(--taille) * 0.095); }
.mini .tuile.d4 > span { font-size: calc(var(--taille) * 0.075); }
/* deux 2 qui se rejoignent sur la premiere ligne et deviennent 4 */
.mini-anim {
  position: absolute;
  top: var(--gap);
  left: var(--gap);
  right: var(--gap);
  height: calc((var(--taille) - 5 * var(--gap)) / 4);
}
.mini-anim .tuile { width: calc((100% - 3 * var(--gap)) / 4); right: auto; }
.mini-anim .a-gauche { left: 0; animation: mini-glisse 3.2s ease-in-out infinite; }
.mini-anim .a-droite { left: calc(3 * (100% - 3 * var(--gap)) / 4 + 3 * var(--gap)); animation: mini-glisse-d 3.2s ease-in-out infinite; }
.mini-anim .a-fusion { left: calc(3 * (100% - 3 * var(--gap)) / 4 + 3 * var(--gap)); opacity: 0; animation: mini-fusion 3.2s ease-in-out infinite; }
@keyframes mini-glisse {
  0%, 25% { transform: translateX(0); opacity: 1; }
  40% { transform: translateX(calc(3 * (100% + var(--gap)))); opacity: 1; }
  41%, 100% { transform: translateX(calc(3 * (100% + var(--gap)))); opacity: 0; }
}
@keyframes mini-glisse-d {
  0%, 40% { opacity: 1; }
  41%, 100% { opacity: 0; }
}
@keyframes mini-fusion {
  0%, 40% { opacity: 0; transform: scale(.6); }
  48% { opacity: 1; transform: scale(1.2); }
  56%, 88% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}

/* ---------- fin de partie -------------------------------------------------- */
.fin { --taille: 420px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.fin-tuile { position: relative; width: 104px; height: 104px; animation: rebond 500ms cubic-bezier(.3, 1.5, .5, 1); }
.fin-tuile > span { border-radius: 20px; }
.fin-legende { margin: 0 !important; font-size: .85rem; }

/* ---------- petits ecrans : la barre tient sur une ligne ------------------ */
.lf-bar a, .lf-menu { white-space: nowrap; }
@media (max-width: 520px) {
  .lf-bar { gap: 6px; padding: 10px; }
  .lf-title { display: none; }
  .lf-bar a, .lf-menu { padding: 6px 11px; font-size: .9rem; }
  .lf-scores { margin-left: auto; gap: 5px; }
  .lf-scores > div { min-width: 0; padding: 4px 9px 3px; border-radius: 12px; }
  .lf-scores b { font-size: 1rem; }
  .lf-scores span { font-size: .56rem; }
}

@media (prefers-reduced-motion: reduce) {
  body::before, .mini, .lf-card[data-screen="home"] h2 { animation: none; }
  .tuile { transition: none; }
  .tuile > span, .mini-anim .tuile, .coach-main, .victoire strong, .fin-tuile { animation: none !important; }
  .mini-anim { display: none; }
}
