/* ==========================================================================
   MASTER QUIZ & REVIEWER STYLESHEET
   Consolidated styling for TLE, Chemistry, Math, English, and Arts
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. GLOBAL RESETS & BASE STYLES
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
  max-width: 100%;
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

/* --------------------------------------------------------------------------
   2. COLOR PALETTES & THEME VARIABLES
   -------------------------------------------------------------------------- */
:root {
  /* Default / Theme Variables */
  --card-accent: #2563eb;
  --card-accent-strong: #1d4ed8;
  --blue-gradient: linear-gradient(135deg, rgba(37, 99, 235, 0.22) 0%, rgba(30, 64, 175, 0.1) 100%);
  --blue-bg-light: rgba(37, 99, 235, 0.15);
  --blue-border: rgba(37, 99, 235, 0.4);

  --green-gradient: linear-gradient(135deg, rgba(16, 185, 129, 0.22) 0%, rgba(5, 150, 105, 0.1) 100%);
  --green-bg-light: rgba(16, 185, 129, 0.15);
  --green-border: rgba(16, 185, 129, 0.4);

  --rule: #334155;
  --bg-raised: #1e293b;
  --bg: #0f172a;
  --ink: #f8fafc;
  --ink-secondary: #94a3b8;
  --shadow: rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --text-unanswered: #ef4444;
}

/* Light Theme Variables */
body[data-theme="light"] {
  --bg-raised: #ffffff;
  --bg: #f1f5f9;
  --ink: #0f172a;
  --ink-secondary: #475569;
  --rule: #cbd5e1;
  --shadow: rgba(0, 0, 0, 0.08);
  --green-bg-light: rgba(16, 185, 129, 0.1);
  --green-border: rgba(16, 185, 129, 0.3);
}

/* --------------------------------------------------------------------------
   3. TOP NAVIGATION & HEADER BAR
   -------------------------------------------------------------------------- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--rule);
  gap: 12px;
}

.top-bar a {
  color: var(--card-accent);
  text-decoration: none;
  font-weight: 600;
}

.top-bar .title {
  font-weight: 700;
  font-size: 1.05rem;
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--rule);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.streak-emoji {
  font-size: 1rem;
  line-height: 1;
}

.streak-count {
  font-weight: 700;
}

.streak-label {
  font-size: 0.78rem;
  color: var(--ink-secondary);
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: var(--blue-bg-light, var(--green-bg-light));
  border-color: var(--card-accent);
}

/* --------------------------------------------------------------------------
   4. CONTENT LAYOUT & HERO SECTION
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
}

.content {
  width: 100%;
  max-width: 1050px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
}

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.hero .eyebrow {
  color: var(--card-accent);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.hero .subtitle {
  color: var(--ink-secondary);
  font-size: 0.98rem;
  margin: 0 auto;
  max-width: 680px;
}

/* --------------------------------------------------------------------------
   5. WIZARD PROGRESS BAR
   -------------------------------------------------------------------------- */
.wizard-progress-card {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px var(--shadow);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 10px;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--rule);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--card-accent), var(--card-accent-strong));
  border-radius: 999px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.5);
}

/* --------------------------------------------------------------------------
   6. WIZARD TWO-COLUMN LAYOUT
   -------------------------------------------------------------------------- */
.wizard-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.wizard-main {
  flex: 1;
  min-width: 0;
}

.wizard-sidebar {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
}

/* --------------------------------------------------------------------------
   7. QUIZ CONTAINER & QUESTION CARDS
   -------------------------------------------------------------------------- */
.quiz-container {
  position: relative;
  min-height: 280px;
  counter-reset: question-counter;
}

.quiz-item {
  display: none;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-left: 5px solid var(--card-accent);
  border-radius: var(--radius);
  padding: 24px 24px 24px 28px;
  box-shadow: 0 6px 18px var(--shadow);
  position: relative;
  animation: fadeIn 0.25s ease-in-out forwards;
  transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
}

.quiz-item.active {
  display: block;
}

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

.category-pill {
  display: inline-block;
  padding: 4px 10px;
  background: var(--blue-bg-light, var(--green-bg-light));
  border: 1px solid var(--blue-border, var(--green-border));
  color: var(--card-accent);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  transition: all 0.3s ease;
}

.question {
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.45;
  margin-bottom: 18px;
  color: var(--ink);
  display: block;
  transition: color 0.3s ease;
}

/* Question Counter Auto-Prefix (Photography/Arts Mode) */
.quiz-item[data-correct] {
  counter-increment: question-counter;
  padding-left: 50px;
}

.quiz-item[data-correct] .question::before {
  content: counter(question-counter) ".) ";
  position: absolute;
  left: 15px;
  font-weight: 800;
  color: var(--card-accent);
}

/* --------------------------------------------------------------------------
   8. OPTIONS & MULTIPLE CHOICE SELECTION
   -------------------------------------------------------------------------- */
