:root {
  --navy: #17233d;
  --navy-2: #22335a;
  --navy-soft: #2c3f6b;
  --beige: #f4ecdf;
  --beige-2: #ece0cc;
  --beige-card: #fbf7ee;
  --cream-line: #ddceac;
  --gold: #b08d4f;
  --text-main: #23262e;
  --text-soft: #5c6270;
  --ok: #4c7a54;
  --warn: #a3512c;
  --shadow: 0 10px 30px rgba(23, 35, 61, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--beige);
  color: var(--text-main);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100%;
}

h1, h2, h3, .brand-text {
  font-family: "Playfair Display", Georgia, serif;
  color: var(--navy);
  letter-spacing: 0.01em;
}

/* ---------- University strip ---------- */
.uni-strip {
  background: var(--beige-card);
  color: var(--navy);
  text-align: center;
  padding: 8px 12px;
  font-family: "Playfair Display", "Latin Modern Roman", Georgia, serif;
  font-size: 1rem;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--cream-line);
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--navy);
  border-bottom: 3px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  font-weight: 700;
  font-family: "Playfair Display", serif;
}
.brand-text { color: var(--beige-card); font-size: 1.15rem; }
.brand-text em { color: var(--gold); font-style: normal; }
.user-greeting {
  display: none;
  align-items: center;
  gap: 10px;
  color: var(--beige-card);
  font-size: 0.9rem;
}
.user-greeting.visible { display: flex; }
.user-greeting .greeting-name { color: var(--gold); font-weight: 600; }
.user-greeting button {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--beige-2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.78rem;
  font-family: "Inter", sans-serif;
  cursor: pointer;
}
.user-greeting button:hover { background: rgba(255,255,255,0.1); color: #fff; }

.flag-it {
  width: 20px;
  height: auto;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.25);
  flex-shrink: 0;
}
.uni-logo {
  height: 30px;
  width: auto;
  margin-right: 6px;
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

/* Lien de retour au site, posé dans le topbar sombre : `.back-link` de base
   est en `--navy-2` (pensé pour un fond clair, cf. plus bas dans ce fichier)
   et serait quasi invisible ici. */
.topbar .back-link {
  color: var(--beige-card);
  opacity: 0.85;
  font-weight: 600;
  margin-bottom: 0;
}
.topbar .back-link:hover { color: var(--gold); opacity: 1; }

.topnav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav-link {
  background: transparent;
  border: 1px solid transparent;
  color: var(--beige-2);
  font-family: "Inter", sans-serif;
  font-size: 0.92rem;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-link.active { background: var(--gold); color: var(--navy); font-weight: 600; }

/* ---------- Layout ---------- */
main#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  min-height: 60vh;
}

.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-soft);
  font-size: 0.85rem;
}

/* ---------- Hero / Home ---------- */
.hero {
  text-align: center;
  padding: 40px 20px 20px;
}
.hero h1 { font-size: 2.3rem; margin-bottom: 10px; }
.hero p { color: var(--text-soft); font-size: 1.05rem; max-width: 620px; margin: 0 auto 30px; }

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 24px;
  margin-top: 20px;
}
.choice-card {
  background: var(--beige-card);
  border: 1px solid var(--cream-line);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  text-align: left;
}
.choice-card:hover { transform: translateY(-4px); box-shadow: 0 16px 34px rgba(23,35,61,0.14); }
.choice-card .icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--navy);
  color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  margin-bottom: 16px;
}
.choice-card h3 { margin: 0 0 8px; font-size: 1.25rem; }
.choice-card p { margin: 0; color: var(--text-soft); font-size: 0.94rem; line-height: 1.5; }

