/* Hànzì — feuille de style. Aucune ressource externe : polices du système uniquement. */
:root {
  --bg: #f6f2ea;
  --surface: #fffdf9;
  --surface-2: #efe9dd;
  --ink: #24211d;
  --muted: #6c655b;
  --line: #e0d8ca;
  --accent: #c8402f;
  --accent-ink: #fffaf3;
  --accent-soft: #f6e1dc;
  --ok: #24764a;
  --ok-soft: #dcefe3;
  --bad: #b3261e;
  --bad-soft: #f8dedb;
  --warn-soft: #fbeecb;
  --warn-ink: #5c4300;
  --stroke: #24211d;
  --outline: #d8d0c1;
  --grid: #e6dece;
  --draw: #3d6fb4;
  --shadow: 0 1px 2px rgba(60, 45, 20, .08), 0 4px 14px rgba(60, 45, 20, .06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #151311;
  --surface: #201d1a;
  --surface-2: #2a2622;
  --ink: #efe9df;
  --muted: #a69e91;
  --line: #3a352f;
  --accent: #ec7362;
  --accent-ink: #1c100d;
  --accent-soft: #43231e;
  --ok: #74d39c;
  --ok-soft: #1d3a2a;
  --bad: #ff9184;
  --bad-soft: #472320;
  --warn-soft: #3f3413;
  --warn-ink: #f3dc9a;
  --stroke: #efe9df;
  --outline: #4b453d;
  --grid: #302b26;
  --draw: #8db8f2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151311;
    --surface: #201d1a;
    --surface-2: #2a2622;
    --ink: #efe9df;
    --muted: #a69e91;
    --line: #3a352f;
    --accent: #ec7362;
    --accent-ink: #1c100d;
    --accent-soft: #43231e;
    --ok: #74d39c;
    --ok-soft: #1d3a2a;
    --bad: #ff9184;
    --bad-soft: #472320;
    --warn-soft: #3f3413;
    --warn-ink: #f3dc9a;
    --stroke: #efe9df;
    --outline: #4b453d;
    --grid: #302b26;
    --draw: #8db8f2;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  overscroll-behavior-y: contain;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.45rem; line-height: 1.2; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; line-height: 1.3; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.zh { font-family: "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", "Heiti SC", sans-serif; font-style: normal; }
.py { font-family: system-ui, Roboto, "Noto Sans", sans-serif; color: var(--accent); font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }

#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; }
#view { padding: 16px 16px calc(92px + env(safe-area-inset-bottom)); outline: none; }
body.in-session #view { padding: 0; }
body.in-session #tabs { display: none; }

/* ─── Barre d'onglets ─── */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs .tabs-in { display: flex; width: 100%; max-width: 520px; }
#tabs a {
  flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 2px 8px; min-height: 60px; text-decoration: none; color: var(--muted);
  font-size: .7rem; font-weight: 500;
}
#tabs a svg { width: 24px; height: 24px; }
#tabs a[aria-current="page"] { color: var(--accent); }
#tabs .badge {
  position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: .68rem; font-weight: 700; line-height: 18px; text-align: center;
}

svg.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ─── En-têtes de page ─── */
.top { display: flex; align-items: center; gap: 6px; min-height: 48px; margin-bottom: 12px; }
.top .back { display: grid; place-items: center; width: 44px; height: 44px; margin-left: -10px; color: var(--ink); border-radius: 50%; }
.top h1 { flex: 1; }
.stack > * + * { margin-top: 14px; }
.stack-lg > * + * { margin-top: 22px; }

/* ─── Bandeaux ─── */
#notice { max-width: 520px; margin: 0 auto; }
body.in-session #notice { display: none; }
.banner {
  display: flex; gap: 10px; align-items: flex-start; margin: 12px 16px 0; padding: 12px 12px 12px 14px;
  border-radius: 14px; background: var(--warn-soft); color: var(--warn-ink); font-size: .9rem; line-height: 1.4;
}
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner > div { flex: 1; }
.banner a { color: inherit; font-weight: 600; white-space: nowrap; }
.banner .x { border: 0; background: none; padding: 4px; margin: -4px -4px 0 0; color: inherit; }
.banner .x svg { width: 18px; height: 18px; }

