/*
===============================================================================
 SI ARBEZ — SI-EXERCICES.CSS
 Compatibilité avec :
 - cames_qcm / T2-01 : .qcard .choice .feedback .grid2 ...
 - algorithmique / réseaux : .choices .choice.good/.bad ...
 - anciens QCM : .question .options .option .check-btn ...
 - didacticiels : .answer-grid .answer .btn .note .callout ...
===============================================================================
*/

/* ---------- Cartes et sections ---------- */

:where(.card, .qcard, .chapter-card, .question, .section, .panel, .panel-soft) {
  min-width: 0;
}

:where(.card, .qcard, .chapter-card) img,
:where(.question, .section, .panel) img {
  max-width: 100%;
  height: auto;
}

/* Centrage des illustrations d'énoncé quand elles sont plus petites. */
:where(.qimg, .question > img, .qprompt > img, .qtext > img) {
  display: block;
  margin-inline: auto;
}

/* ---------- Questions / énoncés ---------- */

:where(.qprompt, .qtext, .question-text) {
  line-height: 1.5;
}

:where(.question, .qcard) {
  scroll-margin-top: 12px;
}

/* ---------- Choix : famille .choice ---------- */

:where(.choices, .options, .answer-grid) {
  min-width: 0;
}

.choice {
  min-width: 0;
}

.choice input[type="radio"],
.choice input[type="checkbox"] {
  flex: 0 0 auto;
  accent-color: var(--si-accent);
}

.choice.good,
.choice.correct,
.choice.is-correct {
  border-color: var(--si-success) !important;
  background: #e8f5e9 !important;
  color: #1b5e20;
}

.choice.bad,
.choice.wrong,
.choice.incorrect,
.choice.is-wrong {
  border-color: var(--si-danger) !important;
  background: #ffebee !important;
  color: #8f1d1d;
}

.choice.selected,
.choice.is-selected {
  border-color: var(--si-primary);
  background: #eef6ff;
}

/* ---------- Anciens QCM : .option ---------- */

.option {
  min-width: 0;
}

.option input[type="radio"],
.option input[type="checkbox"] {
  accent-color: var(--si-accent);
}

.option.good,
.option.correct,
.option.is-correct {
  border-color: var(--si-success) !important;
  background: #e8f5e9 !important;
  color: #1b5e20;
}

.option.bad,
.option.wrong,
.option.incorrect,
.option.is-wrong {
  border-color: var(--si-danger) !important;
  background: #ffebee !important;
  color: #8f1d1d;
}

.option.selected,
.option.is-selected {
  border-color: var(--si-primary);
  background: #eef6ff;
}

/* ---------- Didacticiels : .answer ---------- */

.answer {
  min-width: 0;
}

.answer.selected,
.answer.is-selected {
  border-color: var(--si-primary) !important;
  background: #eef6ff !important;
}

.answer.correct,
.answer.good,
.answer.is-correct {
  border-color: var(--si-success) !important;
  background: #e8f5e9 !important;
}

.answer.wrong,
.answer.bad,
.answer.incorrect,
.answer.is-wrong {
  border-color: var(--si-danger) !important;
  background: #ffebee !important;
}

/* ---------- Feedback : toutes les conventions rencontrées ---------- */

.feedback,
.plan-feedback,
.liaison-feedback,
.rapp-feedback,
.clearn-feedback,
.cad-status,
.rev-status,
.situation-result {
  max-width: 100%;
  line-height: 1.45;
}

.feedback.ok,
.feedback.correct,
.feedback.success,
.feedback.show.ok,
.plan-feedback.ok,
.liaison-feedback.ok,
.rapp-feedback.ok,
.clearn-feedback.ok,
.cad-status.ok,
.rev-status.ok,
.situation-result.ok {
  background: #e8f5e9;
  color: var(--si-success);
  border-color: #a5d6a7;
}

.feedback.bad,
.feedback.ko,
.feedback.incorrect,
.feedback.error,
.feedback.show.ko,
.plan-feedback.ko,
.liaison-feedback.ko,
.rapp-feedback.bad,
.clearn-feedback.bad,
.cad-status.bad,
.rev-status.bad,
.situation-result.bad {
  background: #ffebee;
  color: var(--si-danger);
  border-color: #ef9a9a;
}

.feedback.warn,
.feedback.warning {
  background: #fff3e0;
  color: var(--si-warning);
  border-color: #ffcc80;
}

/* ---------- Aides, remarques, encadrés ---------- */

:where(.help, .help-box, .callout, .note, .warning, .warning-box,
       .lesson-box, .algo-note, .lab-explain, .surface-note,
       .stage-objective, .stage-intro, .binary-case) {
  max-width: 100%;
}

.callout.ok {
  background: #e8f5e9;
  border-left-color: var(--si-success);
}

