/* ==========================================================================
   Memories — design system (thème clair/sombre)
   ========================================================================== */

:root,
[data-theme="dark"] {
  --bg: #0b0b12;
  --surface: #15151f;
  --surface-alt: #1d1d2a;
  --border: #2a2a3a;
  --text: #f3f2fa;
  --text-muted: #9694ac;

  --primary: #5b5fef;
  --primary-dark: #4347c4;
  --primary-soft: rgba(91, 95, 239, .16);
  --accent: #f5a623;
  --accent-soft: rgba(245, 166, 35, .16);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, .16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, .16);

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-md: 0 10px 30px -10px rgba(0, 0, 0, .55);
  --shadow-glow: 0 0 26px -6px rgba(91, 95, 239, .5);
}

[data-theme="light"] {
  --bg: #f6f6fc;
  --surface: #ffffff;
  --surface-alt: #f1f0f9;
  --border: #e4e2f0;
  --text: #17161f;
  --text-muted: #6b6980;
  --shadow-md: 0 10px 30px -12px rgba(23, 22, 31, .18);
  --shadow-glow: 0 0 26px -8px rgba(91, 95, 239, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  transition: background .2s, color .2s;
}

h1, h2, h3, h4 { font-family: "ClashDisplay-SemiBold", sans-serif; margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: var(--primary-soft); color: var(--text); }

/* ---------- Layout ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 110px 24px 60px; }
.center { display: flex; align-items: center; justify-content: center; }

/* ---------- Navbar (pilule flottante) ---------- */
.navbar {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 200;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  width: min(880px, calc(100% - 32px));
  padding: 10px 12px 10px 18px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
}

.nav-logo { display: flex; align-items: center; gap: 10px; font-family: "ClashDisplay-Medium", sans-serif; font-size: 1.1rem; letter-spacing: .3px; }
.nav-logo img { height: 28px; width: 28px; border-radius: 8px; }

.nav-links { display: flex; align-items: center; gap: 6px; }

.nav-link {
  padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: .92rem;
  color: var(--text-muted); transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-alt); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }

.nav-icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--surface-alt); color: var(--text-muted); cursor: pointer;
  transition: color .15s, background .15s;
}
.nav-icon-btn:hover { color: var(--text); }
.nav-icon-btn svg { width: 18px; height: 18px; }
.nav-icon-btn .icon-moon { display: none; }
[data-theme="light"] .nav-icon-btn .icon-sun { display: none; }
[data-theme="light"] .nav-icon-btn .icon-moon { display: block; }

.nav-profile { position: relative; }
.nav-profile-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--primary-dark);
  background: var(--primary); color: #fff; font-weight: 700; font-size: .95rem;
  cursor: pointer; transition: box-shadow .15s;
}
.nav-profile-btn:hover { box-shadow: var(--shadow-glow); }

.profile-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 10px);
  min-width: 190px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-md); padding: 8px; z-index: 50;
}
.profile-menu.open { display: block; }
.profile-menu-user {
  padding: 8px 10px; font-size: .8rem; font-weight: 600; color: var(--text-muted);
  border-bottom: 1px solid var(--border); margin-bottom: 6px; word-break: break-all;
}
.profile-menu-logout {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--danger); font-weight: 600; font-size: .88rem; transition: background .15s;
}
.profile-menu-logout:hover { background: var(--danger-soft); }
.profile-menu-logout svg { width: 16px; height: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px; border: none; cursor: pointer;
  font-weight: 600; font-size: .92rem; letter-spacing: .2px; transition: transform .12s, box-shadow .12s, opacity .12s;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 22px -8px rgba(91, 95, 239, .6); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow); }
