:root {
  --night: #0f1a33;
  --night-2: #16264a;
  --felt: #0e5240;
  --felt-dark: #083428;
  --brass: #d4a94e;
  --brass-light: #f0cf7a;
  --brass-dark: #8a6a1f;
  --terracotta: #c4562b;
  --cream: #f6efe0;
  --muted: #aab6d3;
  --ok: #4fb38a;
  --danger: #d9534f;
  --panel: rgba(15, 26, 51, 0.94);
  --cw: clamp(92px, min(7.8vw, 15vh), 128px);   /* largeur d'une carte en main (grandit avec l'écran) */
  --radius: 14px;
  --font: 'Outfit', system-ui, sans-serif;
  --display: 'Aref Ruqaa', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--cream);
  background-color: var(--night);
  /* Motif zellige discret */
  background-image:
    radial-gradient(ellipse at 50% -10%, rgba(212, 169, 78, 0.18), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cg fill='none' stroke='%23d4a94e' stroke-opacity='.09' stroke-width='1.2'%3E%3Cpath d='M32 8l7 17 17 7-17 7-7 17-7-17-17-7 17-7z'/%3E%3Crect x='20' y='20' width='24' height='24' transform='rotate(45 32 32)'/%3E%3Ccircle cx='0' cy='0' r='6'/%3E%3Ccircle cx='64' cy='0' r='6'/%3E%3Ccircle cx='0' cy='64' r='6'/%3E%3Ccircle cx='64' cy='64' r='6'/%3E%3C/g%3E%3C/svg%3E");
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.grow { flex: 1; }

/* ---------- Boutons & champs ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 0.95rem;
  padding: 10px 16px; border-radius: 999px; cursor: pointer;
  color: var(--cream); background: rgba(255, 255, 255, 0.08);
  border: 1.5px solid rgba(212, 169, 78, 0.45);
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(212, 169, 78, 0.16); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn.brass {
  color: #2a1d00; border-color: var(--brass-light);
  background: linear-gradient(180deg, var(--brass-light), var(--brass) 60%, #b98a2e);
  box-shadow: 0 2px 0 var(--brass-dark), 0 6px 18px rgba(212, 169, 78, 0.25);
}
.btn.brass:hover:not(:disabled) { background: linear-gradient(180deg, #f7dc93, var(--brass-light) 60%, var(--brass)); }
.btn.terracotta { background: var(--terracotta); border-color: #e07a4f; box-shadow: 0 2px 0 #7d3015; }
.btn.terracotta:hover:not(:disabled) { background: #d4643a; }
.btn.ghost { background: transparent; border-color: rgba(255, 255, 255, 0.15); }
.btn.small { padding: 7px 12px; font-size: 0.85rem; }
.btn.big { padding: 13px 20px; font-size: 1.05rem; }

input {
  font: inherit; font-size: 1rem; width: 100%;
  padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid rgba(212, 169, 78, 0.35);
  background: rgba(0, 0, 0, 0.3); color: var(--cream);
}
input:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px rgba(212, 169, 78, 0.2); }
input::placeholder { color: rgba(246, 239, 224, 0.35); }

/* ---------- Accueil / salle d'attente : panneau en arche ---------- */
.screen.center { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.arch {
  position: relative; width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 14px;
  padding: 40px 28px 28px;
  background: linear-gradient(180deg, rgba(22, 38, 74, 0.97), rgba(15, 26, 51, 0.97));
  border: 2px solid var(--brass);
  border-radius: 210px 210px 18px 18px / 150px 150px 18px 18px;
  box-shadow: 0 0 0 6px rgba(15, 26, 51, 0.9), 0 0 0 7px rgba(212, 169, 78, 0.35), 0 30px 60px rgba(0, 0, 0, 0.5);
}
.hero-cards { position: relative; height: 112px; margin: -4px auto 0; width: 200px; }
.hero-cards .card { position: absolute; left: 50%; top: 0; --cw: 70px; margin-left: -35px; transform-origin: 50% 120%; }
.brand { text-align: center; }
.brand-ar { font-family: var(--display); font-size: 1.6rem; color: var(--brass); line-height: 1; }
h1 { margin: 0; font-family: var(--display); font-size: 3.2rem; line-height: 1.05; letter-spacing: 0.02em; }
h1 span { color: var(--brass); }
h2 { margin: 0; font-family: var(--display); font-size: 2rem; text-align: center; color: var(--brass-light); }
.tagline, .hint, .eyebrow { margin: 0; text-align: center; color: var(--muted); font-size: 0.92rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.2em; font-size: 0.75rem; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.8rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(212, 169, 78, 0.3); }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.35em; text-align: center; font-weight: 700; }
.join-row .btn { flex: none; }
.big-code { font-family: var(--display); font-size: 3.4rem; letter-spacing: 0.25em; text-align: center; color: var(--brass); line-height: 1; padding-left: 0.25em; }

.rules summary { cursor: pointer; color: var(--brass); font-size: 0.9rem; text-align: center; list-style: none; }
.rules summary::-webkit-details-marker { display: none; }
.rules ul { padding-left: 18px; margin: 10px 0 0; font-size: 0.85rem; line-height: 1.5; color: var(--muted); }
.rules b { color: var(--cream); }

.seat-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.seat-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(212, 169, 78, 0.15);
}
.seat-list .nm { flex: 1; font-weight: 500; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: rgba(212, 169, 78, 0.18); color: var(--brass-light); }
.tag.off { background: rgba(217, 83, 79, 0.2); color: #f1a19e; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 0.95rem; color: #fff;
  border: 2px solid var(--brass);
}

