/* Quiz du Bréviaire 2026 – feuille de style (mobile d'abord, mode sombre) */

:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efebe3;
  --line: #ddd6c8;
  --ink: #1d1b18;
  --ink-2: #4f4a42;
  --ink-3: #6f695f;
  --accent: #5b3fa8;
  --accent-ink: #ffffff;
  --accent-soft: #ece6fa;
  --ok: #1d6f46;
  --ok-soft: #e1f2e8;
  --ko: #a8291f;
  --ko-soft: #fbe5e2;
  --warn: #8a5a00;
  --warn-soft: #fbefd5;
  --mark: #ffe58a;
  --meter: #5b3fa8;
  --meter-track: #e6e0d4;
  --shadow: 0 1px 2px rgba(30, 25, 15, .06), 0 4px 16px rgba(30, 25, 15, .05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141318;
    --surface: #1f1d25;
    --surface-2: #29262f;
    --line: #3a3742;
    --ink: #ece9f1;
    --ink-2: #c3bfcb;
    --ink-3: #9d98a8;
    --accent: #b9a3ff;
    --accent-ink: #18141f;
    --accent-soft: #2f2742;
    --ok: #74d6a1;
    --ok-soft: #173326;
    --ko: #ff998f;
    --ko-soft: #3d1d1a;
    --warn: #f1c46b;
    --warn-soft: #3a2e14;
    --mark: #6b5713;
    --meter: #b9a3ff;
    --meter-track: #34303d;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141318;
  --surface: #1f1d25;
  --surface-2: #29262f;
  --line: #3a3742;
  --ink: #ece9f1;
  --ink-2: #c3bfcb;
  --ink-3: #9d98a8;
  --accent: #b9a3ff;
  --accent-ink: #18141f;
  --accent-soft: #2f2742;
  --ok: #74d6a1;
  --ok-soft: #173326;
  --ko: #ff998f;
  --ko-soft: #3d1d1a;
  --warn: #f1c46b;
  --warn-soft: #3a2e14;
  --mark: #6b5713;
  --meter: #b9a3ff;
  --meter-track: #34303d;
  --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- Barre supérieure / navigation ------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.brand span { color: var(--accent); }
.mainnav { display: flex; gap: 4px; }
.mainnav a {
  text-decoration: none; color: var(--ink-2); padding: 6px 10px; border-radius: 999px; font-weight: 500; font-size: .95rem;
}
.mainnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 720px) {
  .topbar { backdrop-filter: none; background: var(--bg); }
  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0;
    justify-content: space-around;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mainnav a { font-size: .8rem; padding: 8px 6px; text-align: center; flex: 1; }
}
@media (min-width: 721px) { body { padding-bottom: 32px; } }

main { max-width: 860px; margin: 0 auto; padding: 16px; outline: none; }
.loading { color: var(--ink-3); text-align: center; padding: 48px 0; }

/* --- Cartes, boutons, champs -------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card > :last-child { margin-bottom: 0; }
.muted { color: var(--ink-3); }
.small { font-size: .875rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.grid { display: grid; gap: 12px; }
@media (min-width: 560px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--ko); border-color: var(--ko); background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: 1px solid transparent; background: transparent; border-radius: 10px; cursor: pointer;
  font-size: 1.15rem; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

label { font-weight: 600; display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
textarea { min-height: 96px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; cursor: pointer; min-height: 32px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  font-weight: 500; font-size: .9rem; cursor: pointer; background: var(--surface); user-select: none;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.badge { display: inline-block; white-space: nowrap; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.ko { background: var(--ko-soft); color: var(--ko); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* --- Tableau de bord ---------------------------------------------------- */
.hello { font-family: var(--serif); font-size: 1.6rem; margin-bottom: 4px; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .v { font-size: 1.6rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .l { font-size: .8rem; color: var(--ink-3); }

.due-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: var(--accent-soft); border-color: transparent; }
.due-card .n { font-size: 2rem; font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }

.meter { height: 8px; border-radius: 4px; background: var(--meter-track); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--meter); border-radius: 4px; }
.meter.ok > i { background: var(--ok); }