.callout.warn,
.warning,
.warning-box {
  border-left-color: var(--si-warning);
}

.callout.bad {
  background: #ffebee;
  border-left-color: var(--si-danger);
}

/* Nouvelles classes facultatives */
.si-info,
.si-help,
.si-example,
.si-warning {
  padding: .9rem 1rem;
  margin-block: .8rem;
  border-radius: var(--si-radius-md);
}

.si-info,
.si-help {
  background: #e3f2fd;
  border: 1px solid rgba(30,136,229,.25);
}

.si-example {
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
}

.si-warning {
  background: #fff3e0;
  border: 1px solid #ffcc80;
}

/* ---------- Boutons ---------- */

:where(.check-btn, .btn-tool, .btn, .si-btn) {
  max-width: 100%;
}

.si-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 42px;
  padding: .65rem 1rem;
  border: 1px solid var(--si-border);
  border-radius: 10px;
  background: #fff;
  color: var(--si-text);
  font-weight: 650;
  cursor: pointer;
}

.si-btn--primary {
  color: #fff;
  background: var(--si-primary);
  border-color: var(--si-primary);
}

/* ---------- Progression ---------- */

:where(.progress, .progress-bar, .quiz-progress, .stage-pills,
       .rapp-progress, .progress-wrap) {
  max-width: 100%;
}

:where(.kpi, .metric-grid, .sizing-kpis, .kpi-line) {
  min-width: 0;
}

/* ---------- Grilles communes ---------- */

.si-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.si-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

/*
 * Important : les pages actuelles définissent déjà leurs colonnes.
 * On ne change ici que leur capacité à rétrécir.
 */
:where(.grid2, .grid3, .hero-grid, .learning-grid, .rule-grid, .bool-grid,
       .gallery, .lab-grid, .lab-one, .trace-grid, .compare-grid,
       .stage-example-grid, .scale-compare, .metric-grid, .general-card,
       .arch-controls, .schema-card, .liaison-wrap, .sizing-grid,
       .implant-wrap, .robust-grid, .robust-compare, .robust-methods,
       .robust-driver-grid, .rapp-layout, .clearn-layout, .cad-layout,
       .rev-layout, .mem-grid, .pivot-grid, .pivot-study-grid,
       .pivot-stop-layout, .pivot-answer-grid) > * {
  min-width: 0;
}

/* ---------- SVG / canvas interactifs ---------- */

:where(.construction-svg, .network-svg, .clearn-svg, .robust-svg,
       #rappSvg, #cadSketch, #revSketch) {
  max-width: 100%;
}

:where(.svgbox, .plan-scroll, .video-study, .cad-sketch-wrap,
       .rev-sketch-wrap, .liaison-board, .schema-stage-wrap) {
  max-width: 100%;
}

/* ---------- Détails / accordéons ---------- */

details {
  max-width: 100%;
}

summary {
  min-height: 38px;
}

/* ---------- Tables connues ---------- */

:where(.table, .table-mini, .activation-table, .loss-demo-table,
       .choice-table) {
  max-width: 100%;
}

/* Le wrapper reste la solution la plus sûre pour un tableau très large. */
.si-table-scroll > table,
.table-scroll > table,
.table-responsive > table {
  min-width: 620px;
}

/*
===============================================================================
 INTERACTIONS ET PROFONDEUR VISUELLE
 Couche volontairement légère : les thèmes locaux conservent leurs couleurs.
===============================================================================
*/

/* Les grandes cartes gagnent en relief sans devenir instables au survol. */
:where(.card, .qcard, .chapter-card, .question, .panel) {
  transition:
    border-color .2s ease,
    box-shadow .22s ease,
    transform .22s ease;
}

:where(.qcard, .question):focus-within {
  border-color: color-mix(in srgb, var(--si-primary) 42%, var(--si-border));
  box-shadow: 0 14px 34px color-mix(in srgb, var(--si-primary) 12%, transparent);
}

@media (hover: hover) and (pointer: fine) {
  :where(.card, .qcard, .chapter-card):hover {
    border-color: color-mix(in srgb, var(--si-primary) 28%, var(--si-border));
    box-shadow: 0 16px 36px color-mix(in srgb, var(--si-primary) 12%, transparent);
    transform: translateY(-2px);
  }
}

/* Réponses : déplacement discret, reflet et état coché immédiatement visible. */
:where(.choice, .option, .answer) {
  position: relative;
  isolation: isolate;
  transition:
    transform .16s ease,
    border-color .16s ease,
    background-color .16s ease,
    box-shadow .18s ease;
}

