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

html, body {
  margin: 0;
  padding: 0;
  background: #1b6b32;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  max-width: 500px;
  margin: 0 auto;
  padding: 8px 4px calc(104px + env(safe-area-inset-bottom));
}

/* ===== Rangée du haut ===== */

#top-row {
  display: flex;
  gap: 4px;
  align-items: flex-start;
  margin-bottom: 14px;
}

#stock { position: relative; width: var(--cw); height: var(--ch); flex: none; }
#waste { position: relative; width: calc(var(--cw) * 1.7); height: var(--ch); flex: none; }
.spacer { flex: 1; }
#foundations { display: flex; gap: 4px; flex: none; }

.cardslot { position: relative; width: var(--cw); height: var(--ch); }

/* ===== Cartes ===== */

.card, .slot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  border-radius: calc(var(--cw) * 0.1);
}

.card.up {
  background: #fdfdf8;
  border: 1px solid #999;
  color: #1a1a2e;
  overflow: hidden;
}

.card.up.red { color: #c81e1e; }

/* Entete : le rang collé à gauche, le symbole collé à droite. */
.card .ce {
  position: absolute;
  top: calc(var(--cw) * 0.01);
  left: 0;
  right: 0;
  height: calc(var(--cw) * 0.54);
}

.card .cr {
  position: absolute;
  left: calc(var(--cw) * 0.06);
  top: 0;
  font-size: calc(var(--cw) * 0.48);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: calc(var(--cw) * -0.035);
}

/* Le 10 fait deux caractères : on le réduit pour qu'il n'écrase pas l'entête. */
.card .cr2 {
  font-size: calc(var(--cw) * 0.38);
  top: calc(var(--cw) * 0.04);
  letter-spacing: calc(var(--cw) * -0.05);
}

.card .cu {
  position: absolute;
  right: calc(var(--cw) * 0.06);
  top: calc(var(--cw) * 0.04);
  font-size: calc(var(--cw) * 0.4);
  line-height: 1.1;
}

/* As et 2-10 : gros symbole centré dans l'espace restant sous l'entête. */
.card .cs {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--cw) * 0.55);
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cw) * 0.78);
  line-height: 1;
}

/* Figures (V, D, R) : illustration SVG dans le bas de la carte. */
.card .cf {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 72%;
  object-fit: contain;
  object-position: bottom;
  pointer-events: none;
}

.card.back {
  background: repeating-linear-gradient(45deg, #3949ab, #3949ab 4px, #303f9f 4px, #303f9f 8px);
  border: 1px solid #263077;
}

.card.sel {
  outline: 5px solid #ffd54f;
  outline-offset: -3px;
}

/* Petit mouvement du coach : la carte du bon choix se soulève brièvement */
.card.nudge, .slot.nudge {
  animation: nudge-up 0.35s ease-in-out 2;
  z-index: 5;
}

@keyframes nudge-up {
  50% { transform: translateY(-10px); }
}

.slot {
  border: 1px dashed rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.12);
}

.slot.ghost, .slot.recycle {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 3px 5px;
  font-size: calc(var(--cw) * 0.5);
  color: rgba(255, 255, 255, 0.4);
}

.slot.recycle { color: rgba(255, 255, 255, 0.8); }

/* ===== Tableau ===== */

#tableau {
  display: flex;
  gap: 4px;
}

.t-col {
  position: relative;
  width: var(--cw);
  flex: none;
  min-height: var(--ch);
}

/* ===== Barre d'outils ===== */

#toolbar {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  background: #145126;
  border-radius: 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

#stats {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
}

#stats-links {
  display: flex;
  gap: 10px;
}

#guide-link,
#lang-link,
#site-link {
  color: rgba(255, 255, 255, 0.6);
  text-decoration: underline;
}

/* jackfortin.com s'ouvre en superposition, sans quitter la partie en cours. */
#site-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 400;
  background: #1a1a1a;
  flex-direction: column;
}

#site-overlay.visible {
  display: flex;
}

#site-overlay-header {
  flex-shrink: 0;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

#site-overlay-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  font-family: inherit;
  font-size: 14px;
  padding: 8px 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

#site-iframe {
  flex: 1;
  width: 100%;
  border: none;
}

#err-count {
  min-width: 22px;
  padding: 1px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: 700;
  text-align: center;
}

#toolbar button {
  flex: 1;
  font-size: 15px;
  padding: 10px 6px;
  border: none;
  border-radius: 8px;
  background: #2e7d32;
  color: #fff;
}

#toolbar button:active { background: #1b5e20; }

/* ===== Victoire ===== */

#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#win-overlay[hidden] { display: none; }

#win-box {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
}

#win-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
}

#win-sub {
  font-size: 15px;
  color: #333;
  margin-bottom: 16px;
}

/* Partie parfaite : zéro coup manqué, écran doré. */
#win-box.perfect {
  background: linear-gradient(160deg, #fffdf4, #fdf3d0);
  border: 2px solid #d4a017;
  box-shadow: 0 0 26px rgba(255, 200, 40, 0.75);
  animation: perfect-glow 1.6s ease-in-out infinite alternate;
}

#win-box.perfect #win-title { color: #9a6a00; }

@keyframes perfect-glow {
  from { box-shadow: 0 0 14px rgba(255, 200, 40, 0.45); }
  to { box-shadow: 0 0 34px rgba(255, 200, 40, 0.9); }
}

#win-box button {
  display: block;
  width: 100%;
  font-size: 16px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #2e7d32;
  color: #fff;
}

#win-box button + button { margin-top: 10px; }

#btn-win-restart { background: #1565c0; }

/* Fermer la boîte pour revenir à la table (annuler, remonter des coups).
   Bouton pleine largeur comme les deux autres : le × en coin passait
   inaperçu, surtout sur l'écran doré. */
#btn-win-close {
  background: #546e7a;
}

#btn-win-restart[hidden] { display: none; }

/* ===== Confirmation (remplace confirm() du navigateur) ===== */

#ask-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}

#ask-overlay[hidden] { display: none; }

#ask-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
}

#ask-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

#ask-box button {
  display: block;
  width: 100%;
  font-size: 16px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #2e7d32;
  color: #fff;
}

#ask-box button + button { margin-top: 10px; }

#btn-ask-cancel { background: #546e7a; }