.prog-list { list-style: none; padding: 0; margin: 0; }
.prog-list li { padding: 10px 0; border-top: 1px solid var(--line); }
.prog-list li:first-child { border-top: 0; }
.prog-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 6px; }
.prog-head .t { font-weight: 600; }
.prog-head .p { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
details.mod > summary { cursor: pointer; list-style: none; }
details.mod > summary::-webkit-details-marker { display: none; }
details.mod > summary .prog-head .t::before { content: "▸ "; color: var(--ink-3); }
details.mod[open] > summary .prog-head .t::before { content: "▾ "; }
details.mod .sub { padding-left: 14px; margin-top: 6px; }
details.mod .sub li { padding: 6px 0; border-top: 0; }

.activity { display: grid; grid-template-columns: repeat(30, 1fr); gap: 3px; margin: 8px 0 4px; }
.activity i { aspect-ratio: 1; border-radius: 3px; background: var(--meter-track); }
.activity i.l1 { background: color-mix(in srgb, var(--meter) 35%, var(--meter-track)); }
.activity i.l2 { background: color-mix(in srgb, var(--meter) 65%, var(--meter-track)); }
.activity i.l3 { background: var(--meter); }
.legend-scale { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.legend-scale i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.weak a { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-decoration: none; color: inherit; padding: 10px 0; border-top: 1px solid var(--line); }
.weak a:first-child { border-top: 0; }
.weak a:hover .t { color: var(--accent); }

/* --- Choix du mode ------------------------------------------------------ */
.modes { display: grid; gap: 10px; grid-template-columns: 1fr; margin-bottom: 14px; }
@media (min-width: 560px) { .modes { grid-template-columns: 1fr 1fr; } }
@media (min-width: 820px) { .modes { grid-template-columns: repeat(3, 1fr); } }
.mode { position: relative; }
.mode input { position: absolute; opacity: 0; }
.mode span {
  display: block; height: 100%; padding: 12px 14px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface); cursor: pointer;
}
.mode b { display: block; }
.mode small { color: var(--ink-3); display: block; line-height: 1.35; margin-top: 2px; }
.mode input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.mode input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.tree { list-style: none; padding: 0; margin: 0; }
.tree ul { list-style: none; padding-left: 26px; margin: 2px 0 6px; }
.tree details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.tree details > summary::-webkit-details-marker { display: none; }
.tree .tog { width: 22px; text-align: center; color: var(--ink-3); flex: none; }
.tree details[open] > summary .tog { transform: rotate(90deg); }
.tree .check { font-weight: 500; }
.tree .count { color: var(--ink-3); font-size: .8rem; margin-left: auto; padding-left: 8px; white-space: nowrap; }
.tree li > .check, .tree summary .check { flex: 1; }

.sticky-go {
  position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 5;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
@media (min-width: 721px) { .sticky-go { bottom: 12px; } }

/* --- Question ----------------------------------------------------------- */
.qbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.qbar .meter { flex: 1; }
.qbar .pos { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.timer.low { background: var(--ko-soft); color: var(--ko); }

.qmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.qtext { font-family: var(--serif); font-size: 1.25rem; line-height: 1.45; margin: 4px 0 14px; }
.qtools { display: flex; gap: 2px; margin-left: auto; }

.choices { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.choice {
  width: 100%; text-align: left; display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  cursor: pointer; line-height: 1.4;
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .k {
  flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); color: var(--ink-2);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem;
}
.choice.selected { border-color: var(--accent); background: var(--accent-soft); }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .k { background: var(--ok); color: var(--surface); }
.choice.wrong { border-color: var(--ko); background: var(--ko-soft); }
.choice.wrong .k { background: var(--ko); color: var(--surface); }
.choice:disabled { cursor: default; }
.choice .why { display: block; font-size: .8rem; font-weight: 700; margin-top: 2px; }
.vf { grid-template-columns: 1fr 1fr; }
.vf .choice { justify-content: center; font-weight: 700; font-size: 1.05rem; }

.feedback { margin-top: 14px; border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); background: var(--surface); }
.feedback.ok { border-color: var(--ok); }
.feedback.ko { border-color: var(--ko); }
.feedback.half { border-color: var(--warn); }
.verdict { font-weight: 800; font-size: 1.05rem; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.feedback.ok .verdict { color: var(--ok); }
.feedback.ko .verdict { color: var(--ko); }
.feedback.half .verdict { color: var(--warn); }
.answer-line { font-weight: 600; margin-bottom: 8px; }
blockquote.cite {
  margin: 10px 0; padding: 10px 14px; border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: 0 10px 10px 0;
  font-family: var(--serif); font-style: italic;
}
.ref { font-size: .875rem; color: var(--ink-2); }
.model { white-space: pre-line; }

.selfeval { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.selfeval .btn { flex-direction: column; gap: 0; font-size: .9rem; padding: 8px; }
.selfeval .ok { border-color: var(--ok); color: var(--ok); }
.selfeval .half { border-color: var(--warn); color: var(--warn); }
.selfeval .ko { border-color: var(--ko); color: var(--ko); }

.navq { display: flex; gap: 8px; justify-content: space-between; margin-top: 14px; }
.navq .btn { flex: 1; }
.kbd-hint { font-size: .8rem; color: var(--ink-3); text-align: center; margin-top: 8px; }
@media (hover: none) { .kbd-hint { display: none; } }

.exam-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.exam-grid button {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .85rem;
}
.exam-grid button.done { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.exam-grid button.cur { outline: 2px solid var(--ink); }

/* --- Résultats ---------------------------------------------------------- */
.score-big { font-size: 3rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.result-list { list-style: none; margin: 0; padding: 0; }
.result-list > li { border-top: 1px solid var(--line); padding: 12px 0; }
.result-list > li:first-child { border-top: 0; }
.result-list .q { font-weight: 600; }

/* --- Fiches ------------------------------------------------------------- */
.fiche-index h3 { margin-top: 16px; }
.fiche-index ul { list-style: none; padding: 0; margin: 0; }
.fiche-index li a { display: flex; gap: 10px; padding: 9px 0; text-decoration: none; color: inherit; border-top: 1px solid var(--line); align-items: baseline; }
.fiche-index li:first-child a { border-top: 0; }
.fiche-index .n { font-weight: 700; color: var(--accent); min-width: 2.2em; font-variant-numeric: tabular-nums; }
.fiche-index .pct { margin-left: auto; color: var(--ink-3); font-size: .85rem; white-space: nowrap; }

.fiche { font-size: 1rem; }
.fiche h3.fh { font-family: var(--serif); font-size: 1.1rem; margin: 18px 0 6px; color: var(--accent); }
.fiche h3.fh:first-child { margin-top: 0; }
.fiche p { margin: 4px 0; }
.fiche .l1 { padding-left: 16px; position: relative; }
.fiche .l1::before { content: "–"; position: absolute; left: 0; color: var(--ink-3); }
.fiche .l2 { padding-left: 34px; position: relative; }
.fiche .l2::before { content: "•"; position: absolute; left: 18px; color: var(--ink-3); }
.fiche .l3 { padding-left: 52px; position: relative; }
.fiche .l3::before { content: "▪"; position: absolute; left: 36px; color: var(--ink-3); font-size: .8em; }
.fiche .pg { font-size: .75rem; color: var(--ink-3); font-weight: 600; margin: 14px 0 4px; letter-spacing: .02em; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

/* --- Fenêtre modale ----------------------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(10, 8, 15, .55); display: flex; align-items: flex-end; justify-content: center; }
.modal-box {
  background: var(--bg); width: 100%; max-width: 760px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
}
@media (min-width: 721px) { .modal { align-items: center; } .modal-box { border-radius: 18px; max-height: 86vh; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 8px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { overflow-y: auto; padding: 16px 18px 24px; -webkit-overflow-scrolling: touch; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.center { text-align: center; }
.mt { margin-top: 12px; }
body.login-page { padding-bottom: 32px; }
.login { max-width: 400px; margin: 8vh auto 0; }
.login .brand { display: block; text-align: center; font-size: 1.6rem; margin-bottom: 4px; }
.error { color: var(--ko); font-weight: 600; }
.empty { text-align: center; padding: 28px 12px; color: var(--ink-3); }

table.simple { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.simple th, table.simple td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); }
table.simple td.num, table.simple th.num { text-align: right; font-variant-numeric: tabular-nums; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .topbar, .mainnav, .navq, .qtools { display: none !important; } body { background: #fff; } }
