/* ================================================================
   PrimacyEbooks — CBT Practice Styles
   World-class exam interface
   ================================================================ */

/* ── Hero ──────────────────────────────────────────────────────── */
.cbt-hero {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  padding: 4rem 0;
  position: relative;
  overflow: hidden;
}
.cbt-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(79, 70, 229, 0.15) 0%, transparent 70%);
  border-radius: 50%;
}
.cbt-hero-illustration {
  position: relative;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

/* ── Exam Type Cards ───────────────────────────────────────────── */
.cbt-exam-card {
  transition: transform 0.2s, box-shadow 0.2s;
  border-radius: 16px;
}
.cbt-exam-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.12) !important;
}
.cbt-exam-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Subject Selection Cards ───────────────────────────────────── */
.cbt-subject-card {
  display: block;
  padding: 14px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  background: #fff;
}
.cbt-subject-card:hover:not(.disabled) {
  border-color: var(--bs-primary);
  background: #f7f7ff;
}
.cbt-subject-card.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.cbt-subject-card.at-limit {
  opacity: 0.4;
  cursor: not-allowed;
}
.cbt-subject-card .cbt-subject-checkbox:checked ~ .d-flex {
  color: var(--bs-primary);
}
.cbt-subject-card:has(.cbt-subject-checkbox:checked) {
  border-color: var(--bs-primary);
  background: #eff3ff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.cbt-subject-checkbox {
  display: none;
}
.cbt-subject-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #f0f4ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--bs-primary);
  flex-shrink: 0;
}

/* ================================================================
   EXAM INTERFACE — Full-screen, mobile-first
   ================================================================ */

:root {
  --cbt-vh: 1vh;
  --cbt-topbar: 52px;
}

.cbt-exam-body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: calc(var(--cbt-vh, 1vh) * 100);
  background: #f0f2f5;
}

/* ── Top Bar ───────────────────────────────────────────────────── */
.cbt-topbar {
  height: var(--cbt-topbar);
  background: linear-gradient(135deg, #1a1a2e 0%, #0f3460 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.cbt-timer {
  background: rgba(255,255,255,0.12);
  color: #fff;
  padding: 5px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  transition: all 0.3s;
  backdrop-filter: blur(4px);
  letter-spacing: 0.5px;
}
.cbt-timer-warning {
  background: rgba(255, 193, 7, 0.35);
  color: #ffc107;
  animation: timerPulse 1s ease-in-out infinite;
}
.cbt-timer-danger {
  background: rgba(220, 53, 69, 0.45);
  color: #ff4444;
  animation: timerPulse 0.5s ease-in-out infinite;
}
@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.cbt-progress-info {
  color: rgba(255,255,255,0.7);
  font-size: 0.85rem;
}

/* Mini progress bar in topbar */
.cbt-progress-bar-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,0.1);
}
.cbt-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ade80, #22c55e);
  transition: width 0.4s ease;
  border-radius: 0 2px 2px 0;
}

/* ── Layout ────────────────────────────────────────────────────── */
.cbt-layout {
  display: flex;
  height: calc(var(--cbt-vh, 1vh) * 100 - var(--cbt-topbar));
  margin-top: var(--cbt-topbar);
  position: relative;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.cbt-sidebar {
  width: 250px;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}
.cbt-sidebar-header {
  padding: 12px 16px;
  font-weight: 700;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.95rem;
}
.cbt-subject-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  overflow-x: auto;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
  scrollbar-width: none;
}
.cbt-subject-tabs::-webkit-scrollbar { display: none; }
.cbt-subject-tab {
  border: none;
  background: #f0f4f8;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cbt-subject-tab.active {
  background: var(--bs-primary);
  color: #fff;
}

.cbt-question-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
}
.cbt-q-btn {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid #e2e8f0;
  background: #fff;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.cbt-q-btn:hover {
  border-color: var(--bs-primary);
  background: #f0f4ff;
}
.cbt-q-btn.answered {
  background: #d4edda;
  border-color: #28a745;
  color: #155724;
}
.cbt-q-btn.current {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.cbt-q-btn.flagged::after {
  content: '\1F6A9';
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 0.6rem;
}

.cbt-sidebar-footer {
  padding: 10px;
  border-top: 1px solid #e2e8f0;
  font-size: 0.72rem;
  color: #666;
}
.cbt-legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 2px solid #e2e8f0;
  background: #fff;
  vertical-align: middle;
  margin-right: 3px;
}
.cbt-legend-dot.answered {
  background: #d4edda;
  border-color: #28a745;
}
.cbt-legend-dot.current {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
}

/* Mobile overlay for sidebar */
.cbt-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 998;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.cbt-sidebar-overlay.active {
  display: block;
}

/* ── Main Question Area ────────────────────────────────────────── */
.cbt-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f5f7fa;
  min-width: 0;
}

/* Scrollable question content — separate from fixed nav */
.cbt-question-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 24px 16px;
  scroll-behavior: smooth;
}

