:root {
  --bg: #0f1021;
  --indigo: #6366f1;
  --violet: #8b5cf6;
  --teal: #2dd4bf;
  --pink: #f472b6;
  --amber: #f59e0b;
  --text: #eef0ff;
  --text-dim: #a6aac9;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --radius: 20px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 800px at 15% -10%, #1e1b4b 0%, transparent 55%),
    radial-gradient(1000px 700px at 110% 15%, #134e4a 0%, transparent 50%),
    linear-gradient(160deg, #0f1021 0%, #14152c 50%, #0d0f1f 100%);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- Orbes décoratifs ---------- */
.bg-orbs { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.45; }
.orb-1 { width: 420px; height: 420px; background: var(--indigo); top: -120px; left: -100px; animation: drift 18s ease-in-out infinite; }
.orb-2 { width: 380px; height: 380px; background: var(--teal); bottom: -140px; right: -80px; animation: drift 22s ease-in-out infinite reverse; }
.orb-3 { width: 260px; height: 260px; background: var(--violet); top: 40%; left: 60%; animation: drift 26s ease-in-out infinite; }
@keyframes drift { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(40px,-30px) scale(1.12); } }

.glass {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.screen { position: relative; z-index: 1; min-height: 100dvh; }
.screen-center { display: flex; align-items: center; justify-content: center; padding: 24px; }
[hidden] { display: none !important; }

/* ---------- Écran de connexion ---------- */
.login-card {
  width: 100%; max-width: 400px;
  border-radius: 28px;
  padding: 40px 32px 32px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.04) inset;
  animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }

.login-badge {
  width: 64px; height: 64px; margin: 0 auto 18px;
  display: grid; place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--indigo), var(--violet));
  color: #fff;
  box-shadow: 0 12px 30px rgba(99,102,241,0.45);
}
.login-badge svg { width: 32px; height: 32px; }

.login-title { font-family: var(--font-display); font-size: 34px; font-weight: 700; letter-spacing: -0.5px; }
.login-title span {
  background: linear-gradient(90deg, var(--teal), var(--indigo));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.login-sub { color: var(--text-dim); font-size: 14px; margin-top: 6px; line-height: 1.5; }

.login-form { margin-top: 28px; display: flex; flex-direction: column; gap: 16px; }
.field { display: block; text-align: left; }
.field-label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); margin-bottom: 7px; }
.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.25);
}
.field input::placeholder { color: #5a5e80; }

.btn {
  font-family: var(--font);
  font-size: 16px; font-weight: 600;
  border: none; border-radius: 14px;
  padding: 14px 22px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, var(--indigo), var(--violet));
  color: #fff;
  box-shadow: 0 10px 26px rgba(99,102,241,0.4);
}
.btn-primary:hover { box-shadow: 0 14px 34px rgba(99,102,241,0.55); transform: translateY(-1px); }

.login-error { color: #fca5a5; font-size: 13px; min-height: 18px; margin-top: 12px; }
.login-links { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.doc-link, .login-links a {
  color: #b8bcf5;
  font-size: 13.5px;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.18);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.doc-link:hover, .login-links a:hover {
  border-color: var(--indigo);
  background: rgba(99,102,241,0.12);
  color: #fff;
}
.login-hint { color: var(--text-dim); font-size: 12px; margin-top: 14px; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: 14px 20px;
  border-radius: 0;
  border-left: none; border-right: none; border-top: none;
  display: flex; align-items: center; gap: 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.topbar-profile { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px; color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--violet));
}
.topbar-id { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-name { font-weight: 600; font-size: 15px; }
.link-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 12px; cursor: pointer; text-align: left; padding: 0;
  text-decoration: underline; text-underline-offset: 2px;
}
.link-btn:hover { color: var(--text); }

.topbar-progress { flex: 1; min-width: 120px; }
.progress-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
#progress-label { font-weight: 700; color: var(--text); font-family: var(--font-display); }
.progress-track {
  height: 10px; border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--indigo), var(--violet));
  border-radius: 999px;
  position: relative;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.progress-fill::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.45), transparent);
  animation: shimmer 2.4s linear infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- Zone d'étude ---------- */
.study-area {
  max-width: 640px; margin: 0 auto;
  padding: 28px 20px 60px;
  display: flex; flex-direction: column; gap: 20px;
}
.deck-status {
  text-align: center;
  font-size: 13px; color: var(--text-dim);
}
.deck-status b { color: var(--text); }

.card-wrap { perspective: 1400px; }
.flashcard {
  width: 100%; min-height: 320px;
  cursor: pointer;
}
.flashcard-inner {
  position: relative; width: 100%; min-height: 320px;
  transition: transform 0.6s cubic-bezier(0.4, 0.1, 0.2, 1);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  padding: 26px 26px 22px;
  display: flex; flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}
.flashcard-front { }
.flashcard-back {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, rgba(99,102,241,0.16), rgba(45,212,191,0.10)), var(--card-bg);
  border-color: rgba(99,102,241,0.35);
}

.card-tag {
  align-self: flex-start;
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 5px 12px; border-radius: 999px;
  background: rgba(99,102,241,0.18); color: #c7cbff;
}
.card-tag-back { background: rgba(45,212,191,0.16); color: #8ef0dd; }

.card-question, .card-answer {
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  font-size: 20px; font-weight: 500; line-height: 1.55;
  padding: 10px 0;
}
.card-answer { font-size: 17px; font-weight: 400; }
.card-question .MathJax, .card-answer .MathJax { font-size: 1.02em; }

.card-hint {
  text-align: center; font-size: 12px; color: var(--text-dim);
  margin-top: 8px;
}
kbd {
  font-family: var(--font); font-size: 11px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 5px; padding: 1px 6px; color: var(--text-dim);
}

.actions { display: flex; gap: 14px; }
.btn-fail, .btn-pass { flex: 1; padding: 16px; font-size: 16px; color: #fff; }
.btn-fail { background: rgba(244,63,94,0.16); border: 1px solid rgba(244,63,94,0.4); }
.btn-fail:hover { background: rgba(244,63,94,0.28); }
.btn-pass { background: linear-gradient(135deg, #10b981, #14b8a6); box-shadow: 0 10px 26px rgba(16,185,129,0.35); }
.btn-pass:hover { box-shadow: 0 14px 34px rgba(16,185,129,0.5); transform: translateY(-1px); }

.keyboard-hint { text-align: center; color: var(--text-dim); font-size: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 50;
  transform: translateX(-50%);
  padding: 12px 20px; border-radius: 12px;
  background: rgba(0,0,0,0.85); color: var(--text);
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  animation: toast-in 0.3s cubic-bezier(0.22,1,0.36,1);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; padding: 12px 14px; }
  .topbar-profile { justify-content: space-between; }
  .flashcard, .flashcard-inner { min-height: 300px; }
  .card-question { font-size: 18px; }
  .card-answer { font-size: 15.5px; }
  .login-card { padding: 32px 22px 26px; }
}
@media (max-width: 360px) {
  .flashcard, .flashcard-inner { min-height: 280px; }
  .card-question { font-size: 16px; }
}
