/* ========================
   General Page Styling
======================== */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f8f9fa;
  margin: 0;
  padding: 0;
}

/* ========================
   Exam Page Header
======================== */
.exam-header {
  text-align: center;
  background: linear-gradient(to right, #eaf6fc, #f0f8ff);
  padding: 2rem 1rem;
  border-bottom: 2px solid #3f87a6;
}

.exam-header h1 {
  /* Scale across screen sizes */
  font-size: clamp(1.4rem, 2.5vw, 2rem);
  color: #2a658f;
  margin-bottom: 0.3rem;
}

.exam-header p {
  font-size: clamp(0.9rem, 1.8vw, 1rem);
  color: #555;
  font-style: italic;
  margin: 0;
}

/* ========================
   Main Exam Container
======================== */
.exam-container {
  width: 100%;
  max-width: 900px;               /* a bit wider on desktop */
  margin: 2rem auto;
  padding: 2rem;
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* ========================
   Question Section
======================== */
.question-box {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.question-content h2 {
  font-size: clamp(1.1rem, 2.2vw, 1.4rem);
  color: #2a658f;
  margin: 0 0 0.5rem 0;
}

.question-content p {
  font-size: clamp(1rem, 2vw, 1.1rem);
  font-weight: bold;
  margin: 0;
}

.question-content img {
  max-width: 100%;
  height: auto;
  margin-top: 1rem;
  border-radius: 10px;
  border: 1px solid #ddd;
}

/* ========================
   Hint Section
======================== */
.hint-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap; /* allow wrap on small screens */
}

.hint-toggle {
  background-color: #ffc107;
  color: #222;
  border: none;
  padding: 0.5rem 1.1rem;
  font-size: 0.95rem;
  border-radius: 999px;
  cursor: pointer;
}

.hint-box {
  background-color: #fff8dc;
  border-left: 4px solid #f0ad4e;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  display: none; /* hidden by default; JS toggles this */
  overflow-x: auto; /* safe if MathJax is wider */
}

/* ========================
   Reveal Answer Section
======================== */
.reveal-section {
  text-align: left;
}

.answer-block {
  background-color: #e8f4fa;
  border-left: 4px solid #3f87a6;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
}

.answer-block strong {
  color: #2a658f;
}

.explanation-box {
  background-color: #f1f8fc;
  padding: 0.8rem;
  border-left: 4px solid #87c3e8;
  border-radius: 8px;
  margin-top: 1rem;
}

.explanation-box p {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
}

/* Wrap long MathJax blocks so the layout never breaks */
.answer-block, .question-border-box, .hint-box {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ========================
   Buttons Section (Reveal + Next)
======================== */
.button-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-top: 2rem;
  flex-wrap: wrap; /* allows wrap on tight widths */
}

.reveal-btn {
  background-color: #3f87a6;
  color: white;
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
  flex: 1 1 auto; /* can grow/shrink */
}

.button {
  background-color: #3f87a6;
  color: white;
  padding: 0.7rem 1.4rem;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.button:hover { background-color: #2c6b85; }

.button.finish { background-color: #28a745; }
.button.finish:hover { background-color: #1e7e34; }

/* ========================
   Advertisement Placeholder
======================== */
.ad-placeholder {
  min-height: 90px;
  background: #eee;
  text-align: center;
  line-height: 90px;
  margin: 1rem 0;
  border-radius: 8px;
  font-size: 0.95rem;
}

/* ========================
   Question Border Box
======================== */
.question-border-box {
  background-color: #fdfefe; /* very light background */
  border: 2px solid #dde4ea; /* soft grey-blue border */
  border-radius: 10px;
  padding: 1.2rem;
  margin-top: 1rem;
}

.question-border-box p {
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.1rem);
  font-weight: bold;
  color: #333;
}

.question-border-box img {
  margin-top: 1rem;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #ccc;
}

/* ========================
   Responsive Adjustments
======================== */
@media (max-width: 900px) {
  .exam-container { padding: 1.5rem; max-width: 95%; }
}

@media (max-width: 700px) {
  .exam-container { padding: 1.2rem; }
  .button-row { flex-direction: column; align-items: stretch; }
  .reveal-btn, .button { width: 100%; text-align: center; }
  .ad-placeholder { line-height: normal; padding: 1.2rem 0; }
}

@media (max-width: 480px) {
  .exam-container { padding: 1rem; }
  .hint-toggle { width: 100%; text-align: center; }
}

/* ========================
   Back Button
======================== */
.back-button {
  display: inline-block;
  margin-top: 2rem;
  padding: 0.8rem 1.6rem;
  font-size: 1.1rem;
}

/* ========================
   Print Styles (optional but handy)
======================== */
@media print {
  .ad-placeholder, .hint-section, .button-row, .reveal-btn, .back-button { display: none !important; }
  .exam-container { box-shadow: none; margin: 0; padding: 0; }
  .exam-header { border: 0; padding: 0 0 1rem 0; background: none; }
}

@media (max-width: 700px) {
  .exam-container { padding: 1.2rem; }
  .button-row { flex-direction: column; align-items: stretch; }
  
  /* Make all buttons match size on mobile */
  .reveal-btn,
  .button {
    width: 100%;
    text-align: center;
    padding: 0.8rem 1.4rem; /* same for all */
    font-size: 16px;
    box-sizing: border-box;
  }

  .ad-placeholder { line-height: normal; padding: 1.2rem 0; }
}

  /* Dark tokens */
  html.dark-mode{
    --brand:#3b82f6;
    --text:#e5e7eb;
    --text-dim:#94a3b8;
    --panel:#0b1020;
    --card:#0f172a;
    --border: color-mix(in oklab,var(--brand) 22%,transparent);
  }

  /* Header */
  html.dark-mode .exam-header h1{ color:var(--text); }
  html.dark-mode .exam-header p{ color:var(--text-dim); }

  /* Base text */
  html.dark-mode .exam-container,
  html.dark-mode .question-box,
  html.dark-mode .question-content{ color:var(--text); }

  /* Ad placeholder */
  html.dark-mode .ad-placeholder{
    background:#0b1221;
    color:var(--text-dim);
    border:1px dashed #1f2937;
  }

  /* Question panel */
  html.dark-mode .question-border-box{
    background:linear-gradient(
      180deg,
      color-mix(in oklab,var(--card) 92%,white 8%),
      color-mix(in oklab,var(--panel) 92%,white 8%)
    );
    border:1px solid var(--border);
    box-shadow:0 14px 28px rgba(0,0,0,.35);
  }

  /* Hint */
  html.dark-mode .hint-toggle{
    background:color-mix(in oklab,var(--brand) 18%,transparent);
    border:1px solid color-mix(in oklab,var(--brand) 35%,transparent);
    color:color-mix(in oklab,var(--brand) 80%,white);
  }
  html.dark-mode .hint-box{
    background:color-mix(in oklab,var(--card) 90%,white 10%);
    color:var(--text);
    border:1px solid var(--border);
    box-shadow:0 10px 20px rgba(0,0,0,.35);
  }

  /* Answer / explanation */
  html.dark-mode .answer-block{
    background:linear-gradient(
      180deg,
      color-mix(in oklab,var(--card) 92%,white 8%),
      color-mix(in oklab,var(--panel) 92%,white 8%)
    );
    color:var(--text);
    border:1px solid var(--border);
  }
  html.dark-mode .explanation-box{
    background:#0b1221;
    color:var(--text);
    border:1px solid color-mix(in oklab,var(--brand) 25%,transparent);
  }

  /* Buttons */
  html.dark-mode .button,
  html.dark-mode .reveal-btn,
  html.dark-mode .back-button,
  html.dark-mode .finish{
    background:color-mix(in oklab,var(--brand) 18%,transparent);
    color:color-mix(in oklab,var(--brand) 92%,white);
    border:1px solid color-mix(in oklab,var(--brand) 35%,transparent);
  }
  html.dark-mode .button:hover,
  html.dark-mode .reveal-btn:hover,
  html.dark-mode .back-button:hover,
  html.dark-mode .finish:hover{
    border-color:var(--brand);
  }

  /* MathJax inherits foreground */
  html.dark-mode .question-border-box mjx-container,
  html.dark-mode .answer-block mjx-container{ color:var(--text); }

  /* Keep images natural */
  html.dark-mode img{ filter:none; }

  /* === Dark-mode fixes (append at end) === */
html.dark-mode{
  --brand:#3b82f6;
  --text:#e5e7eb;
  --text-dim:#94a3b8;
  --panel:#0b1020;
  --card:#0f172a;
  --border: color-mix(in oklab,var(--brand) 22%, transparent);
}

/* page background */
html.dark-mode body{
  background-color:#0b0f17; /* was #f8f9fa */
  color:var(--text);
}

/* container */
html.dark-mode .exam-container{
  background-color:#0f172a; /* override white */
  border:1px solid var(--border);
  box-shadow:0 12px 28px rgba(0,0,0,.45);
}

/* header bar */
html.dark-mode .exam-header{
  background:linear-gradient(to right, #0b1221, #0e1424); /* override light gradient */
  border-bottom:2px solid var(--border);
}
html.dark-mode .exam-header h1{ color:var(--text); }
html.dark-mode .exam-header p { color:var(--text-dim); }

/* headings and text inside question */
html.dark-mode .question-content h2{
  color: color-mix(in oklab,var(--brand) 85%, white);
}
html.dark-mode .question-content p,
html.dark-mode .question-border-box p{
  color: var(--text);            /* overrides the hard-coded #333 */
}

/* question panel (you already had most of this; keep for completeness) */
html.dark-mode .question-border-box{
  background:linear-gradient(
    180deg,
    color-mix(in oklab,var(--card) 92%,white 8%),
    color-mix(in oklab,var(--panel) 92%,white 8%)
  );
  border:1px solid var(--border);
  box-shadow:0 14px 28px rgba(0,0,0,.35);
}

/* images/borders */
html.dark-mode .question-content img,
html.dark-mode .question-border-box img{
  border-color:#334155; /* replace #ddd/#ccc */
}

/* hint + answer blocks (you already set most; small tweak to accent color) */
html.dark-mode .hint-toggle{
  background:color-mix(in oklab,var(--brand) 18%,transparent);
  border:1px solid color-mix(in oklab,var(--brand) 35%,transparent);
  color:color-mix(in oklab,var(--brand) 85%, white);
}
html.dark-mode .hint-box{
  background:color-mix(in oklab,var(--card) 90%,white 10%);
  color:var(--text);
  border:1px solid var(--border);
  box-shadow:0 10px 20px rgba(0,0,0,.35);
}
html.dark-mode .answer-block{
  background:linear-gradient(
    180deg,
    color-mix(in oklab,var(--card) 92%,white 8%),
    color-mix(in oklab,var(--panel) 92%,white 8%)
  );
  color:var(--text);
  border:1px solid var(--border);
}
html.dark-mode .answer-block strong{
  color: color-mix(in oklab,var(--brand) 92%, white);
}
html.dark-mode .explanation-box{
  background:#0b1221;
  color:var(--text);
  border:1px solid color-mix(in oklab,var(--brand) 25%,transparent);
}

/* buttons */
html.dark-mode .button,
html.dark-mode .reveal-btn,
html.dark-mode .back-button,
html.dark-mode .finish{
  background:color-mix(in oklab,var(--brand) 18%,transparent);
  color:color-mix(in oklab,var(--brand) 95%, white);
  border:1px solid color-mix(in oklab,var(--brand) 35%,transparent);
}
html.dark-mode .button:hover,
html.dark-mode .reveal-btn:hover,
html.dark-mode .back-button:hover,
html.dark-mode .finish:hover{
  border-color:var(--brand);
}

/* MathJax adopts foreground color */
html.dark-mode .question-border-box mjx-container,
html.dark-mode .answer-block mjx-container{ color:var(--text); }

/* --- Make MathJax 'aligned' blocks wrap instead of overflowing --- */
.answer-block mjx-container,
.question-border-box mjx-container{
  display:block;
  max-width:100%;
}

/* Force aligned table to respect container width and wrap */
.answer-block mjx-container mjx-mtable,
.question-border-box mjx-container mjx-mtable{
  width:100% !important;          /* don't size to content */
  table-layout:fixed !important;  /* allow wrapping inside cells */
}

/* Allow wrapping inside table cells and mtext */
.answer-block mjx-container mjx-mtd,
.question-border-box mjx-container mjx-mtd{
  white-space:normal !important;
  overflow-wrap:anywhere;
  word-break:normal;
}
.answer-block mjx-container mjx-mtext,
.question-border-box mjx-container mjx-mtext{
  white-space:normal !important;
  overflow-wrap:anywhere;
}

/* Optional: soften font size on tiny screens so long lines fit better */
@media (max-width: 480px){
  .answer-block mjx-container,
  .question-border-box mjx-container{ font-size:.96em; }
}