/* ─── Cartes, boutons ─── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.card > h3 { margin-bottom: 10px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 54px; padding: 12px 18px;
  border-radius: 16px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 1.02rem; font-weight: 600; text-decoration: none; text-align: center; cursor: pointer; user-select: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.slim { width: auto; min-height: 46px; padding: 8px 14px; font-size: .95rem; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.985); }
.btn .sub { display: block; font-size: .8rem; font-weight: 500; opacity: .85; }
.btn-col { display: flex; flex-direction: column; align-items: flex-start; text-align: left; flex: 1; line-height: 1.25; }
.btn.wide { justify-content: flex-start; padding: 12px 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.icon-btn { display: grid; place-items: center; width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: transparent; color: var(--ink); cursor: pointer; }
.say { background: var(--accent-soft); color: var(--accent); }
.say.big { width: 96px; height: 96px; }
.say.big svg { width: 44px; height: 44px; }

/* ─── Accueil ─── */
.hero { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.hero .brand { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.hero .brand .zh { color: var(--accent); margin-right: 6px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.stat b { display: block; font-size: 1.7rem; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
.stat b small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.stat span { font-size: .82rem; color: var(--muted); }
.stat.hot b { color: var(--accent); }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.week { display: flex; justify-content: space-between; gap: 4px; }
.week div { flex: 1; text-align: center; font-size: .72rem; color: var(--muted); }
.week i { display: block; width: 26px; height: 26px; margin: 0 auto 3px; border-radius: 50%; border: 1.5px solid var(--line); }
.week .on i { background: var(--accent); border-color: var(--accent); }
.week .today i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── Listes ─── */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px; color: inherit; text-decoration: none; }
a.item:active, button.item:active { background: var(--surface-2); }
.item .num { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); font-weight: 700; font-size: .9rem; }
.item.done .num { background: var(--ok-soft); color: var(--ok); }
.item.next .num { background: var(--accent); color: var(--accent-ink); }
.item .t { font-weight: 600; line-height: 1.25; }
.item .s { font-size: .9rem; color: var(--muted); }
.item .s.zh { font-size: 1.15rem; letter-spacing: .12em; color: var(--ink); }
.item .chev { color: var(--muted); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .72rem; font-weight: 600; white-space: nowrap; }
.tag.acc { background: var(--accent-soft); color: var(--accent); }

.word { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 6px; min-height: 58px; width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.word .w { font-size: 1.45rem; line-height: 1.2; }
.word .p { font-size: .92rem; }
.word .f { font-size: .92rem; color: var(--muted); line-height: 1.3; }
.word .say { width: 40px; height: 40px; }
.word .say svg { width: 20px; height: 20px; }
.word.later .w, .word.later .p { opacity: .7; }
.sent .w { font-size: 1.3rem; }

/* ─── Fiche caractère ─── */
.hz-box, .hz-static { position: relative; margin: 0 auto; background: var(--surface); border: 1.5px solid var(--line); border-radius: 18px; overflow: hidden; }
.hz-box { touch-action: none; user-select: none; -webkit-user-select: none; }
.hz-box::before, .hz-box::after, .hz-static::before, .hz-static::after { content: ""; position: absolute; pointer-events: none; }
.hz-box::before, .hz-static::before { left: 50%; top: 10px; bottom: 10px; border-left: 1.5px dashed var(--grid); }
.hz-box::after, .hz-static::after { top: 50%; left: 10px; right: 10px; border-top: 1.5px dashed var(--grid); }
.hz-box svg, .hz-static svg { position: relative; z-index: 1; display: block; }
.fiche-head { display: flex; align-items: center; gap: 14px; }
.fiche-head .py { font-size: 1.9rem; line-height: 1.1; }
.fiche-head .fr { font-size: 1.1rem; font-weight: 600; line-height: 1.3; margin-top: 4px; }
.facts { display: grid; gap: 10px; }
.fact b { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: 1px; }
.fact .zh { font-size: 1.15em; }
.keydot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-right: 6px; }

/* ─── Séances (leçon, révision, test) ─── */
.session { display: flex; flex-direction: column; min-height: 100dvh; }
.s-head { display: flex; align-items: center; gap: 8px; padding: 6px 16px 6px 6px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.s-head .meter { flex: 1; }
.s-head .s-title { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.s-body { flex: 1; display: flex; flex-direction: column; padding: 6px 16px 16px; }
.s-body > * + * { margin-top: 14px; }
.s-body .push { margin-top: auto; padding-top: 14px; }
.s-foot { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 78%, transparent); z-index: 5; }
.s-foot .btn.primary { flex: 1; }
.s-foot .btn.ghost { width: auto; flex: none; }
.s-foot:empty { display: none; }

.q-label { font-size: .95rem; color: var(--muted); font-weight: 600; }
.stim { flex: 1; min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.stim .big { font-size: 6.2rem; line-height: 1.1; }
.stim .mid { font-size: 3.2rem; line-height: 1.2; }
.stim .txt { font-size: 1.6rem; font-weight: 700; line-height: 1.25; }
.opts { display: grid; gap: 10px; }
.opts.g2 { grid-template-columns: 1fr 1fr; }
.opt { min-height: 58px; padding: 10px 14px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--surface); font-size: 1.02rem; font-weight: 500; line-height: 1.3; text-align: center; cursor: pointer; }
.opt.o-zh { font-size: 2.4rem; min-height: 84px; font-weight: 400; }
.opt.o-word { font-size: 1.6rem; font-weight: 400; }
.opt.o-py { font-size: 1.4rem; color: var(--accent); }
.opt.good { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.opt:disabled { cursor: default; }
.opt:disabled:not(.good):not(.wrong) { opacity: .55; }
.feedback { border-radius: 14px; padding: 10px 14px; font-size: .98rem; line-height: 1.4; }
.feedback:empty { display: none; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.ko { background: var(--bad-soft); color: var(--bad); }
.feedback strong { display: block; }
.feedback .zh { font-size: 1.35em; }
.trace-status { min-height: 1.5em; text-align: center; font-weight: 600; }
.trace-status.ko { color: var(--bad); }
.trace-status.ok { color: var(--ok); }
.prompt { text-align: center; }
.prompt .fr { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
.prompt .py { font-size: 1.2rem; }

.done-mark { width: 84px; height: 84px; margin: 24px auto 8px; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); }
.done-mark svg { width: 44px; height: 44px; stroke-width: 2.6; }
.chars-line { font-size: 2rem; letter-spacing: .18em; text-align: center; }

/* ─── Bibliothèque ─── */
.grid-chars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.tile { aspect-ratio: 1; display: grid; place-items: center; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--muted); font-size: 1.55rem; text-decoration: none; }
.tile.seen { color: var(--ink); border-color: var(--accent); }
.tile.got { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; border: 1.5px solid var(--line); margin-right: 5px; vertical-align: -1px; }
.legend .seen i { border-color: var(--accent); }
.legend .got i { border-color: var(--ok); background: var(--ok-soft); }
.search { width: 100%; min-height: 50px; padding: 10px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; }
.rad { display: flex; gap: 14px; align-items: flex-start; }
.rad .form { font-size: 2.6rem; line-height: 1.1; width: 64px; text-align: center; flex: none; color: var(--accent); }
.rad .alt { display: block; font-size: 1rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: grid; place-items: center; min-width: 40px; height: 40px; padding: 0 6px; border-radius: 10px; background: var(--surface-2); color: var(--ink); font-size: 1.3rem; text-decoration: none; }
.prose p + p, .prose p + ul, .prose ul + p { margin-top: 10px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li + li { margin-top: 6px; }
.tone-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 8px; }
.tone-row .mark { font-size: 1.5rem; width: 52px; text-align: center; flex: none; }
.tone-svg { width: 44px; height: 34px; flex: none; }
.tone-svg path { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.tone-svg line { stroke: var(--line); stroke-width: 1; }
table.sounds { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.sounds td { padding: 7px 6px; border-top: 1px solid var(--line); vertical-align: top; line-height: 1.35; }
table.sounds td:first-child { white-space: nowrap; font-weight: 700; color: var(--accent); width: 1%; padding-right: 12px; }
.ex { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.ex .w { font-size: 1.3rem; }

/* ─── Réglages ─── */
.seg { display: flex; padding: 3px; border-radius: 14px; background: var(--surface-2); }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 11px; background: transparent; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
input[type="range"] { width: 100%; height: 36px; accent-color: var(--accent); }
select { width: 100%; min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; }
.kv span:last-child { text-align: right; font-weight: 600; }
.status-ok { color: var(--ok); }
.status-ko { color: var(--bad); }
ol.steps { margin: 0; padding-left: 22px; }
ol.steps li + li { margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50; max-width: min(440px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: .92rem; text-align: center; box-shadow: var(--shadow); }
body.in-session .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }

/* ─── Compléments ─── */
.item .t, .item .s { display: block; }
.item .tag { flex: none; }
.word .grow > span { display: block; }
.word .tag { flex: none; }
.word.mute { cursor: default; padding-left: 14px; }
.opt small { display: block; margin-top: 2px; font-size: .75rem; font-weight: 500; color: var(--muted); }
.rad h2 { margin-bottom: 4px; }
textarea.search { min-height: 84px; line-height: 1.4; font-size: .9rem; }
.tone-row .zh { font-size: 1.7rem; flex: none; }

/* Feuille de confirmation, en bas de l'écran (à portée du pouce) */
.sheet-back { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; background: rgba(0, 0, 0, .45); }
.sheet { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 10px; padding: 22px 16px calc(16px + env(safe-area-inset-bottom)); border-radius: 22px 22px 0 0; background: var(--surface); box-shadow: var(--shadow); }
.sheet p { margin-bottom: 6px; font-size: 1.02rem; line-height: 1.4; }

@media (prefers-reduced-motion: reduce) { .btn:active { transform: none; } }
