/* ==========================================================================
   CSS DÉDIÉ : TABLES4.PHP - Bataille Navale des Multiplications
   Fichier : css/tables4.css
   École de l'Enfant-Jésus - Morlanwelz
   ========================================================================== */

:root {
    --primary: #0284c7;
    --primary-dark: #0369a1;
    --primary-light: #e0f2fe;
    --accent: #f59e0b;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #ef4444;
    --purple: #8b5cf6;
    --indigo: #6366f1;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --grid-line: #cbd5e1;
  }

  /* Conteneur principal */
  .arch-container {
    width: 100%;
    max-width: 1140px;
    box-sizing: border-box;
    margin: 0 auto 25px auto;
    background: #ffffff;
    border-radius: 24px;
    padding: 20px 24px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.06);
    font-family: 'Nunito', sans-serif;
  }

  /* Boutons utilitaires de la barre de statut */
  .stats-bar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .util-top-btn {
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    color: #334155;
    padding: 5px 12px;
    border-radius: 10px;
    font-family: 'Fredoka', sans-serif;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }

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

  /* Barre de statistiques */
  .stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    padding: 10px 18px;
    margin-bottom: 22px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #475569;
  }

  .stat-badge {
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    padding: 3px 10px;
    border-radius: 20px;
    color: #0284c7;
    font-family: 'Fredoka', sans-serif;
    font-size: 15px;
    font-weight: 700;
  }

  .stat-badge.gold {
    color: #d97706;
    border-color: #fcd34d;
    background: #fef3c7;
  }

  /* Layout principal : Configuration à gauche, Zone de jeu à droite */
  .arch-workspace {
    display: flex;
    gap: 24px;
    align-items: flex-start;
  }

  /* Colonne gauche (modes & réglages) */
  .arch-sidebar {
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-sizing: border-box;
  }

  .side-card {
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 18px;
    padding: 16px;
    box-sizing: border-box;
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
  }

  .side-card-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* Sélecteur de Mode */
  .mode-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .mode-btn {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  .mode-btn:hover {
    border-color: #38bdf8;
    background: #f0f9ff;
    transform: translateY(-1px);
  }

  .mode-btn.active {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    border-color: #0284c7;
    color: white;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.3);
  }

  .mode-btn-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .mode-btn-desc {
    font-size: 11.5px;
    opacity: 0.85;
    line-height: 1.3;
  }

  /* Choix des tables (Mode 1 et 2) */
  .tables-filter-btns {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
  }

  .tbl-filter-btn {
    flex: 1;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 4px 2px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    color: #475569;
    transition: all 0.15s;
  }

  .tbl-filter-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
  }

  .tables-grid-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .tbl-toggle-btn {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 7px 4px;
    font-family: 'Fredoka', sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
  }

  .tbl-toggle-btn:hover {
    border-color: #0284c7;
    color: #0284c7;
  }

  .tbl-toggle-btn.active {
    background: #0284c7;
    border-color: #0284c7;
    color: white;
    box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
  }

  /* Sélecteur de nombres pour le Mode Facteurs */
  .factors-number-picker {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .factor-target-btn {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 10px;
    padding: 7px 2px;
    font-family: 'Fredoka', sans-serif;
    font-size: 13.5px;
    font-weight: 700;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
  }

  .factor-target-btn:hover {
    border-color: #8b5cf6;
    color: #8b5cf6;
  }

  .factor-target-btn.active {
    background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    border-color: #7c3aed;
    color: white;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.35);
  }

  /* Astuce / Pédagogie */
  .pedago-box {
    background: #eff6ff;
    border: 1.5px solid #bfdbfe;
    border-radius: 14px;
    padding: 12px;
    font-size: 12px;
    color: #1e40af;
    line-height: 1.45;
  }

  .pedago-box strong {
    color: #1d4ed8;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
  }

  /* Colonne droite : Arène de jeu principale */
  .arch-main-arena {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  /* Bannière de Mission */
  .mission-card {
    background: #ffffff;
    border: 2px solid #cbd5e1;
    border-radius: 20px;
    padding: 18px 22px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.04);
    text-align: center;
    position: relative;
    overflow: hidden;
  }

  .mission-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 5px;
    background: linear-gradient(90deg, #0ea5e9, #6366f1, #10b981);
  }

  .mission-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-family: 'Fredoka', sans-serif;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
  }

  .badge-mode1 { background: #e0f2fe; color: #0284c7; }
  .badge-mode2 { background: #fef3c7; color: #d97706; }
  .badge-mode3 { background: #ede9fe; color: #7c3aed; }

  .mission-question {
    font-family: 'Fredoka', sans-serif;
    font-size: 24px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 6px;
  }

  .calc-highlight {
    color: #2563eb;
    background: #eff6ff;
    padding: 3px 14px;
    border-radius: 12px;
    border: 2px solid #bfdbfe;
    display: inline-block;
    font-size: 28px;
    letter-spacing: 1px;
  }

  .mission-subtitle {
    font-size: 13.5px;
    color: #64748b;
    font-weight: 600;
  }

  /* Bannière temps réel sous la mission : dimensions actuelles */
  .selection-tracker {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    background: #f1f5f9;
    border-radius: 12px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 700;
    color: #334155;
    flex-wrap: wrap;
  }

  .dim-pill {
    background: #ffffff;
    border: 1.5px solid #cbd5e1;
    padding: 2px 10px;
    border-radius: 8px;
    color: #0284c7;
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
  }

  .dim-pill.area {
    color: #059669;
    border-color: #a7f3d0;
    background: #ecfdf5;
  }

  /* Panneau Facteurs découverts (Mode 3) */
  .factors-collection-card {
    background: #faf5ff;
    border: 2px dashed #c084fc;
    border-radius: 16px;
    padding: 12px 16px;
    box-sizing: border-box;
    display: none;
  }

  .factors-collection-card.visible {
    display: block;
  }

  .factors-coll-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
  }

  .factors-coll-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: #6b21a8;
  }

  .factors-badges-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .factor-slot {
    background: #ffffff;
    border: 2px solid #e9d5ff;
    border-radius: 12px;
    padding: 6px 12px;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #a855f7;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
  }

  .factor-slot.discovered {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border-color: #059669;
    color: white;
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
    animation: popDiscovered 0.4s ease-out;
  }

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

  /* Zone de la Grille Interactive */
  .grid-wrapper-outer {
    background: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    padding: 16px;
    box-sizing: border-box;
    box-shadow: 0 8px 24px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    overflow-x: auto;
    max-width: 100%;
  }

  /* Grille quadrillée avec règles d'axes */
  .grid-board-container {
    display: inline-grid;
    position: relative;
    background: #ffffff;
    padding: 8px;
    touch-action: none; /* Crucial pour le drag tactile sans scroller */
  }

  /* Règle horizontale supérieure */
  .grid-ruler-col {
    display: grid;
    margin-left: 30px; /* 24px règle rangées + 4px marge + 2px bordure grille */
    margin-bottom: 5px;
    gap: 1px; /* Alignement rigoureux avec le gap de la grille */
    font-family: 'Fredoka', sans-serif;
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
    text-align: center;
  }

  .ruler-col-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 18px;
    box-sizing: border-box;
    user-select: none;
    transition: color 0.15s ease, font-weight 0.15s ease;
  }

  .ruler-col-cell.highlight {
    color: #0284c7;
    font-weight: 800;
  }

  /* Zone principale : Règle verticale + Grille de cellules */
  .grid-content-row {
    display: flex;
    align-items: flex-start;
  }

  .grid-ruler-row {
    display: grid;
    margin-right: 4px;
    margin-top: 2px; /* Correspond aux 2px de bordure supérieure de cells-grid */
    gap: 1px; /* Alignement rigoureux avec le gap de la grille */
    font-family: 'Fredoka', sans-serif;
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
    width: 24px;
    text-align: right;
    box-sizing: border-box;
  }

  .ruler-row-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 5px;
    box-sizing: border-box;
    user-select: none;
    transition: color 0.15s ease, font-weight 0.15s ease;
  }

  .ruler-row-cell.highlight {
    color: #0284c7;
    font-weight: 800;
  }

  /* Grille des cellules */
  .cells-grid {
    display: grid;
    background: #cbd5e1;
    border: 2px solid #64748b;
    gap: 1px;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  }

  .grid-cell {
    background: #ffffff;
    cursor: crosshair;
    transition: background-color 0.1s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Fredoka', sans-serif;
    font-size: 10px;
    font-weight: 700;
    color: transparent;
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box;
    position: relative;
  }

  .grid-cell:hover {
    background-color: #e0f2fe;
  }

  /* Cellule sélectionnée en cours de tracé */
  .grid-cell.selected {
    background-color: #38bdf8 !important;
    color: white !important;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4);
  }

  .grid-cell.corner-start {
    background-color: #0284c7 !important;
  }

  /* Cellule validée avec succès */
  .grid-cell.validated {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    color: white !important;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.5);
  }

  /* Cellule erronée (clignotement doux) */
  .grid-cell.error-flash {
    background: #fecaca !important;
    color: #991b1b !important;
    transition: background-color 0.4s ease;
  }

  /* Animation de cascade lors du comptage */
  .grid-cell.counting {
    animation: cellFlash 0.35s ease-out forwards;
    color: #065f46 !important;
    font-size: 11px !important;
  }

  @keyframes cellFlash {
    0% { background: #fef08a; transform: scale(1.15); z-index: 10; }
    50% { background: #6ee7b7; }
    100% { background: #34d399; transform: scale(1); }
  }

  /* Étiquette centrale géante au-dessus du rectangle validé */
  .grid-overlay-banner {
    position: absolute;
    pointer-events: none;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(4px);
    border: 2px solid #38bdf8;
    color: white;
    padding: 6px 14px;
    border-radius: 12px;
    font-family: 'Fredoka', sans-serif;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3);
    display: none;
    align-items: center;
    gap: 6px;
    z-index: 50;
    transform: translate(-50%, -50%);
    animation: bannerPop 0.3s ease-out;
  }

  @keyframes bannerPop {
    0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  }

  /* Barre d'outils et d'actions sous la grille */
  .grid-actions-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 14px;
    width: 100%;
    flex-wrap: wrap;
  }

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

  .action-btn:hover {
    transform: translateY(-2px);
  }

  .btn-validate {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
  }

  .btn-validate:hover {
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.45);
  }

  .btn-reset {
    background: #f1f5f9;
    border: 1.5px solid #cbd5e1;
    color: #475569;
  }

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

  .btn-hint {
    background: #fef3c7;
    border: 1.5px solid #fde68a;
    color: #b45309;
  }

  .btn-hint:hover {
    background: #fde68a;
  }

  .btn-skip {
    background: #eff6ff;
    border: 1.5px solid #bfdbfe;
    color: #1d4ed8;
  }

  .btn-skip:hover {
    background: #dbeafe;
  }



  /* Zone de feedback pédagogique (messages de réussite / explications) */
  .feedback-box {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    padding: 14px 18px;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    color: #334155;
    transition: all 0.3s ease;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .feedback-box.success {
    background: #ecfdf5;
    border-color: #a7f3d0;
    color: #065f46;
  }

  .feedback-box.warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
  }

  .feedback-box.info {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
  }

  /* Modale Popup Règles & Victoire */
  .modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 16px;
    box-sizing: border-box;
  }

  .modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .modal-card {
    background: white;
    border-radius: 24px;
    max-width: 520px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    text-align: center;
    position: relative;
    transform: translateY(20px);
    transition: transform 0.25s ease;
  }

  .modal-overlay.visible .modal-card {
    transform: translateY(0);
  }

  .modal-icon {
    font-size: 44px;
    margin-bottom: 8px;
  }

  .modal-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 12px;
  }

  .modal-body {
    font-size: 14px;
    color: #475569;
    line-height: 1.55;
    text-align: left;
    margin-bottom: 20px;
  }

  .modal-body p {
    margin: 8px 0;
  }

  .modal-close-btn {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 12px;
    font-family: 'Fredoka', sans-serif;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35);
  }

  /* Canvas de Confettis */
  #confetti-canvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10000;
  }

  /* Responsive Design */
  @media screen and (max-width: 960px) {
    .arch-workspace {
      flex-direction: column;
    }
    .arch-sidebar {
      flex: 1 1 100%;
      width: 100%;
    }
    .side-card {
      padding: 14px;
    }
  }

  @media screen and (max-width: 600px) {
    .arch-container {
      padding: 12px 14px;
      border-radius: 16px;
    }
    .arch-header {
      padding: 14px;
      border-radius: 16px;
    }
    .arch-title-group h1 {
      font-size: 20px;
    }
    .mission-question {
      font-size: 20px;
    }
    .calc-highlight {
      font-size: 22px;
      padding: 2px 10px;
    }
    .action-btn {
      padding: 8px 12px;
      font-size: 13px;
    }
  }
