:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #e2e0d8;
  --accent: #3b6fd8;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --surface: #212429;
    --text: #e8e6e1;
    --muted: #a0a6ad;
    --border: #33373d;
  }
}

/* One colour per subject (tiles, chips, badges). Slugs come from the syllabus. */
[data-subject="francais"] { --accent: #c2410c; }
[data-subject="mathematiques"] { --accent: #2563eb; }
[data-subject="histoire-geographie"] { --accent: #a16207; }
[data-subject="emc"] { --accent: #7c3aed; }
[data-subject="anglais"] { --accent: #dc2626; }
[data-subject="italien"] { --accent: #16a34a; }
[data-subject="technologie"] { --accent: #0891b2; }
[data-subject="evars"] { --accent: #db2777; }
[data-subject="svt"] { --accent: #15803d; }
[data-subject="physique-chimie"] { --accent: #4f46e5; }
[data-subject="arts-plastiques"] { --accent: #e11d48; }
[data-subject="education-musicale"] { --accent: #9333ea; }
[data-subject="histoire-des-arts"] { --accent: #b45309; }
[data-subject="eps"] { --accent: #ea580c; }
[data-subject="emi"] { --accent: #0d9488; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 20px 64px;
}

h1 { font-size: 1.9rem; line-height: 1.2; margin: 0.3em 0 0.4em; }
h2 { font-size: 1.2rem; margin: 1.6em 0 0.6em; }

.intro { color: var(--muted); margin-top: 0; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--text); }
.search { flex: 1; max-width: 420px; margin-left: auto; }
.search input {
  width: 100%;
  font: inherit;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
}

.account { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--muted); }
.link-button {
  font: inherit;
  background: none;
  border: 0;
  padding: 8px 4px;
  min-height: 44px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

/* Activity log (parents) */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.filters select {
  font: inherit;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
.event-list { list-style: none; padding: 0; margin: 0; }
.event {
  display: grid;
  grid-template-columns: 140px 90px 160px 1fr;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.event-date, .event-user { color: var(--muted); font-variant-numeric: tabular-nums; }
.event-label { font-weight: 600; }
.event-login_failed .event-label, .event-generation_failed .event-label,
.event-generation_forbidden .event-label { color: #b91c1c; }
.event-answer_contested { background: var(--highlight, rgba(245, 158, 11, 0.12)); }
.event-answer_contested .event-label { color: #b45309; }
.count-badge {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 6px;
  border-radius: 999px;
  background: #d97706;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}
.to-review .contest { border-left: 4px solid #d97706; }
.contest-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 12px 0; }
.contest-facts dt { color: var(--muted); }
.contest-facts dd { margin: 0; }
.contest-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
@media (max-width: 700px) {
  .event { grid-template-columns: 1fr 1fr; }
  .event-detail { grid-column: 1 / -1; }
}

/* Login */
.login {
  max-width: 380px;
  margin: 8vh auto 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.login input:not([type="checkbox"]) {
  font: inherit;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
.login .remember { flex-direction: row; align-items: center; font-weight: 400; }
.login .remember input { width: 22px; height: 22px; }

/* Breadcrumb */
.breadcrumb { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.breadcrumb a { color: var(--muted); }

/* Home: subject tiles */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 112px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 6px solid var(--accent);
  text-decoration: none;
  color: var(--text);
}
.tile:hover, .tile:focus-visible { background: var(--accent-soft); }
.tile-title { font-weight: 650; font-size: 1.1rem; }
.tile-info { color: var(--muted); font-size: 0.85rem; margin-top: auto; }

/* Subject page: domains × grades */
.domain {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 18px 14px;
  margin: 16px 0;
}
.domain h2 { margin-top: 0.8em; }
.grade-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: start;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.grade-row:first-child { border-top: 0; }
.grade-label {
  font-weight: 700;
  color: var(--muted);
  padding-top: 8px;
}
.grade-current {
  background: var(--accent-soft);
  margin: 0 -18px;
  padding: 10px 18px;
  border-radius: 10px;
}
.grade-current .grade-label { color: var(--accent); }
.grade-row:not(.grade-current) .chip { opacity: 0.85; }
.empty { color: var(--muted); padding-top: 8px; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-block;
  padding: 8px 14px;
  min-height: 44px;
  line-height: 28px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.chip:hover, .chip:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.chip-practice { border-style: dashed; }

/* Chapter: list of notions */
.kicker { color: var(--muted); margin: 8px 0 0; font-size: 0.9rem; }
.notion-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.notion-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 18px;
  min-height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.notion-card:hover, .notion-card:focus-visible { background: var(--accent-soft); }
.notion-title { font-weight: 600; }
.notion-excerpt { color: var(--muted); font-size: 0.88rem; }
.notion-badges:empty { display: none; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  vertical-align: middle;
}
.badge-current { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge-cycle { border-style: dashed; }

/* Panels */
.panel {
  margin-top: 28px;
  padding: 4px 18px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.panel .grade-row:first-of-type { border-top: 0; }
.panel h2 { margin-top: 0.8em; }
.official blockquote {
  margin: 0;
  padding: 10px 14px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  font-style: italic;
}
.source { font-size: 0.9rem; }

/* Generated content: lesson sheet and exercises */
.generated-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 1.6em;
}
.generated-header h2 { margin: 0; }
.provenance { color: var(--muted); font-size: 0.8rem; margin: 4px 0 12px; }
.quota { color: var(--muted); font-size: 0.9rem; margin: 1em 0 0; }
.lesson h3 { font-size: 1.05rem; margin: 1.3em 0 0.5em; }
.button {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.button-secondary { background: var(--surface); color: var(--accent); }
.button:disabled { opacity: 0.6; cursor: wait; }
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.flash-error { border-color: #dc2626; color: #b91c1c; }
.summary {
  font-size: 1.1rem;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border-left: 5px solid var(--accent);
}
.key-points { padding-left: 1.2em; }
.key-points li { margin: 8px 0; }
.key-points li p, .bullets li p, .choices li p, .summary p { margin: 0; }
.answer { font-weight: 700; }
.prose p { margin: 0.5em 0; }
.prose ol, .prose ul { padding-left: 1.3em; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 18px;
  margin: 12px 0;
}
.card .kicker { margin-top: 8px; }
details { margin: 8px 0; }
summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  padding: 8px 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.exercise-list { list-style: none; padding: 0; counter-reset: ex; }
.exercise-list > li { counter-increment: ex; position: relative; }
.exercise-list > li .kicker::before { content: "Exercice " counter(ex) " · "; font-weight: 600; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  font: inherit;
  color: var(--text);
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
}
.choice p { margin: 0; }
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice:disabled, .typed-answer :disabled { opacity: 0.6; cursor: default; }
.is-waiting { animation: waiting-pulse 0.8s ease-in-out infinite alternate; }
@keyframes waiting-pulse { to { opacity: 0.35; } }
.typed-answer { display: flex; gap: 8px; flex-wrap: wrap; }
.typed-answer input {
  font: inherit;
  flex: 1 1 200px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}
.feedback { margin-top: 12px; padding: 12px 16px; border-radius: 10px; background: var(--bg); }
.feedback > :first-child { margin-top: 0; }
.feedback-given { color: var(--muted); margin: 0 0 6px; }
.feedback-verdict { font-weight: 700; font-size: 1.1rem; margin: 0 0 4px; }
.feedback-right { color: #15803d; }
.feedback-partial { color: #b45309; }
.feedback-wrong { color: #b91c1c; }
.feedback-explanation { margin: 0 0 8px; }
.feedback-expected p, .feedback-correction p { margin: 6px 0; }
.self-assessment { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.self-assessment p { flex-basis: 100%; margin: 0; }
.feedback-contested { color: var(--muted); font-size: 0.9rem; }
@media (prefers-color-scheme: dark) {
  .feedback-right { color: #4ade80; }
  .feedback-partial { color: #fbbf24; }
  .feedback-wrong { color: #f87171; }
}
.disclaimer { color: var(--muted); font-size: 0.85rem; font-style: italic; margin-top: 24px; }

.bullets { padding-left: 1.2em; }
.bullets li { margin: 6px 0; }

/* Previous / next */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
  font-size: 0.95rem;
}
.pager a {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-decoration: none;
  max-width: 48%;
}

/* Waiting during a generation: bubble game */
.waiting {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  touch-action: none;
}
.waiting-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
  padding: 16px 20px 0;
}
.waiting-title { font-size: 1.2rem; font-weight: 650; margin: 0; }
.waiting-clock { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.waiting-score { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.waiting-score strong { color: var(--text); font-size: 1.2rem; }
.waiting-game { flex: 1; width: 100%; display: block; cursor: pointer; }
.waiting-hint { text-align: center; color: var(--muted); margin: 0 0 16px; }
.waiting-done .waiting-game { opacity: 0.3; transition: opacity 0.3s; }
.waiting-done .waiting-title { color: var(--accent); }

@media (max-width: 600px) {
  :root { font-size: 16px; }
  main { padding: 12px 14px 48px; }
  .topbar { padding: 8px 14px; }
}

/* Progress */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.muted { color: var(--muted); font-size: 0.9rem; }
.stars { font-size: 0.9em; letter-spacing: 1px; white-space: nowrap; }
.star-on { color: #d97706; }
.star-off { color: var(--border); }
.streak-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0 8px; }
.stat {
  display: flex;
  flex-direction: column;
  padding: 12px 18px;
  min-width: 120px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.streak-on { border-color: #d97706; }

/* Activity: one series, bars anchored to the baseline, rounded data end, 2px gaps */
.activity-chart {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 2px;
  align-items: end;
  height: 140px;
  padding-top: 8px;
  border-bottom: 1px solid var(--border);
}
.activity-col { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.activity-bar {
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 0;
  margin: 0 15%;
}
.activity-day {
  position: absolute;
  bottom: -1.6em;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}
.activity-chart { margin-bottom: 2em; }
.activity-col::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  z-index: 1;
}
.activity-col:hover::after, .activity-col:active::after { opacity: 1; }
.activity-col:first-child::after { left: 0; transform: none; }
.activity-col:last-child::after { left: auto; right: 0; transform: none; }

.review-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.subject-progress { list-style: none; padding: 0; display: grid; gap: 14px; }
.subject-progress li {
  display: grid;
  grid-template-columns: minmax(120px, 200px) 1fr;
  gap: 4px 12px;
  align-items: center;
}
.subject-progress-title { font-weight: 600; color: var(--text); text-decoration: none; }
.subject-progress-figures { grid-column: 2; color: var(--muted); font-size: 0.85rem; }
.progress-bar { height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--accent); }
@media (max-width: 600px) {
  .subject-progress li { grid-template-columns: 1fr; }
  .subject-progress-figures { grid-column: 1; }
}
.worked-list { list-style: none; padding: 0; display: grid; gap: 8px; }
.worked-list li { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.rules { margin-top: 32px; color: var(--muted); }
.home-progress { margin-bottom: 32px; }
a.stat { color: var(--text); text-decoration: none; }
a.stat:hover, a.stat:focus-visible { border-color: var(--accent); }
