/* Polices embarquées (pas d'appel à Google : marche hors ligne et dans l'appli) */
@font-face { font-family: 'Lilita One'; src: url('/fonts/lilita-one-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Nunito'; src: url('/fonts/nunito-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Nunito'; src: url('/fonts/nunito-800.woff2') format('woff2'); font-weight: 800; font-display: swap; }

:root {
  --ink: #3a2210;
  --brown: #8a5428;
  --card: #fffaf0;
  --card-edge: #d1bd92;
  --yellow: #ffd23f;
  --yellow-dark: #c99a00;
  --blue: #8fd3e8;
  --blue-dark: #4f9ab3;
  --glass: rgba(255, 255, 255, 0.82);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #a3d0e2;
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  overscroll-behavior: none;
}

/* Le jeu occupe tout l'écran ; le monde s'adapte au format. */
#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  container-type: size;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#stage > * {
  /* Unité d'interface : suit la taille de l'écran, plafonnée sur grand écran. */
  --u: min(1cqw, 0.62cqh, 6px);
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* HUD */

#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: calc(max(10px, env(safe-area-inset-right)) + 3 * 46px + 16px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  font-family: "Lilita One", sans-serif;
}
#hud[hidden] { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--glass);
  box-shadow: 0 3px 0 rgba(30, 70, 90, 0.18), 0 6px 18px rgba(30, 70, 90, 0.12);
  backdrop-filter: blur(6px);
  font-size: 20px;
  color: var(--ink);
  white-space: nowrap;
}
.pill[hidden] { display: none; }
.pill.level { background: var(--yellow); box-shadow: 0 3px 0 var(--yellow-dark), 0 6px 18px rgba(30, 70, 90, 0.12); }
.pill.score { margin-left: auto; }
.pill.streak { background: #9ef08a; box-shadow: 0 3px 0 #4caf50; }
.pill.streak.hot { animation: pulse 0.8s ease-in-out infinite; }
.roll-progress { display: inline-flex; gap: 3px; }
.roll-progress i {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: rgba(31, 90, 22, 0.25);
}
.roll-progress i.on { background: radial-gradient(circle, #5b4330 0 22%, #c99c66 23% 42%, #fdfdfd 44%); box-shadow: inset 0 0 0 1.5px #a9b4bd; }
.lives i.gain { animation: rollgain 0.9s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes rollgain {
  0% { transform: scale(0) rotate(-180deg); }
  60% { transform: scale(1.5) rotate(10deg); }
  100% { transform: scale(1) rotate(0); }
}

.tag {
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
}
.tag[hidden] { display: none; }

/* Rouleaux de PQ (vies) */
.lives { gap: 4px; padding: 0 10px; }
.lives i {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle, #5b4330 0 22%, #c99c66 23% 42%, #fdfdfd 44%);
  box-shadow: inset 0 0 0 2px #a9b4bd;
  transition: transform 0.25s, opacity 0.25s, filter 0.25s;
}
.lives i.lost { opacity: 0.35; filter: grayscale(1); transform: scale(0.8); }

#tools {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 6px;
  z-index: 6;
}

button.icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--glass);
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(30, 70, 90, 0.18);
  backdrop-filter: blur(6px);
  cursor: pointer;
}
button.icon[hidden] { display: none; }
button.icon svg { width: 22px; height: 22px; fill: currentColor; }
button.icon:hover { background: #fff; }
button.icon:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(30, 70, 90, 0.18); }
#btn-mute .off, #stage.muted #btn-mute .on { display: none; }
#stage.muted #btn-mute .off { display: block; }

/* Panneaux */

.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 56px 16px 24px;
  background: radial-gradient(circle at 50% 45%, rgba(12, 40, 52, 0.25), rgba(12, 40, 52, 0.6));
  backdrop-filter: blur(2px);
  text-align: center;
  z-index: 5;
  overflow-y: auto;
  overflow-x: hidden;
}
.panel[hidden] { display: none; }

.card {
  position: relative;
  background: var(--card);
  border-radius: 28px;
  padding: calc(9 * var(--u)) calc(7 * var(--u)) calc(6 * var(--u));
  width: min(92vw, 440px);
  margin: auto;
  box-shadow: 0 10px 0 var(--card-edge), 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

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

.logo {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -58%);
  font-size: 84px;
  line-height: 1;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.18));
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob {
  50% { transform: translate(-50%, -66%) rotate(-5deg); }
}
@keyframes pulse {
  50% { transform: scale(1.06); }
}