/* ---------- Section header ---------- */
.section-head { margin-bottom: 28px; }
.section-head h1 { font-size: 1.8rem; margin: 0 0 6px; }
.section-head p { color: var(--text-soft); margin: 0; }
.results-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.btn-reset { white-space: nowrap; font-size: 0.85rem; padding: 9px 18px; border-color: var(--warn); color: var(--warn); }
.btn-reset:hover { background: var(--warn); color: #fff; }

/* ---------- Theme / Exam cards grid ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}
.item-card {
  background: var(--beige-card);
  border: 1px solid var(--cream-line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
  overflow: hidden;
}
.item-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--gold), var(--cream-line));
}
.item-card:hover { transform: translateY(-3px); border-color: var(--gold); }
.item-card h3 { margin: 6px 0 8px; font-size: 1.12rem; }
.item-card p { margin: 0 0 14px; color: var(--text-soft); font-size: 0.9rem; line-height: 1.45; }
.item-card .meta {
  display: flex; gap: 10px; flex-wrap: wrap;
  font-size: 0.78rem; color: var(--navy-2);
}
.pill {
  background: var(--beige-2);
  border-radius: 999px;
  padding: 3px 10px;
  font-weight: 600;
}

/* ---------- Locked exams ---------- */
.item-card-locked { background: #efe8da; }
.lock-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
  background: var(--beige-2);
  color: var(--warn);
  letter-spacing: 0.02em;
}
.lock-badge-free { color: var(--ok); background: #e3efe4; }
.lock-badge-open { color: var(--ok); background: #e3efe4; }

/* ---------- Modal (login / unlock) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 35, 61, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: var(--beige-card);
  border-radius: var(--radius);
  padding: 32px 30px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  position: relative;
}
.modal-box h3 { margin: 0 0 10px; font-size: 1.3rem; }
.modal-box p { margin: 0 0 20px; color: var(--text-soft); font-size: 0.92rem; line-height: 1.5; }
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; font-size: 1.4rem; color: var(--text-soft); cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--warn); }
.modal-box-wide {
  max-width: 920px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-box-wide .course-table-wrap:last-child { margin-bottom: 0; }
.btn-tables { font-size: 0.85rem; padding: 8px 16px; flex-shrink: 0; }
#login-form { display: flex; flex-direction: column; gap: 10px; }
#login-form input {
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid var(--cream-line);
  font-family: "Inter", sans-serif;
  font-size: 0.92rem;
}
#login-form input:focus { outline: none; border-color: var(--gold); }
.modal-divider {
  text-align: center;
  color: var(--text-soft);
  font-size: 0.8rem;
  margin: 16px 0;
  position: relative;
}

/* ---------- Exam cover fields ---------- */
.exam-cover {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  background: var(--beige-2);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
  font-family: "Inter", sans-serif;
  font-size: 0.88rem;
}
.exam-cover .cover-field { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 200px; }
.exam-cover label { color: var(--navy-2); font-weight: 600; white-space: nowrap; }
.exam-cover input {
  flex: 1;
  border: none;
  border-bottom: 1.5px solid var(--cream-line);
  background: transparent;
  padding: 4px 2px;
  font-family: "Inter", sans-serif;
  font-size: 0.9rem;
}
.exam-cover input:focus { outline: none; border-bottom-color: var(--gold); }

/* ---------- Exercise / Exam runner ---------- */
.runner {
  background: var(--beige-card);
  border: 1px solid var(--cream-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 34px;
}
.runner-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 1px solid var(--cream-line);
  padding-bottom: 18px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.runner-head h2 { margin: 0 0 4px; font-size: 1.4rem; }
.runner-head .subtitle { color: var(--text-soft); font-size: 0.9rem; }

.timer {
  background: var(--navy);
  color: var(--beige-card);
  padding: 10px 20px;
  border-radius: 10px;
  font-family: "Playfair Display", serif;
  font-size: 1.4rem;
  letter-spacing: 0.03em;
  min-width: 110px;
  text-align: center;
  border: 1px solid var(--gold);
}
.timer .label { display: block; font-family: "Inter", sans-serif; font-size: 0.65rem; color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 2px; }
.timer.timer-danger {
  background: var(--warn);
  border-color: var(--warn);
  animation: timer-pulse 1s ease-in-out infinite;
}
.timer.timer-danger .label { color: #fde8dc; }
@keyframes timer-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(163, 81, 44, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(163, 81, 44, 0); }
}
.time-warning {
  display: none;
  background: #fbe9e2;
  border: 1.5px solid var(--warn);
  color: #7a3418;
  border-radius: 10px;
  padding: 16px 20px;
  margin: 20px 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--navy);
  color: var(--beige-card);
  border-radius: 10px;
  padding: 16px 20px;
  margin: 18px 0;
  white-space: nowrap;
}
.katex-display .katex { color: var(--beige-card); white-space: nowrap; }
.katex-display .katex-html { white-space: nowrap; }
.katex { white-space: nowrap; }

.statement, .solution-block {
  line-height: 1.85;
  font-size: 1.08rem;
  font-family: "KaTeX_Main", "Latin Modern Roman", "CMU Serif", Georgia, "Times New Roman", serif;
  color: var(--text-main);
}
.statement strong, .solution-block strong { font-weight: 700; color: var(--navy); }
.statement p, .solution-block p { margin: 0 0 20px; }
.statement p:last-child, .solution-block p:last-child { margin-bottom: 0; }
.statement blockquote, .solution-block blockquote {
  margin: 18px 0;
  padding: 10px 18px;
  border-left: 3px solid var(--gold);
  background: var(--beige-2);
  border-radius: 0 8px 8px 0;
  font-size: 0.95rem;
}
.statement table, .solution-block table {
  border-collapse: collapse;
  margin: 16px 0;
}
.statement th, .statement td, .solution-block th, .solution-block td {
  border: 1px solid var(--cream-line);
  padding: 8px 14px;
  text-align: center;
}
.statement th, .solution-block th { background: var(--beige-2); }

.exam-problem {
  border-top: 1px dashed var(--cream-line);
  padding-top: 22px;
  margin-top: 22px;
}
.exam-problem:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.exam-problem h3 { font-size: 1.1rem; margin: 0 0 4px; }
.exam-problem .pts { color: var(--gold); font-weight: 600; font-size: 0.85rem; }

.solution-reveal {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 2px solid var(--navy);
}
.solution-reveal h3 {
  color: var(--ok);
  font-size: 1.05rem;
  display: flex; align-items: center; gap: 8px;
}

.actions {
  margin-top: 28px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
}

button.btn {
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 26px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
button.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--navy); color: var(--beige-card); }
.btn-primary:hover { box-shadow: 0 6px 16px rgba(23,35,61,0.3); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { box-shadow: 0 6px 16px rgba(176,141,79,0.35); }
.btn-outline { background: transparent; border: 1.5px solid var(--navy); color: var(--navy); }
.btn-outline:hover { background: var(--navy); color: #fff; }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.upload-box {
  background: var(--beige-2);
  border: 1.5px dashed var(--cream-line);
  border-radius: 12px;
  padding: 16px 20px;
  margin-top: 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.upload-label { font-weight: 600; color: var(--navy); font-size: 0.92rem; }
.upload-choose-btn { padding: 8px 18px; font-size: 0.85rem; }
.upload-input-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
.upload-status { font-size: 0.85rem; color: var(--text-soft); }
.upload-status.upload-ok { color: var(--ok); font-weight: 600; }

.score-box {
  background: var(--beige-2);
  border-radius: 12px;
  padding: 18px 22px;
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.score-box label { font-weight: 600; color: var(--navy); }
.score-box input[type="number"] {
  width: 80px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--cream-line);
  font-size: 1rem;
  font-family: "Inter", sans-serif;
  text-align: center;
}
.score-box .max { color: var(--text-soft); }

.confirm-banner {
  margin-top: 16px;
  background: #eaf2ea;
  color: var(--ok);
  border: 1px solid #bfd9c2;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 600;
}

/* ---------- Scores dashboard ---------- */
.theme-score-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 100px 100px;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
  background: var(--beige-card);
  border: 1px solid var(--cream-line);
  border-radius: 10px;
  margin-bottom: 10px;
}
.theme-score-row .name { font-weight: 600; color: var(--navy); }
.bar-track {
  background: var(--beige-2);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.bar-fill { height: 100%; background: var(--gold); }
.theme-score-row .stat { text-align: center; font-size: 0.9rem; color: var(--text-soft); }
.theme-score-row .stat b { color: var(--navy); font-size: 1rem; }

.exam-history-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--beige-card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.exam-history-table th, .exam-history-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--cream-line);
  font-size: 0.92rem;
}
.exam-history-table th {
  background: var(--navy);
  color: var(--beige-card);
  font-weight: 600;
}
.exam-history-table tr:last-child td { border-bottom: none; }

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-soft);
}
.empty-state .icon { font-size: 2.2rem; margin-bottom: 10px; }

