/* Piston King – Core look with CSS Variables */
.piston-king {
  --pk-bg: #ffffff;
  --pk-fg: #111827;
  --pk-muted: #6b7280;
  --pk-primary: #0f172a;
  --pk-ok: #10b981;
  --pk-ko: #ef4444;
  --pk-font-family: 'System-UI', sans-serif;

  background: var(--pk-bg);
  color: var(--pk-fg);
  font-family: var(--pk-font-family);
  border: 1px solid #e5e7eb; border-radius: 16px; padding: 14px;
  max-width: 900px; margin: 16px auto; box-shadow: 0 8px 30px rgba(0,0,0,.06);
  outline: none; position: relative;
  transition: box-shadow .2s ease;
}

.piston-king:focus-within {
    box-shadow: 0 0 0 2px var(--pk-primary);
}

.piston-king.pk-ok { box-shadow: 0 0 0 3px rgba(16,185,129,.2) inset, 0 8px 30px rgba(16,185,129,.25); }
.piston-king.pk-ko { box-shadow: 0 0 0 3px rgba(239,68,68,.2) inset, 0 8px 30px rgba(239,68,68,.25); }
.piston-king.pk-ended { transform: scale(0.996); transition: transform .1s; }
.piston-king.pk-blur > *:not(.pk-overlay) { filter: blur(2px); }

.pk-header { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.pk-title { margin:0; font-size:1.1rem; }
.pk-stats { color: var(--pk-muted); display:flex; gap:14px; font-size:.95rem; }

.pk-score-big { text-align:center; font-size:44px; font-weight:800; letter-spacing:.02em; margin:6px 0 8px; }
.pk-score-big span { display:inline-block; min-width: 2ch; }
#pk-score-big { transition: transform .1s ease; }
.piston-king.pk-ok #pk-score-big { 
  transform: scale(1.1);
  animation: pk-pop-score .15s ease-out;
}

