/* ==========================================================================
   Exam Runner Interface - NTA CBT Simulation & Mobile Optimization
   ========================================================================== */

.exam-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background-color: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  position: fixed;
  inset: 0;
  z-index: 1000;
}

/* Top Exam Header */
.exam-header {
  height: 60px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  flex-shrink: 0;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.btn-icon-exit {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.btn-icon-exit:hover {
  color: var(--accent-rose);
  border-color: var(--accent-rose);
}

.header-title-box {
  min-width: 0;
}

.exam-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.1rem;
}

.badge-cbt {
  background-color: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
}

.badge-practice {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.exam-title {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

/* Subject Tabs in Header */
.subject-tabs-container {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background-color: var(--bg-surface-elevated);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.btn-subject-tab {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-subject-tab.active {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.tab-q-count {
  font-size: 0.72rem;
  opacity: 0.75;
}

/* Timer Display */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-shrink: 0;
}

.timer-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
}

.timer-text-wrap {
  display: flex;
  flex-direction: column;
}

.timer-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
}

.timer-digits {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.timer-warning {
  border-color: var(--accent-rose);
  background-color: rgba(244, 63, 94, 0.12);
  animation: timerBlink 1.5s infinite;
}

@keyframes timerBlink {
  50% { opacity: 0.7; }
}

.btn-submit-exam, .btn-finish-practice {
  padding: 0.5rem 1.15rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.88rem;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
  transition: all var(--transition-fast);
}

.btn-submit-exam:hover, .btn-finish-practice:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.45);
}

.btn-mobile-palette-toggle {
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Main Layout */
.exam-main-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  flex: 1;
  min-height: 0; /* Important for flex scrolling */
  overflow: hidden;
}

/* Question Canvas */
.question-canvas-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
}

.question-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-surface-elevated);
  flex-shrink: 0;
}

.q-meta-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.q-number-pill {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-primary);
}

.q-type-pill {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-cyan);
  background-color: var(--accent-cyan-subtle);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.q-marks-pill {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-emerald);
  background-color: var(--accent-emerald-subtle);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}

.btn-bookmark-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.btn-bookmark-toggle.bookmarked {
  color: var(--accent-amber);
  border-color: var(--accent-amber);
  background-color: rgba(245, 158, 11, 0.12);
}

.btn-bookmark-toggle.bookmarked svg {
  fill: var(--accent-amber);
}

/* Question Scroll Area */
.question-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem 3rem;
  scrollbar-width: thin;
}

.question-statement {
  font-size: 1.12rem;
  line-height: 1.75;
  color: var(--text-primary);
  margin-bottom: 2rem;
  letter-spacing: -0.01em;
}

.q-image-wrap {
  margin: 1.25rem 0;
}

.q-image-wrap img {
  max-width: 100%;
  max-height: 380px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

/* Options Grid */
.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-bottom: 2rem;
}

.option-label {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  background-color: var(--bg-surface-elevated);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
}

.option-label input[type="radio"] {
  display: none;
}

.option-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--bg-surface);
  border: 1.5px solid var(--border-medium);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.option-content {
  font-size: 1.05rem;
  line-height: 1.6;
  flex: 1;
  padding-top: 0.1rem;
}

.option-label:hover {
  border-color: var(--border-bright);
}

.option-label.selected {
  border-color: var(--accent-cyan);
  background-color: rgba(6, 182, 212, 0.08);
  box-shadow: 0 0 0 1px var(--accent-cyan);
}

.option-label.selected .option-letter {
  background-color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  color: #000;
}

/* Practice Mode Option Feedback States */
.option-label.correct-choice {
  border-color: var(--accent-emerald) !important;
  background-color: rgba(16, 185, 129, 0.1) !important;
}

.option-label.correct-choice .option-letter {
  background-color: var(--accent-emerald) !important;
  border-color: var(--accent-emerald) !important;
  color: #fff !important;
}

.option-label.incorrect-choice {
  border-color: var(--accent-rose) !important;
  background-color: rgba(244, 63, 94, 0.1) !important;
}

.option-label.incorrect-choice .option-letter {
  background-color: var(--accent-rose) !important;
  border-color: var(--accent-rose) !important;
  color: #fff !important;
}

/* Numerical Input Card */
.numerical-input-card {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  max-width: 480px;
  margin-bottom: 2rem;
}

.num-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.num-input-wrap {
  margin-bottom: 0.75rem;
}

.num-field {
  width: 100%;
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  border: 2px solid var(--border-medium);
  outline: none;
  transition: border-color var(--transition-fast);
}

.num-field:focus {
  border-color: var(--accent-cyan);
}

.num-help-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Practice Mode Feedback Box */
.practice-feedback-box {
  margin-top: 2rem;
  border-radius: var(--radius-md);
  overflow: hidden;
  animation: fadeIn 0.25s ease-out;
}

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

.feedback-banner {
  padding: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid;
}

.correct-banner {
  background-color: rgba(16, 185, 129, 0.08);
  border-color: var(--accent-emerald);
}

.incorrect-banner {
  background-color: rgba(244, 63, 94, 0.08);
  border-color: var(--accent-rose);
}

