:root {
  --bg: #f3f4f1; --surface: #fff; --soft: #eef1ee; --ink: #1b2120; --muted: #5d6865; --line: #dce1dd;
  --accent: #0f7a63; --accent-d: #0a5c4a; --accent-bg: #e3f2ed; --brand: #b3261e;
  --ok: #18794e; --ok-bg: #e7f5ec; --bad: #c4321f; --bad-bg: #fcebe8; --amber: #a86400; --amber-bg: #fff3d9;
  --focus: #2463eb; --r: 8px;
  --zh: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, var(--zh); background: var(--bg); color: var(--ink); letter-spacing: 0; -webkit-font-smoothing: antialiased; }
.zh { font-family: var(--zh); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.qcard:focus { outline: none; }
.ic, svg.lucide { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: -3px; font-style: normal; line-height: 18px; text-align: center; }

/* En-tete */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 8px 20px; background: var(--surface); border-bottom: 1px solid var(--line); min-height: 56px; }
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand .zh { font-size: 20px; font-weight: 700; color: var(--brand); }
.brand-sub { font-size: 13px; color: var(--muted); }
.tabs { display: flex; gap: 2px; background: var(--soft); padding: 3px; border-radius: var(--r); }
.tabs button { display: flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.stats { margin-left: auto; display: flex; gap: 14px; font-size: 14px; white-space: nowrap; }
.st { display: inline-flex; align-items: center; gap: 5px; }
.st b { font-variant-numeric: tabular-nums; }
.streak.hot { color: var(--amber); }
.tools { display: flex; gap: 4px; }
.ibtn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; background: transparent; border-radius: var(--r); color: var(--muted); }
.ibtn:hover { background: var(--soft); color: var(--ink); }
.py-toggle .zh { font-size: 16px; font-weight: 600; }
.py-toggle[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent-d); border-color: #bfe0d5; }
.hint { cursor: help; }
.side-toggle { display: none; }