.pk-stage { margin:8px 0; background: linear-gradient(#f8fafc, #f1f5f9); border:1px dashed #e5e7eb; border-radius:12px; padding:8px; }
#pk-noteimg { width:25%; height:auto; display:block; }
.piston-king.pk-ko #pk-noteimg {
  animation: pk-shake 0.35s cubic-bezier(.36,.07,.19,.97);
}

.pk-controls { display:flex; justify-content:center; gap:8px; margin: 8px 0 10px; }
.pk-btn {
  appearance:none; border:1px solid #e5e7eb; background:#fff; color:#111;
  border-radius:12px; padding:.6rem 1.0rem; font-weight:700; cursor:pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.06); transition: transform .12s ease, box-shadow .12s ease;
  min-width: 0; /* Correction pour Firefox */
}
.pk-btn.pk-primary { background: var(--pk-primary); color:#fff; border-color: var(--pk-primary); }
.pk-btn.pk-ghost { background:#fff; color:var(--pk-primary); border-color:#cbd5e1; }
.pk-btn:hover { transform: translateY(-1px); }

.pk-pistons { margin-top:6px; display:grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; align-items:end; touch-action: none; }
.pk-piston { background: linear-gradient(#ecfeff, #e0f2fe); border:1px solid #cbd5e1; border-radius:16px; padding:10px; cursor:pointer;
  box-shadow: 0 8px 18px rgba(14,165,233,.15); transition: transform .12s ease, box-shadow .12s ease; position:relative; overflow:hidden; touch-action: none;}
.pk-piston:hover { transform: translateY(-2px); }
.pk-piston:focus { outline:2px solid rgba(14,165,233,.45); }
.pk-piston-img { display:block; width:50%; height:auto; pointer-events:none; user-select:none; transform: translateY(0); transition: transform .12s ease; }
.pk-piston.is-down .pk-piston-img { transform: translateY(8%); }

.pk-keys-tip { text-align:center; color:var(--pk-muted); font-size:.9rem; margin-top:8px; }

.pk-overlay { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background: rgba(15,23,42,.48); border-radius:16px; z-index: 30; }
.pk-overlay[hidden] { display: none !important; }

.pk-card { width:min(540px, 92%); background: var(--pk-bg); color: var(--pk-fg); border-radius:16px; box-shadow: 0 30px 80px rgba(0,0,0,.25);
  padding:18px; border: 1px solid #e5e7eb; }
.pk-card-title { margin:0 0 12px; font-size:1.25rem; text-align:center; }

.pk-menu-grid { width: 100%; display:grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap:10px; }
.pk-card-actions { text-align:center; margin-top:12px; }

.pk-scores-cols { display:grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap:12px; }
.pk-score-col h5 { margin:.25rem 0 .5rem; font-size:1.05rem; text-align: center; }

/* *** CORRECTION MISE EN PAGE DES SCORES *** */
.pk-toplist-header, .pk-toplist li {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto; /* 3 colonnes: Rang (fixe), Pseudo (flexible), Score (auto) */
  gap: 10px;
  align-items: center;
}

.pk-toplist-header {
  padding: 4px 10px; font-weight: 700; font-size: 0.8rem;
  color: var(--pk-muted); border-bottom: 2px solid #e5e7eb; margin-bottom: 6px;
}
.pk-toplist-header .pk-val { text-align: right; }

.pk-toplist { 
  list-style: none; padding:0 4px 0 0; margin:0; 
  max-height: 220px;
  overflow-y: auto; scrollbar-width: thin;
}
.pk-toplist::-webkit-scrollbar { width: 6px; }
.pk-toplist::-webkit-scrollbar-thumb { background-color: #cbd5e1; border-radius: 3px; }

.pk-toplist li { 
  padding:8px 6px; border-radius:8px; margin-bottom:6px; 
  background:#f8fafc; border: 1px solid transparent;
}
.pk-toplist li:nth-child(odd) { background: #f1f5f9; }
.pk-toplist li:hover { border-color: #dbeafe; }

.pk-toplist .pk-rank { font-weight:800; text-align:center; color: var(--pk-primary); }
.pk-toplist .pk-nick { font-weight:700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pk-toplist .pk-val { font-weight:700; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; text-align: right; }
.pk-toplist .pk-tiebreak { font-size: 0.8em; color: var(--pk-muted); font-weight: 400; }
.pk-empty { text-align:center; color: var(--pk-muted); padding: 20px; }

@media (max-width: 520px) {
  .pk-scores-cols { grid-template-columns: 1fr; }
  .pk-score-big { font-size: 36px; }
}

.pk-progress {
  display: none; width: 100%; height: 12px;
  border-radius: 999px; background: #e5e7eb;
  overflow: hidden; margin: 6px 0 10px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.08);
}
.pk-progress-bar {
  height: 100%; width: 100%;
  transition: width .25s ease, background-color .25s ease;
  background: var(--pk-ok);
}
.pk-progress.pk-warn .pk-progress-bar { background: #f59e0b; }
.pk-progress.pk-danger .pk-progress-bar{ background: var(--pk-ko); }

.pk-save-form { display:flex; gap:10px; justify-content:center; align-items:end; margin:8px 0; flex-wrap:wrap; }
.pk-save-form input[type="text"] {
  border:1px solid #cbd5e1; border-radius:10px; padding:.5rem .6rem; min-width: 200px;
}
.pk-rank-line { text-align:center; margin:6px 0; font-size:1.05rem; }

.pk-stage { position: relative; }
.pk-stage::before {
  content: ""; position: absolute; inset: 8px; border-radius: 10px;
  background: linear-gradient(90deg, #f1f5f9 25%, #e5e7eb 37%, #f1f5f9 63%);
  background-size: 400% 100%; animation: pk-shimmer 1.2s ease-in-out infinite;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.piston-king.loading-note .pk-stage::before { opacity: 1; }

@keyframes pk-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@keyframes pk-shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

@keyframes pk-pop-score {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1.1); }
}

.pk-btn.pk-cancel { background:#fee2e2; color:#b91c1c; border-color:#fca5a5; }
.pk-btn.pk-cancel:hover { background:#fecaca; }

.piston-king { --pk-piston-scale: 0.8; }
.pk-piston-img { transform: scale(var(--pk-piston-scale)) translateY(0); transform-origin:center top; }
.pk-lefty .pk-pistons { direction: rtl; }