:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #EFECE5;
  --ink: #1D2A33;
  --ink-soft: #55626B;
  --line: #DCD7CC;
  --accent: #2F4B7C;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3E9F3;
  --ok: #2E7D4F;
  --ok-soft: #E2F1E7;
  --ko: #B3412F;
  --ko-soft: #F7E4E0;
  --retenir: #FBF3DC;
  --retenir-line: #D9B95A;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 42, 51, .06), 0 4px 14px rgba(29, 42, 51, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-scale: 1;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161B20;
    --surface: #1F262D;
    --surface-2: #283039;
    --ink: #E8E6E1;
    --ink-soft: #A3ACB3;
    --line: #36404A;
    --accent: #8FB0E8;
    --accent-ink: #12233F;
    --accent-soft: #24324A;
    --ok: #6CC490;
    --ok-soft: #1E3529;
    --ko: #EE8A78;
    --ko-soft: #3D2420;
    --retenir: #2F2A1A;
    --retenir-line: #A8893A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #161B20;
  --surface: #1F262D;
  --surface-2: #283039;
  --ink: #E8E6E1;
  --ink-soft: #A3ACB3;
  --line: #36404A;
  --accent: #8FB0E8;
  --accent-ink: #12233F;
  --accent-soft: #24324A;
  --ok: #6CC490;
  --ok-soft: #1E3529;
  --ko: #EE8A78;
  --ko-soft: #3D2420;
  --retenir: #2F2A1A;
  --retenir-line: #A8893A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

:root[data-size="grand"] { --text-scale: 1.12; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: calc(17px * var(--text-scale));
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }

button { font: inherit; color: inherit; }

/* ---------- Barre du haut ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar__title {
  flex: 1;
  margin: 0;
  font-size: 1.06rem;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__meta {
  font-size: .85rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.topbar__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: -8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.topbar__back[hidden] { display: none; }

.topbar__back svg { width: 24px; height: 24px; }

/* ---------- Mise en page ---------- */

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  outline: none;
}

.loading { color: var(--ink-soft); text-align: center; margin-top: 40px; }

