/* === Échec Royal — page de jeu (solo) === */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: linear-gradient(135deg, #1a1206, #2b2113, #0f0a04);
  color: #ece3cf;
  padding: 16px;
}

#app {
  position: relative; z-index: 1;
  background: rgba(28, 22, 12, 0.62);
  border: 1px solid rgba(244, 215, 123, 0.18);
  border-radius: 24px;
  padding: 24px 22px 22px;
  max-width: 680px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.back-link { font-size: 0.85rem; color: var(--color-light, #f4d77b); text-decoration: none; font-weight: 600; }
.back-link:hover { color: #fff; }
.top-bar h1 {
  font-size: 1.4rem; font-weight: 800;
  background: linear-gradient(90deg, #f4d77b, #c9a227, #9a7b1c);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.niveau-tag { font-size: 0.8rem; color: #f4d77b; font-weight: 700; white-space: nowrap; }

/* HUD */
.er-hud {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap;
  gap: 10px; margin-bottom: 12px; padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}
.er-hud-item { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; font-weight: 700; }
.er-hud-item .er-ic { font-size: 1.05rem; }
.er-statut { min-height: 1.2em; font-weight: 700; color: #ece3cf; }
.er-statut.er-thinking { color: #f4d77b; }
#er-elo { color: #f4d77b; }
#er-chrono { color: #67e8f9; }
#er-coups { color: #c4b5fd; }

/* Pièces capturées */
.er-captures { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; min-height: 22px; }
.er-captures > div { font-size: 1.15rem; line-height: 1; letter-spacing: 1px; opacity: 0.85; }
#er-cap-white { color: #f5f0e1; }   /* pièces noires prises par les Blancs */
#er-cap-black { color: #3a3326; }

/* ===== Plateau ===== */
#er-board-container { position: relative; display: flex; justify-content: center; margin-bottom: 12px; }

.er-board {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(120, 90, 40, 0.55);
  touch-action: none;
  user-select: none;
}
.er-layer { position: absolute; inset: 0; }

.er-squares { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.er-sq { position: relative; }
.er-light { background: #f0d9b5; }
.er-dark  { background: #b58863; }
.er-sq.er-sel::after {
  content: ''; position: absolute; inset: 0; background: rgba(244, 215, 123, 0.45);
}
.er-sq.er-last::after {
  content: ''; position: absolute; inset: 0; background: rgba(244, 215, 123, 0.30);
}
.er-sq.er-check::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255, 60, 50, 0.85) 0%, rgba(255, 60, 50, 0.35) 45%, transparent 72%);
}
.er-coord { position: absolute; font-size: 0.6rem; font-weight: 700; opacity: 0.65; pointer-events: none; }
.er-file { right: 3px; bottom: 1px; }
.er-rank { left: 2px; top: 1px; }
.er-light .er-coord { color: #b58863; }
.er-dark .er-coord { color: #f0d9b5; }

/* Pièces : positionnées par transform translate(col*100%, row*100%) */
.er-pieces { pointer-events: none; }
.er-piece {
  position: absolute; top: 0; left: 0;
  width: 12.5%; height: 12.5%;
  transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: transform;
  -webkit-user-drag: none;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
}
.er-piece.er-moving { z-index: 5; }
.er-piece.er-drag { transition: none; z-index: 12; transform-origin: center; filter: drop-shadow(0 6px 6px rgba(0,0,0,0.5)); }
.er-piece.er-captured { animation: er-cap-fade 0.18s ease forwards; }
@keyframes er-cap-fade { to { opacity: 0; transform: scale(0.6) translate(var(--tx,0), var(--ty,0)); } }

/* Indices de coups légaux */
.er-hints { pointer-events: none; }
.er-hint { position: absolute; width: 12.5%; height: 12.5%; display: flex; align-items: center; justify-content: center; }
.er-hint-move::after {
  content: ''; width: 30%; height: 30%; border-radius: 50%;
  background: rgba(40, 30, 12, 0.32);
}
.er-hint-capture::after {
  content: ''; width: 92%; height: 92%; border-radius: 50%;
  border: 4px solid rgba(40, 30, 12, 0.32); box-sizing: border-box;
}

/* ===== Explosion de capture ===== */
.er-fx { pointer-events: none; }
.er-explosion { position: absolute; width: 12.5%; height: 12.5%; z-index: 20; }
.er-flash {
  position: absolute; inset: -20%; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,240,200,0.95) 0%, rgba(255,160,60,0.6) 40%, transparent 70%);
  animation: er-flash 0.45s ease-out forwards;
}
@keyframes er-flash { 0% { transform: scale(0.2); opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }
.er-ghost {
  position: absolute; inset: 0; width: 100%; height: 100%;
  animation: er-ghost 0.5s ease-out forwards;
}
@keyframes er-ghost { 0% { opacity: 0.9; transform: scale(1) rotate(0); } 100% { opacity: 0; transform: scale(1.5) rotate(20deg); } }
.er-shard {
  position: absolute; left: 50%; top: 50%;
  width: 12%; height: 12%; border-radius: 2px;
  animation: er-shard 0.6s ease-out forwards;
}
@keyframes er-shard {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2); opacity: 0; }
}

/* Désactivation visuelle (tour de l'IA) */
.er-board.er-disabled { cursor: default; }
.er-board.er-disabled .er-piece { cursor: default; }
.er-board:not(.er-disabled) .er-piece { cursor: grab; }

/* ===== Sélecteur de promotion ===== */
.er-promotion {
  display: none; position: absolute; inset: 0; z-index: 60;
  background: rgba(10, 8, 3, 0.78);
  align-items: center; justify-content: center;
}
.er-promotion.visible { display: flex; }
.er-promotion-box {
  background: rgba(40, 32, 18, 0.96); border: 1px solid rgba(244, 215, 123, 0.3);
  border-radius: 16px; padding: 18px; text-align: center;
}
.er-promotion-box p { font-size: 0.9rem; margin-bottom: 12px; color: #f4d77b; font-weight: 700; }
.er-promotion-choices { display: flex; gap: 10px; }
.er-promo-btn {
  width: 64px; height: 64px; border: 2px solid rgba(244,215,123,0.25); border-radius: 12px;
  background: #f0d9b5; cursor: pointer; padding: 6px; transition: transform 0.15s, border-color 0.15s;
}
.er-promo-btn:hover { transform: translateY(-3px); border-color: #f4d77b; }
.er-promo-btn img { width: 100%; height: 100%; }

/* ===== Boutons ===== */
.er-actions { display: flex; gap: 10px; justify-content: center; margin-bottom: 10px; }
.btn {
  font-family: 'Inter', sans-serif; font-size: 0.9rem; font-weight: 700;
  padding: 10px 22px; border: none; border-radius: 10px; cursor: pointer; color: #1a1206;
  transition: transform 0.18s, box-shadow 0.18s; display: inline-flex; align-items: center;
  justify-content: center; line-height: 1; text-decoration: none;
}
.btn:hover { transform: translateY(-2px); }
.btn-primary { background: linear-gradient(135deg, var(--color-btn1, #b8860b), var(--color-btn2, #d4af37)); box-shadow: 0 4px 15px rgba(184, 134, 11, 0.4); color: #1a1206; }
.btn-secondary { background: linear-gradient(135deg, #4b3f24, #6b5a30); box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3); color: #f4e9c8; }

/* ===== Overlay fin de partie ===== */
.er-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 8, 3, 0.72);
  justify-content: center; align-items: center;
}
.er-overlay.visible { display: flex; }
.er-overlay-box {
  background: rgba(36, 28, 15, 0.97); border: 1px solid rgba(244, 215, 123, 0.18);
  border-radius: 20px; padding: 30px; text-align: center; max-width: 400px; width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
}
.er-fin-titre { font-size: 1.7rem; font-weight: 800; margin-bottom: 6px; }
.er-fin-titre.er-win { color: #4ade80; }
.er-fin-titre.er-lose { color: #f87171; }
.er-fin-titre.er-draw { color: #f4d77b; }
.er-fin-raison { color: #b8a987; font-size: 0.88rem; margin-bottom: 10px; }
.er-fin-elo { font-size: 1rem; margin-bottom: 18px; color: #ece3cf; }
.er-elo-up { color: #4ade80; font-weight: 700; }
.er-elo-down { color: #f87171; font-weight: 700; }
.er-cta-msg { color: #f4d77b; font-size: 0.85rem; margin-bottom: 12px; }
.er-cta-btns { display: flex; gap: 10px; justify-content: center; margin-bottom: 16px; }
.partage-score { margin-bottom: 16px; }
.er-overlay-btns { display: flex; gap: 10px; justify-content: center; }

footer { font-size: 0.78rem; color: #8a7c5e; margin-top: 8px; }
footer a { color: #f4d77b; text-decoration: none; }
footer a:hover { color: #fff; }

@media (max-width: 480px) {
  #app { padding: 16px 10px 14px; border-radius: 18px; }
  .top-bar h1 { font-size: 1.2rem; }
  .er-hud { padding: 8px 10px; gap: 8px; }
  .er-hud-item { font-size: 0.82rem; }
  .er-promo-btn { width: 54px; height: 54px; }
}
