/* ========================================================
   RijExamen Pro — Global Design System
   Dark-first, mobile-optimized
   ======================================================== */

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

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --surface: #232d3f;
  --surface2: #2a3549;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);

  --accent: #4f8ef7;
  --accent-glow: rgba(79,142,247,0.25);
  --accent2: #7c5cfc;
  --green: #22c55e;
  --green-glow: rgba(34,197,94,0.2);
  --red: #ef4444;
  --red-glow: rgba(239,68,68,0.2);
  --amber: #f59e0b;
  --amber-glow: rgba(245,158,11,0.2);

  --text: #e2e8f0;
  --text2: #94a3b8;
  --text3: #64748b;

  --radius: 14px;
  --radius-sm: 8px;
  --radius-lg: 20px;

  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);

  --nav-h: 60px;
  --transition: 0.2s ease;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
}
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
a { color: inherit; text-decoration: none; }
input, textarea, select { font-family: inherit; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 10px; }

/* ── Layout ──────────────────────────────────────────────── */
#app { min-height: 100dvh; display: flex; flex-direction: column; }

.page { display: none; flex-direction: column; flex: 1; animation: fadeIn 0.2s ease; }
.page.active { display: flex; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.container { max-width: 680px; margin: 0 auto; padding: 0 16px; width: 100%; }

/* ── Bottom Navigation ───────────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
  backdrop-filter: blur(16px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  transition: color var(--transition);
  padding-top: 6px;
  position: relative;
}
.nav-item .icon { font-size: 22px; line-height: 1; transition: transform var(--transition); }
.nav-item.active { color: var(--accent); }
.nav-item.active .icon { transform: scale(1.15); }

.nav-badge {
  position: absolute;
  top: 4px; right: calc(50% - 16px);
  background: var(--red);
  color: white;
  font-size: 9px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}

/* Main content area with bottom nav spacing */
.page-content {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}
.card-sm { padding: 12px 14px; border-radius: var(--radius-sm); }
.card-glass {
  background: rgba(35, 45, 63, 0.7);
  backdrop-filter: blur(12px);
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: all var(--transition);
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #3d7ef0; box-shadow: 0 0 20px var(--accent-glow); }
.btn-success { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-ghost { background: var(--surface2); color: var(--text2); border-color: var(--border2); }
.btn-ghost:hover { color: var(--text); background: var(--bg3); }
.btn-outline { border-color: var(--accent); color: var(--accent); }
.btn-lg { padding: 14px 28px; font-size: 16px; border-radius: var(--radius); }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* ── Inputs ──────────────────────────────────────────────── */
.input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--transition);
  outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text3); }

label.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); margin-bottom: 6px; letter-spacing: 0.5px; text-transform: uppercase; }

/* ── Progress Bars ───────────────────────────────────────── */
.progress-track {
  height: 8px;
  background: var(--bg3);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.5s ease;
}
.progress-fill.green { background: var(--green); }
.progress-fill.amber { background: var(--amber); }

/* ── Stat Cards ──────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value { font-size: 28px; font-weight: 800; color: var(--text); }
.stat-label { font-size: 11px; color: var(--text3); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-icon { font-size: 20px; margin-bottom: 4px; }

/* ── Question Card ───────────────────────────────────────── */
.question-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 12px calc(var(--nav-h) + 80px + env(safe-area-inset-bottom));
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}

.question-meta {
  font-size: 11px;
  color: var(--text3);
  font-weight: 500;
}
.question-id {
  font-size: 10px;
  color: var(--text3);
  font-family: monospace;
  background: var(--bg3);
  padding: 2px 7px;
  border-radius: 4px;
}

.question-progress-bar {
  width: 100%;
  height: 3px;
  background: var(--bg3);
  border-radius: 99px;
  margin-bottom: 14px;
}
.question-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  transition: width 0.3s ease;
}

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 10px;
}

.question-image-wrap { position: relative; }
.question-image-wrap img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  background: var(--bg3);
}
.question-image-wrap video {
  width: 100%;
  max-height: 220px;
  background: #000;
}

.question-body { padding: 16px; }
.question-text {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 14px;
}

/* Difficulty badge */
.diff-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 99px;
  margin-bottom: 8px;
  background: rgba(239,68,68,0.15);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
}

/* ── Answer Options ──────────────────────────────────────── */
.options-list { display: flex; flex-direction: column; gap: 8px; }

.option-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  background: var(--bg3);
  border: 2px solid var(--border2);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  transition: all 0.15s ease;
  cursor: pointer;
  line-height: 1.4;
}
.option-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--surface2); }
.option-btn:disabled { cursor: default; }

.option-letter {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text2);
  transition: all 0.15s ease;
}