.loading { text-align: center; padding: 60px; color: var(--text-soft); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--navy-2);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-bottom: 18px;
  font-size: 0.92rem;
}
.back-link:hover { color: var(--gold); }


/* ---------- Course notes ---------- */
.course-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--beige);
  padding: 10px 0 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--cream-line);
}
#course-search {
  width: 100%;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--cream-line);
  background: var(--beige-card);
  font-family: "Inter", sans-serif;
  font-size: 0.95rem;
  margin-bottom: 12px;
}
#course-search:focus { outline: none; border-color: var(--gold); }
.theme-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--beige-card);
  border: 1px solid var(--cream-line);
  color: var(--navy-2);
  font-family: "Inter", sans-serif;
  font-size: 0.82rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { border-color: var(--gold); }
.chip.active { background: var(--navy); color: var(--beige-card); border-color: var(--navy); }

.theme-group { margin-bottom: 30px; }
.theme-group-title {
  font-size: 1.4rem;
  margin: 30px 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--navy);
}
.theme-group:first-of-type .theme-group-title { margin-top: 6px; }
.theme-group-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.theme-group-banner .theme-group-title { flex: 1; min-width: 200px; }
.theme-group-banner .btn-gold { flex-shrink: 0; }

@media print {
  .topbar, .uni-strip, .footer, .course-toolbar, .back-link, #print-tables-btn { display: none !important; }
  .theme-group:not([data-theme-group="ref"]) { display: none !important; }
  body { background: #fff; }
}

.course-section {
  background: var(--beige-card);
  border: 1px solid var(--cream-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 28px;
  margin-bottom: 16px;
}
.course-section h3 {
  font-size: 1.12rem;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--gold);
  padding-bottom: 8px;
}
.course-section .statement,
.course-section .solution-block { font-family: "KaTeX_Main", "Latin Modern Roman", Georgia, serif; }

.course-table-wrap { overflow-x: auto; margin: 20px 0; }
.course-table-wrap table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
.course-table-wrap th, .course-table-wrap td {
  border: 1px solid var(--cream-line);
  padding: 6px 10px;
  text-align: center;
}
.course-table-wrap th { background: var(--navy); color: var(--beige-card); }
.course-table-wrap caption { caption-side: top; text-align: left; font-weight: 600; color: var(--navy); margin-bottom: 8px; }
.table-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--navy);
  color: var(--beige-card);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-right: 8px;
  vertical-align: middle;
}