.feedback-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.feedback-badge {
  font-weight: 700;
  font-size: 1rem;
}

.correct-banner .feedback-badge { color: var(--accent-emerald); }
.incorrect-banner .feedback-badge { color: var(--accent-rose); }

.correct-answer-pill {
  font-size: 0.85rem;
  background-color: var(--bg-surface);
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.solution-content h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.solution-text {
  font-size: 0.98rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

/* Bottom Actions Bar */
.exam-bottom-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  flex-shrink: 0;
}

.actions-left, .actions-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.btn-exam-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.btn-secondary {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background-color: var(--bg-surface);
  border-color: var(--border-medium);
}

.btn-outline-danger {
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.btn-outline-danger:hover {
  color: var(--accent-rose);
  border-color: var(--accent-rose);
}

.btn-warning-subtle {
  background-color: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: var(--accent-purple);
}

.btn-warning-subtle:hover {
  background-color: rgba(139, 92, 246, 0.22);
}

.btn-primary-cta {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.35);
}

.btn-primary-cta:hover {
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.45);
}

.btn-check-answer {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

/* Palette Sidebar */
.palette-sidebar {
  background-color: var(--bg-surface-elevated);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.palette-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.palette-header h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
}

.btn-close-palette {
  display: none;
  color: var(--text-muted);
}

/* Palette Legend */
.palette-legend {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-badge {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.72rem;
  color: #ffffff;
  flex-shrink: 0;
}

.badge-answered { background-color: var(--nta-answered); }
.badge-not-answered { background-color: var(--nta-not-answered); }
.badge-not-visited { background-color: var(--nta-not-visited); }
.badge-marked { background-color: var(--nta-marked); }
.badge-answered-marked {
  background-color: var(--nta-ans-marked);
  position: relative;
}
.badge-answered-marked::after {
  content: '';
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--nta-answered);
}

.palette-subject-label {
  padding: 0.65rem 1.25rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Palette Grid */
.palette-grid {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1.25rem 1.5rem;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.6rem;
  align-content: start;
}

.palette-btn {
  height: 42px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.88rem;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform var(--transition-fast);
}

.palette-btn:hover {
  transform: scale(1.06);
}

.palette-btn.current-active {
  outline: 2.5px solid var(--text-primary);
  outline-offset: 2px;
}

.status-not-visited { background-color: var(--nta-not-visited); }
.status-not-answered { background-color: var(--nta-not-answered); }
.status-answered { background-color: var(--nta-answered); }
.status-marked { background-color: var(--nta-marked); }
.status-ans-marked { background-color: var(--nta-ans-marked); }
.status-ans-marked::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #10b981;
}

.palette-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
}

.btn-submit-exam-palette {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
}

/* Submission Summary Grid in Modal */
.submit-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.85rem;
  margin: 1.5rem 0 2rem;
}

.summary-tile {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
}

.sum-num {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
}

.sum-lbl {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.answered-tile .sum-num { color: var(--nta-answered); }
.not-answered-tile .sum-num { color: var(--nta-not-answered); }
.marked-tile .sum-num { color: var(--nta-marked); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.btn-modal-cancel {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-weight: 600;
}

.btn-modal-confirm {
  padding: 0.65rem 1.4rem;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-weight: 700;
}

/* ==========================================================================
   Mobile Bottom-Sheet Drawer & Responsive Viewport
   ========================================================================== */
@media (max-width: 960px) {
  .exam-main-layout {
    grid-template-columns: 1fr;
  }

  .btn-mobile-palette-toggle {
    display: inline-flex;
  }

  /* Transform palette into a bottom-sheet drawer */
  .palette-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75vh;
    max-height: 550px;
    z-index: 1100;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    border-top: 1px solid var(--border-medium);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .palette-sidebar.open {
    transform: translateY(0);
  }

  .btn-close-palette {
    display: block;
  }

  .palette-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1050;
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .palette-backdrop.open {
    display: block;
    opacity: 1;
  }

  .question-scroll-area {
    padding: 1.25rem 1.25rem 2rem;
  }
}

/* Submit Modal High Z-Index */
.modal-submit-dialog {
  z-index: 99999 !important;
}

.btn-submit-direct {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.35);
}

.btn-submit-direct:hover {
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.45);
}

.btn-exam-share {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface-elevated);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.btn-exam-share:hover {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

@media (max-width: 640px) {
  .exam-header {
    padding: 0 0.75rem;
  }
  .exam-title {
    max-width: 140px;
    font-size: 0.85rem;
  }
  .timer-digits {
    font-size: 0.95rem;
  }
  .btn-submit-exam, .btn-finish-practice {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }
  .exam-bottom-actions {
    padding: 0.75rem 0.85rem;
    gap: 0.5rem;
  }
  .btn-exam-action {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
  }
  .actions-left, .actions-right {
    gap: 0.4rem;
  }
  .question-statement {
    font-size: 1.05rem;
    line-height: 1.6;
  }
  .option-label {
    padding: 0.85rem 1rem;
    gap: 0.75rem;
  }
}