/* Mise en page */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 24px; max-width: 1180px; margin: 0 auto; padding: 20px; }
.layout:not([data-view="train"]) { grid-template-columns: minmax(0, 1fr); }
.layout:not([data-view="train"]) .side { display: none; }
.main { min-width: 0; }
.side { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 96px); overflow: auto; font-size: 14px; }
.side section { margin-bottom: 18px; }
.side h3, .psec h3 { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin: 0 0 6px; }
.h3row { display: flex; align-items: baseline; gap: 8px; }
.h3row h3 { margin-right: auto; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; }
.link:hover { text-decoration: underline; }
.chk { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.chk:hover { background: var(--surface); }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; flex: none; }
.chk .ic, .chk svg.lucide { color: var(--muted); width: 16px; height: 16px; }
.chk.off { opacity: .45; }
.chk .zh { white-space: nowrap; }
.lfr { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cnt { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cnt.warn { color: var(--bad); font-weight: 600; }

/* Carte question */
.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px 24px 22px; max-width: 820px; }
.qcard.is-ok { border-color: #b5dcc4; }
.qcard.is-bad { border-color: #efc2ba; }
.qhead { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.qtype { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--accent-d); }
.qlesson { padding: 1px 8px; border-radius: 4px; background: var(--soft); }
.qreview { padding: 1px 8px; border-radius: 4px; background: var(--amber-bg); color: var(--amber); font-weight: 600; }
.grow { flex: 1; }
.qtitle { font-size: 15px; font-weight: 500; color: var(--muted); margin: 10px 0 12px; }
.prompt { margin-bottom: 18px; }
.pzh { font-size: 40px; font-weight: 600; line-height: 1.25; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.psent { font-size: 22px; line-height: 1.7; }
.psent .say { vertical-align: middle; margin-left: 4px; }
.pfr { font-size: 20px; font-weight: 600; }
.pfr.sm { font-size: 14px; font-weight: 400; color: var(--muted); margin-top: 4px; }
.pmath { font: 600 32px/1.3 "Cambria Math", "STIX Two Math", "Times New Roman", serif; padding: 10px 0; overflow-x: auto; white-space: nowrap; }
.py { color: var(--accent-d); font-size: 15px; }
.q-py { margin-top: 2px; }
.no-py .q-py { display: none; }
.no-fr .fr-line { display: none; }
.blank { display: inline-block; min-width: 3em; border-bottom: 2px solid var(--accent); color: transparent; text-align: center; }
.listen { display: inline-flex; align-items: center; gap: 10px; padding: 14px 22px; font-size: 17px; font-weight: 600; border: 1px solid #bfe0d5; background: var(--accent-bg); color: var(--accent-d); border-radius: var(--r); }
.listen:hover { background: #d3ebe3; }
.listen .ic, .listen svg.lucide { width: 22px; height: 22px; }

.say { display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--accent); flex: none; }
.say:hover { background: var(--accent-bg); }
.pzh .say { width: 38px; height: 38px; }
.pzh .say .ic, .pzh .say svg.lucide { width: 22px; height: 22px; }

/* Options */
.opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.opts.long { grid-template-columns: minmax(0, 1fr); }
.opt { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; text-align: left; min-height: 54px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); transition: background .12s, border-color .12s; }
.opt:hover:not([aria-disabled]) { border-color: var(--accent); background: #f7fbf9; }
.opt .k { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 4px; background: var(--soft); color: var(--muted); font-size: 12px; font-weight: 600; flex: none; }
.ol { font-size: 16px; overflow-wrap: anywhere; flex: 1 1 auto; min-width: 0; }
.ol.zh { font-size: 20px; }
.ol.math { font: 600 26px/1 "Cambria Math", "STIX Two Math", serif; }
.ol.pyopt { font-size: 18px; color: var(--ink); }
/* display (not visibility): a reserved empty line would reveal which option has a hint */
.os { flex-basis: 100%; padding-left: 32px; font-size: 13px; color: var(--muted); display: none; }
.answered .os { display: block; }
.opt.correct { background: var(--ok-bg); border-color: var(--ok); }
.opt.correct .k { background: var(--ok); color: #fff; }
.opt.chosen { background: var(--bad-bg); border-color: var(--bad); }
.opt.chosen .k { background: var(--bad); color: #fff; }
.answered .opt:not(.correct):not(.chosen) { opacity: .65; }

/* Saisie */
.inrow { display: flex; gap: 8px; }
.inrow input { flex: 1; min-width: 0; font-size: 20px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); }
.inrow input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.inrow input.ok { border-color: var(--ok); background: var(--ok-bg); }
.inrow input.bad { border-color: var(--bad); background: var(--bad-bg); }
.fillrow { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.fillline { flex: 1 1 320px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 22px; line-height: 1.4; }
.fillline .fx { padding: 4px 0; }
.fillline .fb { width: calc(4em + 20px); font-size: 20px; padding: 4px 8px; text-align: center; border: 0; border-bottom: 2px solid var(--accent); border-radius: 4px 4px 0 0; background: var(--accent-bg); color: var(--ink); max-width: 100%; }
.fillline .fb:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.fillline .fb.ok { border-bottom-color: var(--ok); background: var(--ok-bg); }
.fillline .fb.bad { border-bottom-color: var(--bad); background: var(--bad-bg); color: var(--bad); text-decoration: line-through; }

/* Associer */
.match { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 10px; }
.mcol { display: flex; flex-direction: column; gap: 8px; }
.mi { text-align: left; padding: 10px 12px; min-height: 48px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); font-size: 15px; overflow-wrap: anywhere; }
.mi.zh { font-size: 17px; }
.mi:hover:not(.done) { border-color: var(--accent); }
.mi.sel { border-color: var(--accent); background: var(--accent-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.mi.done { background: var(--ok-bg); border-color: #b5dcc4; color: var(--ok); cursor: default; }
.mi.wrong { background: var(--bad-bg); border-color: var(--bad); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* Remettre en ordre */
.built { display: flex; flex-wrap: wrap; gap: 6px; min-height: 58px; padding: 8px; border: 1px dashed #b9c2bd; border-radius: var(--r); background: #fafbfa; margin-bottom: 12px; }
.built.ok { border: 1px solid var(--ok); background: var(--ok-bg); }
.built.bad { border: 1px solid var(--bad); background: var(--bad-bg); }
.tiles { display: flex; flex-wrap: wrap; gap: 6px; }
.tile { padding: 8px 12px; font-size: 19px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); }
.tile:hover { border-color: var(--accent); }
.tile.used { visibility: hidden; }

/* Retour et actions */
.feedback:empty { display: none; }
.feedback { margin-top: 18px; }
.verdict { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: 16px; margin-bottom: 10px; }
.is-ok .verdict { color: var(--ok); }
.is-bad .verdict { color: var(--bad); }
.verdict .ic, .verdict svg.lucide { width: 22px; height: 22px; }
.vmsg { color: var(--muted); font-size: 14px; }
.vstreak { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; padding: 2px 8px; border-radius: 4px; background: var(--amber-bg); color: var(--amber); font-size: 13px; font-weight: 600; }
.acard { border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--r); padding: 12px 14px; background: #fafbfa; }
.is-bad .acard { border-left-color: var(--bad); }
.tags { display: flex; gap: 6px; margin-bottom: 4px; }
.tag { font-size: 12px; padding: 0 6px; border-radius: 4px; background: var(--soft); color: var(--muted); }
.cl .clz { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cl.main .clz .zh { font-size: 24px; font-weight: 600; }
.cl.main .py { font-size: 16px; }
.cl .fr { color: var(--ink); }
.cl.sub .clz .zh { font-size: 17px; }
.cl.sub .fr { color: var(--muted); font-size: 14px; }
.cl mark { background: #ffe9a8; color: inherit; padding: 0 2px; border-radius: 3px; }
.xl { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.xlab { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.note { margin: 10px 0 0; font-size: 14px; color: var(--ink); }
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.plist li { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 10px; align-items: center; }
.pa { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 17px; font-weight: 600; }
.pa .py { font-size: 13px; font-weight: 400; }
.qactions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); font-size: 14px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-d); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: #efc2ba; }
.btn kbd { font: 11px/1 inherit; padding: 2px 5px; border-radius: 3px; background: var(--soft); color: var(--muted); }
.qactions [data-act="next"] { margin-left: auto; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty .ic, .empty svg.lucide { width: 32px; height: 32px; }

/* Progression */
.pgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tile-stat { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.tile-stat .ic, .tile-stat svg.lucide { color: var(--accent); }
.tile-stat .tl { font-size: 13px; color: var(--muted); }
.tile-stat b { grid-column: 1 / -1; font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.tile-stat .muted { grid-column: 1 / -1; font-size: 12px; }
.pactions { display: flex; gap: 8px; margin: 14px 0 6px; flex-wrap: wrap; }
.pactions .danger { margin-left: auto; }
.psec { margin-top: 22px; }
.lrow { display: grid; grid-template-columns: 64px minmax(0, 1fr) minmax(120px, 2fr) auto; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lname { font-size: 17px; font-weight: 600; }
.bar { position: relative; height: 10px; border-radius: 5px; background: #e2e6e3; overflow: hidden; }
.bar.sm { height: 6px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.bar i.seen { background: #b8dccf; }
.bar i.mast { background: var(--accent); }
.bar i.mast.low { background: var(--amber); }
.lnum { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lnum b { color: var(--ink); }
.ptable { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.ptable td, .ptable th { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.ptable th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfa; }
.ptable tr:last-child td { border-bottom: 0; }
.ptable .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ptable .barc { width: 35%; }
.ptable td .ic, .ptable td svg.lucide { width: 15px; height: 15px; color: var(--muted); }
.hist tr.cur td { background: var(--accent-bg); }
.missed { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.missed li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 7px 12px; border-bottom: 1px solid var(--line); }
.missed li:last-child { border-bottom: 0; }
.mz { font-size: 17px; font-weight: 600; max-width: 100%; }
.mfr { color: var(--muted); font-size: 14px; flex: 1 1 160px; min-width: 0; }
.mcount { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dots { display: inline-flex; gap: 3px; vertical-align: middle; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: #dfe4e1; }
.dots i.on { background: var(--accent); }
.dots.new i { background: transparent; border: 1px dashed #b9c2bd; }

/* Lexique */
.lexbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.search { display: flex; align-items: center; gap: 6px; flex: 1 1 220px; padding: 0 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; padding: 9px 0; font-size: 14px; background: transparent; color: var(--ink); }
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--focus); outline-offset: 0; }
.lexbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); font-size: 14px; color: var(--ink); }
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.lex { width: 100%; border-collapse: collapse; font-size: 14px; }
.lex th { position: sticky; top: 0; text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; background: #fafbfa; border-bottom: 1px solid var(--line); }
.lex td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lex .lw { white-space: nowrap; }
.lex .lw .zh { font-size: 18px; font-weight: 600; vertical-align: middle; }
.lex .pyc { color: var(--accent-d); white-space: nowrap; }
.lex .ex { font-size: 13px; color: var(--muted); margin-top: 2px; }
.lex .ex .say { width: 24px; height: 24px; vertical-align: middle; }

/* Mobile */
@media (max-width: 860px) {
  .top { flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; }
  .brand-sub { display: none; }
  .tabs { order: 3; width: 100%; }
  .tabs button { flex: 1; justify-content: center; padding: 6px 4px; }
  .stats { margin-left: auto; gap: 10px; }
  .side-toggle { display: inline-grid; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; }
  .side { display: none; position: static; max-height: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
  .side.open { display: block; }
  .layout[data-view="train"] .side.open { display: block; }
  .qcard { padding: 16px; }
  .pzh { font-size: 34px; }
  .psent { font-size: 20px; }
  .pgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lrow { grid-template-columns: 56px minmax(0, 1fr); }
  .lrow .bar { grid-column: 1 / -1; }
  .lrow .lnum { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .opts { grid-template-columns: minmax(0, 1fr); }
  .match { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 6px; }
  .mi { padding: 8px; font-size: 14px; }
  .plist li { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .inrow { flex-direction: column; }
  .tabs button span { font-size: 13px; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

