/* Max Chinois — feuille de style (mobile d'abord, compatible Telegram Mini App) */

:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15171a);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --link: var(--tg-theme-link-color, #2563eb);
  --accent: var(--tg-theme-button-color, #c8322b);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --ok: #1f8a4c;
  --ok-soft: rgba(31, 138, 76, 0.14);
  --warn: #b7791f;
  --warn-soft: rgba(183, 121, 31, 0.14);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --radius: 14px;
  --tab-h: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #0f1114);
    --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1b1f24));
    --text: var(--tg-theme-text-color, #e8eaed);
    --hint: var(--tg-theme-hint-color, #9aa3ad);
    --link: var(--tg-theme-link-color, #6ea8fe);
    --accent: var(--tg-theme-button-color, #e5534b);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans KR", "Noto Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom) + 12px);
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.hint { color: var(--hint); font-size: 14px; }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* En-tête */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px 10px;
  background: var(--bg);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.topbar .sub { display: block; color: var(--hint); font-size: 12px; margin-top: -2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* Pages */
main { padding: 0 16px; }
.page { display: none; flex-direction: column; gap: 12px; }
.page.active { display: flex; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 1px 0 var(--line);
}
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--link); padding-left: 8px; padding-right: 8px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

/* Champs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--hint); }
input[type="text"], input[type="number"], input[type="search"], textarea, select {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  outline: none;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* Tableau de bord */
.progress-hero { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; }
.ring { width: 96px; height: 96px; position: relative; }
.ring svg { width: 96px; height: 96px; transform: rotate(-90deg); }
.ring .track { stroke: var(--line); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray .5s ease; }
.ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.progress-hero > .stack { min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--bg); border-radius: 12px; padding: 10px; text-align: center; }
.stat .v { font-size: 20px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--hint); }
.goal { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.goal > span { display: block; height: 100%; background: var(--ok); width: 0; transition: width .4s ease; }

.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 90px; }
.bars .b { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bars .b i { display: block; width: 100%; max-width: 28px; border-radius: 6px 6px 3px 3px; background: var(--accent-soft); min-height: 3px; }
.bars .b.today i { background: var(--accent); }
.bars .b span { font-size: 11px; color: var(--hint); }

/* Leçons */
.lesson-list { display: flex; flex-direction: column; gap: 6px; }
.lesson {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 12px; background: var(--card);
}
.lesson .num { width: 36px; height: 36px; border: 0; border-radius: 10px; display: grid; place-items: center; font-weight: 700; background: var(--bg); color: var(--text); }
.lesson.done .num { background: var(--ok-soft); color: var(--ok); }
.lesson.doing .num { background: var(--warn-soft); color: var(--warn); }
.lesson .title { font-weight: 600; }
.lesson .meta { font-size: 12px; color: var(--hint); }
.status-btn {
  min-height: 36px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); font-size: 13px; font-weight: 600;
}
.lesson.done .status-btn { color: var(--ok); border-color: var(--ok-soft); background: var(--ok-soft); }
.lesson.doing .status-btn { color: var(--warn); border-color: var(--warn-soft); background: var(--warn-soft); }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.filters button {
  flex: none; min-height: 34px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: 13px; font-weight: 600; color: var(--hint);
}
.filters button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Traduction */
.gloss-list { display: flex; flex-direction: column; gap: 4px; max-height: 60vh; overflow: auto; }
.gloss {
  display: grid; grid-template-columns: 1fr; gap: 2px;
  padding: 10px 12px; border-radius: 12px; background: var(--card);
}
.gloss .ko { font-weight: 700; font-size: 17px; }
.gloss .fr { }
.gloss .zh { font-size: 13px; color: var(--hint); }
mark { background: var(--warn-soft); color: inherit; border-radius: 4px; padding: 0 2px; }
.decoded { display: flex; flex-direction: column; gap: 6px; }
.decoded .line { padding: 8px 10px; border-radius: 10px; background: var(--bg); }

/* Agent */
.log { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow: auto; }
.log .entry { padding: 6px 8px; border-radius: 8px; background: var(--bg); font-size: 13px; }
.log .entry time { color: var(--hint); margin-right: 6px; }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: transparent; color: var(--hint);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600;
}
.tabbar button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

/* Boîte de dialogue */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(92vw, 420px);
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; transition: all .25s ease; pointer-events: none; z-index: 20;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { text-align: center; color: var(--hint); padding: 20px 10px; }
.badge-ex { font-size: 11px; color: var(--warn); font-weight: 700; }
