/*
 * Mathix Proba - Design System & Styles (style.css)
 * Auteur : Arnaud DURAND
 * Licence : GPL v3
 * Thème académique sobre, épuré, à fort contraste (Light/Slate)
 * Supprime les effets de néons, gradients spatiaux et glassmorphismes "style IA".
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

:root {
  --font-title: 'Inter', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  
  /* Thème Académique Épuré (Clair / Slate) */
  --bg-app: #f8fafc; /* Gris ardoise ultra-clair */
  --bg-card: #ffffff; /* Blanc pur solide */
  --border-card: #e2e8f0; /* Frontière fine ardoise 200 */
  --border-card-hover: #cbd5e1; /* Ardoise 300 */
  
  --primary: #2563eb; /* Bleu royal - accessible, sobre et professionnel */
  --primary-hover: #1d4ed8;
  --primary-glow: rgba(37, 99, 235, 0.05);
  
  --secondary: #d97706; /* Ambre foncé pour la théorie/recherche */
  --secondary-glow: rgba(217, 119, 6, 0.06);
  
  --text-main: #0f172a; /* Ardoise 900 - Contraste maximal pour lecture */
  --text-muted: #475569; /* Ardoise 600 - Lisible et sobre */
  --text-light: #64748b; /* Ardoise 500 */
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
}

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

body {
  font-family: var(--font-body);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- EN-TÊTE PRINCIPAL --- */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-card);
  padding: 0.4rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-container h1 {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.5px;
  color: var(--text-main);
}

.logo-container p {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 1px;
}

.mathix-badge {
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid rgba(37, 99, 235, 0.15);
  color: var(--primary);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  letter-spacing: 0.5px;
}

/* --- STRUCTURE EN COMPOSANTS GRILLE --- */
.dashboard-container {
  max-width: 1300px;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
}

/* --- SIDEBAR & TABS --- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tab-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0.8rem 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.2s ease-in-out;
  text-align: left;
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.9rem;
}

.tab-btn svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  transition: color 0.2s;
}

.tab-btn:hover {
  border-color: var(--border-card-hover);
  background: #f1f5f9;
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--primary-glow);
  border-color: var(--primary);
  color: var(--primary);
}

.tab-btn.active svg {
  color: var(--primary);
}

/* --- PANELS DE TRAVAIL PRINCIPAUX --- */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .dashboard-container {
    grid-template-columns: 1fr;
  }
  .main-content {
    grid-template-columns: 1fr;
  }
}

/* --- CARTES SOBRES --- */
.glass-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 0.75rem;
}

.panel-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-title svg {
  color: currentColor;
  width: 18px;
  height: 18px;
}

/* --- SIMULATEUR CONTAINER & CANVAS --- */
.simulator-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.canvas-wrapper {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc; /* Fond clair pour s'insérer sobrement */
  border: 1px solid var(--border-card);
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1;
}

.canvas-wrapper canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* --- CONTROLES DES OUTILS --- */
.tool-section {
  display: none;
  flex-direction: column;
  gap: 1.25rem;
  width: 100%;
}

.tool-section.active {
  display: flex;
}

.control-btn-group {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.btn {
  font-family: var(--font-title);
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  border: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: #f1f5f9;
  border: 1px solid var(--border-card);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.btn-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.btn-danger:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

.btn svg {
  width: 15px;
  height: 15px;
}

/* --- ÉDITEURS DE CONFIGURATION --- */
.editor-box {
  background: #f8fafc;
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.editor-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.editor-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  align-items: center;
}

.select-input, .text-input {
  height: 36px;
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 6px;
  color: var(--text-main);
  padding: 0 0.65rem;
  font-size: 0.82rem;
  outline: none;
  font-family: var(--font-body);
  transition: border-color 0.15s;
  flex: 1;
  min-width: 0;
}

.select-input:focus, .text-input:focus {
  border-color: var(--primary);
}

.editor-form .btn {
  height: 36px;
  padding: 0 1rem;
  flex-shrink: 0;
  border-radius: 6px;
}

.editor-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-card);
  padding-top: 0.5rem;
  margin-top: 0.25rem;
}

