:root {
  --bg: #101218;
  --panel: #1a1d26;
  --panel-2: #262a37;
  --backdrop: #7a7f8c; /* fond gris moyen derrière les images : le graphite et le blanc s'y lisent */
  --text: #eef0f6;
  --muted: #8a90a3;
  --R: #f2483c;
  --B: #2f6fdf;
  --Y: #f7c331;
  --G: #2fb26b;
  --P: #8b5cf6;
  --W: #ece8df;
  --K: #3a3f4c;
  /* Nuances ombrées (minuscule = même teinte dans l'ombre) */
  --r: #a8281f;
  --b: #1b3d8f;
  --y: #c2860f;
  --g: #1b6e40;
  --p: #55339e;
  --w: #b3ad9f;
  --k: #24272f;
  /* Teintes supplémentaires (lumières et ombres mélangées, images de l'atelier) */
  --O: #f28c28;
  --M: #ff6fae;
  --C: #33c9dc;
  --N: #8a5a3c;
  --L: #a8d84a;
  --D: #222f6e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app {
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  position: relative;
}

.screen { height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* Carte des niveaux */
#menu { align-items: center; padding: 8vh 0 24px; gap: 8px; overflow-y: auto; }
#menu h1 { font-size: 44px; font-weight: 800; letter-spacing: 1px; }
.sub { color: var(--muted); margin-bottom: 32px; }
#level-list { display: grid; grid-template-columns: repeat(5, 58px); gap: 10px; }
.level-btn {
  height: 64px;
  border-radius: 6px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 20px;
  font-weight: 700;
}
.level-btn .st { font-size: 10px; color: var(--Y); letter-spacing: 0; }
.level-btn.locked { opacity: 0.3; }
#prefs { display: flex; gap: 10px; margin: -18px 0 18px; }
.pref { height: 36px; padding: 0 14px; border-radius: 18px; background: var(--panel); color: var(--muted); font-size: 14px; font-weight: 600; }
.pref.on { background: var(--panel-2); color: var(--text); }
.menu-title { font-size: 15px; color: var(--muted); font-weight: 600; margin: 22px 0 8px; }
#custom-list { display: flex; flex-direction: column; gap: 8px; width: 330px; max-width: 100%; }
.custom-btn {
  height: 48px; border-radius: 6px; background: var(--panel); padding: 0 14px;
  display: flex; align-items: center; justify-content: space-between; font-weight: 600;
}
.custom-btn .st { font-size: 12px; color: var(--Y); }
.custom-empty { color: var(--muted); font-size: 14px; text-align: center; }
.atelier-link {
  margin-top: 14px; width: 330px; max-width: 100%; height: 48px; border-radius: 6px;
  background: var(--text); color: var(--bg); font-weight: 700; text-decoration: none;
  display: flex; align-items: center; justify-content: center;
}
.off { color: var(--panel-2); }

/* En-tête */
header { display: flex; align-items: center; justify-content: space-between; height: 52px; }
#title { font-weight: 600; color: var(--muted); }
.icon { width: 44px; height: 44px; font-size: 28px; border-radius: 8px; }
.icon:active { background: var(--panel); }

/* Plateau + tapis (canvas) */
#stage { flex: 1; min-height: 0; position: relative; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Jetons */
.token {
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: rgba(0, 0, 0, 0.75);
}
.token.light { color: #fff; }
.c-R { background: var(--R); }
.c-B { background: var(--B); }
.c-Y { background: var(--Y); }
.c-G { background: var(--G); }
.c-P { background: var(--P); }
.c-W { background: var(--W); }
.c-K { background: var(--K); }
.c-r { background: var(--r); }
.c-b { background: var(--b); }
.c-y { background: var(--y); }
.c-g { background: var(--g); }
.c-p { background: var(--p); }
.c-w { background: var(--w); }
.c-k { background: var(--k); }

/* Pastilles liées : chaîne entre voisines (attente, colonnes), pastille vide en pâle */
.slot { position: relative; }
.slot.chain-right::after {
  content: '';
  position: absolute;
  right: -13px;
  top: 50%;
  width: 16px;
  height: 6px;
  margin-top: -3px;
  border-radius: 3px;
  background: repeating-linear-gradient(90deg, var(--text) 0 5px, transparent 5px 7px);
  z-index: 1;
}
.token.chain-down::after {
  content: '';
  position: absolute;
  bottom: -9px;
  left: 50%;
  width: 6px;
  height: 12px;
  margin-left: -3px;
  border-radius: 3px;
  background: repeating-linear-gradient(180deg, var(--text) 0 5px, transparent 5px 7px);
  z-index: 1;
}
.token.spent { opacity: 0.4; outline: 2px dashed var(--text); outline-offset: -2px; }

/* Mécaniques des files */
.token { position: relative; }
.token.mystery { background: var(--panel-2); color: var(--muted); }
.token.linked { box-shadow: 0 0 0 2px var(--text); }
.badge {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  padding: 2px 4px;
}
.badge svg { width: 11px; height: 11px; }
.badge.link { top: -6px; left: -6px; padding: 2px; }
.badge.lock { bottom: -6px; right: -10px; }
.badge.lock i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.token.locked { color: rgba(0, 0, 0, 0.38); }
.token.locked.light { color: rgba(255, 255, 255, 0.45); }
.column { position: relative; }
.column.keyed { outline: 2px dashed var(--text); outline-offset: -2px; }
.column.keyed .token { color: transparent !important; }
.col-key {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 2px;
  background: #fff;
  color: #101218;
  border-radius: 10px;
  padding: 3px 6px;
  font-size: 12px;
  font-weight: 800;
}
.col-key svg { width: 16px; height: 16px; }

/* Bonus */
#bonus-bar { display: flex; justify-content: center; gap: 8px; padding-top: 6px; }
.bonus {
  position: relative;
  width: 46px;
  height: 40px;
  border-radius: 6px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.bonus svg { width: 22px; height: 22px; }
.bonus.empty { opacity: 0.25; }
.bonus.active { background: var(--text); color: var(--bg); }
.bonus .count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  background: var(--Y);
  color: #000;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
#hint {
  position: absolute;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
}
.column.picking .token { outline: 2px solid var(--text); outline-offset: 2px; opacity: 1 !important; }
.chip { position: absolute; left: 0; top: 0; width: 34px; height: 34px; border-radius: 6px; background: var(--Y); color: #000; display: flex; align-items: center; justify-content: center; }
.chip svg { width: 20px; height: 20px; }

/* Bonus trouvé : étiquette au centre du plateau */
#toast {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--Y);
  color: #000;
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 4;
}
#toast svg { width: 34px; height: 34px; }
#toast span { display: flex; flex-direction: column; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
#toast b { font-size: 22px; text-transform: none; letter-spacing: 0; }
#toast.show { animation: toast 1.6s ease-out forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}
.bonus.pulse { animation: pulse 0.9s ease-out; }
@keyframes pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(247, 195, 49, 0.9); }
  30% { transform: scale(1.3); }
  100% { transform: scale(1); box-shadow: 0 0 0 16px rgba(247, 195, 49, 0); }
}