.btn-ghost { background: var(--surface-alt); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-block { width: 100%; }
.btn-round {
  width: 34px; height: 34px; border-radius: 50%; padding: 0;
  background: var(--primary); color: #fff; font-size: 1.15rem; font-weight: 700;
  border: none; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.btn-round:hover { transform: scale(1.08); box-shadow: var(--shadow-glow); }
.btn-icon-danger {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--text-muted); cursor: pointer; transition: .15s;
}
.btn-icon-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-icon-danger svg { width: 17px; height: 17px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; text-align: left; }
.field label {
  display: block; font-size: .76rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px;
}
input[type="text"], input[type="password"], textarea {
  width: 100%; background: var(--surface-alt); border: 1.5px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px;
  font-size: .95rem; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input::placeholder { color: var(--text-muted); }

.alert {
  display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger); font-size: .86rem; font-weight: 600; margin-bottom: 16px;
}

/* ---------- Cartes d'authentification (login / inscription) ---------- */
.auth-shell { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 34px 30px; box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(24px); transition: opacity .5s ease, transform .5s ease;
}
.auth-card.show { opacity: 1; transform: translateY(0); }
.auth-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.auth-logo img { width: 56px; height: 56px; border-radius: 16px; }
.auth-title { text-align: center; font-size: 1.5rem; margin-bottom: 22px; letter-spacing: .3px; }
.auth-switch { text-align: center; font-size: .86rem; color: var(--text-muted); margin: 14px 0 6px; cursor: pointer; transition: color .15s; }
.auth-switch:hover { color: var(--primary); }

/* ---------- Panneau "ajouter" repliable ---------- */
.add-panel {
  display: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; margin: 16px 0; box-shadow: var(--shadow-md);
}
.add-panel.open { display: block; }
.add-panel form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.add-panel .field { flex: 1 1 200px; margin-bottom: 0; }
.add-panel .btn { flex-shrink: 0; }

/* ---------- En-tête de section ---------- */
.section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 6px;
}
.section-head h1 { font-size: 1.9rem; }
.section-sub { color: var(--text-muted); font-size: .92rem; margin: 6px 0 0; }
hr.divider { border: none; border-top: 2px solid var(--border); margin: 18px 0 26px; }

/* ---------- Grille de cartes (matières / sous-thèmes) ---------- */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.item-card {
  position: relative; background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px 20px 18px; cursor: pointer; transition: border-color .2s, box-shadow .2s, transform .2s;
}
.item-card:hover { border-color: var(--primary); box-shadow: var(--shadow-glow); transform: translateY(-2px); }
.item-card h2 { font-size: 1.08rem; color: var(--primary); margin-bottom: 6px; }
[data-theme="light"] .item-card h2 { color: var(--primary-dark); }
.item-card p { color: var(--text-muted); font-size: .86rem; margin: 0; }
.item-card .btn-icon-danger { position: absolute; top: 12px; right: 12px; }
.shared-badge {
  position: absolute; top: 12px; right: 12px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 9px; border-radius: 999px;
}

.empty-state { text-align: center; color: var(--text-muted); padding: 50px 20px; font-size: .92rem; }

/* ---------- Cartes flip (questions/réponses) ---------- */
.card-grid { display: flex; flex-wrap: wrap; gap: 20px; justify-content: flex-start; }
.flip-card { width: 280px; height: 190px; perspective: 1200px; cursor: pointer; }
.flip-inner { position: relative; width: 100%; height: 100%; transition: transform .6s; transform-style: preserve-3d; }
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: var(--radius-lg);
  border: 1.5px solid var(--border); background: var(--surface); padding: 18px;
  display: flex; flex-direction: column; justify-content: center; gap: 8px;
  transition: border-color .2s, box-shadow .2s; overflow: hidden;
}
.flip-card:hover .flip-face { border-color: var(--primary); box-shadow: var(--shadow-glow); }
.flip-face-back { transform: rotateY(180deg); }
.flip-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); }
.flip-face-back .flip-label { color: var(--success); }
.flip-text { font-size: .95rem; word-wrap: break-word; white-space: pre-wrap; }
.flip-face .btn-mastered { align-self: flex-start; margin-top: auto; }
.btn-mastered {
  background: var(--success-soft); color: var(--success); border: none; border-radius: 999px;
  padding: 7px 14px; font-size: .78rem; font-weight: 700; cursor: pointer; transition: background .15s;
}
.btn-mastered:hover { background: var(--success); color: #fff; }

/* ---------- Tableau de bord (accueil) ---------- */
.hero { text-align: center; padding: 20px 0 10px; }
.hero h1 { font-size: 2.1rem; margin-bottom: 10px; }
.hero p { color: var(--text-muted); font-size: 1rem; }
.hero .highlight { color: var(--accent); font-weight: 700; }

.streak-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent; border-radius: 999px;
  padding: 7px 16px; font-size: .85rem; font-weight: 700;
  margin-bottom: 16px; transition: background .3s, border-color .3s;
}
.streak-badge.secured { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.streak-badge #streak-hint { font-weight: 500; opacity: .85; }

.mastery-bar-wrap { max-width: 420px; margin: 26px auto 0; text-align: left; }
.mastery-bar-label {
  display: flex; justify-content: space-between; font-size: .8rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
}
.mastery-bar { height: 10px; border-radius: 999px; background: var(--surface-alt); border: 1px solid var(--border); overflow: hidden; }
.mastery-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .5s ease; }

