/* ==========================================================================
   CSS DÉDIÉ : MATHS.PHP - Procédés de calcul (×10, ×100, ×1000 & ×0,1, ×0,01, ×0,001)
   Fichier : css/maths.css
   École de l'Enfant-Jésus - Morlanwelz
   ========================================================================== */

.maths-container {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 20px 0;
  background: #ffffff;
  border-radius: 20px;
  padding: 15px 18px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.05);
  border: none;
  font-family: 'Nunito', sans-serif;
}

.maths-header {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  border-radius: 14px;
  padding: 12px 18px;
  color: white;
  text-align: center;
  margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.25);
}

.maths-header h2 {
  color: white !important;
  font-family: 'Fredoka', sans-serif;
  font-size: 22px;
  margin: 0 0 4px 0;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}

.maths-header p {
  font-size: 14px;
  margin: 0;
  opacity: 0.95;
}

/* Boîte Rappel de cours / Mémo pédagogique */
.maths-memo-box {
  background: #f0fdf4;
  border: 2px solid #86efac;
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
  color: #14532d;
}

.memo-title {
  font-family: 'Fredoka', sans-serif;
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #15803d;
}

.memo-rules {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-weight: 700;
}

.memo-pill {
  background: white;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid #bbf7d0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.memo-pill strong {
  color: #047857;
}

/* Barre de sélection des héros (12 modèles) */
.drawing-selector-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 14px;
}

.drawing-selector-title {
  width: 100%;
  text-align: center;
  font-weight: 800;
  color: #334155;
  font-size: 14px;
  margin-bottom: 4px;
  font-family: 'Fredoka', sans-serif;
}

.drw-btn {
  background: white;
  border: 2px solid #cbd5e1;
  color: #334155;
  padding: 6px 12px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Fredoka', sans-serif;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.drw-btn:hover {
  border-color: #0284c7;
  color: #0369a1;
  background: #f0f9ff;
  transform: translateY(-1px);
}

.drw-btn.active {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: white;
  border-color: #075985;
  box-shadow: 0 3px 8px rgba(2, 132, 199, 0.35);
}

/* Barre d'informations : Score & Progression */
.game-info-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  padding: 10px 16px;
  margin-bottom: 14px;
}

.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 15px;
  box-shadow: 0 3px 8px rgba(245, 158, 11, 0.3);
  font-family: 'Fredoka', sans-serif;
  transition: transform 0.2s ease, background-color 0.2s ease;
  user-select: none;
}

