@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700;800&display=swap');

/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:        #0d0d1a;
  --surface:   #16162a;
  --surface2:  #1e1e38;
  --border:    #2a2a4a;
  --accent:    #7c3aed;
  --accent-h:  #6d28d9;
  --accent-l:  #a78bfa;
  --gold:      #f59e0b;
  --silver:    #94a3b8;
  --bronze:    #cd7f32;
  --text:      #f1f5f9;
  --text-m:    #94a3b8;
  --text-s:    #64748b;
  --again:     #ef4444;
  --hard:      #f97316;
  --good:      #22c55e;
  --easy:      #3b82f6;
  --card-bg:   #ffffff;
  --card-text: #1e293b;
  --radius:    14px;
  --shadow:    0 20px 60px rgba(0,0,0,0.5);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Poppins', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent-l); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 2rem;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-logo {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--accent-l);
  letter-spacing: -0.5px;
  flex-shrink: 0;
}
.nav-links { display: flex; gap: 0.25rem; flex: 1; }
.nav-links a {
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-m);
  transition: background 0.15s, color 0.15s;
}
.nav-links a:hover, .nav-links a.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}
.nav-user { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; font-size: 0.9rem; color: var(--text-m); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; border: none;
  padding: 0.65rem 1.5rem; border-radius: 10px; font-size: 1rem;
  font-family: inherit; font-weight: 600; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  padding: 0.65rem 1.5rem; border-radius: 10px; font-size: 1rem;
  font-family: inherit; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); text-decoration: none; }

.btn-ghost {
  background: none; border: 1px solid var(--border); color: var(--text-m);
  padding: 0.35rem 0.85rem; border-radius: 8px; font-size: 0.85rem;
  font-family: inherit; font-weight: 600; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

.btn-link {
  background: none; border: none; color: var(--accent-l);
  font-family: inherit; font-size: inherit; cursor: pointer; font-weight: 600;
  padding: 0;
}
.btn-link:hover { text-decoration: underline; }

.btn-full { width: 100%; }

/* ── Loading / Spinner ─────────────────────────────────────────────────────── */
.loading-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; height: calc(100vh - 60px); color: var(--text-m);
}
.spinner {
  width: 44px; height: 44px; border: 4px solid var(--border);
  border-top-color: var(--accent-l); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Auth page ─────────────────────────────────────────────────────────────── */
.auth-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, #1e1040 0%, var(--bg) 60%);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2.5rem;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo .logo-icon { font-size: 3rem; line-height: 1; margin-bottom: 0.5rem; }
.auth-logo h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 0.25rem; }
.auth-logo p { color: var(--text-m); font-size: 0.9rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-m); margin-bottom: 0.4rem; }
.form-group input {
  width: 100%; padding: 0.7rem 1rem;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-family: inherit; font-size: 1rem;
  transition: border-color 0.15s;
  outline: none;
}
.form-group input:focus { border-color: var(--accent-l); }

.error-msg {
  background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.4);
  color: #fca5a5; padding: 0.6rem 1rem; border-radius: 8px;
  font-size: 0.85rem; margin-bottom: 1rem;
}
.auth-toggle {
  text-align: center; margin-top: 1.25rem; font-size: 0.9rem; color: var(--text-m);
}

/* ── Progress bar ──────────────────────────────────────────────────────────── */
.progress-bar {
  height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-l));
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ── Study page ────────────────────────────────────────────────────────────── */
.study-main {
  max-width: 720px; margin: 0 auto; padding: 2rem 1rem 4rem;
}

.session-header { margin-bottom: 1.5rem; }
.session-stats {
  display: flex; gap: 1.25rem; margin-top: 0.5rem;
  font-size: 0.85rem; color: var(--text-m); flex-wrap: wrap;
}
.session-stat { display: flex; align-items: center; gap: 0.3rem; }
.session-stat span:first-child { font-size: 1em; }
.session-stat strong { color: var(--text); font-weight: 700; }
.queue-label { margin-left: auto; font-weight: 600; color: var(--text-m); }

/* ── Flashcard ─────────────────────────────────────────────────────────────── */
.card-area { transition: opacity 0.2s, transform 0.2s; }
.card-area.leaving { opacity: 0; transform: translateX(-30px); }
.card-area.entering { opacity: 0; transform: translateX(30px); transition: none; }

.card-metadata {
  display: flex; align-items: center; gap: 0.75rem;
  margin-bottom: 0.75rem; min-height: 1.5rem;
}
.card-source { font-size: 0.8rem; color: var(--text-s); }
.card-new-badge {
  background: var(--accent); color: #fff;
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem; border-radius: 99px;
}

.card-container {
  perspective: 1200px;
  height: 380px;
  margin-bottom: 1.5rem;
}
.card {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}
.card.flipped { transform: rotateY(180deg); }

.card-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.5rem 2.5rem;
  box-shadow: var(--shadow);
}
.card-back-question {
  font-size: 0.82rem;
  color: #6b7280;
  line-height: 1.5;
  text-align: center;
  width: 100%;
}
.card-back-question p { margin: 0; }
.card-back-divider {
  width: 40%; height: 1px;
  background: #d1d5db;
  margin: 0.85rem 0;
  flex-shrink: 0;
}
.card-front {
  background: var(--card-bg);
  color: var(--card-text);
}
.card-back {
  background: #f0f4ff;
  color: var(--card-text);
  transform: rotateY(180deg);
}
.card-inner-content {
  font-size: 1.1rem;
  line-height: 1.7;
  text-align: center;
  max-height: 100%;
  overflow-y: auto;
}
/* Highlight the underlined answer portion */
.card-back .card-inner-content [style*="text-decoration: underline"],
.card-back .card-inner-content [style*="text-decoration:underline"] {
  background: #fde68a;
  border-radius: 3px;
  padding: 0 3px;
}

