/* ============================================================
   Défi 5ème — styles (mobile d'abord)
   ============================================================ */
:root {
  --accent: #4f46e5;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e6e8ef;
  --ok: #16a34a;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(20, 24, 40, 0.08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  flex: 1;
}

/* ---------- Accueil ---------- */
.hero { text-align: center; padding: 24px 8px 12px; }
.hero h1 { font-size: 2rem; margin: 0 0 6px; }
.subtitle { color: var(--muted); margin: 0; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0 16px;
}
.topbar h1 { font-size: 1.35rem; margin: 0; }
.back {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--card-bg); color: var(--ink);
  text-decoration: none; font-size: 1.3rem; box-shadow: var(--shadow);
}
.lead { color: var(--muted); margin: 4px 0 18px; }

/* ---------- Grilles de cartes ---------- */
.grid { display: grid; gap: 14px; }

.card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card-bg); border-radius: var(--radius);
  padding: 18px 16px; text-decoration: none; color: var(--ink);
  box-shadow: var(--shadow);
  border-left: 6px solid var(--card, var(--accent));
  transition: transform .12s ease;
}
.card:active { transform: scale(.98); }
button.card { font: inherit; text-align: left; cursor: pointer; width: 100%; }
.card-form { margin: 0; }
.subject-head { font-size: 1.15rem; margin: 24px 0 12px; }
.change { font-size: .85rem; color: var(--muted); text-decoration: none; font-weight: 400; }
.mini-classement {
  display: block; text-align: right; text-decoration: none;
  color: var(--muted); font-size: .85rem; margin: -6px 4px 8px;
}
.card-emoji { font-size: 2rem; flex: 0 0 auto; }
.card-body { display: flex; flex-direction: column; }
.card-title { font-weight: 700; font-size: 1.1rem; }
.card-desc { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.card-arrow { margin-left: auto; font-size: 1.4rem; color: var(--card, var(--accent)); }
.subject .card-title { font-size: 1.25rem; }

/* ---------- Panneau / formulaire de départ ---------- */
.panel {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 20px 18px; box-shadow: var(--shadow);
}
.start-form { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 4px; }
.start-form label { font-weight: 600; }
.start-form input[type=text] {
  width: 100%; padding: 14px 16px; font-size: 1.1rem;
  border: 2px solid var(--line); border-radius: 14px; outline: none;
}
.start-form input[type=text]:focus { border-color: var(--accent); }

.btn-go {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  padding: 15px 18px; font-size: 1.1rem; font-weight: 700;
  border-radius: 14px; text-decoration: none; width: 100%;
}
.btn-go:active { filter: brightness(.95); }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; color: var(--ink); border: 2px solid var(--line);
  padding: 13px 18px; font-size: 1rem; font-weight: 600;
  border-radius: 14px; text-decoration: none; cursor: pointer;
}
.link-classement {
  display: block; text-align: center; margin-top: 16px;
  color: var(--accent); font-weight: 600; text-decoration: none;
}

/* ---------- Quiz ---------- */
.qhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.qtitle { font-weight: 700; }
.qtimer { color: var(--muted); font-variant-numeric: tabular-nums; }

.progress { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); transition: width .25s ease; }
.qcount { color: var(--muted); font-size: .9rem; margin: 10px 0; }