.score-badge.gain {
  animation: scoreGain 0.4s ease;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.score-badge.loss {
  animation: scoreLoss 0.4s ease;
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

@keyframes scoreGain {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

@keyframes scoreLoss {
  0%, 100% { transform: translateX(0); }
  25%, 75% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
}

.progress-info {
  flex: 1 1 240px;
}

.progress-container {
  width: 100%;
  background: #e2e8f0;
  border-radius: 10px;
  height: 12px;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981 0%, #059669 100%);
  width: 0%;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 13px;
  font-weight: 800;
  color: #475569;
  margin-bottom: 4px;
}

/* Zone de jeu principale : Configuration à gauche, Grille au centre, Palette à droite */
.game-play-area {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  justify-content: center;
  margin-bottom: 14px;
}

/* Panneau de configuration gauche */
.config-side-left {
  flex: 0 1 215px;
  min-width: 185px;
  max-width: 235px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-sizing: border-box;
}

.side-config-box {
  border-radius: 16px;
  padding: 10px 11px;
  box-sizing: border-box;
  box-shadow: 0 3px 8px rgba(0,0,0,0.03);
}

.side-config-box.diff-box {
  background: #fdf4ff;
  border: 2px solid #d8b4fe;
}

.side-config-box.procedes-box {
  background: #eff6ff;
  border: 2px solid #93c5fd;
}

.side-config-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 6px;
  text-align: center;
}

.diff-box .side-config-title {
  color: #6b21a8;
}

.procedes-box .side-config-title {
  color: #1e40af;
}

.side-config-subtitle {
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  color: #2563eb;
  margin-bottom: 6px;
  font-family: 'Fredoka', sans-serif;
  line-height: 1.2;
}

/* Boutons de difficulté */
.side-diff-buttons {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.diff-btn {
  width: 100%;
  background: white;
  border: 2px solid #e9d5ff;
  border-radius: 12px;
  padding: 7px 9px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Fredoka', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 2px;
  box-sizing: border-box;
}

.diff-btn:hover {
  border-color: #a855f7;
  background: #faf5ff;
  transform: translateY(-1px);
}

.diff-btn .diff-title {
  font-size: 12px;
  font-weight: 800;
  color: #4c1d95;
  line-height: 1.2;
}

.diff-btn .diff-desc {
  font-size: 9.5px;
  font-weight: 600;
  color: #6b7280;
  font-family: 'Nunito', sans-serif;
  line-height: 1.15;
}

.diff-btn-easy.active {
  background: linear-gradient(135deg, #10b981 0%, #047857 100%);
  border-color: #065f46;
  box-shadow: 0 3px 8px rgba(16, 185, 129, 0.35);
}

.diff-btn-normal.active {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  border-color: #1e40af;
  box-shadow: 0 3px 8px rgba(59, 130, 246, 0.35);
}

.diff-btn-hard.active {
  background: linear-gradient(135deg, #ea580c 0%, #9a3412 100%);
  border-color: #7c2d12;
  box-shadow: 0 3px 8px rgba(234, 88, 12, 0.35);
}

.diff-btn.active .diff-title {
  color: #ffffff;
}

.diff-btn.active .diff-desc {
  color: rgba(255, 255, 255, 0.95);
}

/* Grille des 6 procédés */
.side-procedes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}

.proc-btn {
  background: white;
  border: 2px solid #bfdbfe;
  color: #1e3a8a;
  padding: 6px 4px;
  border-radius: 9px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Fredoka', sans-serif;
  text-align: center;
  white-space: nowrap;
  box-sizing: border-box;
}

.proc-btn:hover {
  background: #dbeafe;
  border-color: #2563eb;
  transform: translateY(-1px);
}

.proc-btn.active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  border-color: #1e40af;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

/* Préréglages rapides des procédés */
.procedes-presets {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preset-btn {
  background: white;
  border: 1px solid #cbd5e1;
  color: #475569;
  font-size: 10.5px;
  font-weight: 700;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: 'Nunito', sans-serif;
}

.preset-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
  border-color: #94a3b8;
}

/* Bandeau Loupe de calcul au-dessus de la grille */
.calc-preview-bar {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: white;
  border-radius: 12px;
  padding: 7px 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  box-sizing: border-box;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
  border: 2px solid #38bdf8;
  transition: all 0.2s ease;
}

.calc-preview-bar.active-highlight {
  border-color: #facc15;
  background: linear-gradient(135deg, #0369a1 0%, #0c4a6e 100%);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
}

.preview-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.preview-text {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 14.5px;
  font-weight: 700;
  text-align: center;
  color: #e2e8f0;
}

.preview-text strong.calc-highlight {
  font-size: 19px;
  font-weight: 800;
  color: #fef08a;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* Grille Pixel Art centrale */
.grid-wrapper {
  flex: 1 1 320px;
  max-width: 500px;
  width: 100%;
}

.pixel-grid {
  display: grid;
  gap: 2px;
  background: #cbd5e1;
  padding: 6px;
  border-radius: 16px;
  border: 3px solid #94a3b8;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

.pixel-cell {
  aspect-ratio: 1 / 1;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #1e293b;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease, box-shadow 0.15s ease;
  border-radius: 5px;
  position: relative;
  box-sizing: border-box;
  padding: 1px;
  overflow: visible;
  z-index: 1;
}

/* Structure sur 2 lignes pour lisibilité maximale */
.formula-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  width: 100%;
  pointer-events: none;
  font-family: 'Fredoka', 'Nunito', sans-serif;
}

.formula-top {
  font-size: clamp(10.5px, 1.9vw, 13.5px);
  font-weight: 800;
  color: #0f172a;
  white-space: nowrap;
  letter-spacing: -0.2px;
}

.formula-bot {
  font-size: clamp(9.5px, 1.7vw, 12px);
  font-weight: 800;
  color: #2563eb;
  white-space: nowrap;
  letter-spacing: -0.2px;
}

.formula-box.long-formula .formula-top {
  font-size: clamp(9px, 1.5vw, 11.5px);
}
.formula-box.long-formula .formula-bot {
  font-size: clamp(8.5px, 1.4vw, 10.5px);
}

/* Effet Loupe / Zoom au survol */
.pixel-cell:hover:not(.colored),
.pixel-cell.active-focus:not(.colored) {
  background: #ffffff;
  transform: scale(1.42);
  z-index: 50;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  border: 2px solid #0284c7;
  border-radius: 8px;
}

.pixel-cell:hover:not(.colored) .formula-top,
.pixel-cell.active-focus:not(.colored) .formula-top {
  color: #0369a1;
}

.pixel-cell:hover:not(.colored) .formula-bot,
.pixel-cell.active-focus:not(.colored) .formula-bot {
  color: #d97706;
}

.pixel-cell.colored {
  cursor: default;
  border: none;
}

.pixel-cell.colored .formula-box,
.pixel-cell.colored .formula-text {
  display: none;
}

.pixel-cell.wrong-paint {
  animation: shakeCell 0.4s ease;
}

@keyframes shakeCell {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-3px); }
  40%, 80% { transform: translateX(3px); }
}

/* Palette de peinture (à droite) */
.palette-side {
  flex: 0 1 215px;
  min-width: 165px;
  max-width: 240px;
  background: #fffbeb;
  border: 3px solid #fde047;
  border-radius: 18px;
  padding: 12px;
  box-shadow: 0 4px 12px rgba(251, 191, 36, 0.15);
  box-sizing: border-box;
}

.palette-title {
  font-weight: 800;
  color: #b45309;
  font-size: 13.5px;
  margin-bottom: 10px;
  text-align: center;
  font-family: 'Fredoka', sans-serif;
}

.palette-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
  background: white;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Nunito', sans-serif;
  font-size: 12.5px;
  color: #334155;
  text-align: left;
}

.color-btn:hover {
  transform: translateX(2px);
  border-color: #f59e0b;
}

.color-btn.active {
  border-color: #b45309;
  background: #fef3c7;
  box-shadow: 0 2px 8px rgba(180, 83, 9, 0.25);
  font-weight: 800;
  transform: scale(1.02);
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}

/* Boutons d'action */
.actions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 15px;
}

.btn-action {
  font-family: 'Fredoka', sans-serif;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

.btn-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.12);
}

.btn-restart {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: white;
}

.btn-leaderboard {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 15px;
  backdrop-filter: blur(4px);
}

.modal-overlay.visible {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 20px;
  padding: 24px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  border: 4px solid #0284c7;
  box-sizing: border-box;
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  background: #f1f5f9;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 16px;
  font-weight: 800;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.modal-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 24px;
  color: #0369a1;
  margin: 0 0 8px 0;
}

.stars-row {
  font-size: 32px;
  margin-bottom: 10px;
}

.modal-message {
  font-size: 15px;
  color: #334155;
  margin-bottom: 16px;
  line-height: 1.4;
}

.player-input {
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  outline: none;
  width: 180px;
  font-family: 'Nunito', sans-serif;
}

.player-input:focus {
  border-color: #0284c7;
}

/* Leaderboard Table */
.top10-container {
  max-height: 250px;
  overflow-y: auto;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.top10-title {
  margin: 8px 0;
  font-family: 'Fredoka', sans-serif;
  color: #0369a1;
  font-size: 16px;
}

.top10-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.top10-table th, .top10-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #f1f5f9;
}

.top10-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 800;
  position: sticky;
  top: 0;
}

/* Responsive */
@media (max-width: 900px) {
  .game-play-area {
    flex-direction: column;
    align-items: center;
  }
  .config-side-left, .palette-side {
    max-width: 100%;
    width: 100%;
    flex: 1 1 100%;
  }
  .palette-bar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  .color-btn {
    flex: 1 1 calc(50% - 10px);
    max-width: 200px;
  }
}