.cbt-question-container {
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
  animation: cbtFadeIn 0.2s ease-out;
}
@keyframes cbtFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cbt-question-header {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.cbt-question-number {
  background: linear-gradient(135deg, var(--bs-primary), #4338ca);
  color: #fff;
  font-weight: 800;
  font-size: 0.78rem;
  padding: 4px 12px;
  border-radius: 20px;
  letter-spacing: 0.3px;
}
.cbt-question-subject {
  background: #f0f4f8;
  color: #475569;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 4px 12px;
  border-radius: 20px;
}

.cbt-question-text {
  font-size: 1.05rem;
  line-height: 1.75;
  margin-bottom: 20px;
  color: #1e293b;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.cbt-question-text p { margin-bottom: 0.5em; }
.cbt-question-image img {
  max-height: 280px;
  object-fit: contain;
  border-radius: 8px;
}

/* ── Options ───────────────────────────────────────────────────── */
.cbt-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}
.cbt-option {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 18px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  background: #fff;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.cbt-option:hover {
  border-color: #a5b4fc;
  background: #f8faff;
}
.cbt-option:active {
  transform: scale(0.985);
}
.cbt-option.selected {
  border-color: var(--bs-primary);
  background: linear-gradient(135deg, #eff3ff, #e8ecff);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.cbt-option-label {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f0f4f8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
  transition: all 0.2s;
  color: #64748b;
}
.cbt-option.selected .cbt-option-label {
  background: var(--bs-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.cbt-option-text {
  flex: 1;
  padding-top: 5px;
  line-height: 1.55;
  color: #334155;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.cbt-option.selected .cbt-option-text {
  color: #1e293b;
  font-weight: 500;
}

/* ── Navigation Buttons (ALWAYS VISIBLE bottom bar) ────────────── */
.cbt-nav-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 24px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
  gap: 8px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}
.cbt-nav-buttons .btn {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 20px;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 44px;
}
.cbt-nav-buttons .btn-primary {
  background: linear-gradient(135deg, var(--bs-primary), #4338ca);
  border: none;
  box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.cbt-nav-buttons .btn-primary:active {
  transform: scale(0.97);
}

.cbt-nav-grid-btn {
  background: #f0f4f8 !important;
  border: 1px solid #e2e8f0 !important;
  color: #475569 !important;
  padding: 10px 14px !important;
  position: relative;
}
.cbt-nav-grid-btn .cbt-grid-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 0.65rem;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

/* ── Result Page ───────────────────────────────────────────────── */
.cbt-score-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.cbt-score-pct {
  font-size: 2rem;
  font-weight: 800;
}

.cbt-review-question {
  padding: 20px 24px;
  border-bottom: 1px solid #f0f0f0;
}
.cbt-review-question.correct {
  border-left: 4px solid #28a745;
}
.cbt-review-question.wrong {
  border-left: 4px solid #dc3545;
}
.cbt-review-option {
  padding: 8px 14px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.cbt-review-option.review-correct {
  background: #d4edda;
  border: 1px solid #28a745;
}
.cbt-review-option.review-wrong {
  background: #f8d7da;
  border: 1px solid #dc3545;
}

/* ================================================================
   MOBILE RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
  .cbt-hero { padding: 3rem 0; }
  .cbt-hero h1 { font-size: 1.8rem; }

  .cbt-sidebar {
    position: fixed;
    top: var(--cbt-topbar);
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .cbt-sidebar.open {
    transform: translateX(0);
  }

  .cbt-main {
    width: 100%;
  }
  .cbt-question-scroll {
    padding: 16px 16px 12px;
  }
  .cbt-question-text {
    font-size: 0.95rem;
    line-height: 1.7;
  }

  .cbt-option {
    padding: 12px 14px;
    gap: 10px;
    border-radius: 10px;
  }
  .cbt-option-label {
    width: 30px;
    height: 30px;
    font-size: 0.8rem;
  }
  .cbt-option-text {
    padding-top: 3px;
    font-size: 0.92rem;
  }

  .cbt-nav-buttons {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .cbt-nav-buttons .btn {
    padding: 10px 16px;
    font-size: 0.85rem;
  }

  .cbt-score-circle { width: 100px; height: 100px; }
  .cbt-score-pct { font-size: 1.6rem; }
}

@media (max-width: 480px) {
  :root { --cbt-topbar: 48px; }
  .cbt-topbar {
    padding: 0 10px;
    height: 48px;
  }
  .cbt-timer {
    padding: 4px 10px;
    font-size: 0.88rem;
  }
  .cbt-question-scroll {
    padding: 12px 12px 8px;
  }
  .cbt-question-text { font-size: 0.9rem; }
  .cbt-option {
    padding: 10px 12px;
    gap: 8px;
  }
}

@supports (padding: max(0px)) {
  .cbt-topbar {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .cbt-nav-buttons {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}