:where(.choice, .option, .answer)::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(110deg, transparent 20%, rgba(255,255,255,.58) 48%, transparent 75%);
  transform: translateX(-115%);
  transition: transform .38s ease;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  :where(.choice, .option, .answer):hover {
    border-color: color-mix(in srgb, var(--si-primary) 48%, var(--si-border));
    box-shadow: 0 8px 20px color-mix(in srgb, var(--si-primary) 11%, transparent);
    transform: translateX(3px);
  }

  :where(.choice, .option, .answer):hover::before {
    transform: translateX(115%);
  }
}

:where(.choice, .option, .answer):has(input:checked) {
  border-color: color-mix(in srgb, var(--si-primary) 62%, var(--si-border));
  background: color-mix(in srgb, var(--si-primary) 8%, var(--si-panel));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--si-primary) 10%, transparent);
}

:where(.choice, .option, .answer):has(input:focus-visible) {
  outline: 3px solid color-mix(in srgb, var(--si-primary) 24%, transparent);
  outline-offset: 2px;
}

/* Les états de correction arrivent avec un retour visuel bref. */
:where(.choice, .option, .answer).good,
:where(.choice, .option, .answer).correct,
:where(.choice, .option, .answer).is-correct,
:where(.choice, .option, .answer).is-good {
  animation: si-answer-ok .34s ease-out both;
  box-shadow: 0 8px 20px rgba(46,125,50,.13);
}

:where(.choice, .option, .answer).bad,
:where(.choice, .option, .answer).wrong,
:where(.choice, .option, .answer).incorrect,
:where(.choice, .option, .answer).is-wrong,
:where(.choice, .option, .answer).is-bad {
  animation: si-answer-bad .3s ease-out both;
  box-shadow: 0 8px 20px rgba(198,40,40,.11);
}

@keyframes si-answer-ok {
  0% { transform: scale(.985); }
  60% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

@keyframes si-answer-bad {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-3px); }
  70% { transform: translateX(3px); }
}

/* Feedbacks et messages : apparition plutôt que surgissement brutal. */
:where(.feedback, .plan-feedback, .liaison-feedback, .rapp-feedback,
       .clearn-feedback, .cad-status, .rev-status, .situation-result).ok,
:where(.feedback, .plan-feedback, .liaison-feedback, .rapp-feedback,
       .clearn-feedback, .cad-status, .rev-status, .situation-result).bad,
:where(.feedback, .plan-feedback, .liaison-feedback, .rapp-feedback,
       .clearn-feedback, .cad-status, .rev-status, .situation-result).show {
  animation: si-feedback-in .28s ease-out both;
}

@keyframes si-feedback-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Progression vivante, mais sans animation permanente agressive. */
:where(.progress, .progress-bar, .quiz-progress, .progress-wrap) {
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(15,23,42,.08);
}

:where(.progress > div, .progress .fill, .progress-fill,
       .progress-bar > div, .quiz-progress > div) {
  background-image: linear-gradient(
    105deg,
    transparent 0%,
    rgba(255,255,255,.28) 42%,
    rgba(255,255,255,.62) 50%,
    rgba(255,255,255,.28) 58%,
    transparent 100%
  );
  background-size: 220% 100%;
  animation: si-progress-glint 2.8s ease-in-out infinite;
}

@keyframes si-progress-glint {
  0%, 35% { background-position: 130% 0; }
  75%, 100% { background-position: -90% 0; }
}

/* Boutons plus tactiles et cohérents entre anciennes et nouvelles pages. */
:where(.check-btn, .btn-tool, .btn, .si-btn) {
  transition:
    transform .15s ease,
    box-shadow .18s ease,
    filter .18s ease,
    border-color .18s ease;
}

@media (hover: hover) and (pointer: fine) {
  :where(.check-btn, .btn-tool, .btn, .si-btn):not(:disabled):hover {
    filter: saturate(1.08) brightness(1.02);
    box-shadow: 0 9px 20px color-mix(in srgb, var(--si-primary) 17%, transparent);
    transform: translateY(-2px);
  }
}

:where(.check-btn, .btn-tool, .btn, .si-btn):not(:disabled):active {
  box-shadow: 0 3px 9px color-mix(in srgb, var(--si-primary) 14%, transparent);
  transform: translateY(1px) scale(.99);
}

:where(.check-btn, .btn-tool, .btn, .si-btn):disabled {
  cursor: not-allowed;
  filter: grayscale(.2);
}

/* Les encadrés pédagogiques se signalent par une bordure plus nette. */
:where(.help, .help-box, .callout, .note, .warning, .warning-box,
       .lesson-box, .algo-note, .lab-explain, .stage-objective) {
  transition: border-color .2s ease, box-shadow .2s ease;
}

@media (hover: hover) and (pointer: fine) {
  :where(.help, .help-box, .callout, .note, .lesson-box):hover {
    box-shadow: 0 10px 24px rgba(31,55,91,.08);
  }
}
