:root {
  color-scheme: light;
  --page-bg: #e8e6da;
  --surface: #f7f6f0;
  --panel-bg: rgba(255, 255, 255, 0.94);
  --panel-border: rgba(0, 105, 62, 0.14);
  --panel-shadow: 0 20px 48px rgba(20, 47, 35, 0.08);
  --text-main: #1c1c1a;
  --text-soft: #5c5b54;
  --brand: #00693e;
  --brand-dark: #005533;
  --brand-soft: #dcecdf;
  --accent-soft: #f0eee4;
  --danger-soft: #f8d9dd;
  --danger-text: #8f3540;
  --placeholder-bg: #e5e3d7;
  --placeholder-text: #6a685f;
  --line: #d9d6c9;
}

* {
  box-sizing: border-box;
}

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);
}

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

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

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

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

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

.hero::after {
  content: "";
  position: absolute;
  width: 170px;
  height: 170px;
  inset: auto -70px -100px auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.hero-copy {
  display: grid;
  gap: 0;
  position: relative;
  z-index: 1;
}

.hero-logo {
  position: absolute;
  left: 0.82rem;
  top: 50%;
  z-index: 1;
  width: 40px;
  height: 40px;
  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;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  position: relative;
  z-index: 1;
}

.ghost-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 34px;
  padding: 0.45rem 0.72rem;
  border-radius: 12px;
  border: 1px solid rgba(247, 251, 252, 0.28);
  color: #f7fbfc;
  background: rgba(255, 255, 255, 0.1);
  text-decoration: none;
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease;
  font-size: 0.8rem;
}

.ghost-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.16);
}

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

.stats-toggle-row {
  margin-top: 0.8rem;
}

.stats-toggle {
  min-height: 38px;
  padding: 0.62rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--brand);
  font-size: 0.88rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--panel-shadow);
}

.stats-section {
  margin-top: 0.85rem;
}

.stats-header {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 0.5rem;
}

.stats-header h2,
.stats-copy {
  margin: 0;
}

.stats-copy {
  font-size: 0.84rem;
  color: var(--text-soft);
}

.stat-card,
.flashcard-panel,
.answer-card {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--panel-shadow);
}

.stat-card {
  border-radius: 18px;
  padding: 0.8rem;
}

.stat-label {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.8rem;
}

.stat-value {
  margin: 0.2rem 0 0;
  font-weight: 800;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
}

.flashcard-panel {
  margin-top: 0.8rem;
  border-radius: 20px;
  padding: 0.8rem;
}

.flashcard-prompt {
  margin: 0 0 0.55rem;
  color: var(--brand-dark);
  font-size: 0.96rem;
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
}

.flashcard-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 225px;
  padding: 1rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, #f7f6f0, #ffffff);
  overflow: hidden;
}

.flashcard-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 80%;
  max-height: 80%;
  object-fit: contain;
  object-position: center;
  flex: 0 0 auto;
}

.flashcard-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0.8rem;
  text-align: center;
  line-height: 1.55;
  color: var(--placeholder-text);
  background: var(--placeholder-bg);
  font-weight: 700;
  font-size: 0.84rem;
}

.flashcard-body {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.card-step {
  display: none;
}

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

.answer-card {
  border-radius: 18px;
  padding: 0.8rem;
}

.answer-title {
  margin: 0;
  text-align: center;
  font-size: clamp(1.12rem, 4.5vw, 1.45rem);
  line-height: 1.5;
}

.answer-details {
  margin-top: 0.65rem;
  color: var(--text-soft);
  border-top: 1px solid rgba(217, 214, 201, 0.7);
  border-bottom: 1px solid rgba(217, 214, 201, 0.7);
  font-size: 0.84rem;
}

.extra-details {
  margin-top: 0.5rem;
}

.answer-details p {
  margin: 0;
  padding: 0.5rem 0;
  line-height: 1.55;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.answer-details p + p {
  border-top: 1px solid rgba(217, 214, 201, 0.55);
}

.answer-details strong {
  color: var(--text-main);
}

.details-toggle {
  width: 38px;
  min-height: 38px;
  margin-top: 0.65rem;
  margin-right: auto;
  margin-left: 0;
  padding: 0.15rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--brand);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.details-toggle::before {
  content: "⌄";
  line-height: 1;
}

.details-toggle[aria-expanded="true"]::before {
  content: "⌃";
}

.progress-badge {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 30px;
  padding: 0 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--brand);
  border: 1px solid rgba(0, 105, 62, 0.12);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(20, 47, 35, 0.08);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.action-row:empty {
  display: none;
}

.primary-button,
.secondary-button,
.known-button,
.unknown-button {
  flex: 1 1 180px;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  padding: 0.72rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 800;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.known-button:hover,
.unknown-button:hover {
  transform: translateY(-1px);
}

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

.secondary-button {
  background: var(--accent-soft);
  color: var(--text-main);
  border-color: var(--line);
}

.known-button {
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-color: rgba(0, 105, 62, 0.12);
}

.unknown-button {
  background: var(--danger-soft);
  color: var(--danger-text);
  border-color: rgba(143, 53, 64, 0.12);
}

.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);
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-root[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 28, 26, 0.42);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  padding: 1rem;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--panel-shadow);
}

.modal-title,
.modal-message {
  margin: 0;
}

.modal-title {
  color: var(--brand-dark);
  font-size: 1rem;
}

.modal-message {
  margin-top: 0.45rem;
  color: var(--text-soft);
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 0.55rem;
  margin-top: 0.9rem;
}

.modal-actions .primary-button,
.modal-actions .secondary-button {
  flex: 1 1 0;
}

.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;
    box-shadow:
      0 24px 60px rgba(20, 47, 35, 0.12),
      0 0 0 1px rgba(0, 105, 62, 0.06);
  }

  .hero {
    grid-template-columns: 1fr;
    align-items: center;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .flashcard-panel {
    padding: 0.95rem;
  }

  .flashcard-stage {
    height: 255px;
    padding: 1.1rem;
  }
}

@media (max-width: 759px) {
  .page-shell {
    max-width: none;
    padding-inline: 0.9rem;
  }

  .hero,
  .flashcard-panel,
  .answer-card,
  .stat-card {
    border-radius: 18px;
  }

  .ghost-link,
  .ghost-button,
  .stats-toggle {
    width: 100%;
  }
}

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

  .bottom-nav {
    padding-inline: 0.85rem;
  }
}

/* Identité visuelle alignée sur la page d'accueil */
:root {
  --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-dark: #073d27;
  --brand-soft: #e9efe2;
  --line: #d8ddc9;
}
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; box-shadow: var(--panel-shadow); }
.hero::before { background: #e8aa35; }
.hero::after { background: rgba(12, 95, 56, 0.05); }
.hero h1 { color: var(--brand-dark); }
.hero-action { background: #fffefa; color: var(--brand); border-color: var(--line); }
.flashcard-panel, .stats-toggle, .stats-grid { background: var(--panel-bg); border-color: var(--line); box-shadow: var(--panel-shadow); }
.flashcard-stage { background: #fffefa; border-color: var(--line); border-radius: 20px; }
.primary-button { background: var(--brand); box-shadow: 0 10px 22px rgba(12, 95, 56, 0.18); }
.secondary-button { background: #fffefa; border-color: var(--line); color: var(--brand); }
.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; }