.options {
  list-style-type: upper-alpha;
  padding-left: 22px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.options li {
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  transition: all 0.15s ease;
  cursor: pointer;
  background: var(--bg);
}

.options li:hover {
  border-color: var(--card-accent);
  background: var(--blue-bg-light, var(--green-bg-light));
  color: var(--card-accent);
  transform: translateX(3px);
}

.options li.selected {
  background: var(--card-accent) !important;
  border-color: var(--card-accent-strong) !important;
  color: #ffffff !important;
  font-weight: 600;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.4);
}

.option-btn {
  background: transparent;
  border: none;
  color: inherit;
  padding: 12px 10px;
  border-radius: inherit;
  cursor: inherit;
  font-size: 0.96rem;
  text-align: left;
  width: 100%;
  line-height: 1.4;
}

/* --------------------------------------------------------------------------
   9. PROBLEM-SOLVING & NUMERIC INPUT COMPONENTS
   -------------------------------------------------------------------------- */
.problem-box {
  background: var(--bg);
  border: 1px dashed var(--blue-border, var(--green-border));
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 18px;
}

.step-block {
  margin-bottom: 16px;
}

.step-block:last-child {
  margin-bottom: 0;
}

.step-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--card-accent);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-desc {
  font-size: 0.92rem;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

.input-hint-comment {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-secondary);
  opacity: 0.8;
  margin-bottom: 8px;
  font-style: italic;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 280px;
}

.num-input {
  background: var(--bg-raised);
  border: 2px solid var(--rule);
  border-radius: 8px;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 10px 14px;
  width: 100%;
  outline: none;
  transition: all 0.2s ease;
}

.num-input:focus {
  border-color: var(--card-accent);
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.3);
}

/* Cross-Browser Spin Button Removal */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.unit-tag {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink-secondary);
}

.formula-badge {
  background: var(--blue-bg-light, var(--green-bg-light));
  border: 1px solid var(--blue-border, var(--green-border));
  color: var(--card-accent);
  padding: 4px 8px;
  border-radius: 6px;
  font-family: monospace;
  font-weight: 700;
}

.math-step {
  margin-top: 8px;
  padding-left: 12px;
  border-left: 3px solid var(--card-accent);
}

/* --------------------------------------------------------------------------
   10. INTERACTIVE SCANSION STYLES (ENGLISH)
   -------------------------------------------------------------------------- */
.scansion-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 12px;
  padding: 18px;
  background: var(--bg);
  border: 1px dashed var(--blue-border);
  border-radius: 10px;
  justify-content: center;
}

.syllable-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-raised);
  border: 2px solid var(--rule);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  min-width: 52px;
  transition: all 0.15s ease;
  color: var(--ink);
}

.syllable-btn:hover {
  border-color: var(--card-accent);
  transform: translateY(-2px);
}

.stress-badge {
  font-size: 0.9rem;
  font-weight: 900;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  background: var(--rule);
  color: var(--ink-secondary);
}

.syllable-btn[data-stress="s"] .stress-badge {
  background: var(--card-accent);
  color: #ffffff;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.6);
}

.syllable-btn[data-stress="u"] .stress-badge {
  background: var(--blue-bg-light);
  color: var(--card-accent);
}

.syl-text {
  font-size: 1.02rem;
  font-weight: 600;
}

.scansion-hint {
  font-size: 0.85rem;
  color: var(--ink-secondary);
  margin-top: 6px;
  font-style: italic;
  text-align: center;
}

.syllable-btn.correct-syl {
  background: rgba(34, 197, 94, 0.16) !important;
  border-color: #22c55e !important;
  color: var(--ink) !important;
}

.syllable-btn.correct-syl .stress-badge {
  background: #22c55e !important;
  color: #ffffff !important;
}

.syllable-btn.incorrect-syl {
  background: rgba(239, 68, 68, 0.14) !important;
  border-color: #ef4444 !important;
  color: var(--ink) !important;
}

.syllable-btn.incorrect-syl .stress-badge {
  background: #ef4444 !important;
  color: #ffffff !important;
}

/* --------------------------------------------------------------------------
   11. QUESTION GRID NAVIGATOR SIDEBAR
   -------------------------------------------------------------------------- */
.question-grid-card {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 12px var(--shadow);
}

.grid-label {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-secondary);
  margin-bottom: 12px;
}