.qcard {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 22px 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.qtext { font-size: 1.4rem; font-weight: 700; text-align: center; margin-bottom: 18px; }
.qfigure { margin: 0 auto 16px; max-width: 340px; }
.qfigure svg.circuit { width: 100%; height: auto; display: block; }

.choices { display: grid; gap: 10px; }
.choice {
  width: 100%; text-align: left; padding: 15px 16px; font-size: 1.05rem;
  background: #fff; border: 2px solid var(--line); border-radius: 14px;
  cursor: pointer; color: var(--ink); transition: border-color .1s;
}
.choice:active { transform: scale(.99); }
.choice.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, #fff); }

.input-wrap { display: flex; flex-direction: column; gap: 8px; }
.answer-input {
  width: 100%; padding: 16px; font-size: 1.4rem; text-align: center;
  border: 2px solid var(--line); border-radius: 14px; outline: none;
}
.answer-input:focus { border-color: var(--accent); }
.hint { text-align: center; color: var(--muted); font-size: .9rem; }

.nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.nav .btn-go { width: auto; min-width: 140px; margin-left: auto; }
.nav .btn-ghost { width: auto; }

/* feedback immédiat */
.choice:disabled { cursor: default; }
.choice.correct { border-color: var(--ok); background: #e9f9ef; }
.choice.wrong   { border-color: #dc2626; background: #fdeaea; }
.answer-input.correct { border-color: var(--ok); background: #e9f9ef; }
.answer-input.wrong   { border-color: #dc2626; background: #fdeaea; }
.feedback { text-align: center; font-weight: 700; }
.feedback.show { margin-top: 14px; }
.feedback.ok { color: var(--ok); }
.feedback.ko { color: #dc2626; }

/* récapitulatif de fin (comprendre ses erreurs) */
.recap { margin-top: 28px; }
.recap-title { font-size: 1.1rem; margin: 0 0 12px; }
.recap-item {
  background: var(--card-bg); border-radius: 14px; padding: 14px 16px;
  box-shadow: var(--shadow); margin-bottom: 10px; border-left: 5px solid var(--line);
}
.recap-item.ok { border-left-color: var(--ok); }
.recap-item.ko { border-left-color: #dc2626; }
.recap-q { font-weight: 600; margin-bottom: 6px; }
.recap-q .num { color: var(--muted); margin-right: 4px; }
.recap-badge { float: right; font-weight: 700; margin-left: 8px; }
.recap-figure { max-width: 220px; margin: 8px 0; }
.recap-figure svg { width: 100%; height: auto; }
.recap-line { font-size: .95rem; margin-top: 2px; }
.recap-your-ko { color: #dc2626; }
.recap-good { color: var(--ok); font-weight: 600; }

/* ---------- Classement ---------- */
.myscore {
  display: flex; align-items: center; gap: 16px;
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.myscore-big { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.myscore-big span { font-size: 1.1rem; opacity: .85; }
.myscore-meta { font-size: 1rem; }

.rank-head { font-size: 1.05rem; margin: 22px 0 10px; }
.ranking { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rank-row {
  display: grid; grid-template-columns: 44px 1fr auto auto; align-items: center;
  gap: 10px; background: var(--card-bg); border-radius: 14px;
  padding: 12px 14px; box-shadow: var(--shadow);
}
.rank-row.me { outline: 3px solid var(--accent); }
.rank-pos { font-weight: 800; text-align: center; font-size: 1.1rem; }
.rank-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-score { font-weight: 700; color: var(--accent); }
.rank-time { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

.actions { display: flex; gap: 12px; margin-top: 22px; }
.actions .btn-go, .actions .btn-ghost { flex: 1; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* derniers scores sur la home */
.recent { margin-top: 30px; }
.recent-title { font-size: 1.05rem; margin: 0 0 12px; }
.recent-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.recent-item {
  background: var(--card-bg); border-radius: 12px; padding: 11px 14px;
  box-shadow: var(--shadow); font-size: .92rem; line-height: 1.35;
}
.recent-item .when { color: var(--muted); }
.recent-item .who { font-weight: 700; }
.recent-item .sc { font-weight: 700; color: var(--accent); }

.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px; }

/* Fallback si color-mix non supporté */
@supports not (background: color-mix(in srgb, red 10%, white)) {
  .choice.selected { background: #eef0ff; }
}

/* ---------- Tablette / desktop ---------- */
@media (min-width: 700px) {
  .hero h1 { font-size: 2.4rem; }
  .qtext { font-size: 1.6rem; }
  .grid.two { grid-template-columns: 1fr 1fr; }
}

/* ---------- Fiche de cours (cours.php) ---------- */
.lesson { display: grid; gap: 14px; }
.lesson-sec {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 18px 18px 16px; box-shadow: var(--shadow);
}
.lesson-sec h2 { font-size: 1.15rem; margin: 0 0 10px; }
.lesson-sec p { margin: 0 0 10px; }
.lesson-sec p:last-child { margin-bottom: 0; }
.lesson-sec ul { margin: 0; padding-left: 1.2em; display: grid; gap: 6px; }
.lesson-sec strong { color: var(--accent); }

.formula {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 8px; background: var(--bg); border-radius: 14px; padding: 14px 10px;
  margin: 4px 0 12px; font-weight: 700;
}
.chip { padding: 5px 10px; border-radius: 10px; font-weight: 700; }
.chip-o2  { background: #fde8e8; color: #b91c1c; }
.chip-glc { background: #fef3c7; color: #92400e; }
.chip-nrj { background: #dcfce7; color: #166534; }
.chip-co2 { background: #e0e7ff; color: #3730a3; }

.calc {
  background: var(--bg); border-radius: 12px; padding: 12px 14px;
  font-weight: 600; font-size: .95rem;
}
.calc small { font-weight: 400; color: var(--muted); font-size: .9rem; }

.lesson-table { overflow-x: auto; }
.lesson-table table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 360px; }
.lesson-table th, .lesson-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.lesson-table th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.flow-step {
  background: var(--bg); border: 2px solid var(--line); border-radius: 10px;
  padding: 5px 10px; font-weight: 600; font-size: .95rem;
}
.flow-end { border-color: var(--accent); color: var(--accent); }
.flow-arrow { color: var(--muted); font-weight: 700; }

.retenir {
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); line-height: 1.5;
}
.retenir strong { display: block; margin-bottom: 4px; font-size: 1.05rem; }

.recap-explain { font-size: .9rem; color: var(--muted); margin-top: 6px; }