.review-done { text-align: center; padding: 30px 20px; }
.review-done-emoji { font-size: 2.6rem; margin-bottom: 8px; }
.review-done-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }

.subject-slider { display: flex; align-items: center; gap: 14px; margin: 34px 0; }
.slider-arrow {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 1.1rem; cursor: pointer; transition: .15s;
}
.slider-arrow:hover { border-color: var(--primary); color: var(--primary); }
.slider-track { flex: 1; display: flex; gap: 16px; overflow: hidden; }
.subject-box {
  flex: 1 1 45%; min-width: 220px; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px; transition: border-color .2s, transform .2s;
}
.subject-box:hover { border-color: var(--primary); transform: translateY(-2px); }
.subject-box h2 { font-size: 1.05rem; color: var(--primary); margin-bottom: 4px; }
[data-theme="light"] .subject-box h2 { color: var(--primary-dark); }
.subject-box h3 { font-size: .85rem; font-weight: 500; color: var(--text-muted); }

.review-card { max-width: 480px; margin: 0 auto 40px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 26px; box-shadow: var(--shadow-md); }
.review-card h2 { font-size: 1.2rem; margin-bottom: 4px; }
.review-card hr.divider { margin: 12px 0 18px; }
.review-answer-hint { color: var(--accent); font-weight: 700; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.review-actions { display: flex; gap: 10px; margin-top: 18px; }
.review-actions .btn { flex: 1; }

.stats-section { text-align: center; margin-top: 50px; }
.stats-section h2 { font-size: 1.5rem; }
.stats-section p { color: var(--text-muted); margin-top: 6px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-top: 26px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px 16px; }
.stat-box h2 { font-size: 2rem; color: var(--primary); }
[data-theme="light"] .stat-box h2 { color: var(--primary-dark); }
.stat-box h3 { font-size: .82rem; font-weight: 500; color: var(--text-muted); margin-top: 6px; }

/* ---------- Graphiques ---------- */
.chart-section { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 50px; }
.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px 22px 10px;
}
.chart-card h3 { font-size: 1.05rem; margin-bottom: 4px; }
.chart-card svg { width: 100%; height: auto; margin-top: 8px; }
@media (max-width: 900px) {
  .chart-section { grid-template-columns: 1fr; }
}

/* ---------- Badge de progression (répétition espacée) ---------- */
.srs-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em;
  background: var(--primary-soft); color: var(--primary);
}
[data-theme="light"] .srs-badge { color: var(--primary-dark); }

/* ---------- Révélation au scroll ---------- */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .6s ease, transform .6s ease; }
.reveal.revealed { opacity: 1; transform: translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .navbar { padding: 8px 8px 8px 14px; gap: 10px; }
  .nav-logo span { display: none; }
  .nav-link { padding: 8px 12px; font-size: .85rem; }
  .page { padding: 100px 16px 50px; }
  .subject-slider { flex-direction: column; }
  .slider-track { flex-direction: column; width: 100%; }
  .subject-box { flex: 1 1 auto; }
}