/* ---------- Rejection region diagram ---------- */
.reject-diagram { margin: 24px 0; }
.reject-diagram svg { width: 100%; height: auto; max-width: 960px; display: block; margin: 0 auto; }
.dg-title { font-family: "Playfair Display", serif; font-size: 15px; fill: var(--navy); font-weight: 600; }
.dg-outline { fill: none; stroke: var(--navy); stroke-width: 2; }
.dg-curve { fill: var(--warn); opacity: 0.5; stroke: none; }
.dg-axis { stroke: var(--navy); stroke-width: 1.5; }
.dg-crit { stroke: var(--navy-2); stroke-width: 1.2; stroke-dasharray: 3 3; }
.dg-crit-label { font-size: 11px; fill: var(--navy-2); font-family: "Inter", sans-serif; }
.dg-noreject { font-size: 12px; fill: var(--ok); font-family: "Inter", sans-serif; font-weight: 600; }
.dg-reject { font-size: 12px; fill: var(--warn); font-family: "Inter", sans-serif; font-weight: 600; }
.dg-caption { font-size: 0.85rem; color: var(--text-soft); text-align: center; margin-top: 4px; }

/* ---------- Horizontal probability tree ---------- */
.tree-diagram { margin: 24px 0; }
.tree-diagram svg { width: 100%; height: auto; max-width: 680px; display: block; margin: 0 auto; }
.tr-branch { stroke: var(--navy-2); stroke-width: 1.5; }
.tr-node { fill: var(--gold); }
.tr-root { font-size: 13px; fill: var(--navy); font-weight: 600; font-family: "Inter", sans-serif; }
.tr-node-label { font-size: 12px; fill: var(--navy); font-weight: 600; font-family: "Inter", sans-serif; }
.tr-edge-label { font-size: 11px; fill: var(--navy-2); font-family: "Inter", sans-serif; }
.tr-leaf { font-size: 12px; fill: var(--warn); font-weight: 600; font-family: "Inter", sans-serif; }

@media (max-width: 640px) {
  .theme-score-row { grid-template-columns: 1fr; text-align: left; }
  .runner { padding: 22px 18px; }
}