/* ---------- Partie ---------- */
#game { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.chip { font-size: 0.8rem; color: var(--muted); padding: 5px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); }
.chip b { color: var(--brass-light); letter-spacing: 0.05em; }

.seats { display: flex; gap: 8px; padding: 2px 12px 8px; overflow-x: auto; justify-content: center; flex-wrap: wrap; }
.seat {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px;
  border-radius: 999px; background: rgba(0, 0, 0, 0.3); border: 1.5px solid rgba(212, 169, 78, 0.2);
  font-size: 0.85rem; position: relative;
}
.seat.turn { border-color: var(--brass); box-shadow: 0 0 0 3px rgba(212, 169, 78, 0.25), 0 0 18px rgba(212, 169, 78, 0.35); }
.seat.turn .avatar { animation: pulse 1.6s ease-in-out infinite; }
.seat.off { opacity: 0.7; border-style: dashed; }
.seat .info { display: flex; flex-direction: column; line-height: 1.2; }
.seat .nm { font-weight: 600; }
.seat .sub { font-size: 0.72rem; color: var(--muted); }
.seat .sub .down { color: var(--ok); }
.seat .sub .away { color: #f1a19e; }
.mini-fan { display: flex; margin-left: 4px; }
.mini-fan .card { --cw: 20px; box-shadow: none; }
.mini-fan .card + .card { margin-left: -14px; }
.seat .kick { padding: 3px 8px; font-size: 0.72rem; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(212, 169, 78, 0.25); } }

.felt {
  flex: 1; min-height: 0; overflow-y: auto;
  margin: 0 10px; padding: 14px 12px;
  border-radius: 28px;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 255, 255, 0.07), transparent 65%),
    radial-gradient(ellipse at center, var(--felt), var(--felt-dark));
  border: 3px solid var(--brass-dark);
  box-shadow: inset 0 0 0 2px rgba(212, 169, 78, 0.35), inset 0 0 40px rgba(0, 0, 0, 0.45), 0 10px 30px rgba(0, 0, 0, 0.35);
  /* Pioche/défausse à gauche, combinaisons rangées par joueur à droite */
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px 20px; align-items: start; align-content: start;
}
.piles { display: flex; flex-direction: column; gap: 14px; align-items: center; position: sticky; top: 0; }
.pile-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pile { position: relative; width: clamp(80px, min(6vw, 12vh), 108px); aspect-ratio: 200 / 280; border-radius: 8px; cursor: pointer; }
.pile .card { --cw: 100%; width: 100%; position: absolute; inset: 0; }
.stock .card:nth-child(1) { transform: translate(-3px, 3px); }
.stock .card:nth-child(2) { transform: translate(-1.5px, 1.5px); }
.discard:empty { border: 2px dashed rgba(246, 239, 224, 0.25); }
.pile.active { animation: glow 1.4s ease-in-out infinite; border-radius: 8px; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 3px rgba(212, 169, 78, 0.9); } 50% { box-shadow: 0 0 0 3px rgba(212, 169, 78, 0.3), 0 0 22px rgba(212, 169, 78, 0.6); } }
.pile-label { font-size: 0.75rem; color: rgba(246, 239, 224, 0.75); }
.pile-label b { color: var(--brass-light); }

