/* FreeCell : styles propres à l'outil. Cartes dessinées en CSS ; table et commandes tirées des variables du site. */
.o-freecell {
  min-width: 0;
  --o-freecell-tapis: color-mix(in srgb, var(--marque) 9%, var(--surface-2));
  --o-freecell-face: #ffffff;
  --o-freecell-trait: rgb(20 26 42 / 22%);
  --o-freecell-rouge: #b3122b;
  --o-freecell-noir: #141a2a;
  --o-freecell-ombre: 0 1px 2px rgb(20 26 42 / 25%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .o-freecell {
    --o-freecell-face: #e4e8f1; --o-freecell-trait: rgb(0 0 0 / 45%); --o-freecell-rouge: #b0102a; --o-freecell-noir: #0f1424;
    --o-freecell-ombre: 0 1px 3px rgb(0 0 0 / 60%);
  }
}
:root[data-theme="dark"] .o-freecell {
  --o-freecell-face: #e4e8f1; --o-freecell-trait: rgb(0 0 0 / 45%); --o-freecell-rouge: #b0102a; --o-freecell-noir: #0f1424;
  --o-freecell-ombre: 0 1px 3px rgb(0 0 0 / 60%);
}
.o-freecell [hidden] { display: none !important; }

.o-freecell-options { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 22px; margin-bottom: 8px; }
.o-freecell-numero { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; }
.o-freecell-numero label { display: flex; align-items: center; gap: 8px; font-size: .95rem; color: var(--texte); }
.o-freecell-numero input {
  width: 7.5em; min-height: 42px; padding: 6px 10px; border: 1px solid var(--bord); border-radius: var(--rayon-petit);
  background: var(--surface); color: var(--texte); font: inherit; font-variant-numeric: tabular-nums;
}
.atelier .o-freecell-numero .btn { min-height: 42px; }
.o-freecell-options label.case { display: flex; align-items: center; gap: 8px; font-size: .95rem; color: var(--texte); }
.o-freecell-options label.case input { width: 20px; height: 20px; accent-color: var(--marque); }

.o-freecell-barre { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 18px; margin: 10px 0 12px; }
.o-freecell-barre p { margin: 0; display: inline-flex; align-items: baseline; gap: 6px; color: var(--texte-2); font-size: .9rem; }
.o-freecell-barre strong { color: var(--texte); font: 700 1.2rem/1 var(--mono); font-variant-numeric: tabular-nums; }
.o-freecell-actions { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.atelier .o-freecell-actions .btn { min-height: 42px; }
.o-freecell .btn:disabled { opacity: .45; cursor: default; }
.o-freecell .btn:focus-visible, .o-freecell input:focus-visible { outline: 3px solid var(--marque); outline-offset: 2px; }

/* Table de jeu */
.o-freecell-table {
  --cw: 90px; --ch: 126px; --gap: 12px;
  position: relative; padding: 14px; border-radius: var(--rayon); background: var(--o-freecell-tapis); border: 1px solid var(--bord);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.o-freecell-haut, .o-freecell-colonnes { display: grid; grid-template-columns: repeat(8, var(--cw)); gap: var(--gap); justify-content: center; }
.o-freecell-haut { margin-bottom: calc(var(--gap) + 8px); }
/* Cases libres et fondations : un liseré distingue les deux groupes */
.o-freecell-case .o-freecell-vide { border-style: solid; border-width: 1.5px; background: color-mix(in srgb, var(--surface) 40%, transparent); }
.o-freecell-pile { position: relative; width: var(--cw); height: var(--ch); border-radius: calc(var(--cw) * .1); outline: none; cursor: pointer; }
.o-freecell-colonne { min-height: var(--ch); }
.o-freecell-pile:focus-visible { box-shadow: 0 0 0 3px var(--marque); }
.o-freecell-pile.indice, .o-freecell-carte.indice { box-shadow: 0 0 0 3px var(--ok-texte); }

.o-freecell-vide {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit;
  border: 2px dashed color-mix(in srgb, var(--texte) 22%, transparent); color: color-mix(in srgb, var(--texte) 30%, transparent);
  font: 700 calc(var(--cw) * .42)/1 var(--police);
}

/* Cartes */
.o-freecell-carte {
  position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch); border-radius: calc(var(--cw) * .1);
  background: var(--o-freecell-face); box-shadow: var(--o-freecell-ombre), inset 0 0 0 1px var(--o-freecell-trait);
  font-family: var(--police); line-height: 1; overflow: hidden;
}
.o-freecell-carte.rouge { color: var(--o-freecell-rouge); }
.o-freecell-carte.noire { color: var(--o-freecell-noir); }
.o-freecell-carte[data-mobile] { cursor: grab; touch-action: none; }
.o-freecell-coin { position: absolute; left: calc(var(--cw) * .07); top: calc(var(--cw) * .07); display: flex; flex-direction: column; align-items: center; gap: 1px; }
.o-freecell-coin.bas { left: auto; top: auto; right: calc(var(--cw) * .07); bottom: calc(var(--cw) * .07); transform: rotate(180deg); }
.o-freecell-coin .o-freecell-r { font-weight: 800; font-size: calc(var(--cw) * .22); letter-spacing: -.04em; }
.o-freecell-coin .o-freecell-s { font-size: calc(var(--cw) * .18); }
.o-freecell-milieu { position: absolute; left: 50%; top: 54%; transform: translate(-50%, -50%); font-size: calc(var(--cw) * .5); }
.o-freecell-milieu.as { font-size: calc(var(--cw) * .66); }
.o-freecell-figure {
  position: absolute; inset: calc(var(--cw) * .2) calc(var(--cw) * .22); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 2px solid currentColor; border-radius: calc(var(--cw) * .06);
  background: repeating-linear-gradient(135deg, transparent 0 4px, color-mix(in srgb, currentColor 10%, transparent) 4px 6px);
}
.o-freecell-figure .o-freecell-r { font: 800 calc(var(--cw) * .36)/1 Georgia, 'Times New Roman', serif; }
.o-freecell-figure .o-freecell-s { font-size: calc(var(--cw) * .2); }

/* Cartes compactes (téléphone) : rang et enseigne côte à côte en haut, grand symbole dessous */
.o-freecell-table.compact .o-freecell-coin { flex-direction: row; left: 3px; top: 3px; gap: 1px; align-items: baseline; }
.o-freecell-table.compact .o-freecell-coin .o-freecell-r { font-size: calc(var(--cw) * .36); }
.o-freecell-table.compact .o-freecell-coin .o-freecell-s { font-size: calc(var(--cw) * .3); }
.o-freecell-table.compact .o-freecell-coin.bas { display: none; }
.o-freecell-table.compact .o-freecell-milieu { top: 66%; font-size: calc(var(--cw) * .56); }
.o-freecell-table.compact .o-freecell-figure { inset: calc(var(--cw) * .48) calc(var(--cw) * .14) calc(var(--cw) * .1); border-width: 1.5px; flex-direction: row; gap: 0; }
.o-freecell-table.compact .o-freecell-figure .o-freecell-r { font-size: calc(var(--cw) * .32); }
.o-freecell-table.compact .o-freecell-figure .o-freecell-s { display: none; }
.o-freecell-table.compact 
/* États : visée au clavier, prise, glisser, refus */
.o-freecell-colonne:focus-visible .o-freecell-carte.visee { box-shadow: var(--o-freecell-ombre), inset 0 0 0 2px var(--marque); }
.o-freecell-carte.prise { transform: translateY(-5px); box-shadow: 0 6px 14px rgb(20 26 42 / 30%), inset 0 0 0 3px var(--ok-texte); }
.o-freecell-carte.en-vol { visibility: hidden; }
.o-freecell-vol { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; }
.o-freecell-vol .o-freecell-carte { box-shadow: 0 10px 22px rgb(20 26 42 / 35%), inset 0 0 0 1px var(--o-freecell-trait); }
.o-freecell-carte.refus { animation: o-freecell-refus .28s ease-in-out; }
@keyframes o-freecell-refus { 25% { translate: -4px 0; } 75% { translate: 4px 0; } }

.o-freecell-message { display: block; min-height: 1.5em; margin-top: 10px; text-align: center; font-size: .98rem; line-height: 1.45; color: var(--texte); }

/* Victoire : les quatre rois se soulèvent l'un après l'autre */
.o-freecell.gagne .o-freecell-table { border-color: var(--ok-texte); box-shadow: 0 0 0 2px var(--ok-texte); }
.o-freecell.gagne .o-freecell-message { padding: 8px 10px; border-radius: var(--rayon-petit); background: var(--ok-fond); color: var(--ok-texte); font-weight: 600; }
.o-freecell.gagne .o-freecell-fondation .o-freecell-carte:last-child { animation: o-freecell-saut .7s ease-out both; }
.o-freecell.gagne [data-pile="f1"] .o-freecell-carte:last-child { animation-delay: .12s; }
.o-freecell.gagne [data-pile="f2"] .o-freecell-carte:last-child { animation-delay: .24s; }
.o-freecell.gagne [data-pile="f3"] .o-freecell-carte:last-child { animation-delay: .36s; }
@keyframes o-freecell-saut { 40% { transform: translateY(-12px); } 70% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) {
  .o-freecell.gagne .o-freecell-fondation .o-freecell-carte:last-child, .o-freecell-carte.refus { animation: none; }
  .o-freecell-carte.prise { transform: none; }
}

/* Capacité de déplacement, solveur */
.o-freecell-capacite { margin: 8px 0 0; text-align: center; color: var(--texte-2); font-size: .88rem; font-variant-numeric: tabular-nums; }
.o-freecell-solveur { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 10px 0 4px; }
.atelier .o-freecell-solveur .btn { min-height: 42px; }
.o-freecell[data-sol="calcul"] [data-resoudre] { cursor: progress; }

/* Statistiques */
.o-freecell-bloc { display: grid; gap: 10px; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--bord); }
.o-freecell-bloc h2 { margin: 0; font-size: 1.15rem; }
.o-freecell .o-freecell-aide { margin: 0; color: var(--texte-2); font-size: .92rem; line-height: 1.5; }
.o-freecell-stats { width: 100%; max-width: 520px; border-collapse: collapse; font-size: .95rem; }
.o-freecell-stats th, .o-freecell-stats td { padding: 6px 8px; border-bottom: 1px solid var(--bord); text-align: left; }
.o-freecell-stats td { font-variant-numeric: tabular-nums; }
.o-freecell-stats thead th { color: var(--texte-2); font-weight: 600; font-size: .85rem; }
.o-freecell-stats tbody th { font-weight: 500; }

@media (max-width: 560px) {
  .o-freecell-table { padding: 8px 4px; margin-inline: -8px; }
  .o-freecell-haut { margin-bottom: 10px; }
  .o-freecell-table { padding: 8px 2px; }
  .o-freecell-barre { gap: 6px 12px; }
  .o-freecell-barre strong { font-size: 1.05rem; }
  .atelier .o-freecell-actions .btn { padding-inline: 12px; }
    .o-freecell-stats { font-size: .88rem; }
  .o-freecell-numero input { width: 6.5em; }
  .o-freecell-stats th, .o-freecell-stats td { padding: 5px 4px; }
}