.question-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.q-grid-btn {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.q-grid-btn:hover {
  border-color: var(--card-accent);
  color: var(--card-accent);
  transform: translateY(-1px);
}

.q-grid-btn.answered-q {
  border-color: var(--blue-border, var(--green-border)) !important;
  background: var(--blue-bg-light, var(--green-bg-light)) !important;
  color: var(--card-accent) !important;
}

.q-grid-btn.active-q {
  border-color: var(--card-accent) !important;
  border-style: solid !important;
  background: var(--card-accent) !important;
  color: #ffffff !important;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.5);
}

/* Optional Styling for Problem-Solving / Input Buttons */
.q-grid-btn.problem-q {
  border: 1.5px dashed var(--card-accent);
  background: var(--blue-bg-light, var(--green-bg-light));
  font-weight: 800;
  position: relative;
}

.q-grid-btn.problem-q::after {
  content: "✏️";
  font-size: 0.55rem;
  position: absolute;
  top: -4px;
  right: -4px;
  line-height: 1;
}

.q-grid-btn.problem-q:hover {
  border-style: solid;
  box-shadow: 0 0 8px rgba(37, 99, 235, 0.35);
}

/* --------------------------------------------------------------------------
   12. WIZARD & ACTION BUTTON CONTROLS
   -------------------------------------------------------------------------- */
.wizard-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.nav-btn,
.action-btn {
  background-color: var(--card-accent);
  border: none;
  color: #ffffff;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.action-btn {
  margin-top: 15px;
  padding: 10px 20px;
  font-size: 16px;
}

.nav-btn:hover:not(:disabled),
.action-btn:hover {
  background-color: var(--card-accent-strong);
  transform: translateY(-1px);
}

.nav-btn.secondary {
  background-color: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
}

.nav-btn.secondary:hover:not(:disabled) {
  background-color: var(--bg-raised);
  border-color: var(--card-accent);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

/* --------------------------------------------------------------------------
   13. RESULT PANEL & ANSWER REVIEW MODE
   -------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------
   13. RESULT PANEL & ANSWER REVIEW MODE
   -------------------------------------------------------------------------- */
.result-panel {
  text-align: center;
  margin: 24px auto;
  display: none;
  background: var(--blue-gradient, var(--green-gradient));
  border: 2px solid var(--card-accent);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 6px 20px var(--shadow);
  max-width: 700px;
  width: 100%;
}

.score-text {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 8px;
}

.score-message {
  color: var(--ink-secondary);
  margin-bottom: 0;
}

.answer-review {
  display: none;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  color: var(--ink-secondary);
  font-size: 0.94rem;
  line-height: 1.45;
}

.answer-review strong {
  color: var(--ink);
}

/* REVIEW MODE AUTO-NUMBERING */
.quiz-item.review-mode {
  display: block !important;
  margin-bottom: 20px;
  counter-increment: question-counter;
  position: relative;
}

.quiz-item.review-mode .question::before {
  content: counter(question-counter) ". ";
  font-weight: 800;
  color: var(--card-accent);
}

.quiz-item.correct {
  border: 2px solid #10b981 !important;
  border-left: 6px solid #10b981 !important;
  background: rgba(16, 185, 129, 0.08) !important;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.25) !important;
}

.quiz-item.correct .question {
  color: #10b981 !important;
}

.quiz-item.correct .category-pill {
  background: rgba(16, 185, 129, 0.18) !important;
  border-color: rgba(16, 185, 129, 0.5) !important;
  color: #10b981 !important;
}

.quiz-item.incorrect {
  border: 2px solid #ef4444 !important;
  border-left: 6px solid #ef4444 !important;
  background: rgba(239, 68, 68, 0.05) !important;
}

.quiz-item.incorrect .question {
  color: #ef4444 !important;
}

.options li.correct-answer {
  background: rgba(34, 197, 94, 0.16) !important;
  color: var(--ink) !important;
  border: 1px solid rgba(34, 197, 94, 0.45) !important;
}

.options li.incorrect-answer {
  background: rgba(239, 68, 68, 0.14) !important;
  color: var(--ink) !important;
  border: 1px solid rgba(239, 68, 68, 0.35) !important;
}

.answer-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.8rem;
  font-weight: 800;
}

.retake-container {
  margin-top: 18px;
}

.footer-note {
  text-align: center;
  margin-top: 24px;
  font-size: 0.88rem;
  color: var(--ink-secondary);
}

/* --------------------------------------------------------------------------
   14. RESPONSIVE MEDIA QUERIES
   -------------------------------------------------------------------------- */
/* Mobile KaTeX Equation & Math Container Overflow Fix */
@media screen and (max-width: 490px) {
  .katex-display,
  .katex {
    font-size: 0.75em !important;
  }

  .quiz-item,
  .answer-review,
  .problem-box,
  .formula-badge,
  .math-step {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .katex-display {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px !important;
    display: block !important;
  }

  body,
  html {
    overflow-x: hidden !important;
    width: 100vw !important;
  }
}

/* Tablet & General Mobile Optimization */
@media (max-width: 768px) {
  .wizard-layout {
    flex-direction: column;
  }

  .wizard-sidebar {
    width: 100%;
    position: static;
  }

  .top-bar {
    padding: 10px 14px;
    gap: 8px;
  }

  .top-bar .title {
    font-size: 0.9rem;
  }

  .scansion-box {
    padding: 10px 6px;
    gap: 6px;
  }

  .syllable-btn {
    min-width: 44px;
    padding: 8px 6px;
  }

  .syl-text {
    font-size: 0.88rem;
  }

  .quiz-item {
    padding: 16px;
  }

  .wizard-nav {
    flex-direction: column;
  }

  .nav-btn {
    width: 100%;
    justify-content: center;
  }
}

/* Collapse sidebar container when grid card is hidden */
.wizard-sidebar:has(#questionGridCard[style*="display: none"]) {
  display: none;
}