/* =====================================================================
   Mahjong — styles communs. Les couleurs viennent du thème actif
   (variables posées par app.js à partir de themes/<id>/theme.js).
   ===================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden; background: #0a2621; color: var(--texte, #f4ecd8);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; overscroll-behavior: none;
  display: flex; flex-direction: column; height: 100dvh;
}
button { font: inherit; color: inherit; }

#decor { position: fixed; inset: 0; background: var(--fond); z-index: 0; transition: opacity .4s; }
#decor::before { content: ""; position: absolute; inset: 0; opacity: .5;
  background:
    radial-gradient(circle at 50% 50%, var(--filet) 0 1px, transparent 1.5px) 0 0 / 22px 22px,
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.05) 0 1px, transparent 1.5px) 11px 11px / 22px 22px; }
#decor::after { content: ""; position: absolute; inset: 10px; border: 1px solid var(--filet); border-radius: 22px; opacity: .6; }
#particules { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

/* ---------- bandeau ---------- */
#hud {
  position: relative; z-index: 2; flex: none;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 12px) 6px calc(env(safe-area-inset-left) + 12px);
}
.pastille {
  justify-self: start; border: 1px solid var(--filet); background: var(--voile); color: var(--texte);
  border-radius: 999px; padding: 7px 13px; font-size: 13px; letter-spacing: .02em; white-space: nowrap;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
button.pastille { cursor: pointer; }
#btn-niveau b { color: var(--accent); font-weight: 600; }
#chrono {
  font-family: var(--police-titre); font-size: 25px; font-variant-numeric: tabular-nums; letter-spacing: .04em;
  color: var(--texte); text-shadow: 0 1px 8px rgba(0,0,0,.35);
}
.hud-droite { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
#restantes { font-variant-numeric: tabular-nums; min-width: 46px; text-align: center; }
.rond {
  width: 38px; height: 38px; flex: none; border-radius: 50%; border: 1px solid var(--filet); background: var(--voile);
  display: grid; place-items: center; cursor: pointer; padding: 0;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.rond svg { width: 20px; height: 20px; }
.rond:active, .pastille:active { transform: scale(.95); }

/* ---------- plateau ---------- */
#zone {
  position: relative; z-index: 1; flex: 1; min-height: 0;
  display: grid; place-items: center;
  padding: 4px calc(env(safe-area-inset-right) + 4px) 6px calc(env(safe-area-inset-left) + 4px);
}
#plateau { position: relative; }

.tuile {
  position: absolute; width: var(--l); height: var(--h); padding: 0; border: 0; cursor: pointer;
  border-radius: calc(var(--l) * .17); background: var(--cadre, var(--tuile-bord)); box-shadow: var(--tranche);
  transition: transform .12s ease-out; -webkit-tap-highlight-color: transparent; outline: none;
  isolation: isolate;   /* le voile d'une tuile bloquée ne doit pas déborder sur ses voisines */
}
/* l'illustration : un morceau de la planche du thème, sertie dans le cadre */
.tuile .face {
  position: absolute; inset: calc(var(--l) * .07); border-radius: calc(var(--l) * .11); pointer-events: none;
  background: var(--planche) no-repeat; background-size: calc(var(--colonnes) * 100%) calc(var(--rangees) * 100%);
  box-shadow: 0 0 0 1px rgba(0,0,0,.34), inset 0 0 0 1px rgba(255,255,255,.18);
}
/* reflet du cadre : arête claire en haut à gauche, sombre en bas à droite */
.tuile::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: inset 1.5px 1.5px 0 rgba(255,255,255,.8), inset -1px -1.5px 0 rgba(0,0,0,.22);
}
/* tuile bloquée (recouverte, ou serrée des deux côtés) : assombrie */
.tuile.prise::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1;
  background: rgba(10,12,26,.46);
}
/* couleurs de cadre, quand une même illustration existe en plusieurs couleurs :
   cadre teinté + jeton en coin (rond rouge, losange bleu, carré vert) */
