:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #1c2638;
  --muted: #6b7587;
  --line: #e2ddd2;
  --accent: #b8914a;
  --accent-ink: #ffffff;
  --navy: #1c2638;
  --danger: #b03a3a;
  --ok: #3f7a52;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 38, 56, .06), 0 4px 14px rgba(28, 38, 56, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161f;
    --surface: #1a212d;
    --ink: #ece8df;
    --muted: #97a0b0;
    --line: #2a3342;
    --accent: #c9a25a;
    --accent-ink: #1c2638;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px;
  font: inherit; font-weight: 600; text-decoration: none;
  color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; }
.btn:disabled { opacity: .6; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  color: inherit; background: none; border: 0; border-radius: 50%; cursor: pointer;
}
.icon-btn:active { background: rgba(127, 127, 127, .15); }

/* Connexion */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--navy); }
.login-card {
  width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center;
  background: var(--surface); padding: 28px 22px; border-radius: 20px;
}
.login-card img { margin: 0 auto; border-radius: 16px; }
.login-card p { margin: 0; color: var(--muted); }
.error { color: var(--danger) !important; min-height: 1.4em; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px 16px;
  background: var(--navy); color: #f4f1ea;
}
.topbar h1 { flex: 1; font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.content { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }

/* Nouveau lien */
.new-job { display: grid; gap: 10px; padding: 16px; }
.new-job label { font-weight: 600; }
.url-row { display: flex; gap: 6px; }
.url-row .icon-btn { color: var(--muted); }
details summary { color: var(--muted); font-size: 14px; cursor: pointer; }
details textarea { margin-top: 8px; resize: vertical; }

/* Jobs en cours */
.jobs { display: grid; gap: 8px; margin-top: 12px; }
.job {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  font-size: 14px;
}
.job .txt { flex: 1; min-width: 0; }
.job .url { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job.error .msg { color: var(--danger); }
.job.done .msg { color: var(--ok); }
.job .x { color: var(--muted); }
.spinner {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
.dot { width: 20px; height: 20px; flex: none; display: grid; place-items: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Filtres */
.filters { position: sticky; top: calc(env(safe-area-inset-top) + 60px); z-index: 4; background: var(--bg); padding: 16px 0 10px; display: grid; gap: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 0 14px;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}
.chip[aria-selected="true"] { background: var(--navy); border-color: var(--navy); color: #f4f1ea; }
@media (prefers-color-scheme: dark) { .chip[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); } }
.chip .n { opacity: .6; font-weight: 500; margin-left: 4px; }

/* Liste des slides */
.decks { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); }
.deck {
  display: flex; gap: 12px; align-items: center; text-align: left;
  width: 100%; padding: 10px; font: inherit; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer;
}
.thumb {
  width: 96px; aspect-ratio: 16 / 9; flex: none; border-radius: 8px; overflow: hidden;
  background: var(--navy); display: grid; place-items: center; color: var(--accent);
}
.thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.deck .info { flex: 1; min-width: 0; }
.deck .title { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.deck .meta { color: var(--muted); font-size: 13px; margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.badge { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--ink); padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.star { color: var(--accent); }
.deck .more { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

/* Lecteur */
.viewer { position: fixed; inset: 0; background: #0b0f16; display: flex; flex-direction: column; }
.viewer .topbar { background: #0b0f16; }
.pages { flex: 1; overflow-y: auto; padding: 12px 8px calc(env(safe-area-inset-bottom) + 40px); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.page { flex: none; width: 100%; max-width: 1100px; aspect-ratio: 16 / 9; background: #1a212d; border-radius: 6px; overflow: hidden; }
.page canvas { width: 100%; height: 100%; display: block; }
.page-counter {
  position: fixed; bottom: calc(env(safe-area-inset-bottom) + 12px); left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, .65); color: #fff; font-size: 13px; padding: 4px 12px; border-radius: 999px; pointer-events: none;
}
.viewer-msg { color: #c8ccd4; text-align: center; padding: 40px 16px; }

/* Fiche */
.sheet {
  width: 100%; max-width: 520px; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink);
}
@media (min-width: 600px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet form { display: grid; gap: 14px; padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.sheet label.check { display: flex; align-items: center; gap: 10px; color: var(--ink); font-size: 16px; }
.sheet label.check input { width: 20px; height: 20px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet-actions .primary, .sheet-actions .ghost { grid-column: 1 / -1; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  max-width: calc(100% - 32px); z-index: 50;
  background: var(--navy); color: #f4f1ea; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}

/* ------------------------------------------------------------------ v2 : onglets, étude, révision, stats */
:root { --tabbar: 64px; --good: #2f8a55; --bad: #c0392b; }
#app { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
body.locked { overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.intro { color: var(--muted); margin: 0 0 12px; font-size: 15px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 8px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 22px 0 10px; }
.section-head h2 { font-size: 17px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.deck .meta .studied { color: var(--good); font-weight: 700; }
.deck .meta .score { font-weight: 600; }

/* Barre d'onglets */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0; background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
}
.tabbar button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar button[aria-current="page"] svg { stroke-width: 2.4; }

/* Superpositions (fiche, notes, révision) */
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; }
.overlay .topbar h1 { font-size: 18px; }

/* Accueil */
.today {
  width: 100%; margin-top: 12px; padding: 14px 16px; display: flex; align-items: center; gap: 14px;
  text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.today .big { font-size: 30px; font-weight: 750; color: var(--accent); min-width: 32px; text-align: center; }
.today span:nth-child(2) { flex: 1; font-weight: 600; }
.today small { color: var(--muted); font-weight: 400; }

/* Fiche d'un slide */
.deck-hero { display: flex; justify-content: center; }
.thumb.big { width: 100%; max-width: 520px; border-radius: 12px; box-shadow: var(--shadow); }
.deck-title { font-size: 21px; margin: 16px 0 8px; }
#deck-body > .meta { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; flex-wrap: wrap; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.action {
  display: grid; justify-items: start; gap: 2px; padding: 14px; text-align: left;
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.action svg { color: var(--accent); width: 26px; height: 26px; margin-bottom: 4px; }
.action small { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.action:disabled { opacity: .8; }
.spinner.small { width: 14px; height: 14px; border-width: 2px; }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 24px 0; }

/* Notes */
.prose { line-height: 1.6; }
.prose h2, .prose h3, .prose h4 { margin: 20px 0 6px; line-height: 1.3; }
.prose h2 { font-size: 20px; } .prose h3 { font-size: 17px; } .prose h4 { font-size: 15px; }
.prose p { margin: 8px 0; }
.prose ul, .prose ol { padding-left: 22px; }
.prose blockquote { margin: 10px 0; padding: 6px 12px; border-left: 3px solid var(--accent); color: var(--muted); font-style: italic; }

/* Révision */
.progress { position: sticky; top: calc(env(safe-area-inset-top) + 60px); z-index: 4; height: 4px; background: var(--line); }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.q-kind { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 6px 0; }
.q { font-size: 20px; line-height: 1.35; margin: 0 0 16px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  padding: 14px; font: inherit; color: inherit; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer;
}
.option .letter { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--bg); font-weight: 700; font-size: 13px; }
.option.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.option.right .letter { background: var(--good); color: #fff; }
.option.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); }
.option.wrong .letter { background: var(--bad); color: #fff; }
.option:disabled { cursor: default; color: inherit; }
.explain { margin: 16px 0; padding: 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.explain.ok { border-color: var(--good); } .explain.ko { border-color: var(--bad); }
.explain.coach { border-color: var(--accent); }
.explain.coach p:first-child { margin-top: 0; }
#q-after .btn, .quiz-end .btn { width: 100%; }
#reflect-answer { margin: 4px 0 10px; resize: vertical; }
.row { display: flex; gap: 8px; } .row .primary { flex: 1; }
.quiz-end { display: grid; gap: 10px; text-align: center; justify-items: center; padding-top: 12px; }
.quiz-end h2 { font-size: 20px; }
.ring {
  width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 6px;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0);
}
.ring span { width: 108px; height: 108px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-size: 28px; font-weight: 750; }

/* Application */
.new-task { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px; }
.new-task #task-text { grid-column: 1 / -1; }
.new-task input[type="date"] { min-width: 0; }
.new-task .btn { min-width: 44px; padding: 0; font-size: 22px; }
.task-list { display: grid; gap: 8px; }
.task {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.task .check {
  flex: none; width: 28px; height: 28px; margin-top: 1px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--accent); background: none; color: #fff; font-weight: 800; font: inherit;
}
.task.done .check { background: var(--good); border-color: var(--good); }
.task.done .t { text-decoration: line-through; color: var(--muted); }
.task .txt { flex: 1; min-width: 0; }
.task .t { font-weight: 600; }
.task .d { display: none; color: var(--muted); font-size: 14px; margin-top: 4px; }
.task.open .d { display: block; }
.task .m { color: var(--muted); font-size: 13px; margin-top: 3px; }
.task .late { color: var(--bad); font-weight: 600; }
.task .del { color: var(--muted); width: 36px; height: 36px; }
.done-list { margin-top: 20px; }
.done-list summary { color: var(--muted); font-weight: 600; cursor: pointer; margin-bottom: 10px; }

/* Stats */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(46%, 170px), 1fr)); gap: 10px; }
.tile { display: grid; gap: 2px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tile .n { font-size: 26px; font-weight: 750; }
.tile .l { font-weight: 600; }
.tile .s { color: var(--muted); font-size: 13px; }
.card.cal, .genres-card, .card.form { margin-top: 14px; padding: 14px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head h2 { font-size: 17px; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-top: 8px; text-align: center; }
.cal-grid .wd { font-size: 12px; color: var(--muted); font-weight: 600; }
.day {
  min-width: 0; width: 100%; height: auto; aspect-ratio: 1; align-self: start; padding: 0;
  border-radius: 10px; border: 0; font: inherit; font-size: 14px; color: inherit; cursor: pointer;
  background: var(--bg);
}
.day.study { background: var(--good); color: #fff; font-weight: 700; }
.day.added { background: color-mix(in srgb, var(--accent) 35%, var(--bg)); }
.day.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.day:disabled { opacity: .35; cursor: default; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; background: var(--bg); border: 1px solid var(--line); }
.legend i.study { background: var(--good); border-color: var(--good); }
.legend i.added { background: color-mix(in srgb, var(--accent) 35%, var(--bg)); }
.cal-detail { min-height: 1.4em; margin: 10px 0 0; font-size: 14px; }
.genres-card h2, .card.form h2 { font-size: 17px; margin-bottom: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 9em) 1fr auto; gap: 10px; align-items: center; margin: 8px 0; font-size: 14px; }
.bar-row .g { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar .all { height: 100%; background: color-mix(in srgb, var(--accent) 35%, var(--bg)); border-radius: 999px; }
.bar .st { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-row .c { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Profil */
.card.form { display: grid; gap: 12px; }
.card.form label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.card.form:first-child { margin-top: 0; }
.toast { bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px); }
