:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #1d1b18;
  --muted: #6b665d;
  --line: #e3dfd6;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --ok: #1f8a4c;
  --ok-soft: #e3f4ea;
  --warn: #b86e00;
  --warn-soft: #fdf1dc;
  --bad: #c2353a;
  --bad-soft: #fbe6e6;
  --shadow: 0 1px 2px rgba(30, 25, 15, .06), 0 6px 20px rgba(30, 25, 15, .06);
  --radius: 18px;
  --kid: var(--accent);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151413;
    --surface: #1f1e1c;
    --surface-2: #2a2825;
    --text: #f2efe9;
    --muted: #a49e94;
    --line: #36332e;
    --accent: #6d8dff;
    --accent-ink: #0d1330;
    --ok: #4cc27f;
    --ok-soft: #1b3326;
    --warn: #f0a83a;
    --warn-soft: #3a2c14;
    --bad: #ff7a7f;
    --bad-soft: #3d1d1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151413; --surface: #1f1e1c; --surface-2: #2a2825; --text: #f2efe9; --muted: #a49e94; --line: #36332e;
  --accent: #6d8dff; --accent-ink: #0d1330; --ok: #4cc27f; --ok-soft: #1b3326; --warn: #f0a83a; --warn-soft: #3a2c14;
  --bad: #ff7a7f; --bad-soft: #3d1d1f; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.hidden { display: none !important; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { color: var(--muted); font-size: .85rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.1rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; cursor: pointer;
}

main { max-width: 1180px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-left)) 120px; outline: none; }

.banner {
  max-width: 1180px; margin: 12px auto 0; padding: 0 16px;
}
.banner div {
  background: var(--warn-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 14px; padding: 10px 14px; font-size: .95rem;
}

/* ---------- boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 600; text-decoration: none; cursor: pointer; touch-action: manipulation;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--kid); border-color: transparent; color: #fff; }
.btn.big { min-height: 58px; font-size: 1.1rem; padding: 12px 24px; border-radius: 16px; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: .92rem; border-radius: 11px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.stack { display: grid; gap: 14px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .84rem; font-weight: 600; background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.avatar {
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; flex: none;
  background: var(--kid); color: #fff; font-weight: 800; font-size: 1.5rem;
}
.avatar.sm { width: 40px; height: 40px; border-radius: 13px; font-size: 1.1rem; }

/* ---------- accueil ---------- */
.hello { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.kid-card { display: grid; gap: 16px; border-top: 6px solid var(--kid); }
.kid-head { display: flex; align-items: center; gap: 14px; }
.kid-head h2 { font-size: 1.5rem; }
.tonight {
  border-radius: 14px; padding: 14px 16px; background: color-mix(in srgb, var(--kid) 9%, var(--surface));
  display: grid; gap: 10px;
}
.tonight.done { background: var(--ok-soft); }
.tonight .title { font-weight: 700; font-size: 1.08rem; }
.progress { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--kid); border-radius: inherit; transition: width .3s ease; }
.tonight.done .progress > i { background: var(--ok); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; text-decoration: none; }
.stat b { display: block; font-size: 1.5rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--muted); }
.stat.bad b { color: var(--bad); }
.daylist { display: grid; gap: 6px; }
.daylist .item { display: flex; gap: 10px; align-items: center; font-size: .95rem; }
.daylist .time { width: 48px; font-variant-numeric: tabular-nums; color: var(--muted); }
.daylist .now { font-weight: 700; }
.foot-note { margin-top: 18px; text-align: center; }

/* ---------- page enfant ---------- */
.kid-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.back { width: 44px; height: 44px; }
.tabs {
  display: flex; gap: 6px; padding: 5px; border-radius: 16px; background: var(--surface-2);
  overflow-x: auto; margin-bottom: 18px; scrollbar-width: none;
}
.tabs a {
  flex: 1 0 auto; text-align: center; padding: 10px 14px; border-radius: 12px; text-decoration: none;
  font-weight: 600; color: var(--muted); white-space: nowrap; min-height: 44px;
}
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.subject {
  border-left: 6px solid var(--subj, var(--kid));
  display: grid; gap: 10px;
}
.subject .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.subject .head h3 { font-size: 1.2rem; }
.hint { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: .95rem; display: grid; gap: 4px; }
.hint b { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.write { position: relative; }
textarea {
  width: 100%; min-height: 130px; resize: vertical; border-radius: 14px; border: 2px solid var(--line);
  padding: 12px 56px 12px 14px; background: var(--bg); font-size: 1.05rem; line-height: 1.5;
}
textarea:focus { outline: none; border-color: var(--subj, var(--kid)); }
.mic {
  position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: var(--surface-2); display: grid; place-items: center; cursor: pointer;
}
.mic.rec { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.meter { display: flex; justify-content: space-between; font-size: .88rem; color: var(--muted); }
.meter .okay { color: var(--ok); font-weight: 700; }

.submit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.submit-bar .inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.submit-bar .progress { flex: 1; }

.celebrate { text-align: center; display: grid; gap: 10px; justify-items: center; padding: 26px 18px; background: var(--ok-soft); border-color: transparent; }
.celebrate .big-emoji { font-size: 3rem; line-height: 1; }
.feedback { display: grid; gap: 12px; }
.fb-item { display: grid; gap: 4px; padding: 10px 0; border-top: 1px solid var(--line); }
.fb-item:first-of-type { border-top: 0; }
.question { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }

/* devoirs */
.hw-group h3 { margin: 6px 0 10px; display: flex; gap: 8px; align-items: center; }
.hw {
  display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start;
  padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); margin-bottom: 8px;
}
.hw.done { opacity: .6; }
.hw.done .desc { text-decoration: line-through; }
.check {
  width: 34px; height: 34px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg);
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.hw.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.hw .desc { white-space: pre-line; }
.hw .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }

/* emploi du temps */
.week-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.week { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.day { display: grid; gap: 8px; align-content: start; }
.day h3 { font-size: .95rem; padding: 6px 4px; color: var(--muted); }
.day.today h3 { color: var(--kid); }
.lesson { border-radius: 12px; padding: 9px 10px; background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--subj, var(--line)); font-size: .92rem; }
.lesson .t { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .82rem; }
.lesson b { display: block; }
.lesson.canceled { opacity: .55; }
.lesson.canceled b { text-decoration: line-through; }
@media (max-width: 760px) {
  .week { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* historique */
.hist { display: grid; gap: 10px; }
details.card { padding: 0; }
details.card > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > .body { padding: 0 16px 16px; display: grid; gap: 10px; }
.strip { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.strip span { width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: .75rem; }
.strip .s-ok { background: var(--ok); color: #fff; }
.strip .s-bad { background: var(--bad); color: #fff; }

/* parents */
.pin-wrap { max-width: 360px; margin: 30px auto; text-align: center; display: grid; gap: 16px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; height: 22px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.keypad button { min-height: 66px; font-size: 1.5rem; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
.keypad button:active { background: var(--surface-2); }

.form { display: grid; gap: 14px; align-content: start; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: .95rem; }
.field small { color: var(--muted); }
input[type=text], input[type=password], input[type=time], input[type=number], input[type=url], select {
  min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 8px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { width: 24px; height: 24px; accent-color: var(--accent); }
.fields-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; }
.note { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: .93rem; }
.note ol { margin: 6px 0 0; padding-left: 20px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.log { display: grid; gap: 0; font-size: .92rem; }
.log div { display: grid; grid-template-columns: 120px 1fr; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.log .err { color: var(--bad); }
.timeline { display: flex; gap: 6px; flex-wrap: wrap; }

#toasts { position: fixed; left: 50%; top: 76px; transform: translateX(-50%); z-index: 50; display: grid; gap: 8px; width: min(92vw, 520px); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; box-shadow: var(--shadow); font-weight: 600; animation: pop .2s ease; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .big-emoji { font-size: 2.6rem; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* simulateur Alexa */
.sim { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
@media (max-width: 760px) { .sim { grid-template-columns: 1fr; } .sim-side { order: -1; } }
.sim-side { display: grid; gap: 14px; justify-items: center; padding-top: 10px; }
.echo { position: relative; width: 170px; height: 170px; }
.echo-body { position: absolute; inset: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #4a4f5c, #1f2229 70%); box-shadow: inset 0 0 0 6px #2b2f38; }
.echo-ring { position: absolute; inset: 0; border-radius: 50%; border: 8px solid #3b4252; transition: border-color .2s ease, box-shadow .2s ease; }
.echo-ring.talking { border-color: #2fb7ff; box-shadow: 0 0 26px #2fb7ff88; animation: ring 1s ease-in-out infinite; }
.echo-ring.listening { border-color: #6be3ff; box-shadow: 0 0 18px #6be3ff66; }
@keyframes ring { 50% { box-shadow: 0 0 6px #2fb7ff55; } }
.sim-main { display: grid; gap: 14px; min-height: 420px; grid-template-rows: 1fr auto; }
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 56vh; overflow-y: auto; padding: 4px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; line-height: 1.4; white-space: pre-line; }
.bubble.alexa { align-self: flex-start; background: color-mix(in srgb, #2fb7ff 14%, var(--surface)); border: 1px solid color-mix(in srgb, #2fb7ff 30%, transparent); border-bottom-left-radius: 4px; }
.bubble.alexa::before { content: "Alexa"; display: block; font-size: .75rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.bubble.kid { align-self: flex-end; background: var(--surface-2); border-bottom-right-radius: 4px; }
.sim-controls { display: grid; gap: 10px; }
.btn.rec { background: var(--bad); color: #fff; }
@media (max-width: 760px) {
  .echo { width: 96px; height: 96px; }
  .echo-ring { border-width: 6px; }
  .echo-body { inset: 9px; }
  .sim-main { min-height: 0; }
}

/* Étapes de la soirée : exercices → validation → révision */
.steps { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); background: var(--surface-2); border-radius: 99px; padding: 3px 10px 3px 4px; }
.steps li span { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); font-weight: 700; font-size: .75rem; }
.steps li.now { color: var(--text); font-weight: 700; box-shadow: inset 0 0 0 2px var(--kid); }
.steps li.now span { background: var(--kid); color: #fff; }
.steps li.ok { color: var(--ok); background: var(--ok-soft); }
.steps li.ok span { background: var(--ok); color: #fff; }
.ex-item { display: grid; gap: 2px; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.ex-item b { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.lesson { border-left: 4px solid var(--subj, var(--kid)); padding: 4px 0 4px 12px; display: grid; gap: 4px; }
details > summary { cursor: pointer; }
/* Bilan : répartition des niveaux de maîtrise */
.skillbar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; gap: 2px; background: var(--surface-2); }
.skillbar i { display: block; min-width: 6px; }
.skillbar .l4 { background: var(--ok); }
.skillbar .l3 { background: color-mix(in srgb, var(--ok) 55%, var(--surface)); }
.skillbar .l2 { background: var(--warn); }
.skillbar .l1 { background: var(--bad); }