.melds { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.melds:empty::before {
  content: attr(data-empty); color: rgba(246, 239, 224, 0.35); font-size: 0.9rem;
  display: grid; place-items: center; min-height: 140px; border: 2px dashed rgba(246, 239, 224, 0.12); border-radius: 16px;
}
.meld-row {
  display: flex; gap: 12px; align-items: center; padding: 8px 12px; border-radius: 16px;
  background: rgba(0, 0, 0, 0.14); border: 1px solid rgba(212, 169, 78, 0.12);
}
.meld-row.mine { border-color: rgba(212, 169, 78, 0.4); background: rgba(212, 169, 78, 0.06); }
.meld-row .who {
  flex: none; width: 58px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: 0.72rem; color: rgba(246, 239, 224, 0.75); text-align: center; overflow: hidden; text-overflow: ellipsis;
}
.meld-list { display: flex; flex-wrap: wrap; gap: 8px 14px; min-width: 0; }
.meld {
  padding: 5px; border-radius: 10px; cursor: zoom-in;
  border: 1.5px solid transparent; transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.meld:hover { background: rgba(255, 255, 255, 0.05); }
.meld.target { cursor: pointer; }
.meld.target:hover { border-color: var(--brass); background: rgba(212, 169, 78, 0.12); transform: translateY(-2px); }
.meld .cards { display: flex; }
/* Éventail serré : seul le coin (valeur + symbole) dépasse, comme sur une vraie table */
.meld .card { --cw: clamp(56px, min(4.4vw, 8.6vh), 80px); }
.meld .card + .card { margin-left: calc(var(--cw) * -0.64); }
.meld .card .as { font-size: 0.55rem; bottom: -6px; }

/* Loupe sur une combinaison */
.meld-zoom {
  position: fixed; z-index: 80; pointer-events: none;
  padding: 12px 14px 10px; border-radius: 16px;
  background: rgba(15, 26, 51, 0.96); border: 1.5px solid var(--brass);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  animation: zoomIn 0.14s ease-out;
}
.meld-zoom .cards { display: flex; }
.meld-zoom .card { --cw: clamp(84px, min(7vw, 14vh), 120px); }
.meld-zoom .card + .card { margin-left: calc(var(--cw) * -0.28); }
.zoom-info { text-align: center; font-size: 0.75rem; color: var(--muted); margin-top: 10px; }
@keyframes zoomIn { from { opacity: 0; transform: scale(0.92); } }

/* ---------- Cartes ---------- */
.card {
  width: var(--cw); aspect-ratio: 200 / 280; flex: none; position: relative;
  border-radius: calc(var(--cw) * 0.07);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 3px 8px rgba(0, 0, 0, 0.25);
  user-select: none; -webkit-user-select: none;
}
.card svg { display: block; width: 100%; height: 100%; }
.card .as {
  position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  font-size: 0.62rem; font-weight: 700; white-space: nowrap; padding: 0 5px; border-radius: 6px;
  background: var(--night); color: var(--brass-light); border: 1px solid var(--brass);
}

/* ---------- Zone du joueur ---------- */
.rack {
  padding: 8px 0 max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.35) 30%);
}
.status { text-align: center; font-size: 0.95rem; padding: 4px 12px 8px; min-height: 1.6em; }
.status b { color: var(--brass-light); }
.status .warn { color: #f1a19e; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px; justify-content: center; align-items: center; }
.staging { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; padding: 0 12px 10px; }
.staging:empty { display: none; }
.group {
  padding: 6px 8px; border-radius: 12px; cursor: pointer;
  background: rgba(255, 255, 255, 0.05); border: 1.5px solid rgba(255, 255, 255, 0.15);
}
.group.ok { border-color: var(--ok); }
.group.bad { border-color: var(--danger); }
.group .cards { display: flex; }
.group .card { --cw: 56px; }
.group .card + .card { margin-left: -32px; }
.group .pts { font-size: 0.7rem; color: var(--muted); text-align: center; margin-top: 4px; }

.hand {
  display: flex; justify-content: center; align-items: flex-end;
  padding: 22px 12px 4px; min-height: calc(var(--cw) * 1.4 + 26px);
  touch-action: none;
}
.hand .card { cursor: grab; transition: transform 0.14s ease, box-shadow 0.14s; margin-left: var(--step, 0px); }
.hand .card:first-child { margin-left: 0; }
.hand .card:hover { transform: translateY(-6px); }
.hand .card.selected { transform: translateY(-20px); box-shadow: 0 0 0 3px var(--brass), 0 10px 18px rgba(0, 0, 0, 0.45); }
.hand .card.fresh::after {
  content: ''; position: absolute; inset: -3px; border-radius: inherit;
  border: 2px solid #7fd1ff; pointer-events: none;
}
.hand .card.dragging { opacity: 0.35; }
.drag-ghost { position: fixed; pointer-events: none; z-index: 100; transform: rotate(5deg) scale(1.05); }

.log {
  position: fixed; right: 12px; top: 52px; width: min(320px, calc(100vw - 24px)); max-height: 50vh; overflow-y: auto;
  background: var(--panel); border: 1px solid rgba(212, 169, 78, 0.3); border-radius: 14px;
  padding: 10px 14px; font-size: 0.85rem; line-height: 1.55; z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ---------- « À toi de jouer ! » ---------- */
.turn-pop {
  position: fixed; inset: 0; z-index: 70; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.turn-pop-inner {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--display); font-size: clamp(1.8rem, 4.5vw, 3rem); color: #2a1d00;
  padding: 14px 34px; border-radius: 999px;
  background: linear-gradient(180deg, var(--brass-light), var(--brass) 60%, #b98a2e);
  border: 2px solid #fff3cf;
  box-shadow: 0 0 0 6px rgba(212, 169, 78, 0.25), 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: turnPop 1.9s cubic-bezier(.2, .9, .3, 1.2) forwards;
}
.turn-star { display: inline-block; animation: spin 1.9s ease-out; }
@keyframes turnPop {
  0% { transform: scale(0.4) translateY(30px); opacity: 0; }
  15% { transform: scale(1.08); opacity: 1; }
  25% { transform: scale(1); }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9) translateY(-20px); opacity: 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Ma place clignote en doré et la zone de jeu « respire » tant que c'est mon tour */
.rack.my-turn { box-shadow: inset 0 3px 0 var(--brass), inset 0 24px 40px -24px rgba(212, 169, 78, 0.45); }
.rack.my-turn .status { animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: scale(1.04); } }
.piles.shake { animation: shake 0.6s ease-in-out 2; }
@keyframes shake {
  0%, 100% { transform: none; } 20% { transform: translateX(-8px) rotate(-2deg); }
  40% { transform: translateX(8px) rotate(2deg); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}
@media (prefers-reduced-motion: reduce) {
  .turn-pop-inner, .turn-star, .rack.my-turn .status, .piles.shake { animation-duration: 0.01s; }
}

.overlay {
  position: fixed; inset: 0; z-index: 60; padding: 16px;
  background: rgba(5, 10, 22, 0.7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.overlay .arch { max-width: 520px; max-height: 92vh; overflow-y: auto; }
.reveal { display: flex; flex-direction: column; gap: 4px; }
.reveal .who { font-size: 0.8rem; color: var(--muted); }
.reveal .cards { display: flex; flex-wrap: wrap; }
.reveal .card { --cw: 48px; margin-right: -18px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200;
  background: #2b1212; border: 1px solid var(--danger); color: #ffe3e1;
  padding: 10px 18px; border-radius: 999px; max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.toast.info { background: #13283f; border-color: var(--brass); color: var(--cream); }
.net-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 300; text-align: center;
  background: var(--terracotta); color: #fff; font-size: 0.85rem; font-weight: 600; padding: 6px;
}
.net-banner.parked {
  background: var(--night-2); border-bottom: 1.5px solid var(--brass);
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 8px;
}
.net-banner.parked .btn { padding: 4px 12px; }

@media (max-width: 600px) {
  :root { --cw: 74px; }
  .arch { padding: 34px 20px 22px; }
  h1 { font-size: 2.7rem; }
  .felt { margin: 0 6px; border-radius: 22px; padding: 10px 8px; }
  .felt { grid-template-columns: minmax(0, 1fr); }
  .piles { flex-direction: row; justify-content: center; position: static; gap: 22px; }
  .pile { width: 60px; }
  .meld .card { --cw: 46px; }
  .meld-row { padding: 6px 8px; gap: 8px; }
  .meld-row .who { width: 40px; font-size: 0.65rem; }
  .meld-zoom .card { --cw: 72px; }
  .btn { padding: 8px 12px; font-size: 0.88rem; }
  .actions .grow { display: none; }
  .seat { font-size: 0.78rem; padding-right: 10px; }
  .avatar { width: 28px; height: 28px; font-size: 0.8rem; }
}

/* ---------- Confettis ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti span {
  position: absolute; top: -40px; font-weight: 700; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translate(var(--drift), 110vh) rotate(var(--spin)); opacity: 0.9; }
}

/* ---------- Fermeture au Joker ---------- */
.joker-finish {
  position: fixed; inset: 0; z-index: 85; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(circle at 50% 45%, rgba(60, 20, 30, 0.85), rgba(5, 10, 22, 0.95) 70%);
  animation: jfFade 0.4s ease-out; overflow: hidden;
}
.joker-finish.out { animation: jfOut 0.5s ease-in forwards; }
.jf-rays {
  position: absolute; width: 160vmax; height: 160vmax; left: 50%; top: 45%;
  margin: -80vmax 0 0 -80vmax; opacity: 0.35;
  background: repeating-conic-gradient(from 0deg, rgba(240, 207, 122, 0.55) 0deg 8deg, transparent 8deg 22deg);
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 55%); mask-image: radial-gradient(circle, #000 0%, transparent 55%);
  animation: raysSpin 14s linear infinite;
}
.jf-card {
  position: relative; width: clamp(150px, 22vmin, 230px); aspect-ratio: 200 / 280;
  filter: drop-shadow(0 0 30px rgba(240, 207, 122, 0.8)) drop-shadow(0 20px 30px rgba(0, 0, 0, 0.5));
  animation: jfCard 1.3s cubic-bezier(.2, .8, .25, 1.1) both, jfFloat 2.6s ease-in-out 1.3s infinite;
}
.jf-card svg { width: 100%; height: 100%; display: block; }
.jf-title {
  position: relative; font-family: var(--display); font-size: clamp(2rem, 6vw, 4rem); line-height: 1.1; text-align: center;
  background: linear-gradient(180deg, #fff3cf, var(--brass-light) 45%, var(--brass) 70%, #b98a2e);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(240, 207, 122, 0.35);
  animation: jfTitle 0.8s cubic-bezier(.2, .9, .3, 1.3) 0.7s both;
}
.jf-sub { position: relative; color: var(--cream); font-size: 1.05rem; animation: jfFade 0.6s ease-out 1.1s both; }
@keyframes jfFade { from { opacity: 0; } }
@keyframes jfOut { to { opacity: 0; } }
@keyframes raysSpin { to { transform: rotate(360deg); } }
@keyframes jfCard {
  0% { transform: translateY(60vh) rotateY(0) scale(0.4); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translateY(0) rotateY(1080deg) scale(1); opacity: 1; }
}
@keyframes jfFloat { 50% { transform: translateY(-10px) rotate(-3deg); } }
@keyframes jfTitle { from { transform: scale(0.3); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .jf-rays, .jf-card, .confetti span { animation-duration: 0.01s !important; animation-iteration-count: 1 !important; }
}

/* ---------- 1re carte (premier tour) ---------- */
.first-wrap .pile { animation: none; }
.first-wrap .pile-label b { color: var(--ok); }

/* ---------- Feuille de score ---------- */
.scoresheet-wrap { overflow-x: auto; }
.scoresheet { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scoresheet thead th { padding: 0 6px 8px; font-weight: 600; font-size: 0.8rem; vertical-align: bottom; }
.scoresheet thead th .avatar { width: 26px; height: 26px; font-size: 0.75rem; margin: 0 auto 4px; }
.scoresheet thead th .nm { max-width: 90px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoresheet tbody th {
  width: 1%; white-space: nowrap; padding: 6px 8px 6px 0; text-align: left;
  font-size: 0.7rem; font-weight: 500; color: var(--muted);
}
.scoresheet td {
  border-left: 1px solid rgba(212, 169, 78, 0.25); border-top: 1px solid rgba(212, 169, 78, 0.12);
  padding: 6px 10px; min-width: 84px;
}
.scoresheet td .add, .scoresheet td .tot { display: inline-block; width: 50%; }
.scoresheet td .add { color: var(--muted); font-size: 0.85rem; }
.scoresheet td .tot { text-align: right; font-weight: 700; }
.scoresheet tr.start td .tot { color: var(--muted); font-weight: 500; }
.scoresheet .bar { display: inline-block; width: 26px; height: 3px; border-radius: 2px; background: var(--brass); vertical-align: middle; }
.score-panel { width: min(460px, calc(100vw - 24px)); max-height: 70vh; }
.score-panel h3 { margin: 4px 0 12px; font-family: var(--display); color: var(--brass-light); font-size: 1.3rem; display: flex; align-items: center; gap: 8px; }
.help-btn {
  font: inherit; font-size: 0.9rem; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 999px;
  background: transparent; color: var(--muted); border: 1px solid rgba(212, 169, 78, 0.35);
}
.help-btn:hover { color: var(--brass-light); border-color: var(--brass); }
.help-pop {
  position: fixed; z-index: 120; width: 240px; padding: 12px 14px; border-radius: 12px;
  background: var(--night-2); border: 1px solid var(--brass); color: var(--cream);
  font-size: 0.82rem; line-height: 1.6; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.help-pop b { color: var(--brass-light); }

/* ---------- Réglage : score maximum ---------- */
.setting {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(212, 169, 78, 0.2);
}
.setting .hint { width: 100%; text-align: left; font-size: 0.8rem; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; color: var(--cream); font-size: 0.95rem; flex-direction: row; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: relative; width: 42px; height: 24px; border-radius: 999px; flex: none;
  background: rgba(255, 255, 255, 0.15); border: 1px solid rgba(212, 169, 78, 0.35); transition: background 0.2s;
}
.switch .slider::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--cream); transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.switch input:checked + .slider { background: var(--brass); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(212, 169, 78, 0.35); }
.switch input:disabled + .slider { opacity: 0.6; }
.readonly .switch { cursor: default; }
.stepper { display: flex; align-items: center; gap: 4px; transition: opacity 0.2s; }
.stepper.off { opacity: 0.35; }
.stepper b { min-width: 52px; text-align: center; font-size: 1.3rem; color: var(--brass-light); font-variant-numeric: tabular-nums; }
.step-btn {
  width: 34px; height: 34px; border-radius: 50%; font: inherit; font-size: 1.2rem; font-weight: 700; line-height: 1; cursor: pointer;
  color: var(--cream); background: rgba(255, 255, 255, 0.08); border: 1.5px solid rgba(212, 169, 78, 0.45);
}
.step-btn:hover:not(:disabled) { background: rgba(212, 169, 78, 0.2); }
.step-btn:disabled { opacity: 0.35; cursor: default; }
.readonly .step-btn { display: none; }

/* ---------- Podium de fin de partie ---------- */
.podium-screen {
  position: fixed; inset: 0; z-index: 95; overflow-y: auto;
  display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(42, 60, 120, 0.96), rgba(5, 10, 22, 0.98) 70%);
}
.podium-rays {
  position: fixed; left: 50%; top: 40%; width: 150vmax; height: 150vmax; margin: -75vmax 0 0 -75vmax; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(240, 207, 122, 0.28) 0deg 7deg, transparent 7deg 20deg);
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 50%); mask-image: radial-gradient(circle, #000 0%, transparent 50%);
  opacity: 0;
}
.podium-screen.play .podium-rays { animation: raysSpin 18s linear infinite, fadeIn 1s ease 1.8s forwards; }
.podium-inner { position: relative; width: 100%; max-width: 560px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.podium-title {
  font-family: var(--display); font-size: clamp(2.2rem, 7vw, 3.4rem); line-height: 1.1; text-align: center;
  background: linear-gradient(180deg, #fff3cf, var(--brass-light) 45%, var(--brass) 75%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.podium-sub { color: var(--muted); text-align: center; }
.podium-screen.play .podium-title { animation: dropIn 0.7s cubic-bezier(.2, .9, .3, 1.3) 0.1s both; }
.podium-screen.play .podium-sub { animation: fadeIn 0.6s ease 0.4s both; }

.podium-stage { display: flex; align-items: flex-end; justify-content: center; gap: 10px; width: 100%; margin-top: 18px; min-height: 290px; }
.podium-col { flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; }
.podium-who { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 10px; position: relative; }
.podium-avatar { width: 58px; height: 58px; font-size: 1.5rem; border-width: 3px; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4); }
.place-1 .podium-avatar { width: 72px; height: 72px; font-size: 1.8rem; border-color: #f7d774; box-shadow: 0 0 24px rgba(247, 215, 116, 0.7); }
.podium-crown { position: absolute; top: -34px; font-size: 2rem; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4)); }
.podium-name { font-weight: 600; text-align: center; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-score { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.podium-block {
  width: 100%; border-radius: 12px 12px 4px 4px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 10px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 12px 30px rgba(0, 0, 0, 0.45);
  transform-origin: bottom;
}
.place-1 .podium-block { height: 150px; background: linear-gradient(180deg, #f7d774, #d4a94e 60%, #a8792a); }
.place-2 .podium-block { height: 110px; background: linear-gradient(180deg, #eef1f5, #b9c1cc 60%, #8b95a3); }
.place-3 .podium-block { height: 80px; background: linear-gradient(180deg, #f0b68a, #c47a45 60%, #8f522b); }
.podium-medal { font-size: 1.6rem; position: relative; z-index: 1; }
.podium-num { font-family: var(--display); font-size: 2rem; color: rgba(0, 0, 0, 0.45); position: relative; z-index: 1; line-height: 1; }

/* Chorégraphie : les marches montent (3e, 2e, 1er), puis chaque joueur tombe sur sa marche */
.podium-screen.play .place-3 .podium-block { animation: grow 0.6s cubic-bezier(.2, .8, .3, 1.15) 0.5s both; }
.podium-screen.play .place-2 .podium-block { animation: grow 0.6s cubic-bezier(.2, .8, .3, 1.15) 0.9s both; }
.podium-screen.play .place-1 .podium-block { animation: grow 0.7s cubic-bezier(.2, .8, .3, 1.15) 1.3s both; }
.podium-screen.play .place-3 .podium-who { animation: landOn 0.6s cubic-bezier(.3, 1.4, .5, 1) 1.0s both; }
.podium-screen.play .place-2 .podium-who { animation: landOn 0.6s cubic-bezier(.3, 1.4, .5, 1) 1.4s both; }
.podium-screen.play .place-1 .podium-who { animation: landOn 0.7s cubic-bezier(.3, 1.4, .5, 1) 1.9s both; }
.podium-screen.play .podium-crown { animation: crownIn 0.8s cubic-bezier(.2, .9, .3, 1.4) 2.5s both, crownBob 2.4s ease-in-out 3.3s infinite; }
.podium-screen.play .podium-rest,
.podium-screen.play .podium-actions,
.podium-screen.play .hint { animation: fadeIn 0.6s ease 2.6s both; }

@keyframes grow { from { transform: scaleY(0); } }
@keyframes landOn { 0% { transform: translateY(-140px); opacity: 0; } 60% { opacity: 1; } 100% { transform: none; opacity: 1; } }
@keyframes crownIn { from { transform: translateY(-40px) rotate(-200deg) scale(0); opacity: 0; } }
@keyframes crownBob { 50% { transform: translateY(-5px) rotate(-6deg); } }
@keyframes dropIn { from { transform: translateY(-30px) scale(0.8); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.podium-rest { list-style: decimal; margin: 4px 0 0; padding-left: 22px; color: var(--muted); align-self: center; }
.podium-rest:empty { display: none; }
.podium-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.podium-sheet { width: 100%; background: rgba(15, 26, 51, 0.9); border: 1px solid rgba(212, 169, 78, 0.3); border-radius: 14px; padding: 12px; }

@media (max-width: 600px) {
  .podium-stage { gap: 6px; min-height: 250px; }
  .podium-avatar { width: 46px; height: 46px; font-size: 1.2rem; }
  .place-1 .podium-avatar { width: 58px; height: 58px; }
  .place-1 .podium-block { height: 120px; }
  .place-2 .podium-block { height: 88px; }
  .place-3 .podium-block { height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  .podium-screen.play * { animation-duration: 0.01s !important; animation-delay: 0s !important; }
}

/* ---------- Langue ---------- */
.lang-float { position: fixed; top: max(12px, env(safe-area-inset-top)); inset-inline-end: 12px; z-index: 40; }
.lang-picker { position: relative; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--cream);
  padding: 7px 12px; border-radius: 999px;
  background: rgba(15, 26, 51, 0.85); border: 1.5px solid rgba(212, 169, 78, 0.45);
  transition: background 0.15s, border-color 0.15s;
}
.lang-btn:hover, .lang-picker.open .lang-btn { background: rgba(212, 169, 78, 0.16); border-color: var(--brass); }
.lang-btn .globe { font-size: 0.95rem; line-height: 1; }
.lang-btn .chev {
  width: 7px; height: 7px; border-right: 2px solid var(--brass); border-bottom: 2px solid var(--brass);
  transform: translateY(-2px) rotate(45deg); transition: transform 0.2s;
}
.lang-picker.open .lang-btn .chev { transform: translateY(1px) rotate(-135deg); }
.lang-picker.small .lang-btn { padding: 5px 10px; font-size: 0.8rem; }
.lang-menu {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; z-index: 130; min-width: 160px;
  display: flex; flex-direction: column; gap: 2px; padding: 6px;
  background: var(--night-2); border: 1.5px solid var(--brass); border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  opacity: 0; transform: translateY(-6px) scale(0.97); transform-origin: top right; pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
.lang-picker.open .lang-menu { opacity: 1; transform: none; pointer-events: auto; }
.lang-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer;
  font: inherit; font-size: 0.92rem; color: var(--cream); text-align: start;
  padding: 9px 12px; border: 0; border-radius: 11px; background: transparent;
}
.lang-item[lang="ar"] { font-family: 'Cairo', var(--font); }
.lang-item:hover, .lang-item:focus-visible { background: rgba(212, 169, 78, 0.16); outline: none; }
.lang-item.on { color: var(--brass-light); font-weight: 600; }
.lang-item.on::after { content: '✓'; color: var(--brass); }

/* Darija : police arabe, lecture de droite à gauche… */
html[lang="ar"] body, html[lang="ar"] .btn, html[lang="ar"] input, html[lang="ar"] .lang-btn { font-family: 'Cairo', var(--font); }
html[lang="ar"] .status, html[lang="ar"] .hint, html[lang="ar"] .rules ul { line-height: 1.8; }
/* La mise en page ne change pas en darija : seules les phrases se lisent de droite à gauche
   (sinon la ponctuation se place du mauvais côté : « !نوبتك »). */
html[lang="ar"] :is(.status, .hint, .tagline, .eyebrow, .toast, .net-banner, h2, .podium-title, .podium-sub,
  .jf-title, .jf-sub, .zoom-info, .pile-label, .seat .nm, .seat .sub, .meld-row .who, .switch-label,
  .divider span, .field span, .reveal .who, .rules summary, .btn, .turn-pop-inner span:last-child,
  .chip span, .lang-btn .cur, .lang-item, .podium-name, .scoresheet .nm) { unicode-bidi: plaintext; }
/* Blocs de texte longs : alignés à droite, comme un texte en arabe */
html[lang="ar"] :is(.rules ul, .log, .help-pop) { direction: rtl; text-align: right; }
html[lang="ar"] .rules ul { padding: 0 18px 0 0; }

/* Boutons − / + : même police et centrage dans toutes les langues (la police arabe les décalait vers le bas) */
.step-btn { display: inline-grid; place-items: center; padding: 0; font-family: var(--font) !important; line-height: 1; }

/* ---------- Mode duo ---------- */
:root { --team-0: #d4a94e; --team-1: #3fb0a0; }
#duoSetting.unavailable .switch { opacity: 0.55; }
.duo-teams { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.duo-team { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 12px; background: rgba(0, 0, 0, 0.2); border: 1.5px solid var(--team-color); }
.duo-team.team-0 { --team-color: var(--team-0); }
.duo-team.team-1 { --team-color: var(--team-1); }
.duo-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--team-color); }
.duo-player {
  display: flex; align-items: center; gap: 8px; width: 100%; cursor: pointer;
  font: inherit; font-size: 0.88rem; color: var(--cream); text-align: start;
  padding: 6px 8px; border-radius: 10px; border: 1px solid transparent; background: rgba(255, 255, 255, 0.05);
}
.duo-player .avatar { width: 26px; height: 26px; font-size: 0.75rem; }
.duo-player:hover:not(:disabled) { border-color: var(--team-color); background: rgba(255, 255, 255, 0.1); }
.duo-player:disabled { cursor: default; }
.duo-rules { width: 100%; }
.duo-rules summary { text-align: start; }

/* Couleur d'équipe : sièges, lignes de la table, feuille de score, podium */
.team-0 { --team-color: var(--team-0); }
.team-1 { --team-color: var(--team-1); }
.seat.team-0 .avatar, .seat.team-1 .avatar,
.meld-row.team-0 .avatar, .meld-row.team-1 .avatar { box-shadow: 0 0 0 2.5px var(--team-color); }
.meld-row.team-0, .meld-row.team-1 { border-inline-start: 3px solid var(--team-color); }
.seat .sub .mate { color: var(--team-color); font-weight: 600; }
.scoresheet .team-head { border-bottom: 2px solid var(--team-color); }
.team-avatars { display: flex; justify-content: center; margin-bottom: 4px; }
.team-avatars .avatar { margin: 0 -4px; }
.podium-pair { display: flex; justify-content: center; }
.podium-pair .podium-avatar { margin: 0 -6px; }
.podium-col.team-0 .podium-avatar, .podium-col.team-1 .podium-avatar { border-color: var(--team-color); }
.scoresheet .team-head .nm { max-width: 180px; white-space: normal; line-height: 1.25; }