/* ── Controls ──────────────────────────────────────────────────────────────── */
.card-controls { display: flex; flex-direction: column; align-items: center; gap: 1rem; }

.btn-show-answer {
  background: var(--surface2); color: var(--text);
  border: 2px solid var(--border); border-radius: 12px;
  padding: 0.8rem 2.5rem; font-size: 1rem; font-family: inherit;
  font-weight: 600; cursor: pointer; transition: background 0.15s, border-color 0.15s;
  display: flex; align-items: center; gap: 0.6rem;
}
.btn-show-answer:hover { background: var(--border); border-color: var(--accent-l); }
.btn-show-answer kbd {
  font-size: 0.7rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.1rem 0.4rem; color: var(--text-m);
}

.rate-buttons {
  display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center;
}
.btn-rate {
  display: flex; flex-direction: column; align-items: center;
  min-width: 90px; padding: 0.65rem 1rem;
  border: none; border-radius: 12px; cursor: pointer;
  font-family: inherit; transition: transform 0.1s, filter 0.15s;
}
.btn-rate:hover { filter: brightness(1.1); }
.btn-rate:active { transform: scale(0.95); }
.btn-rate:disabled { opacity: 0.5; cursor: not-allowed; }
.rate-label { font-size: 0.95rem; font-weight: 700; color: #fff; }
.rate-hint  { font-size: 0.72rem; color: rgba(255,255,255,0.75); margin-top: 2px; }

.btn-again { background: var(--again); }
.btn-hard  { background: var(--hard); }
.btn-good  { background: var(--good); }
.btn-easy  { background: var(--easy); }

.keyboard-hint {
  font-size: 0.78rem; color: var(--text-s);
}
.keyboard-hint kbd {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.1rem 0.4rem; font-size: 0.72rem;
}

/* ── Complete screen ───────────────────────────────────────────────────────── */
.complete-screen {
  display: flex; align-items: center; justify-content: center;
  padding: 4rem 1rem;
}
.complete-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 3rem 2.5rem; text-align: center;
  max-width: 440px; width: 100%;
  animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes pop-in {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.complete-icon { font-size: 4rem; line-height: 1; margin-bottom: 1rem; }
.complete-card h2 { font-size: 1.8rem; font-weight: 800; margin-bottom: 0.5rem; }
.complete-card p { color: var(--text-m); margin-bottom: 2rem; }
.complete-actions { display: flex; flex-direction: column; gap: 0.75rem; }

/* ── Leaderboard page ──────────────────────────────────────────────────────── */
.leaderboard-main {
  max-width: 900px; margin: 0 auto; padding: 2rem 1rem 4rem;
}

.my-stats-section, .leaderboard-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.75rem; margin-bottom: 1.5rem;
}
.my-stats-section h2, .leaderboard-section h2 {
  font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; color: var(--text-m);
  text-transform: uppercase; letter-spacing: 0.08em;
}

.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem; margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--surface2); border-radius: 12px; padding: 1rem;
  text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 0.3rem; }
.stat-label { font-size: 0.75rem; color: var(--text-m); font-weight: 600; }

.seen-progress { margin-top: 0.5rem; }
.seen-label {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; color: var(--text-m); margin-bottom: 0.4rem;
}
.seen-label strong { color: var(--text); }

.leaderboard-table {
  width: 100%; border-collapse: collapse; font-size: 0.95rem;
}
.leaderboard-table th {
  text-align: left; padding: 0.6rem 0.75rem;
  font-size: 0.75rem; font-weight: 700; color: var(--text-s);
  text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.leaderboard-table td {
  padding: 0.85rem 0.75rem; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.leaderboard-table tr:last-child td { border-bottom: none; }
.leaderboard-table tr.my-row td { background: rgba(124,58,237,0.08); }
.leaderboard-table tr:hover td { background: var(--surface2); }

.rank-cell { font-size: 1.2rem; width: 2.5rem; }
.name-cell { font-weight: 600; }
.num-cell  { text-align: right; color: var(--text-m); font-variant-numeric: tabular-nums; }
.today-cell { color: var(--accent-l); font-weight: 700; }
.streak-cell { color: var(--gold); }

.you-badge {
  display: inline-block; background: var(--accent);
  color: #fff; font-size: 0.65rem; font-weight: 700;
  padding: 0.1rem 0.45rem; border-radius: 99px; margin-left: 0.5rem;
  vertical-align: middle; letter-spacing: 0.03em;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .navbar { padding: 0 1rem; }
  .nav-links a { padding: 0.35rem 0.6rem; font-size: 0.85rem; }
  .card-face { padding: 1.25rem 1.5rem; }
  .card-container { height: 340px; }
  .card-inner-content { font-size: 0.95rem; }
  .rate-buttons { gap: 0.5rem; }
  .btn-rate { min-width: 72px; padding: 0.55rem 0.7rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
