/* ==========================================================================
   Chess Loaders - pure CSS loading icons built from chess-piece glyphs.
   No images, no build step. See chess-loaders.js for the catalog and the
   chessoraLoaderOverlay/chessoraLoaderHtml helpers that use these classes.

   Customize by overriding these variables on :root (or on any ancestor
   of the loader) in your own stylesheet:
     --cl-ink          silhouette color
     --cl-classic      "Ebony & Oak" piece color
     --cl-classic-hi   "Ebony & Oak" highlight (inner light catch)
     --cl-outline      "Line" finish color
     --cl-brass-1      "Brass" gradient start
     --cl-brass-2      "Brass" gradient end
     --cl-shadow       knight's drop-shadow color
   ========================================================================== */

:root {
  --cl-ink: #211D16;
  --cl-classic: #4A2F1D;
  --cl-classic-hi: rgba(255, 246, 228, .35);
  --cl-outline: #2E4B3B;
  --cl-brass-1: #8C6A2E;
  --cl-brass-2: #C79A4B;
  --cl-shadow: rgba(33, 29, 22, .28);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --cl-ink: #F1ECDF;
    --cl-classic: #D8B383;
    --cl-classic-hi: rgba(255, 255, 255, .18);
    --cl-outline: #8FC3A3;
    --cl-brass-1: #C79A4B;
    --cl-brass-2: #EAC888;
    --cl-shadow: rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  --cl-ink: #F1ECDF;
  --cl-classic: #D8B383;
  --cl-classic-hi: rgba(255, 255, 255, .18);
  --cl-outline: #8FC3A3;
  --cl-brass-1: #C79A4B;
  --cl-brass-2: #EAC888;
  --cl-shadow: rgba(0, 0, 0, .55);
}

