/* Prépa FG2 — feuille de style unique (mobile first, thème clair/sombre) */
:root {
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-2: #eceee8;
  --text: #17201b;
  --muted: #56625b;
  --border: #cfd5cc;
  --accent: #2f5d46;
  --accent-ink: #ffffff;
  --accent-soft: #dce9e1;
  --ok: #1d7a3e;
  --ok-soft: #dff3e5;
  --ko: #b3261e;
  --ko-soft: #fbe4e2;
  --warn: #8a5a00;
  --warn-soft: #fff1d1;
  --info-soft: #e3ecf7;
  --friend: #1e5bb8;
  --friend-fill: #a9c8f0;
  --enemy: #c4161c;
  --enemy-fill: #f4a6a6;
  --neutral: #138a3a;
  --neutral-fill: #a8e2b6;
  --unknown: #a68a00;
  --unknown-fill: #fff09a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --focus: 0 0 0 3px #f2b705;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1714; --surface: #17221d; --surface-2: #1f2c26; --text: #e6ece8; --muted: #a2b0a8;
    --border: #304039; --accent: #7cc39d; --accent-ink: #0c1511; --accent-soft: #23392e;
    --ok: #6fd58f; --ok-soft: #173524; --ko: #ff8a80; --ko-soft: #3d1d1b; --warn: #ffcc66; --warn-soft: #3b2f12;
    --info-soft: #1c2a3a; --friend: #8ab8ff; --friend-fill: #1d3557; --enemy: #ff7b7b; --enemy-fill: #5a1f22;
    --neutral: #7be29a; --neutral-fill: #1b4a2a; --unknown: #ffe066; --unknown-fill: #4a4214;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1714; --surface: #17221d; --surface-2: #1f2c26; --text: #e6ece8; --muted: #a2b0a8;
  --border: #304039; --accent: #7cc39d; --accent-ink: #0c1511; --accent-soft: #23392e;
  --ok: #6fd58f; --ok-soft: #173524; --ko: #ff8a80; --ko-soft: #3d1d1b; --warn: #ffcc66; --warn-soft: #3b2f12;
  --info-soft: #1c2a3a; --friend: #8ab8ff; --friend-fill: #1d3557; --enemy: #ff7b7b; --enemy-fill: #5a1f22;
  --neutral: #7be29a; --neutral-fill: #1b4a2a; --unknown: #ffe066; --unknown-fill: #4a4214;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: .2em 0 .5em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: .4em 0 .8em; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; background: var(--accent); color: var(--accent-ink); }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.icon-btn { background: transparent; color: inherit; border: 0; padding: 8px; border-radius: 8px; cursor: pointer; min-width: 44px; min-height: 44px; }
.tabs { position: sticky; top: 60px; z-index: 19; display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.tabs a { flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; text-decoration: none; color: var(--text); font-size: .95rem; white-space: nowrap; }
.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

main { max-width: 860px; margin: 0 auto; padding: 16px; outline: none; }
.loading { color: var(--muted); }
.foot { max-width: 860px; margin: 24px auto; padding: 0 16px 24px; color: var(--muted); font-size: .85rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow); }
.card.tight { padding: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: 1fr 1fr 1fr; } }
.tile { display: block; text-decoration: none; color: var(--text); }
.tile h3 { margin-bottom: .2em; }
.tile p { color: var(--muted); margin: 0; font-size: .92rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.pill { display: inline-block; font-size: .78rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.accent { background: var(--accent-soft); color: var(--text); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

button, .btn { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: 10px 14px; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button:disabled { opacity: .55; cursor: not-allowed; }
select, input[type="text"], input[type="number"], input[type="search"] {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px; min-height: 44px; max-width: 100%; }
label.inline { display: inline-flex; align-items: center; gap: 6px; }
.filters { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.filters .full { grid-column: 1 / -1; }
@media (min-width: 620px) { .filters { grid-template-columns: repeat(4, 1fr); } .filters .full { grid-column: auto; } }

/* Questions */
.q-head { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.q-prompt { font-weight: 600; margin: 4px 0 10px; white-space: pre-line; }
.q-context { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: .93rem; white-space: pre-line; margin-bottom: 10px; }
.opts { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.opt { width: 100%; text-align: left; justify-content: flex-start; background: var(--surface); line-height: 1.4; padding: 10px 12px; }
.opt .letter { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--surface-2); font-weight: 700; font-size: .85rem; margin-right: 4px; }
.opt[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.opt.is-ok { background: var(--ok-soft); border-color: var(--ok); }
.opt.is-ko { background: var(--ko-soft); border-color: var(--ko); }
.why { font-size: .9rem; margin: 4px 0 0 36px; padding: 6px 10px; border-left: 3px solid var(--border); color: var(--text); }
.why.ok { border-color: var(--ok); }
.why.ko { border-color: var(--ko); }
.verdict { font-weight: 700; margin: 12px 0 6px; }
.verdict.ok { color: var(--ok); } .verdict.ko { color: var(--ko); }
.feedback { margin-top: 10px; }
.feedback h4 { margin: 12px 0 4px; font-size: .95rem; }
.box-exp { background: var(--info-soft); border-radius: 10px; padding: 10px 12px; white-space: pre-line; }
.box-cpl { background: var(--warn-soft); border-radius: 10px; padding: 10px 12px; white-space: pre-line; }
.src { font-size: .8rem; color: var(--muted); margin-top: 8px; }

/* Ordering */
.order-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.order-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  touch-action: none; user-select: none; -webkit-user-select: none; }
.order-item .handle { cursor: grab; padding: 6px; color: var(--muted); }
.order-item .num { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); display: inline-grid; place-items: center; font-weight: 700; flex: 0 0 auto; }
.order-item .txt { flex: 1; }
.order-item .mv { min-width: 40px; min-height: 40px; padding: 4px; }
.order-item.dragging { opacity: .6; border-style: dashed; }
.order-item.is-ok { background: var(--ok-soft); border-color: var(--ok); }
.order-item.is-ko { background: var(--ko-soft); border-color: var(--ko); }
.pool { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip { border-radius: 999px; padding: 8px 12px; min-height: 40px; }

/* Matching */
.match-row { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
@media (min-width: 620px) { .match-row { grid-template-columns: 1fr 1fr; align-items: center; } }
.match-row.is-ok select { border-color: var(--ok); background: var(--ok-soft); }
.match-row.is-ko select { border-color: var(--ko); background: var(--ko-soft); }

/* Flashcards */
.flash { perspective: 1000px; min-height: 220px; }
.flash-inner { position: relative; min-height: 220px; transition: transform .45s; transform-style: preserve-3d; cursor: pointer; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: grid; place-items: center; text-align: center;
  padding: 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); font-size: 1.25rem; white-space: pre-line; overflow: auto; }
.flash-back { transform: rotateY(180deg); background: var(--accent-soft); font-size: 1.05rem; }
@media (prefers-reduced-motion: reduce) { .flash-inner { transition: none; } }

/* Progress */
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; background: var(--accent); }
table.prog { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.prog th, table.prog td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.prog td.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* Exam */
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; }
.timer.low { color: var(--ko); }
.score-big { font-size: 2.6rem; font-weight: 800; margin: 0; }

/* Symbol figure */
.figure { display: flex; justify-content: center; margin: 6px 0 12px; }
.figure svg { max-width: min(100%, 340px); width: 100%; height: auto; }
.sym-stroke { stroke: var(--text); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: opacity .25s; max-width: calc(100% - 32px); z-index: 60; }
.toast.show { opacity: 1; }
audio { width: 100%; }
details > summary { cursor: pointer; min-height: 32px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.filters > * { min-width: 0; }
.filters label.stack { display: flex; flex-direction: column; gap: 4px; }
.filters label.stack > * + * { margin-top: 0; }
.filters select, .filters input[type="search"] { width: 100%; }
main:focus, main:focus-visible { box-shadow: none; }
.opt:disabled { opacity: 1; }

/* À retenir, drapeaux, cours */
.box-memo { background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.box-memo h4 { margin: 2px 0 4px; }
.box-memo ul { margin: 0; padding-left: 1.2em; }
.box-memo p { margin: 0; }
.flags { display: grid; gap: 8px; margin: 10px 0; }
.flag { border: 1px solid var(--warn); border-left-width: 4px; background: var(--warn-soft); border-radius: 10px; padding: 8px 12px; }
.flag p { margin: .2em 0; }
.flag-head strong { color: var(--warn); }
.flag-trancher { border-color: var(--ko); background: var(--ko-soft); }
.flag-trancher .flag-head strong { color: var(--ko); }
.flag-src { margin: 4px 0 0; padding-left: 1.2em; }
.flag-src a { overflow-wrap: anywhere; }
.cours-sec { scroll-margin-top: 120px; }
.cours-sec.is-target { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cours-sec:focus { outline: none; }
.cours-sec:focus-visible { box-shadow: var(--focus); }
.md table { margin: 8px 0; }
.md ul, .md ol { padding-left: 1.3em; }
.md h3, .md h4, .md h5 { margin: 12px 0 4px; font-size: 1rem; }
details.practice { margin-top: 10px; }
details.practice > summary { font-weight: 600; color: var(--accent); padding: 8px 0; }

/* Changer d'appareil */
.sync-code { font: 700 2rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .12em; margin: 0; }
.sync-in { text-transform: uppercase; width: 9em; }
.sync-in::placeholder { color: var(--muted); opacity: 1; text-transform: none; }
.sync-err { color: var(--ko); font-weight: 600; }
form.row { margin: 12px 0 4px; }

/* Planches à imprimer (63 × 88 mm). La feuille reste blanche, quel que soit le thème. */
.sheets { display: flex; flex-direction: column; align-items: safe center; gap: 16px; margin: 16px 0; overflow-x: auto; }
.sheet { position: relative; flex: none; background: #fff; color: #111; box-shadow: 0 2px 10px rgba(0,0,0,.25);
  --text: #111; --friend: #1e5bb8; --friend-fill: #a9c8f0; --enemy: #c4161c; --enemy-fill: #f4a6a6;
  --neutral: #138a3a; --neutral-fill: #a8e2b6; --unknown: #a68a00; --unknown-fill: #fff09a; }
.pc { position: absolute; width: 63mm; height: 88mm; border: .2mm dashed #bbb; padding: 5mm 4.5mm 6mm; display: flex; flex-direction: column; justify-content: center; gap: 2.5mm; overflow: hidden;
  font-family: system-ui, sans-serif; white-space: pre-line; }
.pc p { margin: 0; }
.pc-q { font: 600 4mm/1.3 system-ui, sans-serif; }
.pc-q.big { font-size: 7mm; text-align: center; }
.pc-a { font: 700 3.8mm/1.3 system-ui, sans-serif; }
.pc-memo { font: 3.1mm/1.35 system-ui, sans-serif; color: #333; border-top: .2mm solid #999; padding-top: 2mm; }
.pc-sym svg { width: 100%; height: auto; max-height: 60mm; }
.pc-sym.small-sym svg { max-height: 32mm; }
.pc-num { position: absolute; right: 4mm; bottom: 3mm; font: 600 2.6mm/1 system-ui, sans-serif; color: #777; }
.pc-deck { font: 600 2.6mm/1.2 system-ui, sans-serif; color: #555; text-transform: uppercase; letter-spacing: .2mm; }
.pc-name { font: 700 4.4mm/1.25 system-ui, sans-serif; }
.pc-frame { flex: 1; border: .4mm solid #111; border-radius: 2mm; }
.pc:has(.pc-frame) { justify-content: flex-start; }
.pc-test { margin: auto; font: 700 8mm/1 system-ui, sans-serif; }
.cm { position: absolute; background: #000; }
.cm.v { width: .2mm; }
.cm.h { height: .2mm; }
.sheet-lab { position: absolute; left: 50%; bottom: 2mm; transform: translateX(-50%); font: 2.4mm/1 system-ui, sans-serif; color: #888; white-space: nowrap; }
@media screen and (max-width: 900px) { .sheets { zoom: .45; } }
@media print {
  body.printing { background: #fff; color: #111; padding: 0; }
  body.printing .topbar, body.printing .tabs, body.printing .foot, body.printing .skip, .no-print, .toast, .confetti { display: none !important; }
  body.printing main { max-width: none; padding: 0; margin: 0; }
  body.printing-cards main { max-width: none; padding: 0; margin: 0; }
  /* Corrigé : cartes sans ombre, une question ne se coupe pas, les liens des sources sont écrits en clair */
  body.printing .corr-q { box-shadow: none; break-inside: avoid; border-color: #999; }
  body.printing .flag-src a::after { content: " — " attr(href); }
  *, *::before, *::after { animation: none !important; }
  body.printing-cards .sheets { display: block; margin: 0; gap: 0; zoom: 1; overflow: visible; }
  body.printing-cards .sheet { box-shadow: none; break-after: page; }
  body.printing-cards .sheet:last-child { break-after: auto; }
  body.printing-cards .pc { border-color: transparent; } /* on coupe sur les traits de coupe, pas sur le pointillé */
}

/* Étoile « revenir plus tard » et « Ma note » */
.q-tools { display: flex; justify-content: flex-end; margin: -6px -6px 4px 0; }
button.star { min-height: 36px; padding: 4px 10px; font-size: .85rem; }
button.star[aria-pressed="true"] { border-color: var(--warn); color: var(--warn); }
.my-note-wrap { display: grid; gap: 4px; margin: 10px 0; }
textarea.my-note { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; width: 100%; resize: vertical; }
textarea.my-note::placeholder { color: var(--muted); opacity: 1; }

/* Petites animations (toutes coupées par prefers-reduced-motion plus bas) */
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes pop { 40% { transform: scale(1.06); } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@keyframes grow { from { width: 0; } }
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(540deg); opacity: .9; } }
main > *, .card { animation: rise .25s ease-out both; }
.verdict.ok, .opt.is-ok, .order-item.is-ok, button.star.pop { animation: pop .35s ease-out; }
.verdict.ko, .opt.is-ko { animation: shake .35s ease-in-out; }
.bar > span { animation: grow .7s ease-out; }
.confetti { position: fixed; inset: 0 0 auto 0; height: 0; pointer-events: none; z-index: 70; }
.confetti i { position: absolute; top: -12px; width: 7px; height: 12px; border-radius: 2px; animation: fall 2.2s cubic-bezier(.3,.6,.5,1) both; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
/* Corrigés (#/corrige/<id>) et impression / PDF */
.corrige h1 { font-size: 1.3rem; }
.c-q { break-inside: avoid; margin: 14px 0; }
.c-q h3 { font-size: 1rem; margin: 0 0 6px; }
.c-q h2 { font-size: 1.05rem; }
.c-opt { margin: 2px 0; padding: 2px 6px; border-radius: 6px; color: var(--muted); }
.c-opt.ok { color: var(--ok); background: var(--ok-soft); font-weight: 700; }
.c-list { margin: 4px 0; padding-left: 1.4em; }
.c-list li { margin: 2px 0; }
.c-dl { margin: 0; padding-left: 1.1em; }
.c-dl li { margin: 6px 0; }
.corrige .figure svg { max-width: 260px; }
@media print {
  .topbar, .tabs, .foot, .no-print, .skip, .toast { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  main { padding: 0; max-width: none; }
  .q-context { white-space: pre-line; font-size: 9.5pt; }
  .c-opt.ok { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
}