.editor-reset-btn {
  background: transparent;
  border: none;
  color: #b91c1c;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.15s;
}

.editor-reset-btn:hover {
  background: #fef2f2;
}

.editor-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.5rem;
  max-height: 110px;
  overflow-y: auto;
  padding-right: 4px;
}

.editor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
  animation: itemReveal 0.2s ease-out forwards;
  min-width: 0;
}

.editor-item-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.editor-item-remove {
  background: #f1f5f9;
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.editor-item-remove:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
}

/* Dés configuration spécifique */
.dice-config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
}

.dice-config-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dice-config-group label {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Personnalisation Scrollbar */
.editor-list::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
.editor-list::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
  background: transparent;
}
.editor-list::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

/* --- HISTORIQUE RECENT DES TIRAGES --- */
.history-box {
  background: #f8fafc;
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0.75rem;
  width: 100%;
}

.history-list {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  min-height: 32px;
  align-items: center;
}

.history-item {
  animation: itemReveal 0.2s forwards;
}

@keyframes itemReveal {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(3px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* --- ATELIER DE QUESTION & LOI GRANDS NOMBRES --- */
.quiz-question-box {
  background: #f8fafc;
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 1.15rem;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--text-main);
}

.quiz-answer-form {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.quiz-answer-form .text-input {
  font-size: 0.9rem;
  height: 38px;
  border-radius: 6px;
  background: #ffffff;
}

.quiz-answer-form .btn {
  height: 38px;
  border-radius: 6px;
}

/* Feedback Quiz */
.quiz-feedback-box {
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}

.quiz-explanation-box {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explanation-steps {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.explanation-steps strong {
  color: var(--text-main);
}

.explanation-result-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.82rem;
  color: #b45309;
  font-family: var(--font-title);
  font-weight: 700;
  text-align: center;
}

/* --- LOI DES GRANDS NOMBRES - GRAPHIQUE CONVERGENCE --- */
.convergence-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sim-button-group {
  display: flex;
  gap: 0.4rem;
  width: 100%;
}

.sim-button-group .btn {
  flex: 1;
  min-width: 80px;
  padding: 0.55rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

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

.progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  border-radius: 10px;
  transition: width 0.1s linear;
}

.chart-wrapper {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}

.chart-wrapper canvas {
  width: 100%;
  height: auto;
  display: block;
}

/* Formules de Math fraction CSS */
.math-fraction {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.1;
  padding: 0 4px;
  font-weight: 700;
  transform: translateY(-0.12em);
  color: var(--text-main);
}

.math-num {
  border-bottom: 1.5px solid var(--text-main);
  padding-bottom: 1px;
  display: block;
  width: 100%;
}

.math-denom {
  padding-top: 1px;
  display: block;
  width: 100%;
}

/* --- CLASSES SÉMANTIQUES D'HISTORIQUE --- */
.ball-item {
  color: #ffffff;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  font-size: 0.78rem;
  font-family: var(--font-title);
}

.wheel-item {
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  font-weight: 700;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  font-size: 0.78rem;
  font-family: var(--font-title);
}

.dice-item {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
  font-family: var(--font-title);
}

.dice-item-val {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  text-align: center;
  line-height: 18px;
  font-size: 0.7rem;
  color: #ffffff;
  font-weight: 800;
}

.dice-item-sum {
  color: var(--secondary);
  font-weight: 700;
  margin-left: 0.15rem;
}

.coin-item {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
  font-family: var(--font-title);
}

.coin-item-val {
  display: inline-block;
  padding: 0 6px;
  height: 18px;
  border-radius: 9999px;
  text-align: center;
  line-height: 18px;
  font-size: 0.7rem;
  color: #ffffff;
  font-weight: 800;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.2);
}

/* --- COMPOSANT STATISTIQUES SIMULATION --- */
.sim-stats-container {
  background: #f8fafc;
  border: 1px solid var(--border-card);
  border-radius: 10px;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 100%;
  margin-top: 1rem;
  box-shadow: var(--shadow-sm);
}

.sim-stats-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.95rem;
}

.sim-stats-title svg {
  width: 18px;
  height: 18px;
  color: var(--primary);
}

.sim-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.sim-stats-card {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sim-stats-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.sim-stats-value {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.5rem;
  margin-top: 0.1rem;
}

.sim-stats-value.real-freq {
  color: var(--primary);
}

.sim-stats-value.theory-prob {
  color: var(--secondary);
}

.sim-stats-sublabel {
  font-size: 0.7rem;
  color: var(--text-light);
}

.sim-stats-info-box {
  background: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.sim-stats-info-box strong {
  color: var(--text-main);
}

.sim-stats-highlight-blue {
  color: var(--primary);
  font-weight: 600;
}

.sim-stats-highlight-orange {
  color: var(--secondary);
  font-weight: 600;
}

/* --- CLASSEUR D'UTILITAIRES LEGER (COMPATIBILITÉ ET SOUPLESSE) --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-1\.5 { gap: 0.375rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-3\.5 { gap: 0.875rem; }
.gap-4 { gap: 1rem; }
.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.85rem; }
.text-lg { font-size: 1.15rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.italic { font-style: italic; }
.text-center { text-align: center; }
.text-white { color: #ffffff !important; }
.text-slate-200 { color: var(--text-main); }
.text-slate-300 { color: var(--text-muted); }
.text-slate-400 { color: var(--text-light); }
.text-slate-500 { color: var(--text-muted); }
.text-red-400 { color: #ef4444; }
.text-red-500 { color: #dc2626; }
.text-green-500 { color: #16a34a; }
.text-orange-400 { color: var(--secondary); }
.block { display: block; }
.inline-block { display: inline-block; }
.w-full { width: 100%; }
.mt-2 { margin-top: 0.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.pt-4 { padding-top: 1rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.border { border: 1px solid var(--border-card); }
.border-t { border-top: 1px solid var(--border-card); }
.rounded { border-radius: 4px; }
.rounded-lg { border-radius: 8px; }
.rounded-xl { border-radius: 12px; }
.rounded-full { border-radius: 9999px; }
.shadow { box-shadow: var(--shadow-sm); }
.shadow-sm { box-shadow: var(--shadow-sm); }

/* --- CRÉDITS & BADGE EN-TÊTE PRINCIPAL --- */
.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-credits {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  line-height: 1.4;
}

.header-credits strong {
  color: var(--text-main);
}

/* Mobile responsive fixes */
@media (max-width: 768px) {
  header {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
    padding: 1rem;
  }
  .header-right {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.5rem;
  }
  .header-credits {
    text-align: center;
  }
  
  /* Barre latérale transformée en onglets horizontaux tactiles fluides */
  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    gap: 0.5rem;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    width: 100%;
  }
  .sidebar::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    flex: 0 0 auto;
    scroll-snap-align: start;
    padding: 0.6rem 0.9rem;
    font-size: 0.8rem;
    gap: 0.5rem;
    white-space: nowrap;
  }
  
  /* Réduction de la perte de place sur petits écrans */
  .dashboard-container {
    margin: 0.75rem auto;
    padding: 0 0.75rem;
    gap: 1rem;
  }
  .glass-panel {
    padding: 1rem;
    gap: 1rem;
  }
  
  /* Boutons et formulaires empilés pour cible tactile optimale */
  .quiz-answer-form {
    flex-direction: column;
  }
  .sim-button-group {
    flex-direction: column;
  }
  .control-btn-group {
    flex-direction: column;
    gap: 0.5rem;
  }
  .control-btn-group .btn {
    width: 100%;
  }
  .editor-form {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  .editor-form .btn {
    width: 100%;
  }
}

/* Utilitaires généraux */
.hidden {
  display: none !important;
}
