:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1c1f23;
  --muted: #6a6f76;
  --line: #e2dfd7;
  --accent: #1f5f5b;
  --accent-ink: #ffffff;
  --accent-soft: #e1eeec;
  --good: #1f7a4d;
  --good-soft: #e0f1e7;
  --bad: #b3382c;
  --bad-soft: #f8e4e1;
  --mid: #b07a12;
  --mid-soft: #f7ecd2;
  --radius: 14px;
  --tabs-h: 62px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --surface-2: #262a30;
    --text: #eceae4;
    --muted: #9aa0a8;
    --line: #30343b;
    --accent: #6cc3b9;
    --accent-ink: #0f1f1e;
    --accent-soft: #1f3432;
    --good: #5fc48d;
    --good-soft: #1b3327;
    --bad: #ef8377;
    --bad-soft: #3a211e;
    --mid: #e0b354;
    --mid-soft: #382e17;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 1.5rem; margin: 0 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
h2.section { margin: 26px 0 10px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
p { margin: 0 0 10px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:disabled { cursor: default; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { min-height: 100dvh; display: grid; place-items: center; }
.center-text { text-align: center; }
.error { color: var(--bad); }
.grow { flex: 1; }

/* ---- structure ---- */
.app { max-width: 720px; margin: 0 auto; }
.content { padding: 18px 16px calc(var(--tabs-h) + 28px + env(safe-area-inset-bottom)); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; max-width: 144px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 0.7rem;
}
.tab.active { color: var(--accent); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 14px; }
.foot { margin-top: 22px; }

/* ---- boutons ---- */
.primary { background: var(--accent); color: var(--accent-ink); border-radius: 12px; padding: 12px 18px; font-weight: 600; }
.primary:disabled { opacity: 0.6; }
.ghost { background: var(--surface-2); border-radius: 12px; padding: 12px 18px; font-weight: 600; }
.big { width: 100%; min-height: 52px; font-size: 1.05rem; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 7px 14px; font-size: 0.88rem; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); font-size: 1rem; flex: none; }
.pill { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 4px 12px; font-size: 0.82rem; font-weight: 600; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* ---- barres ---- */
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }
.bar-fill.good, .seg.good, .dot.good { background: var(--good); }
.bar-fill.mid, .seg.mid, .dot.mid { background: var(--mid); }
.bar-fill.bad { background: var(--bad); }
.bar.stack { display: flex; }
.seg { height: 100%; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 6px 0 12px; }
.dot.new { background: var(--surface-2); border: 1px solid var(--line); }
.legend { font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; }
.legend .dot:first-child { margin-left: 0; }

/* ---- accueil ---- */
.hero-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.hero-top h1 { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 560px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; }
.kpi-v { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-l { font-size: 0.78rem; color: var(--muted); }
.hero { margin-bottom: 18px; }
.sync-card { border-color: var(--accent); background: var(--accent-soft); }
.phrase { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--surface); border: 1px dashed var(--accent); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-weight: 600; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.coach summary, details.card > summary { display: flex; flex-direction: column; gap: 2px; }
.coach-title { font-weight: 700; }
.coach[open] summary, details.card[open] > summary { margin-bottom: 12px; }
.rich h3 { margin: 14px 0 6px; }
.rich ul { margin: 0 0 10px; padding-left: 20px; }
.rich li { margin-bottom: 5px; }
.missions { display: flex; flex-direction: column; gap: 10px; }
.mission { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; width: 100%; }
.mission:not(.done):active { background: var(--surface-2); }
.mission.done { opacity: 0.6; }
.mission-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.mission-title { font-weight: 650; }
.mission-count { font-size: 0.85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mission-desc { font-size: 0.88rem; color: var(--muted); margin: 4px 0 10px; }
.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 560px) { .actions { grid-template-columns: repeat(3, 1fr); } }
.action { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; min-height: 104px; }
.action:active { background: var(--surface-2); }
.action.empty .action-n { color: var(--muted); }
.action-n { font-size: 1.5rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.action-title { font-weight: 650; margin-top: 4px; }
.action-sub { font-size: 0.78rem; color: var(--muted); }

/* ---- lecteur ---- */
.player { max-width: 640px; margin: 0 auto; padding: 12px 16px 120px; min-height: 100dvh; }
.player-top { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; background: var(--bg); padding: 6px 0 10px; z-index: 3; }
.count { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
.player-title { font-size: 0.8rem; color: var(--muted); margin-bottom: 14px; }
.label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); font-weight: 650; margin-bottom: 12px; }
.prompt { font-size: 1.15rem; line-height: 1.5; margin-bottom: 8px; }
.prompt.big { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }
.hint { color: var(--muted); margin-bottom: 8px; }
.pre { white-space: pre-line; }
.choices { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.choice { display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; min-height: 56px; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 1.05rem; }
.choice:not(:disabled):active { background: var(--surface-2); }
.choice .key { flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.choice.good { border-color: var(--good); background: var(--good-soft); }
.choice.good .key { background: var(--good); color: #fff; }
.choice.bad { border-color: var(--bad); background: var(--bad-soft); }
.choice.bad .key { background: var(--bad); color: #fff; }
.choice.dim { opacity: 0.5; }
.passage { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; max-height: 46dvh; overflow-y: auto; }
.passage-title { font-weight: 700; margin-bottom: 8px; }
.passage-text { white-space: pre-wrap; font-size: 0.98rem; line-height: 1.55; }
.feedback { border-radius: var(--radius); padding: 14px; margin-top: 6px; }
.feedback.ok { background: var(--good-soft); }
.feedback.ko { background: var(--bad-soft); }
.verdict { font-weight: 700; margin-bottom: 8px; }
.feedback.ok .verdict { color: var(--good); }
.feedback.ko .verdict { color: var(--bad); }
.explain { margin-bottom: 10px; }
.wcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 8px 0; }
.wcard-head { display: flex; align-items: baseline; gap: 10px; }
.wcard .w { font-size: 1.35rem; font-weight: 700; }
.pos { color: var(--muted); font-size: 0.85rem; }
.speak { margin-left: auto; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); font-size: 1.05rem; flex: none; }
.fr { font-size: 1.05rem; margin: 4px 0 10px; }
.colloc { font-weight: 650; color: var(--accent); }
.ex { margin: 4px 0; }
.note { font-size: 0.9rem; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; margin-top: 8px; }
.flag { margin-top: 10px; font-size: 0.88rem; }
.flag summary { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.flag input { margin-top: 10px; }
.intro-tag { display: inline-block; background: var(--mid-soft); color: var(--mid); border-radius: 999px; padding: 3px 12px; font-size: 0.8rem; font-weight: 650; margin-bottom: 6px; }
.sticky-action { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); display: flex; gap: 10px; justify-content: center; }
.sticky-action > * { max-width: 608px; }
.sticky-action.two > *, .sticky-action.three > * { flex: 1; max-width: 300px; }
.rate { min-height: 52px; border-radius: 12px; font-weight: 650; }
.rate.bad { background: var(--bad-soft); color: var(--bad); }
.rate.mid { background: var(--mid-soft); color: var(--mid); }
.rate.good { background: var(--good-soft); color: var(--good); }
.type-form { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
input[type="text"], input[type="password"], input[type="search"], textarea {
  width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 1.05rem;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; margin: 10px 0; resize: vertical; }
.summary { text-align: center; padding-top: 24px; }
.score { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); }
.summary h3 { margin-top: 24px; text-align: left; }
.wrong-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.wrong-list li { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 2px; }
.wrong-list .q { color: var(--muted); font-size: 0.9rem; }
.wrong-list .a { font-weight: 650; }

/* ---- mots ---- */
.search { margin-bottom: 4px; }
.words { display: flex; flex-direction: column; gap: 6px; }
.word { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.word summary { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; align-items: center; }
.word-w { font-weight: 650; }
.word-fr { grid-column: 1; color: var(--muted); font-size: 0.88rem; }
.lv { grid-column: 2; grid-row: 1 / span 2; font-size: 0.72rem; font-weight: 650; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.lv-new { background: var(--surface-2); color: var(--muted); }
.lv-weak { background: var(--bad-soft); color: var(--bad); }
.lv-mid { background: var(--mid-soft); color: var(--mid); }
.lv-ok { background: var(--good-soft); color: var(--good); }
.word-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.word-meta { display: flex; align-items: center; color: var(--muted); font-size: 0.8rem; }

/* ---- progrès ---- */
.rate-row { margin-bottom: 12px; }
.rate-head { display: flex; justify-content: space-between; gap: 10px; font-size: 0.9rem; margin-bottom: 5px; }
.days { display: flex; gap: 4px; align-items: flex-end; height: 130px; margin-bottom: 8px; }
.day { flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.day-col { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.day-bar { width: 100%; min-height: 2px; background: var(--accent-soft); border-radius: 4px 4px 0 0; display: flex; align-items: flex-end; overflow: hidden; }
.day-ok { width: 100%; background: var(--accent); }
.day-l { font-size: 0.65rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- divers ---- */
.auth { max-width: 400px; margin: 12dvh auto 0; }
.auth form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.auth label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
@media (max-width: 440px) { .auth { margin: 8dvh 16px 0; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 20; background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 16px; max-width: min(92vw, 480px); font-size: 0.92rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); }
.toast-err { background: var(--bad); color: #fff; }
.veil { position: fixed; inset: 0; z-index: 15; background: color-mix(in srgb, var(--bg) 60%, transparent); display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.token-box { background: var(--surface-2); border-radius: 10px; padding: 10px; margin: 10px 0; overflow-x: auto; }
.token-box code { font-size: 0.75rem; white-space: pre-wrap; word-break: break-all; }
.token-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 0.85rem; padding: 8px 0; border-top: 1px solid var(--line); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0.01s !important; } }