.tuile[data-c="1"] { --cadre: linear-gradient(150deg, #ff7a70, #d92b2f); --jeton: #e5342f; }
.tuile[data-c="2"] { --cadre: linear-gradient(150deg, #6fb4ff, #1f6fe0); --jeton: #2478ea; }
.tuile[data-c="3"] { --cadre: linear-gradient(150deg, #6fe08f, #159a4b); --jeton: #19a552; }
.tuile:not([data-c="0"]) .face::after {
  content: ""; position: absolute; top: 5%; right: 7%; width: 27%; aspect-ratio: 1; border-radius: 50%;
  background: var(--jeton); box-shadow: 0 0 0 calc(var(--l) * .035) #fff, 0 1px 3px 1px rgba(0,0,0,.55);
}
.tuile[data-c="2"] .face::after { border-radius: 12%; transform: rotate(45deg) scale(.82); }
.tuile[data-c="3"] .face::after { border-radius: 12%; transform: scale(.9); }
.tuile:focus-visible::after { box-shadow: inset 0 0 0 2px var(--accent), 0 0 0 2px var(--accent); }
.tuile.refus { animation: refus .28s; }
.tuile.part { animation: retrait .45s ease-out forwards; }
.tuile.entree { animation: entree .5s cubic-bezier(.2,.8,.3,1) backwards; animation-delay: calc(var(--i) * 4ms); }
@keyframes retrait {
  30%  { transform: scale(1.12) translateY(-4%); filter: brightness(1.25); opacity: 1; }
  100% { transform: scale(.7) translateY(-18%); filter: brightness(2); opacity: 0; }
}
@keyframes refus { 25% { transform: translateX(-3px); } 50% { transform: translateX(3px); } 75% { transform: translateX(-2px); } }
@keyframes entree { from { opacity: 0; transform: translateY(-14px) scale(.92); } }

/* ---------- réserve : quatre cases ---------- */
#reserve {
  position: relative; z-index: 3; flex: none; display: flex; justify-content: center; gap: calc(var(--l) * .22);
  margin: 0 auto calc(env(safe-area-inset-bottom) + 12px); padding: calc(var(--l) * .2) calc(var(--l) * .26) calc(var(--l) * .32);
  border-radius: calc(var(--l) * .42); border: 1px solid var(--filet); background: var(--voile);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#reserve .case {
  position: relative; width: var(--l); height: var(--h); border-radius: calc(var(--l) * .17);
  border: 1.5px dashed var(--filet); background: rgba(0,0,0,.14);
}
#reserve .tuile {
  left: -1.5px; top: -1.5px; cursor: default; pointer-events: none; transform-origin: 0 0;
  transition: transform .24s cubic-bezier(.25,.8,.3,1);
}
#reserve.pleine { animation: refus .3s; border-color: #d9584a; }

/* ---------- feuilles (menu, fin de partie, question) ---------- */
dialog.feuille {
  border: 1px solid var(--filet); background: var(--panneau); color: var(--texte);
  width: min(100%, 520px); max-width: 100%; max-height: 90dvh; overflow: auto;
  margin: auto auto 0; border-radius: 24px 24px 0 0; border-bottom: 0;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: 0 -10px 50px rgba(0,0,0,.45);
}
dialog.feuille[open] { animation: monte .28s cubic-bezier(.2,.8,.3,1); }
dialog.feuille.centre, dialog.feuille.centre[open] { margin: auto; width: min(92vw, 380px); border-radius: 24px; border-bottom: 1px solid var(--filet); text-align: center; padding: 26px 22px 22px; animation-name: apparait; }
dialog::backdrop { background: var(--voile); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
@keyframes monte { from { transform: translateY(40px); opacity: 0; } }
@keyframes apparait { from { transform: scale(.94); opacity: 0; } }
@media (min-width: 640px) and (min-height: 560px) {
  dialog.feuille { margin: auto; border-radius: 24px; border-bottom: 1px solid var(--filet); }
}

.feuille h2 { font-family: var(--police-titre); font-weight: 600; font-size: 26px; margin: 0 0 4px; letter-spacing: .03em; color: var(--accent); }
.feuille h3 { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--texte-doux); margin: 22px 0 9px; }
.feuille p { margin: 6px 0; color: var(--texte-doux); }
.feuille .note { font-size: 12.5px; }
.entete { display: flex; align-items: center; justify-content: space-between; }
.action {
  display: block; width: 100%; margin-top: 12px; padding: 13px 16px; border-radius: 14px; cursor: pointer;
  border: 0; background: var(--accent); color: var(--accent-texte); font-weight: 650; font-size: 15.5px; letter-spacing: .01em;
}
.action.discret { background: transparent; color: var(--texte); border: 1px solid var(--filet); font-weight: 500; }
.action:active { transform: scale(.98); }

.niveaux { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.niveau {
  border: 1px solid var(--filet); background: transparent; border-radius: 14px; padding: 9px 4px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.niveau b { font-family: var(--police-titre); font-size: 20px; font-weight: 600; }
.niveau span { font-size: 12px; color: var(--texte-doux); }
.niveau.actif { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
.niveau.actif span { color: inherit; opacity: .8; }
.niveau:disabled { opacity: .35; cursor: default; }

.puces { display: flex; flex-wrap: wrap; gap: 8px; }
.puce { border: 1px solid var(--filet); background: transparent; border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 14px; }
.puce.actif { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); font-weight: 600; }

.son { display: flex; align-items: center; gap: 14px; }
.son input[type=range] { flex: 1; accent-color: var(--accent); height: 28px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats div { border: 1px solid var(--filet); border-radius: 14px; padding: 9px 2px 7px; }
.stats b { display: block; font-family: var(--police-titre); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11.5px; color: var(--texte-doux); }
.records { margin: 10px 0 0; padding: 0; list-style: none; font-size: 13.5px; color: var(--texte-doux); }
.records li { display: flex; justify-content: space-between; padding: 4px 2px; border-bottom: 1px dashed var(--filet); }
.records li:last-child { border-bottom: 0; }
.records span:last-child { font-variant-numeric: tabular-nums; color: var(--texte); }

.grand { font-family: var(--police-titre); font-size: 44px; font-variant-numeric: tabular-nums; color: var(--texte); margin: 8px 0 2px; line-height: 1.1; }
.insigne { display: inline-block; margin-top: 6px; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); font-size: 12.5px; letter-spacing: .06em; }

/* téléphone couché : bandeau resserré */
@media (max-height: 460px) {
  #hud { padding-top: calc(env(safe-area-inset-top) + 4px); padding-bottom: 2px; }
  #chrono { font-size: 19px; }
  .pastille { padding: 4px 11px; } .rond { width: 30px; height: 30px; }
}
@media (max-width: 360px) { #btn-niveau .nom { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .tuile.entree, dialog.feuille[open] { animation: none; }
}
