:root {
  color-scheme: light;
  --page-bg: #fbfaf4;
  --surface: #f4f3eb;
  --panel-bg: rgba(255, 254, 250, 0.96);
  --panel-border: rgba(12, 95, 56, 0.16);
  --panel-shadow: 0 10px 26px rgba(35, 53, 38, 0.09);
  --text-main: #193528;
  --text-soft: #686960;
  --brand: #0c5f38;
  --brand-soft: #e9efe2;
  --brand-dark: #073d27;
  --success-bg: #7fdaa0;
  --success-text: #045d18;
  --danger-bg: #ef7e8e;
  --danger-text: #8f1024;
  --placeholder-bg: #e5e3d7;
  --placeholder-text: #6a685f;
  --line: #d8ddc9;
}

* {
  box-sizing: border-box;
}

button,
input,
select,
textarea,
label,
a {
  font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: inherit;
  font-weight: inherit;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Tajawal", "Segoe UI", Tahoma, Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(0, 105, 62, 0.08), transparent 28%),
    linear-gradient(180deg, #f4f2e8 0%, var(--page-bg) 100%);
  color: var(--text-main);
}

/* Identité visuelle alignée sur la page d'accueil */
body { background: #f2f1e9; }
.page-shell { background: var(--page-bg); }
.hero { border: 1px solid var(--line); background: var(--panel-bg); color: var(--brand-dark); border-radius: 20px; }
.hero::before { background: #e8aa35; }
.hero h1 { color: var(--brand-dark); }
.hero-logo { background: #fff; border-color: var(--line); }
.quiz-panel { background: var(--panel-bg); border-color: var(--line); box-shadow: var(--panel-shadow); }
.primary-button { background: var(--brand); border-color: var(--brand); box-shadow: 0 10px 22px rgba(12, 95, 56, 0.18); }
.secondary-button { background: #fffefa; border-color: var(--line); }
.option-card { border-color: var(--line); border-radius: 20px; }
.option-card.selected { border-color: #c9962f; background: #fff6d8; box-shadow: 0 0 0 4px rgba(201, 150, 47, 0.18); }
.option-card.correct { border-color: var(--brand); background: #dff0e3; }
.option-card.incorrect { border-color: #bd3847; background: #f8dfe3; }
.result-panel.result-green { background: #e6f1e5; border-color: #a8cba8; }
.result-panel.result-yellow { background: #fff6d8; border-color: #e5cc70; }
.result-panel.result-red { background: #f8e1e4; border-color: #dfa4ac; }
.bottom-nav { padding-inline: 0.6rem; }
.bottom-nav-inner { border: 1px solid rgba(28, 58, 40, 0.08); border-radius: 28px 28px 18px 18px; background: rgba(255, 255, 255, 0.97); box-shadow: 0 -6px 20px rgba(35, 53, 38, 0.12); }
.bottom-nav-link { position: relative; color: #414740; }
.bottom-nav-link.active { background: transparent; color: var(--brand); }
.bottom-nav-link.active::before { content: ""; position: absolute; top: -0.45rem; width: 26px; height: 4px; border-radius: 4px; background: var(--brand); }
.bottom-nav-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.page-shell {
  width: 100%;
  max-width: 460px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 0.8rem 0.9rem 5.6rem;
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(0, 105, 62, 0.04);
}

.hero,
.quiz-panel {
  animation: fade-up 360ms ease both;
}

#quiz-setup {
  padding: 1.25rem;
}

.hero {
  position: relative;
  display: grid;
  gap: 0.3rem;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(0, 105, 62, 0.97), rgba(14, 128, 81, 0.93));
  color: #f7fbfc;
  border-radius: 18px;
  padding: 0.72rem 3.5rem 0.72rem 0.85rem;
  box-shadow: var(--panel-shadow);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: #ce1126;
}

.hero-copy {
  position: relative;
  z-index: 1;
}

.hero-logo {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  z-index: 1;
  width: 38px;
  height: 38px;
  transform: translateY(-50%);
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 18px rgba(20, 47, 35, 0.14);
}

.hero h1 {
  margin: 0;
  font-family: "Amiri", serif;
  font-size: clamp(1.32rem, 4.4vw, 1.75rem);
  line-height: 1.02;
}

.quiz-panel {
  margin-top: 0.65rem;
  padding: 0.9rem;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel-bg);
  box-shadow: var(--panel-shadow);
}

.quiz-heading {
  display: grid;
  gap: 0.35rem;
}

.quiz-panel[hidden] {
  display: none;
}

.quiz-setup-form {
  display: grid;
  gap: 1.05rem;
  margin-top: 1.2rem;
}

.quiz-field {
  display: grid;
  gap: 0.35rem;
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 700;
}

.quiz-field select,
.quiz-field input {
  width: 100%;
  min-height: 56px;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  color: var(--text-main);
}

#quiz-setup .primary-button {
  min-height: 56px;
  margin-top: 0.15rem;
}

.setup-message {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 14px;
  background: #fff5d8;
  color: #765500;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.55;
}

.setup-message:empty,
.setup-message[hidden] {
  display: none;
}

#session-limit-message {
  margin-bottom: 0.8rem;
}

.quiz-label {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.small-section-icon,
.field-icon {
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  margin-inline-end: 0.35rem;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.72rem;
  line-height: 1;
  vertical-align: middle;
}

.field-icon {
  width: 1.2rem;
  height: 1.2rem;
  font-size: 0.68rem;
}

.question-counter {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  min-height: 34px;
  width: fit-content;
  margin: 0;
  padding: 0.35rem 0.75rem;
  border: 1px solid rgba(0, 105, 62, 0.14);
  border-radius: 999px;
  background: #eef7f1;
  color: var(--brand-dark);
  font-weight: 800;
  font-size: 0.84rem;
  box-shadow: 0 8px 18px rgba(20, 47, 35, 0.06);
}

.question-title {
  margin: 0;
  color: var(--brand-dark);
  font-size: 1.18rem;
  line-height: 1.45;
}

.question-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.question-row .question-title {
  flex: 1 1 auto;
}

.quiz-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin-top: 0.85rem;
}

.option-card {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 0.7rem;
  border: 2px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, background-color 160ms ease;
}

.option-card:hover {
  transform: translateY(-1px);
}

.option-card.selected {
  border-width: 3px;
  border-color: #4b6f98;
  background: #e8f0fb;
  box-shadow: 0 0 0 4px rgba(75, 111, 152, 0.24);
}

.option-card.correct {
  border-width: 3px;
  border-color: #167c3d;
  background: #9fe0b3;
  box-shadow: 0 0 0 4px rgba(22, 124, 61, 0.26);
}

.option-card.incorrect {
  border-width: 3px;
  border-color: #be2d43;
  background: #f4a1ae;
  box-shadow: 0 0 0 4px rgba(190, 45, 67, 0.24);
}

.option-card.selected::after,
.option-card.correct::after,
.option-card.incorrect::after {
  position: absolute;
  top: 0.45rem;
  left: 0.45rem;
  display: grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1;
}

.option-card.selected::after {
  content: "✓";
  background: #4b6f98;
  color: #ffffff;
}

.option-card.correct::after {
  content: "✓";
  background: #0f6d34;
  color: #ffffff;
}

.option-card.incorrect::after {
  content: "✕";
  background: #9f1730;
  color: #ffffff;
}

.option-image {
  display: block;
  max-width: 100%;
  max-height: 118px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.option-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 118px;
  padding: 0.8rem;
  text-align: center;
  border-radius: 14px;
  background: var(--placeholder-bg);
  color: var(--placeholder-text);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.4;
}

.feedback-root:empty {
  display: none;
}

.feedback-root {
  margin-top: 0;
  flex: 0 0 auto;
}

.feedback-card {
  padding: 0.75rem 0.85rem;
  border-radius: 16px;
  font-size: 0.9rem;
  font-weight: 700;
}

.countdown-ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: conic-gradient(var(--brand) var(--countdown-progress, 360deg), rgba(0, 105, 62, 0.14) 0deg);
  color: var(--brand-dark);
  cursor: pointer;
}

.countdown-ring::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(0, 105, 62, 0.08);
}

.countdown-ring-value {
  position: relative;
  z-index: 1;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1;
}

.countdown-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 32px;
  padding: 0.3rem 0.55rem;
  border: 1px dashed rgba(0, 105, 62, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-soft);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

.feedback-card.correct {
  background: var(--success-bg);
  color: var(--success-text);
}

.feedback-card.incorrect {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.quiz-actions {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 44px;
  padding: 0.72rem 0.9rem;
  border-radius: 14px;
  border: 1px solid transparent;
  cursor: pointer;
}

.primary-button {
  background: var(--brand);
  color: #f7fbfc;
  font-weight: 800;
  box-shadow: 0 14px 28px rgba(0, 105, 62, 0.18);
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.secondary-button {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--line);
  font-weight: 800;
}

.result-panel {
  text-align: center;
  border-width: 2px;
}

.result-panel.result-green { background: #e5f4e9; border-color: #9bd4aa; }
.result-panel.result-yellow { background: #fff6d8; border-color: #e5cc70; }
.result-panel.result-red { background: #fbe7ea; border-color: #e4a3ad; }

.result-status {
  margin: 0.35rem 0 0;
  color: var(--brand-dark);
  font-size: 1.18rem;
  line-height: 1.5;
}

.result-score {
  margin: 0.55rem 0 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.result-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.result-summary-grid div {
  display: grid;
  gap: 0.2rem;
  padding: 0.65rem;
  border: 1px solid rgba(0, 105, 62, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
}

.result-summary-grid span { color: var(--text-soft); font-size: 0.76rem; font-weight: 700; }
.result-summary-grid strong { color: var(--brand-dark); font-size: 1rem; }
.result-actions { display: grid; gap: 0.55rem; margin-top: 0.85rem; }

.review-header { display: grid; gap: 0.75rem; }
.review-toggle { display: flex; align-items: center; gap: 0.45rem; width: fit-content; color: var(--text-soft); font-size: 0.8rem; font-weight: 700; }
.review-toggle input { width: 1.1rem; height: 1.1rem; accent-color: var(--brand); }
.review-list { display: grid; gap: 0.7rem; margin: 0.85rem 0; }
.review-card { padding: 0.75rem; border: 1px solid var(--line); border-inline-start-width: 4px; border-radius: 16px; background: #fff; text-align: right; }
.review-card.correct { border-inline-start-color: #258b4a; }
.review-card.incorrect { border-inline-start-color: #c23d51; }
.review-card-heading { display: flex; justify-content: space-between; gap: 0.5rem; color: var(--brand-dark); font-size: 0.8rem; }
.review-card.incorrect .review-card-heading span { color: #a32136; }
.review-card.correct .review-card-heading span { color: #147038; }
.review-question { margin: 0.55rem 0 0; font-weight: 800; line-height: 1.5; }
.review-image-shell { display: grid; place-items: center; min-height: 150px; margin-top: 0.6rem; padding: 0.65rem; border-radius: 14px; background: var(--surface); }
.review-image-shell img { display: block; max-width: 100%; max-height: 130px; object-fit: contain; }
.review-details { display: grid; gap: 0.45rem; margin: 0.65rem 0 0; }
.review-details div { display: grid; gap: 0.1rem; padding-top: 0.45rem; border-top: 1px solid var(--line); }
.review-details dt { color: var(--text-soft); font-size: 0.72rem; font-weight: 700; }
.review-details dd { margin: 0; font-size: 0.82rem; font-weight: 700; line-height: 1.5; }
.review-empty { margin: 0; padding: 0.8rem; border-radius: 14px; background: #e5f4e9; color: #147038; text-align: center; font-weight: 700; }

.result-effect-neutral { animation: result-neutral 650ms ease both; }
.result-effect-failure { animation: result-failure 520ms ease both; }

@keyframes result-neutral {
  0% { opacity: 0.72; transform: translateY(5px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes result-failure {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(3px); }
  70% { transform: translateX(-3px); }
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(460px, 100vw);
  padding: 0 0.9rem calc(0.65rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
}

.bottom-nav-inner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.45rem;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 -10px 24px rgba(20, 47, 35, 0.08);
}

.bottom-nav-link {
  display: grid;
  justify-items: center;
  gap: 0.12rem;
  min-height: 44px;
  padding: 0.35rem 0.2rem;
  border-radius: 14px;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 0.72rem;
  font-weight: 700;
}

.bottom-nav-link.active {
  background: #eaf4ed;
  color: var(--brand);
}

.bottom-nav-icon {
  font-size: 1rem;
  line-height: 1;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 760px) {
  body {
    padding-inline: 1rem;
  }

  .page-shell {
    border-radius: 28px;
    margin-block: 1rem;
    min-height: calc(100vh - 2rem);
    padding: 0.95rem 1rem 5.6rem;
  }
}

@media (max-width: 420px) {
  .page-shell,
  .bottom-nav {
    padding-inline: 0.85rem;
  }

  .quiz-grid {
    gap: 0.55rem;
  }

  .option-card {
    min-height: 138px;
    padding: 0.6rem;
  }

  .option-image,
  .option-placeholder {
    max-height: 108px;
    min-height: 108px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .result-effect-neutral,
  .result-effect-failure {
    animation: none;
  }
}

/* Couche finale d'harmonisation */
.page-shell { background: var(--page-bg); }
.hero { border: 1px solid var(--line); background: var(--panel-bg); color: var(--brand-dark); border-radius: 20px; box-shadow: var(--panel-shadow); }
.hero::before { background: #e8aa35; }
.hero h1 { color: var(--brand-dark); }
.quiz-panel { background: var(--panel-bg); border-color: var(--line); box-shadow: var(--panel-shadow); }
.quiz-field select, .quiz-field input { background: #fffefa; border-color: var(--line); }
.bottom-nav-inner { border: 1px solid rgba(28, 58, 40, 0.08); border-radius: 28px 28px 18px 18px; background: rgba(255, 255, 255, 0.97); box-shadow: 0 -6px 20px rgba(35, 53, 38, 0.12); }
.bottom-nav-link.active { background: transparent; color: var(--brand); }