/* Pastilles en vol */
#fly { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.flyer { position: absolute; left: 0; top: 0; will-change: transform; }

/* Attente */
#info { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; padding: 8px 4px 6px; }
#wait { display: flex; justify-content: center; gap: 10px; padding-bottom: 12px; }
.slot {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px dashed var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.slot.full { border-style: solid; border-color: transparent; }
.slot .token { width: 48px; height: 48px; font-size: 18px; }
.slot.danger { border-color: var(--R); }

/* Files de jetons */
#queue { display: flex; justify-content: center; gap: 10px; padding: 2px 0 12px; height: 186px; }
/* Jusqu'à 5 colonnes : elles se partagent la largeur. */
.column {
  flex: 1 1 0;
  min-width: 0;
  max-width: 76px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  border-radius: 6px;
  background: var(--panel);
}
.column:active { background: var(--panel-2); }
/* Pile de pastilles : celles du bas dépassent et sont coupées, avec un fondu. */
.column .stack {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 0 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
}
.column .token.front { width: min(54px, calc(100% - 8px)); height: auto; aspect-ratio: 1; font-size: 20px; }
.column .token.next { width: min(34px, calc(70% - 4px)); height: auto; aspect-ratio: 1; font-size: 13px; }
/* Pastilles suivantes : vraie couleur (on ne doit pas les confondre avec une nuance ombrée), chiffre discret. */
.column .token.next { color: rgba(0, 0, 0, 0.38); }
.column .token.next.light { color: rgba(255, 255, 255, 0.45); }
.column .more { font-size: 12px; color: var(--muted); }
.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.pop { animation: pop 0.25s ease-out; }
@keyframes pop { 0% { transform: scale(0.4); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* Résultat */
#overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 9, 13, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.card { background: var(--panel); border-radius: 10px; padding: 28px 24px; width: 100%; max-width: 340px; text-align: center; }
.card h2 { font-size: 28px; margin-bottom: 8px; }
#result-stars { font-size: 40px; color: var(--Y); letter-spacing: 6px; min-height: 48px; }
#result-text { color: var(--muted); margin: 8px 0 22px; line-height: 1.4; }
.actions { display: flex; gap: 12px; }
.actions button { flex: 1; height: 50px; border-radius: 6px; background: var(--panel-2); font-weight: 600; }
.actions button.primary { background: var(--text); color: var(--bg); }
