/* CSS modele Devoirati: calculAbs_hard1.html / chaine.css
   Source: C:\mon-site-SAUVEGARDE-AVANT-MIGRATION\Devoirati\8eme\AddifQ8\quiz\chaines\chaine_abs\chaine.css
   Injecte automatiquement: ne pas editer page par page. */
* {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
            direction: rtl;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        /* Header avec titre et gamification */
        .header {
            background: white;
            border-radius: 20px;
            padding: 25px;
            margin-bottom: 20px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.2);
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .header h1 {
            color: #667eea;
            font-size: 2em;
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .header-icon {
            font-size: 1.2em;
            animation: pulse 2s infinite;
        }
        
        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.1); }
        }
        
        /* Système de gamification */
        .gamification-panel {
            display: flex;
            gap: 20px;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .score-display {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 15px 25px;
            border-radius: 15px;
            font-size: 1.3em;
            font-weight: bold;
            box-shadow: 0 5px 15px rgba(240,147,251,0.4);
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .stars-display {
            display: flex;
            gap: 5px;
            font-size: 1.5em;
        }
        
        .star {
            color: #ffd700;
            filter: drop-shadow(0 0 5px rgba(255,215,0,0.5));
            transition: transform 0.3s;
        }
        
        .star.earned {
            animation: starEarn 0.5s ease-out;
        }
        
        @keyframes starEarn {
            0% { transform: scale(0) rotate(0deg); }
            50% { transform: scale(1.5) rotate(180deg); }
            100% { transform: scale(1) rotate(360deg); }
        }
        
        .progress-bar-container {
            background: rgba(255,255,255,0.3);
            border-radius: 10px;
            height: 20px;
            width: 200px;
            overflow: hidden;
            position: relative;
        }
        
        .progress-bar {
            background: linear-gradient(90deg, #00c6ff 0%, #0072ff 100%);
            height: 100%;
            width: 0%;
            transition: width 0.5s ease-out;
            border-radius: 10px;
        }
        
        .progress-text {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-weight: bold;
            font-size: 0.9em;
            text-shadow: 0 1px 3px rgba(0,0,0,0.5);
        }
        
        /* Zone principale */
        .main-content {
            display: grid;
            grid-template-columns: 1fr;
            gap: 20px;
        }
        
        /* Énoncé */
        .enonce-section {
            background: white;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.2);
            border: 3px solid #667eea;
        }
        
        .enonce-section h2 {
            color: #667eea;
            margin-bottom: 20px;
            font-size: 1.5em;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .operation-display {
            background: linear-gradient(135deg, #e0e7ff 0%, #f3e7ff 100%);
            padding: 25px;
            border-radius: 15px;
            font-size: 1.8em;
            text-align: center;
            border: 2px solid #667eea;
            box-shadow: inset 0 2px 10px rgba(102,126,234,0.1);
        }
        
        /* Instructions */
        .instructions {
            background: linear-gradient(135deg, #fff3cd 0%, #ffe8a1 100%);
            padding: 20px;
            border-radius: 15px;
            margin-top: 20px;
            border-right: 5px solid #ffc107;
        }
        
        .instructions h3 {
            color: #856404;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .instructions p {
            color: #856404;
            line-height: 1.6;
        }
        
        /* Zone des cartes à ordonner */
        .cards-section {
            background: white;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.2);
        }
        
        .cards-section h2 {
            color: #764ba2;
            margin-bottom: 20px;
            font-size: 1.5em;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .cards-pool {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 15px;
            min-height: 200px;
            padding: 20px;
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-radius: 15px;
            border: 2px dashed #764ba2;
        }
        
        .card {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            cursor: pointer;
            transition: all 0.3s ease;
            border: 2px solid #e0e0e0;
            position: relative;
            overflow: hidden;
        }
        
        .card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(135deg, rgba(102,126,234,0.1) 0%, rgba(118,75,162,0.1) 100%);
            opacity: 0;
            transition: opacity 0.3s;
        }
        
        .card:hover {
            transform: translateY(-5px) scale(1.02);
            box-shadow: 0 10px 30px rgba(102,126,234,0.3);
            border-color: #667eea;
        }
        
        .card:hover::before {
            opacity: 1;
        }
        
        .card.selected {
            border-color: #28a745;
            background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
            box-shadow: 0 8px 25px rgba(40,167,69,0.4);
        }
        
        .card.error {
            animation: shake 0.5s;
            border-color: #dc3545;
            background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
        }
        
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-10px); }
            75% { transform: translateX(10px); }
        }
        
        .card.flying {
            animation: flyToTarget 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        }
        
        @keyframes flyToTarget {
            0% {
                transform: scale(1);
                opacity: 1;
            }
            50% {
                transform: scale(1.2) translateY(-20px);
                opacity: 0.7;
            }
            100% {
                transform: scale(1);
                opacity: 1;
            }
        }
        
        .card-number {
            position: absolute;
            top: 5px;
            right: 5px;
            background: #667eea;
            color: white;
            width: 25px;
            height: 25px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.9em;
            font-weight: bold;
        }
        
        .card-content {
            position: relative;
            z-index: 1;
            font-size: 1.1em;
            color: #333;
            line-height: 1.6;
        }
        
        /* Zone de construction */
        .construction-section {
            background: white;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.2);
        }
        
        .construction-section h2 {
            color: #28a745;
            margin-bottom: 20px;
            font-size: 1.5em;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .construction-zone {
            min-height: 300px;
            padding: 20px;
            background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
            border-radius: 15px;
            border: 3px dashed #28a745;
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .construction-zone.empty {
            display: flex;
            align-items: center;
            justify-content: center;
            color: #666;
            font-size: 1.2em;
        }
        
        .construction-zone.empty::before {
            content: '👆 انقر على الخطوات أعلاه لترتيبها هنا';
            font-style: italic;
        }
        
        .placed-card {
            background: white;
            padding: 20px;
            border-radius: 12px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.15);
            border-right: 5px solid #28a745;
            position: relative;
            animation: slideIn 0.5s ease-out;
        }
        
        @keyframes slideIn {
            from {
                transform: translateX(50px);
                opacity: 0;
            }
            to {
                transform: translateX(0);
                opacity: 1;
            }
        }
        
        .placed-card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }
        
        .placed-card-order {
            background: #28a745;
            color: white;
            padding: 5px 12px;
            border-radius: 20px;
            font-weight: bold;
        }
        
        .remove-card-btn {
            background: #dc3545;
            color: white;
            border: none;
            padding: 5px 15px;
            border-radius: 20px;
            cursor: pointer;
            font-size: 0.9em;
            transition: all 0.3s;
        }
        
        .remove-card-btn:hover {
            background: #c82333;
            transform: scale(1.05);
        }
        
        .placed-card-content {
            font-size: 1.1em;
            color: #333;
            line-height: 1.6;
        }
        
        /* Boutons d'action */
        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 20px;
            flex-wrap: wrap;
        }
        
        .btn {
            padding: 15px 30px;
            border: none;
            border-radius: 12px;
            font-size: 1.1em;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            gap: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.2);
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0,0,0,0.3);
        }
        
        .btn-validate {
            background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
            color: white;
        }
        
        .btn-reset {
            background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
            color: white;
        }
        
        .btn-hint {
            background: linear-gradient(135deg, #ffc107 0%, #ff9800 100%);
            color: white;
        }
        
        .btn-video {
            background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
            color: white;
        }
        
        .btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none !important;
        }
        
        /* Avatar intelligent */
        .avatar-container {
            position: fixed;
            bottom: 30px;
            left: 30px;
            z-index: 1000;
            transition: all 0.3s;
        }
        
        .avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 3em;
            cursor: pointer;
            box-shadow: 0 10px 30px rgba(102,126,234,0.5);
            transition: all 0.3s;
            animation: float 3s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-10px); }
        }
        
        .avatar:hover {
            transform: scale(1.1);
        }
        
        .avatar-message {
            position: absolute;
            bottom: 140px;
            left: 0;
            background: white;
            padding: 20px;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            max-width: 300px;
            opacity: 0;
            transform: translateY(20px);
            transition: all 0.3s;
            pointer-events: none;
            border: 2px solid #667eea;
        }
        
        .avatar-message.show {
            opacity: 1;
            transform: translateY(0);
            pointer-events: all;
        }
        
        .avatar-message::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50px;
            width: 0;
            height: 0;
            border-left: 10px solid transparent;
            border-right: 10px solid transparent;
            border-top: 10px solid white;
        }
        
        .avatar-message-text {
            color: #333;
            line-height: 1.6;
            margin-bottom: 10px;
        }
        
        .avatar-close-btn {
            background: #667eea;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 0.9em;
            float: left;
        }
        
        /* Modal de résultat */
        .result-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.8);
            z-index: 2000;
            justify-content: center;
            align-items: center;
        }
        
        .result-modal.show {
            display: flex;
        }
        
        .result-content {
            background: white;
            padding: 40px;
            border-radius: 20px;
            max-width: 600px;
            width: 90%;
            text-align: center;
            box-shadow: 0 20px 60px rgba(0,0,0,0.5);
            animation: modalAppear 0.5s ease-out;
        }
        
        @keyframes modalAppear {
            from {
                transform: scale(0.8);
                opacity: 0;
            }
            to {
                transform: scale(1);
                opacity: 1;
            }
        }
        
        .result-icon {
            font-size: 5em;
            margin-bottom: 20px;
        }
        
        .result-title {
            font-size: 2em;
            margin-bottom: 15px;
            color: #333;
        }
        
        .result-message {
            font-size: 1.2em;
            color: #666;
            margin-bottom: 20px;
            line-height: 1.6;
        }
        
        .result-score {
            font-size: 2.5em;
            font-weight: bold;
            color: #667eea;
            margin: 20px 0;
        }
        
        .confetti {
            position: fixed;
            width: 10px;
            height: 10px;
            background: #f0f;
            position: absolute;
            animation: confetti-fall 3s linear infinite;
        }
        
        @keyframes confetti-fall {
            to {
                transform: translateY(100vh) rotate(360deg);
                opacity: 0;
            }
        }
        
        /* Modal vidéo */
        .video-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.9);
            z-index: 2000;
            justify-content: center;
            align-items: center;
        }
        
        .video-modal.show {
            display: flex;
        }
        
        .video-content {
            background: white;
            padding: 20px;
            border-radius: 15px;
            max-width: 800px;
            width: 90%;
        }
        
        .video-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .video-close-btn {
            background: #dc3545;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 1em;
        }
        
        .video-container {
            position: relative;
            padding-bottom: 56.25%;
            height: 0;
            overflow: hidden;
        }
        
        .video-container iframe {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 10px;
        }
        
        /* Responsive */
        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                gap: 15px;
            }
            
            .gamification-panel {
                width: 100%;
                justify-content: center;
            }
            
            .cards-pool {
                grid-template-columns: 1fr;
            }
            
            .avatar-container {
                bottom: 15px;
                left: 15px;
            }
            
            .avatar {
                width: 80px;
                height: 80px;
                font-size: 2em;
            }
            
            .action-buttons {
                flex-direction: column;
            }
            
            .btn {
                width: 100%;
                justify-content: center;
            }
        }
        
        /* Animations de succès */
        .success-animation {
            animation: successPulse 0.6s ease-out;
        }
        
        @keyframes successPulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.05); }
        }
        
        /* Badge de niveau */
        .level-badge {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 8px 15px;
            border-radius: 20px;
            font-weight: bold;
            display: flex;
            align-items: center;
            gap: 8px;
        }