.option-btn.correct { border-color: var(--green); background: rgba(34,197,94,0.1); }
.option-btn.correct .option-letter { background: var(--green); color: white; }
.option-btn.wrong { border-color: var(--red); background: rgba(239,68,68,0.1); }
.option-btn.wrong .option-letter { background: var(--red); color: white; }

/* ── Explanation ─────────────────────────────────────────── */
.explanation-card {
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid;
  animation: slideUp 0.2s ease;
}
.explanation-card.correct {
  background: rgba(34,197,94,0.08);
  border-color: rgba(34,197,94,0.25);
  color: #86efac;
}
.explanation-card.wrong {
  background: rgba(239,68,68,0.08);
  border-color: rgba(239,68,68,0.25);
  color: #fca5a5;
}
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ── Fixed bottom action bar ─────────────────────────────── */
.action-bar {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  z-index: 99;
}

/* ── Session complete screen ─────────────────────────────── */
.session-complete {
  text-align: center;
  padding: 40px 20px;
}
.session-score {
  font-size: 72px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── XP Toast ────────────────────────────────────────────── */
#xp-toast {
  position: fixed;
  top: 20px;
  right: 16px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease forwards;
}
.toast.xp { color: var(--amber); border-color: var(--amber-glow); }
.toast.badge { color: var(--green); border-color: var(--green-glow); }
.toast.level { color: var(--accent); border-color: var(--accent-glow); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }

/* ── Login Page ──────────────────────────────────────────── */
.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(ellipse at 50% 0%, rgba(79,142,247,0.12) 0%, transparent 60%), var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .logo-icon { font-size: 48px; }
.login-logo h1 { font-size: 22px; font-weight: 800; margin-top: 8px; }
.login-logo p { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* ── Page Headers ────────────────────────────────────────── */
.page-header {
  padding: 16px 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.page-title { font-size: 20px; font-weight: 800; }
.page-subtitle { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ── Level Badge ─────────────────────────────────────────── */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
}

/* ── Streak Banner ───────────────────────────────────────── */
.streak-banner {
  background: linear-gradient(135deg, rgba(245,158,11,0.15), rgba(239,68,68,0.1));
  border: 1px solid rgba(245,158,11,0.3);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.streak-flame { font-size: 32px; }
.streak-info { flex: 1; }
.streak-number { font-size: 22px; font-weight: 800; color: var(--amber); }
.streak-label { font-size: 11px; color: var(--text2); }

/* ── Activity Calendar ───────────────────────────────────── */
.activity-dots { display: flex; gap: 4px; margin-top: 6px; }
.activity-dot {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: var(--bg3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: var(--text3);
  gap: 2px;
}
.activity-dot.active { background: rgba(79,142,247,0.2); color: var(--accent); }
.activity-dot.goal { background: rgba(34,197,94,0.2); color: var(--green); }
.activity-dot span { font-size: 8px; font-weight: 600; }

/* ── Badges ──────────────────────────────────────────────── */
.badges-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.badge-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border);
}
.badge-chip.earned { background: rgba(34,197,94,0.1); color: var(--green); border-color: rgba(34,197,94,0.25); }
.badge-chip .badge-icon { font-size: 16px; }

/* ── Admin ───────────────────────────────────────────────── */
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.user-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 700; font-size: 15px; }
.user-stats { font-size: 11px; color: var(--text2); margin-top: 2px; }

/* ── Navigator ───────────────────────────────────────────── */
.nav-question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.nav-question-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* ── Report Modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-overlay.open {
  display: flex !important;
  opacity: 1;
  pointer-events: all;
}
.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg2);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  transform: scale(0.95);
  transition: transform 0.2s ease;
  border: 1px solid var(--border2);
  box-shadow: 0 20px 45px rgba(0,0,0,0.65);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-overlay.open .modal-sheet {
  transform: scale(1);
}
.modal-handle {
  display: none;
}

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 14px;
}
.tab-btn {
  flex: 1;
  padding: 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text3);
  transition: all var(--transition);
}
.tab-btn.active { background: var(--surface2); color: var(--text); }

/* ── Chip filters ────────────────────────────────────────── */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border2);
  color: var(--text2);
  background: var(--bg3);
  transition: all var(--transition);
}
.chip.active { border-color: var(--accent); color: var(--accent); background: rgba(79,142,247,0.1); }

/* ── Error / empty states ────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text2);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 6px; }

.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 8px;
}

/* ── Utility ─────────────────────────────────────────────── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-2 { margin-bottom: 8px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--text2); }
.text-accent { color: var(--accent); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.font-bold { font-weight: 700; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive desktop improvements ─────────────────────── */
@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .question-container { padding: 20px 20px calc(var(--nav-h) + 100px); }
  .action-bar { padding: 12px 24px; }
  .login-card { padding: 44px 40px; }
}