h1, h2 {
  font-family: "Lilita One", sans-serif;
  font-weight: 400;
  margin: 8px 0 10px;
  line-height: 0.95;
  color: var(--brown);
}
h1 {
  font-size: clamp(44px, 13vw, 72px);
  letter-spacing: 1px;
  text-shadow: 0 5px 0 #e4cfa3;
}
h2 { font-size: clamp(34px, 9vw, 48px); }

p { margin: 8px 0; font-size: 17px; font-weight: 600; }
.tagline { font-size: 19px; font-weight: 800; }
.howto { font-size: 14px; opacity: 0.7; margin-top: 14px; }
.best { font-family: "Lilita One", sans-serif; font-size: 18px; color: #2b6f8a; margin: 4px 0; }
.best:empty { display: none; }
.big { font-family: "Lilita One", sans-serif; font-size: 40px; color: var(--ink); margin: 4px 0; }
.score { font-family: "Lilita One", sans-serif; font-size: 22px; color: #2b6f8a; }
.newbest { font-family: "Lilita One", sans-serif; font-size: 22px; color: #2f9e44; animation: pulse 1s ease-in-out infinite; }
.newbest[hidden] { display: none; }

.buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px auto 12px;
  width: min(100%, 300px);
}

.btn {
  font-family: "Lilita One", sans-serif;
  font-size: 26px;
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 0 6px 0 var(--yellow-dark);
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--yellow-dark); }
.btn.secondary { background: var(--blue); box-shadow: 0 6px 0 var(--blue-dark); }
.btn.secondary:active { box-shadow: 0 1px 0 var(--blue-dark); }
.btn.ghost { background: transparent; box-shadow: none; font-size: 20px; color: var(--brown); padding: 4px; }
.btn.ghost:active { transform: translateY(2px); }

.lang { display: flex; justify-content: center; gap: 6px; margin-top: 14px; }
.lang button {
  font-family: "Lilita One", sans-serif;
  font-size: 15px;
  padding: 5px 12px;
  border: none;
  border-radius: 999px;
  background: #efe4cc;
  color: var(--brown);
  cursor: pointer;
}
.lang button.on { background: var(--brown); color: #fff; }

button:focus-visible { outline: 3px solid #2b6f8a; outline-offset: 3px; }

/* Petits écrans */
@media (max-width: 480px) {
  .pill { height: 34px; font-size: 17px; padding: 0 11px; }
  .lives i { width: 18px; height: 18px; }
  button.icon { width: 36px; height: 36px; }
  #hud { right: calc(max(10px, env(safe-area-inset-right)) + 3 * 42px + 8px); gap: 6px; }
  .pill.score { margin-left: 0; }
  .logo { font-size: 68px; }
  .btn { font-size: 23px; }
}

/* Étoiles du niveau */
.pill.stars { gap: 2px; padding: 0 10px; font-size: 20px; }
.pill.stars i { font-style: normal; color: rgba(58, 34, 16, 0.22); transition: transform 0.2s, color 0.2s; }
.pill.stars i.got { color: #f2b400; text-shadow: 0 2px 0 #a67c00; transform: scale(1.15); }

/* Menu : petits boutons */
.minis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 10px;
}
.mini {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 7px;
  border: none;
  border-radius: 16px;
  background: #efe4cc;
  color: var(--brown);
  box-shadow: 0 4px 0 #d6c39c;
  cursor: pointer;
  font-family: "Lilita One", sans-serif;
  font-size: 14px;
}
.mini span { font-size: 24px; line-height: 1.1; }
.mini b { font-weight: 400; }
.mini:hover { filter: brightness(1.04); }
.mini:active { transform: translateY(3px); box-shadow: 0 1px 0 #d6c39c; }
.badge {
  position: absolute;
  top: -6px;
  right: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #e63946;
  color: #fff;
  font-style: normal;
  font-size: 14px;
  line-height: 22px;
  animation: pulse 1s ease-in-out infinite;
}
.badge[hidden] { display: none; }
.gold { color: #c28d00 !important; }

/* Fin de partie : envoi du score */
.send { display: flex; gap: 8px; margin: 14px auto 4px; width: min(100%, 320px); }
.send input {
  flex: 1;
  min-width: 0;
  font: 800 17px "Nunito", sans-serif;
  padding: 10px 14px;
  border: 2px solid #d6c39c;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
}
.send input:focus { outline: none; border-color: #2b6f8a; }
.btn.small { font-size: 18px; padding: 8px 16px; box-shadow: 0 4px 0 var(--yellow-dark); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.status { font-size: 15px; min-height: 1.2em; color: #2b6f8a; margin: 4px 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 .btn { font-size: 20px; padding: 9px 10px; }

/* Réglages */
.settings { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 6px; text-align: left; }
.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 800; font-size: 17px; }
.settings .row[hidden] { display: none; }
.settings .lang { margin: 0; }
.toggle {
  min-width: 70px;
  font-family: "Lilita One", sans-serif;
  font-size: 16px;
  padding: 6px 14px;
  border: none;
  border-radius: 999px;
  background: #e2d6bd;
  color: var(--brown);
  cursor: pointer;
}
.toggle[aria-pressed="true"] { background: #9ef08a; color: #1f5a16; box-shadow: 0 3px 0 #4caf50; }

/* Collection */
.card.wide { width: min(94vw, 560px); }
h3 { font-family: "Lilita One", sans-serif; font-weight: 400; font-size: 20px; color: var(--brown); margin: 14px 0 8px; }
.preview { display: flex; justify-content: center; margin-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.look {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px 8px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: #f3ead7;
  color: var(--ink);
  font: 800 12px "Nunito", sans-serif;
  cursor: pointer;
}
.look.on { border-color: var(--yellow); background: #fff6d6; }
.look.locked { cursor: default; opacity: 0.55; }
.look.locked canvas { filter: grayscale(1) brightness(0.8); }
.look:not(.locked):hover { background: #fff6d6; }

/* Classement */
.tabs { display: flex; gap: 6px; justify-content: center; margin: 8px 0 12px; }
.tabs button {
  font-family: "Lilita One", sans-serif;
  font-size: 16px;
  padding: 7px 14px;
  border: none;
  border-radius: 999px;
  background: #efe4cc;
  color: var(--brown);
  cursor: pointer;
}
.tabs button.on { background: var(--brown); color: #fff; }
.board { list-style: none; margin: 0; padding: 0; max-height: min(46vh, 420px); overflow-y: auto; text-align: left; }
.board li {
  display: grid;
  grid-template-columns: 34px 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 12px;
  font-weight: 800;
}
.board li:nth-child(odd) { background: #f6eedd; }
.board li.me { background: #fff1b8; box-shadow: inset 0 0 0 2px var(--yellow); }
.board .rank { font-family: "Lilita One", sans-serif; color: var(--brown); text-align: center; }
.board li:nth-child(1) .rank { color: #c28d00; }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .lvl { font-size: 13px; color: #2b6f8a; }
.board .pts { font-family: "Lilita One", sans-serif; }

@media (max-width: 480px) {
  .mini { font-size: 12px; }
  .mini span { font-size: 21px; }
  .pill.stars { font-size: 17px; }
}

/* Mode infini */
.btn.endless {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
  background: #c6b0fa;
  box-shadow: 0 6px 0 #8a6fd1;
}
.btn.endless:active { box-shadow: 0 1px 0 #8a6fd1; }
.btn.endless small { font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 14px; opacity: 0.75; }
.btn.endless small:empty { display: none; }
.lives.infinite { gap: 8px; }
.lives.infinite b { font-size: 26px; line-height: 1; color: #6b4fc4; }
.lives.infinite span { font-size: 15px; }

/* Décors */
.grid.themes { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.look.theme canvas { border-radius: 10px; }

/* Appli Android : bouton du menu et panneau de téléchargement */
.btn.app {
  display: inline-block;
  margin-top: 6px;
  font-size: 19px;
  padding: 9px 20px;
  background: #3ddc84;
  color: #073b1d;
  text-decoration: none;
  box-shadow: 0 5px 0 #1f9d55;
}
.btn.app:active { box-shadow: 0 1px 0 #1f9d55; }
.btn.app[hidden] { display: none; }
#btn-app { font-size: 17px; padding: 8px 18px; white-space: nowrap; }
.app-text { margin: 6px 0 10px; font-weight: 700; }
.app-qr { margin: 4px 0 6px; }
.app-qr[hidden] { display: none; }
.app-qr img {
  display: block;
  width: 180px;
  height: 180px;
  margin: 0 auto 6px;
  border-radius: 14px;
  box-shadow: 0 0 0 4px #3ddc84;
}
.app-qr p { margin: 0 0 4px; font-family: "Lilita One", sans-serif; font-size: 18px; color: var(--brown); }
.app-direct { font-weight: 800; font-size: 15px; color: #1f7a45; }
.app-steps { margin: 14px auto 6px; padding-left: 22px; max-width: 380px; text-align: left; font-weight: 700; font-size: 15px; }
.app-steps li { margin: 4px 0; }
.app-steps[hidden] { display: none; }
