:root {
  --bg: #fbf6ee;
  --card: #ffffff;
  --ink: #2b2522;
  --muted: #8a7f78;
  --line: #ece3d6;
  --accent: #d6453d;
  --accent-ink: #ffffff;
  --soft: #fde9e4;
  --good: #2f9e5b;
  --mid: #e6a019;
  --bad: #d6453d;
  /* Couleurs de tons (convention Pleco) */
  --t1: #e0453a;
  --t2: #2f9e5b;
  --t3: #2f6fd6;
  --t4: #8e44c9;
  --t5: #8a7f78;
  --radius: 20px;
  --shadow: 0 2px 0 var(--line), 0 6px 18px rgba(60, 40, 20, .06);
  --han: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a18;
    --card: #2a2623;
    --ink: #f4ede6;
    --muted: #a99d94;
    --line: #3a3430;
    --soft: #3c2724;
    --t1: #ff7a6e;
    --t2: #5fd18d;
    --t3: #74a6ff;
    --t4: #c38bf0;
    --t5: #a99d94;
    --shadow: 0 2px 0 var(--line);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: Nunito, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  min-height: 100dvh;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 32px);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
h1 { font-size: 28px; font-weight: 900; margin: 8px 0 4px; }
h2 { font-size: 20px; font-weight: 900; margin: 24px 0 10px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.han { font-family: var(--han); }

.topbar { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.topbar .title { font-weight: 900; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { width: 44px; height: 44px; border-radius: 50%; font-size: 22px; background: var(--card); box-shadow: var(--shadow); }

.hello { display: flex; align-items: baseline; gap: 10px; margin: 12px 0 18px; }
.hello .han { font-size: 34px; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 999px;
  background: var(--card); box-shadow: var(--shadow); font-weight: 700;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 #a8322b; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 64px; font-size: 20px; }
.btn:active { transform: translateY(2px); }
.btn[disabled] { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 12px 0;
}
.lesson { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; }
.lesson .meta { flex: 1; }
.lesson .name { font-weight: 900; }
.stars { color: var(--mid); letter-spacing: 2px; }

/* Caractères avec pinyin au-dessus, colorés par ton */
.word { display: flex; flex-wrap: wrap; gap: 2px 4px; justify-content: center; }
.syl { display: flex; flex-direction: column; align-items: center; border-radius: 12px; padding: 2px 4px; }
.syl .py { font-size: 15px; font-weight: 700; min-height: 1.3em; }
.syl .ch { font-family: var(--han); font-size: 40px; line-height: 1.15; }
.word.small .syl .ch { font-size: 30px; }
.word.huge .syl .ch { font-size: 64px; }
.word.huge .syl .py { font-size: 20px; }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t5 { color: var(--t5); }
.syl.s-good { background: color-mix(in srgb, var(--good) 18%, transparent); }
.syl.s-mid { background: color-mix(in srgb, var(--mid) 22%, transparent); }
.syl.s-bad { background: color-mix(in srgb, var(--bad) 20%, transparent); }
.fr { text-align: center; color: var(--muted); margin-top: 6px; }

.item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; }
.item .word { justify-content: flex-start; }
.item .fr { text-align: left; }
.icons { display: flex; gap: 6px; }
.icon {
  width: 46px; height: 46px; border-radius: 50%; font-size: 22px;
  background: var(--soft); display: inline-grid; place-items: center;
}

.practice { text-align: center; padding: 24px 16px; }
.mic {
  width: 112px; height: 112px; border-radius: 50%; font-size: 46px;
  background: var(--accent); color: #fff; box-shadow: 0 5px 0 #a8322b; margin: 18px auto 6px; display: grid; place-items: center;
}
.mic.rec { animation: pulse 1s infinite; background: #b8322b; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.score { font-size: 44px; font-weight: 900; }
.feedback { margin-top: 10px; }
.progress { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 6px 0 4px; }
.progress > div { height: 100%; background: var(--good); transition: width .3s; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.choice {
  font-family: var(--han); font-size: 34px; min-height: 96px; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
}
.choice.long { font-size: 20px; padding: 10px; }
.btn.mood { flex-direction: column; gap: 2px; padding: 10px 8px; border-radius: 18px; }
.btn.mood span { font-size: 26px; }
.choice.ok { background: color-mix(in srgb, var(--good) 25%, var(--card)); }
.choice.ko { background: color-mix(in srgb, var(--bad) 25%, var(--card)); }

.field { display: block; margin: 10px 0; }
.field span { display: block; font-weight: 700; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 2px solid var(--line); background: var(--card);
}
.input:focus { outline: none; border-color: var(--accent); }
.edit-item { display: grid; gap: 6px; padding: 12px; }
.edit-item .han.input { font-size: 24px; }
.edit-item .warn { color: var(--bad); font-size: 14px; font-weight: 700; }
.edit-item .del { justify-self: end; color: var(--bad); font-weight: 700; min-height: 36px; }
.photo { position: relative; overflow: hidden; }
.photo input { position: absolute; inset: 0; opacity: 0; }

.empty { text-align: center; padding: 32px 16px; }
.empty .han { font-size: 56px; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px);
  max-width: 528px; margin: 0 auto; background: var(--ink); color: var(--bg);
  padding: 14px 18px; border-radius: 14px; font-weight: 700;
}
.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { color: var(--muted); text-decoration: underline; font-size: 15px; min-height: 44px; }
.center { text-align: center; }
.tones { margin: 10px 0; padding: 10px 12px; border-radius: 14px; background: var(--soft); text-align: left; }
.tones p { margin: 4px 0; }
.tones .han { font-size: 22px; }