/* Adaptation minimale RACR -> classes du modele calculAbs_hard1 */
.wrap.container{max-width:1200px;margin:0 auto;padding:20px}
.top.header{margin-bottom:20px}
.top.header h1{display:flex;align-items:center;justify-content:center;gap:12px;flex-wrap:wrap}
.top.header h1:before{content:"🔗";font-size:1.2em}
.top.header .badge{margin-top:12px}
.top.header .badge:before{content:"🏆 ";margin-left:4px}
.grid.main-content{display:grid;grid-template-columns:1fr 1fr;gap:24px}
.panel.enonce-section,.panel.construction-section{margin:0}
.cards.cards-pool{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:12px;max-height:none}
.card.step-card{position:relative}
.card.step-card small{display:block;margin-bottom:8px;font-weight:800;color:#667eea}
.zone.construction-zone{min-height:260px}
.zone.construction-zone.empty{display:flex;align-items:center;justify-content:center}
.placed.selected-step{margin-bottom:12px}
.btns.action-buttons{justify-content:center}
.btn.check-btn,.btn.reset-btn,.btn.solution-btn{min-width:150px}
.result.feedback{display:none}
.result.feedback.show{display:block}
.solution.solution-panel{margin-top:18px}
.nav{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-top:20px}
.nav a{display:inline-flex;align-items:center;justify-content:center;padding:12px 18px;border-radius:12px;text-decoration:none;font-weight:800;background:linear-gradient(135deg,#667eea,#764ba2);color:white;box-shadow:0 6px 20px rgba(102,126,234,.3)}
.nav a.disabled{opacity:.45;pointer-events:none}
.mathbox{direction:ltr;unicode-bidi:isolate;text-align:center;overflow-x:auto}
@media(max-width:900px){.grid.main-content{grid-template-columns:1fr}.cards.cards-pool{grid-template-columns:1fr}}

/* Harmonisation RACR externe */
.nav{
  display:flex !important;
  justify-content:space-between !important;
  align-items:center !important;
  gap:12px !important;
  width:min(980px,96vw);
  margin:18px auto 0 !important;
}
.nav a{
  display:inline-flex !important;
  align-items:center !important;
  justify-content:center !important;
  min-width:112px;
  padding:11px 18px !important;
  border-radius:999px !important;
  background:linear-gradient(135deg,#667eea,#764ba2) !important;
  color:#fff !important;
  text-decoration:none !important;
  font-weight:800 !important;
  box-shadow:0 8px 18px rgba(76,29,149,.22);
}
.nav a.disabled{
  opacity:.55 !important;
  pointer-events:none !important;
  box-shadow:none !important;
}
.nav span,.nav .badge{
  color:#111827 !important;
  background:rgba(255,255,255,.86) !important;
  border:1px solid rgba(255,255,255,.5) !important;
  border-radius:999px !important;
  padding:8px 14px !important;
  font-weight:800 !important;
}
.mathbox{
  direction:ltr;
  unicode-bidi:isolate;
  text-align:center;
  overflow-x:auto;
}
@media(max-width:720px){
  .nav{flex-direction:column !important;align-items:stretch !important;text-align:center !important}
  .nav a,.nav span,.nav .badge{width:100%}
}
/* Support des elements crees par JavaScript dans les pages RACR */
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:12px;max-height:none}
.card{position:relative;background:#fff;border:2px solid #e0e7ff;border-radius:15px;padding:14px;cursor:pointer;transition:all .25s ease;box-shadow:0 5px 15px rgba(0,0,0,.08)}
.card:hover{transform:translateY(-3px);border-color:#667eea;box-shadow:0 8px 25px rgba(102,126,234,.25)}
.card.used{opacity:.45;pointer-events:none;filter:grayscale(.2)}
.card small{display:block;margin-bottom:8px;font-weight:800;color:#667eea}
.zone{min-height:260px;border:3px dashed #4caf50;border-radius:15px;background:linear-gradient(135deg,#f0fff4 0%,#e8f5e8 100%);padding:20px;transition:all .3s ease}
.zone.empty{display:flex;align-items:center;justify-content:center;color:#6b7280;font-weight:800;text-align:center}
.placed{background:white;border:2px solid #4caf50;border-radius:12px;padding:12px;margin-bottom:10px;box-shadow:0 3px 12px rgba(76,175,80,.18)}
.num{display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;margin-left:8px;border-radius:50%;background:#667eea;color:#fff;font-weight:900}
.rm{border:0;border-radius:10px;background:#ff6b6b;color:#fff;padding:6px 10px;cursor:pointer;font-weight:800}
.btn{border:0;border-radius:999px;background:linear-gradient(135deg,#667eea,#764ba2);color:#fff;font-weight:900;padding:12px 20px;cursor:pointer;box-shadow:0 6px 18px rgba(102,126,234,.25)}
.btn.secondary{background:linear-gradient(135deg,#94a3b8,#64748b)}
.btn.ok{background:linear-gradient(135deg,#22c55e,#16a34a)}
.result.show,.solution.show{display:block}
