:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel2: #1f242c;
  --line: #2c333d;
  --text: #e6e9ee;
  --muted: #98a2b0;
  --accent: #4fb0c6;
  --accent-ink: #062027;
  --ok: #3fb67a;
  --ok-bg: rgba(63, 182, 122, .14);
  --bad: #e5675f;
  --bad-bg: rgba(229, 103, 95, .14);
  --warn: #e0b04f;
  --radius: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel2: #eef0f3;
  --line: #d9dde3;
  --text: #1a1e24;
  --muted: #5d6673;
  --accent: #127a91;
  --accent-ink: #ffffff;
  --ok: #1d8a54;
  --ok-bg: rgba(29, 138, 84, .1);
  --bad: #c2382f;
  --bad-bg: rgba(194, 56, 47, .09);
  --warn: #a8740c;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--line);
}

button, .opt, .rate button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.brand { background: none; border: 0; font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.logo { color: var(--accent); font-size: 1.3rem; }
.top nav { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
.top nav button { background: none; border: 0; padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.top nav button:hover, .top nav button.on { background: var(--panel2); color: var(--text); }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 80px; }

/* generic */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel2); padding: 10px 16px; border-radius: 10px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.pill.accent { color: var(--accent); border-color: var(--accent); }

/* home */
.hero { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 22px; }
.due-box { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.due-num { font-size: 2.4rem; font-weight: 800; color: var(--accent); line-height: 1; }
.section-title { margin: 26px 0 10px; display: flex; align-items: baseline; gap: 10px; }
.theme-tile {
  text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 6px; min-height: 104px;
}
.theme-tile:hover { border-color: var(--accent); }
.theme-tile .t-name { font-weight: 700; }
.bar { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin-top: auto; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.mode-switch button { border: 0; background: none; padding: 7px 12px; color: var(--muted); }
.mode-switch button.on { background: var(--accent); color: var(--accent-ink); }

/* quiz */
.quiz-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.progress { flex: 1; min-width: 120px; }
.qwrap { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 820px) { .qwrap { grid-template-columns: 1fr; } }
.img-box {
  background: #000; border-radius: var(--radius); overflow: hidden; position: relative; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; min-height: 240px;
}
.img-box img { display: block; max-width: 100%; max-height: 70vh; cursor: zoom-in; }
.img-box .zoom { position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.65); color: #fff; border: 0; border-radius: 8px; padding: 5px 10px; font-size: .85rem; }
.img-meta { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.stem { font-weight: 600; margin-bottom: 4px; }
.hint { font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; text-align: left;
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.opt .L { width: 28px; height: 28px; border-radius: 7px; border: 1.5px solid var(--line); display: grid; place-items: center; font-weight: 700; font-size: .9rem; }
.opt.sel { border-color: var(--accent); }
.opt.sel .L { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.opt.locked { cursor: default; }
.opt.true { border-color: var(--ok); background: var(--ok-bg); }
.opt.false-sel { border-color: var(--bad); background: var(--bad-bg); }
.opt.missed { border-color: var(--ok); border-style: dashed; }
.opt .why { grid-column: 2; font-size: .9rem; color: var(--muted); margin-top: 4px; }
.opt .why b.v { color: var(--ok); }
.opt .why b.f { color: var(--bad); }
.verdict { margin: 14px 0 6px; padding: 12px 14px; border-radius: 10px; font-weight: 700; }
.verdict.ok { background: var(--ok-bg); color: var(--ok); }
.verdict.part { background: rgba(224,176,79,.14); color: var(--warn); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.correction { margin-top: 16px; }
.correction h3 { color: var(--accent); margin-top: 14px; }
.correction p, .correction li { margin: .35em 0; }
.correction ul { padding-left: 1.2em; margin: .3em 0; }
.retenir { border-left: 3px solid var(--accent); background: var(--panel2); padding: 10px 12px; border-radius: 0 8px 8px 0; margin-top: 12px; }
.source { margin-top: 14px; font-size: .78rem; color: var(--muted); }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.rate button { padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-weight: 600; font-size: .9rem; }
.rate button small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.rate button.r1 { border-color: var(--bad); }
.rate button.r4 { border-color: var(--ok); }
.actions { position: sticky; bottom: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); display: flex; gap: 10px; margin-top: 12px; }

/* results */
.score { font-size: 3rem; font-weight: 800; color: var(--accent); }
.res-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.res-item { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); }
.res-item img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; background: #000; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* bases */
.bases article { margin-bottom: 14px; }
.bases table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.bases th, .bases td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: left; vertical-align: top; }
.bases .tbl { overflow-x: auto; }

/* forms */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.form input[type=text], .form textarea, .form select {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
.form textarea { min-height: 70px; }
.opt-edit { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); }
.drop img { max-width: 100%; max-height: 240px; }

/* viewer */
.viewer { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: calc(8px + env(safe-area-inset-top)) 12px 8px;background: #111; color: #ddd; font-size: .85rem; }
.viewer-bar input { width: 110px; vertical-align: middle; }
.viewer-bar button { background: #222; border: 1px solid #333; color: #ddd; border-radius: 7px; padding: 5px 10px; }
#vClose { margin-left: auto; }
.viewer-stage { flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center; touch-action: none; cursor: grab; }
.viewer-stage img { max-width: 100%; max-height: 100%; transform-origin: center; user-select: none; -webkit-user-drag: none; }
.viewer-hint { text-align: center; color: #777; font-size: .75rem; margin: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
#vClose { font-size: 1.1rem; padding: 6px 14px; }
body.noscroll { overflow: hidden; }

.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
kbd { font: .8rem ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }

/* sigles */
abbr.ac { text-decoration: underline dotted; text-decoration-color: var(--accent); text-underline-offset: 3px; cursor: help; }
.gloss-pop {
  position: absolute; z-index: 60; background: var(--panel); color: var(--text); border: 1px solid var(--accent);
  border-radius: 10px; padding: 10px 12px; font-size: .88rem; line-height: 1.45; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.gloss-pop[hidden] { display: none; }

@media (max-width: 560px) {
  .brand .brand-txt { display: none; }
  .brand .logo { font-size: 1.4rem; }
  .top nav button { padding: 6px 7px; font-size: .88rem; }
  .top nav { flex-wrap: nowrap; }
  .top { gap: 4px; }
  main { padding-top: 14px; }
  .card { padding: 14px; }
  .opt { padding: 10px; }
  .img-box img { max-height: 55vh; }
}

/* repères sur l'image */
.fig { position: relative; display: inline-block; line-height: 0; max-width: 100%; }
.fig img { display: block; max-width: 100%; max-height: 70vh; cursor: zoom-in; }
.mk-layer { position: absolute; inset: 0; pointer-events: none; }
.mk-layer[hidden] { display: none; }
.mk { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.mk .mk-line { fill: none; stroke: #ffd400; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.mk .mk-halo { fill: none; stroke: rgba(0,0,0,.75); stroke-width: 5; vector-effect: non-scaling-stroke; }
.mk-label {
  position: absolute; transform: translate(-50%, calc(-100% - 4px)); white-space: nowrap;
  background: #ffd400; color: #111; font: 700 12px/1.2 system-ui, sans-serif; padding: 2px 6px; border-radius: 5px;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.mk-label.below { transform: translate(-50%, 4px); }
.img-box .mk-toggle { left: 8px; right: auto; }
.viewer-stage .fig { transform-origin: center; }
.viewer-stage .fig img { max-width: 100vw; max-height: calc(100vh - 60px); cursor: grab; user-select: none; -webkit-user-drag: none; }
.actions.static { position: static; border-top: 0; }
@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .theme-tile { min-height: 92px; padding: 12px; }
  .theme-tile .t-name { font-size: .95rem; }
}

/* ===== téléphone ===== */
.actions .btn.primary { min-width: 160px; }
@media (max-width: 820px) {
  body.quiz .top { display: none; }
  body.quiz main { padding-top: calc(8px + env(safe-area-inset-top)); }
  .quiz-head { margin-bottom: 8px; gap: 8px; }
  .quiz-head .btn { padding: 8px 12px; }
  .img-box { margin: 0 -16px; border-radius: 0; border-left: 0; border-right: 0; min-height: 200px; }
  .img-box img, .fig img { max-height: 58vh; }
  .img-meta { display: none; }
  .stem { margin-top: 4px; font-size: 1.02rem; }
  .actions { position: sticky; bottom: 0; margin: 12px -16px 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .actions .btn.primary { width: 100%; padding: 14px; font-size: 1.05rem; }
  .actions.static { position: sticky; }
  .rate button { padding: 12px 4px; }
  .correction { margin-left: -6px; margin-right: -6px; }
  .opt { padding: 12px 10px; }
}
.see-marks { width: 100%; margin-top: 8px; border-color: #ffd400; color: #ffd400; background: rgba(255,212,0,.08); }
:root[data-theme="light"] .see-marks { color: #8a6d00; border-color: #c9a600; }

/* ===== aucun défilement horizontal ===== */
html, body { max-width: 100%; overflow-x: hidden; overscroll-behavior-x: none; }
@supports (overflow: clip) { html, body { overflow-x: clip; } }
main, .card, .opt, .correction, .stem, .bases, .res-item { min-width: 0; overflow-wrap: anywhere; word-break: normal; hyphens: auto; }
img, svg, video { max-width: 100%; }
.bases .tbl { overflow-x: visible; }
.bases table { table-layout: fixed; width: 100%; }
.bases th, .bases td { overflow-wrap: anywhere; hyphens: auto; }
@media (max-width: 560px) {
  .bases table, .bases tbody, .bases tr, .bases td, .bases th { display: block; width: 100%; }
  .bases tr { padding: 8px 0; border-bottom: 1px solid var(--line); }
  .bases td, .bases th { border: 0; padding: 2px 0; }
  .bases td:first-child, .bases th:first-child { font-weight: 700; color: var(--text); }
  .correction table { display: block; }
  .img-box, .actions { max-width: 100vw; }
}
/* droite / gauche */
.side-box { margin: 14px 0; padding: 12px; border-radius: 10px; border: 1px dashed var(--accent); background: var(--panel2); }
.side-box p { margin: .45em 0; }
.side-svg { display: block; width: 100%; max-width: 360px; height: auto; margin: 8px auto; color: var(--text); }
.side-tag { position: absolute; top: 6px; padding: 2px 6px; border-radius: 5px; font: 700 11px/1.2 system-ui, sans-serif; background: rgba(0,0,0,.72); color: #ffd400; border: 1px solid #ffd400; line-height: 1.3; }
.side-tag.l { left: 6px; }
.side-tag.r { right: 6px; color: #7fd3e6; border-color: #7fd3e6; }
@media (max-width: 560px) { .bases tr:has(th) { display: none; } .bases td + td { margin-top: 2px; } }
.install { margin-top: 18px; border-color: var(--accent); }
.install ol { padding-left: 1.2em; margin: 8px 0; }
.install li { margin: 6px 0; }
.ios-share { display: inline-block; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
/* en mode app : pas de rebond ni de sélection accidentelle */
@media (display-mode: standalone) { html, body { overscroll-behavior-y: none; } }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.correction, .stem, .opt .why, .bases { -webkit-user-select: text; user-select: text; }