/* ---------- shared piece shell ---------- */
.cl-piece {
  display: inline-block;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
}
.cl-piece--silhouette { color: var(--cl-ink); }
.cl-piece--ebony {
  color: var(--cl-classic);
  text-shadow: 0 1px 0 var(--cl-classic-hi), 0 -1px 1.5px rgba(0, 0, 0, .3);
}
.cl-piece--line { color: var(--cl-outline); }
.cl-piece--brass {
  background: linear-gradient(155deg, var(--cl-brass-1), var(--cl-brass-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cl-loader {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Knight's Jump ---------- */
.cl-loader--knight { width: 64px; height: 64px; }
.cl-loader--knight .cl-piece {
  position: absolute;
  font-size: 36px;
  transform-origin: 50% 85%;
  animation: cl-knightHop 1.9s cubic-bezier(.6, 0, .35, 1) infinite;
}
.cl-loader--knight .cl-shadow {
  position: absolute;
  bottom: 10px;
  width: 24px;
  height: 7px;
  border-radius: 50%;
  background: var(--cl-shadow);
  filter: blur(1px);
  animation: cl-knightShadow 1.9s cubic-bezier(.6, 0, .35, 1) infinite;
}
@keyframes cl-knightHop {
  0%   { transform: translate(-16px, 0) scale(1, 1) rotate(0deg); }
  8%   { transform: translate(-13px, 3px) scale(1.1, .88) rotate(0deg); }
  32%  { transform: translate(2px, -24px) scale(.95, 1.05) rotate(10deg); }
  50%  { transform: translate(16px, 0) scale(1, 1) rotate(0deg); }
  58%  { transform: translate(13px, 3px) scale(1.1, .88) rotate(0deg); }
  82%  { transform: translate(-2px, -24px) scale(.95, 1.05) rotate(-10deg); }
  100% { transform: translate(-16px, 0) scale(1, 1) rotate(0deg); }
}
@keyframes cl-knightShadow {
  0%, 100% { transform: scale(1); opacity: .9; }
  8%, 58%  { transform: scale(1.15, .7); opacity: .5; }
  32%, 82% { transform: scale(.55); opacity: .22; }
  50%      { transform: scale(1); opacity: .9; }
}

/* ---------- Full Set (ring) ---------- */
.cl-loader--ring { width: 78px; height: 78px; }
.cl-loader--ring .cl-piece {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 19px;
  margin: -11px 0 0 -8px;
  animation: cl-ringPulse 2s ease-in-out infinite;
  animation-delay: calc(var(--i) * .18s);
}
@keyframes cl-ringPulse {
  0%, 100% { transform: rotate(calc(var(--i) * 72deg)) translateY(-26px) rotate(calc(var(--i) * -72deg)) scale(.65); opacity: .32; }
  18%      { transform: rotate(calc(var(--i) * 72deg)) translateY(-26px) rotate(calc(var(--i) * -72deg)) scale(1); opacity: 1; }
  40%      { transform: rotate(calc(var(--i) * 72deg)) translateY(-26px) rotate(calc(var(--i) * -72deg)) scale(.65); opacity: .32; }
}

/* ---------- Promotion ---------- */
.cl-loader--promotion { width: 70px; height: 70px; }
.cl-loader--promotion .cl-piece {
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 36px;
  margin: -18px 0 0 -12px;
}
.cl-loader--promotion .cl-flare {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--cl-brass-2) 0%, transparent 68%);
  opacity: 0;
  animation: cl-flarePulse 2.3s ease-in-out infinite;
}
.cl-loader--promotion .cl-pawn { animation: cl-promoPawn 2.3s ease-in-out infinite; }
.cl-loader--promotion .cl-queen { animation: cl-promoQueen 2.3s ease-in-out infinite; }
@keyframes cl-promoPawn {
  0%, 18%  { opacity: 1; transform: translateY(0) scale(1); }
  34%, 88% { opacity: 0; transform: translateY(-9px) scale(1.2); }
  100%     { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cl-promoQueen {
  0%, 18%  { opacity: 0; transform: translateY(9px) scale(.78); }
  34%, 88% { opacity: 1; transform: translateY(0) scale(1); }
  100%     { opacity: 0; transform: translateY(9px) scale(.78); }
}
@keyframes cl-flarePulse {
  0%, 20%, 32% { opacity: 0; }
  26%          { opacity: .55; }
  40%, 100%    { opacity: 0; }
}

/* ---------- First Rank ---------- */
.cl-loader--rank {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 4px;
  width: 62px;
  height: 62px;
}
.cl-loader--rank .cl-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(128, 128, 128, .25);
  border-radius: 4px;
}
.cl-loader--rank .cl-piece {
  font-size: 19px;
  opacity: 0;
  transform: scale(.4);
  animation: cl-rankAppear 2.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * .22s);
}
@keyframes cl-rankAppear {
  0%, 4%    { opacity: 0; transform: scale(.4); }
  16%, 52%  { opacity: 1; transform: scale(1); }
  66%, 100% { opacity: 0; transform: scale(.4); }
}

/* ---------- Chessora Logo (marchio animato, per wizard/superadmin) ---------- */
.cl-loader--logo { width: 72px; height: 72px; }
.cl-loader--logo .cl-logo-ring {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--cl-brass-2);
  border-right-color: var(--cl-brass-1);
  animation: cl-logoSpin 1.1s linear infinite;
}
.cl-loader--logo .cl-logo-img {
  position: relative;
  width: 46px;
  height: auto;
  animation: cl-logoPulse 1.4s ease-in-out infinite;
  filter: drop-shadow(0 2px 5px var(--cl-shadow));
  /* Il marchio ha tratti scuri: senza una base chiara sparisce sui fondi
     scuri (es. l'overlay di attesa a schermo intero, quasi nero) - stesso
     rimedio già usato per il logo in barra (.wizard-topbar-logo-chip). */
  background: #fff;
  border-radius: .5rem;
  padding: 5px;
  box-sizing: border-box;
}
@keyframes cl-logoSpin {
  to { transform: rotate(360deg); }
}
@keyframes cl-logoPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(.86); opacity: .8; }
}

@media (prefers-reduced-motion: reduce) {
  .cl-piece, .cl-shadow, .cl-flare {
    animation: none !important;
  }
  .cl-loader--knight .cl-piece { transform: translate(-16px, 0) !important; }
  .cl-loader--ring .cl-piece {
    opacity: 1 !important;
    transform: rotate(calc(var(--i) * 72deg)) translateY(-26px) rotate(calc(var(--i) * -72deg)) scale(1) !important;
  }
  .cl-loader--promotion .cl-pawn { opacity: 1 !important; transform: none !important; }
  .cl-loader--promotion .cl-queen { opacity: 0 !important; }
  .cl-loader--rank .cl-piece { opacity: 1 !important; transform: scale(1) !important; }
  .cl-loader--logo .cl-logo-ring { animation: none !important; }
  .cl-loader--logo .cl-logo-img { animation: none !important; }
}

/* ---------- Overlay a schermo intero (chessoraLoaderOverlay) ---------- */
.chessora-loader-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 17, 13, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.chessora-loader-overlay--visible {
  opacity: 1;
  pointer-events: auto;
}
.chessora-loader-overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}
.chessora-loader-overlay-text {
  color: #F1ECDF;
  font-size: .95rem;
  font-weight: 500;
  letter-spacing: .02em;
}

/* ---------- Uso inline (dentro pulsanti, righe di testo, ecc.) ---------- */
.chessora-loader-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  vertical-align: middle;
}
.chessora-loader-inline > span {
  display: inline-block;
}