.section-title {
  margin: 28px 0 10px;
  font-size: .8rem;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

/* ---------- Accueil ---------- */

.countdown {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}

.countdown__days {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.countdown__label { color: var(--ink-soft); font-size: .95rem; line-height: 1.35; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.stat {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.stat__value {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__label { display: block; font-size: .75rem; color: var(--ink-soft); line-height: 1.25; }

.actions { display: grid; gap: 10px; margin-top: 16px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease;
}

.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }

.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--secondary { background: var(--accent-soft); color: var(--accent); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--danger { background: transparent; border-color: var(--ko); color: var(--ko); }
.btn--small { min-height: 40px; padding: 8px 14px; font-size: .9rem; }

.btn__count {
  display: inline-block;
  min-width: 26px;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.themes { display: grid; gap: 8px; }

.theme {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.theme:active { background: var(--surface-2); }

.theme__row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.theme__name { font-weight: 600; }
.theme__count { font-size: .82rem; color: var(--ink-soft); white-space: nowrap; font-variant-numeric: tabular-nums; }
.theme__desc { display: block; margin-top: 2px; font-size: .85rem; color: var(--ink-soft); line-height: 1.35; }

.bar {
  height: 6px;
  margin-top: 10px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
}

.bar__fill { height: 100%; background: var(--ok); }
.bar__fill--seen { background: var(--retenir-line); opacity: .55; }

.links { display: grid; gap: 8px; margin-top: 28px; }

.footnote { margin-top: 24px; font-size: .8rem; color: var(--ink-soft); text-align: center; }

/* ---------- Carte de question ---------- */

.progress {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}

.progress__dot {
  flex: 1;
  height: 5px;
  border-radius: 99px;
  background: var(--surface-2);
}

.progress__dot--ok { background: var(--ok); }
.progress__dot--ko { background: var(--ko); }
.progress__dot--current { background: var(--accent); }

.q-theme {
  display: inline-block;
  margin-bottom: 8px;
  padding: 2px 10px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 600;
}

.q-text {
  margin: 0 0 16px;
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.4;
}

.choices { display: grid; gap: 8px; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  line-height: 1.38;
  -webkit-tap-highlight-color: transparent;
}

.choice:active:not([disabled]) { background: var(--surface-2); }

.choice__key {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: .8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.choice[disabled] { cursor: default; }
.choice--correct { border-color: var(--ok); background: var(--ok-soft); }
.choice--correct .choice__key { background: var(--ok); color: #fff; }
.choice--wrong { border-color: var(--ko); background: var(--ko-soft); }
.choice--wrong .choice__key { background: var(--ko); color: #fff; }
.choice--dim { opacity: .55; }

.feedback { margin-top: 16px; scroll-margin-top: 76px; }

.verdict {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-weight: 700;
}

.verdict--ok { color: var(--ok); }
.verdict--ko { color: var(--ko); }

.verdict svg { width: 22px; height: 22px; flex: none; }

.explain p { margin: 0 0 10px; }

.retenir {
  margin: 14px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--retenir-line);
  border-radius: 0 10px 10px 0;
  background: var(--retenir);
}

.retenir__title {
  display: block;
  margin-bottom: 4px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.retenir p { margin: 0; }

.sources {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  font-size: .86rem;
  color: var(--ink-soft);
}

.sources li { margin-bottom: 4px; }
.sources a { word-break: break-word; }

.checked { font-size: .8rem; color: var(--ink-soft); margin-top: 6px; }

.q-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  margin-top: 18px;
}

.sticky-next {
  position: sticky;
  bottom: 0;
  margin-left: -16px;
  margin-right: -16px;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.sticky-next .btn--ghost { background: var(--surface); }

/* ---------- Fin de session ---------- */

.score {
  text-align: center;
  padding: 24px 16px;
}

.score__value {
  font-size: 3rem;
  font-weight: 750;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.score__label { margin-top: 8px; color: var(--ink-soft); }

.missed { display: grid; gap: 8px; }

.missed__item { padding: 12px 14px; }
.missed__q { margin: 0 0 6px; font-weight: 600; font-size: .95rem; }
.missed__a { margin: 0; font-size: .9rem; color: var(--ok); }

/* ---------- Parcourir ---------- */

.browse-item { margin-bottom: 10px; }
.browse-item summary {
  cursor: pointer;
  font-weight: 600;
  line-height: 1.4;
  list-style: none;
}
.browse-item summary::-webkit-details-marker { display: none; }
.browse-item__id { display: block; font-size: .75rem; font-weight: 500; color: var(--ink-soft); margin-bottom: 2px; font-variant-numeric: tabular-nums; }
.browse-item__answer { margin: 10px 0; color: var(--ok); font-weight: 600; }
.browse-item__wrong { margin: 0 0 10px; padding-left: 18px; font-size: .88rem; color: var(--ink-soft); }

.filter {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin: 0 -16px 14px;
  padding: 0 16px 4px;
  scrollbar-width: none;
}

.filter::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: .85rem;
  cursor: pointer;
}

.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Signalements et réglages ---------- */

.flag-item { margin-bottom: 10px; }
.flag-item__meta { font-size: .78rem; color: var(--ink-soft); }
.flag-item__q { margin: 4px 0; font-weight: 600; font-size: .95rem; }
.flag-item__c { margin: 0; font-size: .92rem; }

.empty { color: var(--ink-soft); text-align: center; padding: 24px 0; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting__label { font-weight: 600; }
.setting__hint { display: block; font-size: .82rem; color: var(--ink-soft); font-weight: 400; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.segmented button { border: 0; background: var(--surface); padding: 8px 12px; font-size: .88rem; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- Boîte de dialogue ---------- */

.dialog {
  width: min(560px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
}

.dialog::backdrop { background: rgba(10, 14, 18, .45); }

.dialog__body { padding: 18px; }
.dialog__title { margin: 0 0 6px; font-size: 1.1rem; }
.dialog__card { margin: 0 0 12px; font-size: .88rem; color: var(--ink-soft); }
.dialog__actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; margin-top: 12px; }
.dialog__hint { margin: 10px 0 0; font-size: .78rem; color: var(--ink-soft); }

.field { display: block; }
.field__label { display: block; margin-bottom: 6px; font-weight: 600; font-size: .92rem; }

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  resize: vertical;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: .9rem;
  transform: translate(-50%, 140%);
  opacity: 0;
  transition: transform .25s ease, opacity .25s ease;
  pointer-events: none;
}

.toast--show { transform: translate(-50%, 0); opacity: 1; }

.update-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 616px;
  margin: 0 auto;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: .92rem;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
