/* upsc-dynamic-test.css — standalone styles for the UPSC dynamic test engine */

/* ── CSS Variables ─────────────────────────────────────────────────────────── */
:root {
  --upsc-saffron:   #e65100;
  --upsc-navy:      #1e3a8a;
  --upsc-gold:      #f9a825;
  --upsc-green:     #2e7d32;
  --upsc-bg:        #f5f5f0;
  --upsc-card:      #ffffff;
  --upsc-border:    #e0e0d8;
  --upsc-text:      #212121;
  --upsc-muted:     #757575;

  --answered-color: #2e7d32;
  --marked-color:   #2563eb;
  --unanswered-color: #e65100;
  --unvisited-color:  #bdbdbd;
  --current-color:  #1e3a8a;

  --header-h: 64px;
  --radius:   10px;
  --mtm-diagram-muted: #64748b;
  --mtm-diagram-paper: #ffffff;
}

[data-theme="dark"] {
  --upsc-bg:    #0a0f1a;
  --upsc-card:  #111827;
  --upsc-border:#1e293b;
  --upsc-text:  #e0e0e0;
  --upsc-muted: #9e9e9e;
  --mtm-diagram-muted: #94a3b8;
  --mtm-diagram-paper: #111827;
}

/* ── Reset / Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* upsc-dynamic-test.html is fully self-contained (does NOT load main.css/
   nav.css), so the site-wide --font-scale rule from main.css never reaches
   this page. Duplicated here so the A-/A+ controls actually take effect —
   theme-init.js (always loaded first) sets --font-scale on <html> from the
   visitor's saved preference before paint, same as every other page. */
html {
  font-size: calc(16px * var(--font-scale, 1));
}

body {
  font-family: 'Poppins', sans-serif;
  background: var(--upsc-bg);
  color: var(--upsc-text);
  min-height: 100vh;
}

/* ── Auth Overlay ──────────────────────────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center; justify-content: center;
  z-index: 9999;
}
.auth-box {
  background: #fff; border-radius: 16px;
  padding: 40px 32px; text-align: center;
  max-width: 380px; width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.auth-box .lock-icon { font-size: 2.5rem; margin-bottom: 12px; }
.auth-box h2 { margin: 0 0 8px; color: var(--upsc-navy); }
.auth-box p  { color: #666; margin: 0 0 24px; font-size: 0.95rem; }
.auth-box a  {
  display: inline-block; padding: 11px 32px;
  background: var(--upsc-navy); color: #fff;
  border-radius: 8px; text-decoration: none;
  font-weight: 600; font-size: 1rem;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.upsc-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--upsc-navy);
  color: #fff;
  display: flex; align-items: center;
  padding: 0 1.5rem; gap: 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.header-title {
  flex: 1; font-size: 1rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header-right { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }

.timer-wrap {
  display: flex; align-items: center; gap: 0.4rem;
  background: rgba(255,255,255,0.15);
  padding: 5px 12px; border-radius: 20px;
  font-weight: 600; font-size: 0.95rem;
}
.timer-wrap.warning { background: var(--upsc-saffron); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.7} }

.user-chip {
  font-size: 0.85rem; opacity: 0.85;
  display: none;
}
@media(min-width:640px){ .user-chip { display: block; } }

.header-btn {
  padding: 6px 14px; border-radius: 6px; border: none;
  font-family: inherit; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: opacity .2s;
}
.header-btn:hover { opacity: .85; }
.btn-submit   { background: var(--upsc-saffron); color: #fff; }
.btn-reset    { background: rgba(255,255,255,0.15); color: #fff; }
.btn-theme    { background: transparent; color: #fff; font-size: 1.1rem; border: none; cursor: pointer; }

/* Font size controls (A-/100%/A+) — .upsc-header's navy background doesn't
   change between light/dark (only --upsc-bg/--upsc-card etc. do), so a
   single white-tint treatment (matching .btn-reset) works unconditionally. */
.font-scale-controls {
  display: flex;
  align-items: center;
  gap: 1px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  overflow: hidden;
}
.font-scale-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 28px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: background .2s;
}
.font-scale-btn:hover:not(:disabled) { background: rgba(255,255,255,0.28); }
.font-scale-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.font-scale-btn[data-role="dec"] { font-size: 0.68rem; }
.font-scale-btn[data-role="inc"] { font-size: 0.95rem; }
.font-scale-btn[data-role="reset"] {
  width: auto;
  padding: 0 6px;
  font-size: 0.6rem;
  font-weight: 600;
  border-left: 1px solid rgba(255,255,255,0.25);
  border-right: 1px solid rgba(255,255,255,0.25);
}

/* ── Start Screen ──────────────────────────────────────────────────────────── */
#start-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - var(--header-h));
  padding: 2rem 1rem;
}
.start-card {
  background: var(--upsc-card);
  border: 1px solid var(--upsc-border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  max-width: 560px; width: 100%;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.start-card h2 { color: var(--upsc-navy); margin-bottom: 1.25rem; font-size: 1.3rem; }
.start-card ul { padding-left: 1.4rem; margin-bottom: 1.5rem; display: flex; flex-direction: column; gap: .55rem; }
.start-card li { font-size: 0.92rem; color: var(--upsc-text); }
.test-meta-row {
  display: flex; gap: .75rem; flex-wrap: wrap;
  margin-bottom: 1.75rem;
}
.meta-tag {
  background: #e8eaf6; color: var(--upsc-navy);
  padding: 4px 12px; border-radius: 20px;
  font-size: 0.8rem; font-weight: 600;
}
.btn-start {
  width: 100%; padding: 13px;
  background: var(--upsc-saffron); color: #fff;
  border: none; border-radius: 8px;
  font-family: inherit; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: background .2s;
}
.btn-start:hover { background: #bf360c; }

/* ── Main Test Layout ──────────────────────────────────────────────────────── */
#test-container {
  display: none;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  gap: 1.5rem;
}
#test-container.visible { display: block; }
@media(min-width:900px){
  #test-container.visible { display: grid; grid-template-columns: 1fr 280px; }
}

/* ── Question Area ─────────────────────────────────────────────────────────── */
.question-area { display: flex; flex-direction: column; gap: 1rem; }

.progress-row {
  display: flex; align-items: center; gap: .75rem;
}
.progress-bar { flex: 1; height: 6px; background: var(--upsc-border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--upsc-saffron); border-radius: 3px; transition: width .3s; }
.progress-label { font-size: 0.8rem; color: var(--upsc-muted); white-space: nowrap; }

.question-card {
  background: var(--upsc-card);
  border: 1px solid var(--upsc-border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.q-meta { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.q-tag {
  font-size: 0.72rem; font-weight: 600;
  padding: 2px 10px; border-radius: 20px;
  background: #e8eaf6; color: var(--upsc-navy);
}
.q-tag.diff-easy   { background: #e8f5e9; color: #2e7d32; }
.q-tag.diff-medium { background: #fff3e0; color: #e65100; }
.q-tag.diff-hard   { background: #fce4ec; color: #c62828; }

.q-number { font-size: 0.8rem; color: var(--upsc-muted); margin-bottom: .5rem; }
.q-text   {
  font-size: 0.97rem; line-height: 1.75;
  margin-bottom: 1.5rem; white-space: pre-line;
}

/* Options */
.options-list { display: flex; flex-direction: column; gap: .75rem; }
.option-btn {
  display: flex; align-items: flex-start; gap: .75rem;
  padding: 0.9rem 1rem;
  border: 2px solid var(--upsc-border);
  border-radius: 8px;
  background: var(--upsc-card);
  cursor: pointer; text-align: left;
  font-family: inherit; font-size: 0.9rem;
  color: var(--upsc-text);
  transition: border-color .15s, background .15s;
  width: 100%;
}
.option-btn:hover { border-color: var(--upsc-navy); background: #f0f4ff; }
.option-btn.selected {
  border-color: var(--upsc-navy);
  background: #e8eaf6;
  font-weight: 600;
}
[data-theme="dark"] .option-btn:hover   { background: #2a2a3a; }
[data-theme="dark"] .option-btn.selected{ background: #1a2040; }

.option-letter {
  min-width: 26px; height: 26px;
  border-radius: 50%; border: 2px solid var(--upsc-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
  flex-shrink: 0; margin-top: 1px;
  background: var(--upsc-bg);
}
.option-btn.selected .option-letter {
  border-color: var(--upsc-navy);
  background: var(--upsc-navy);
  color: #fff;
}

/* Navigation */
.nav-row {
  display: flex; gap: .75rem; justify-content: space-between;
  flex-wrap: wrap;
}
.nav-btn {
  padding: 9px 22px; border-radius: 8px; border: none;
  font-family: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; transition: opacity .2s;
}
.nav-btn:disabled { opacity: .4; cursor: not-allowed; }
.nav-btn.prev  { background: var(--upsc-border); color: var(--upsc-text); }
.nav-btn.mark  { background: #dbeafe; color: #2563eb; }
.nav-btn.mark.active { background: #2563eb; color: #fff; }
.nav-btn.next  { background: var(--upsc-saffron); color: #fff; }

/* ── Palette Sidebar ───────────────────────────────────────────────────────── */
.palette-sidebar {
  background: var(--upsc-card);
  border: 1px solid var(--upsc-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  align-self: start; position: sticky; top: calc(var(--header-h) + 1rem);
  display: none;
}
@media(min-width:900px){ .palette-sidebar { display: block; } }

.palette-title { font-size: 0.95rem; font-weight: 700; color: var(--upsc-navy); margin-bottom: 1rem; }

.palette-legend { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.legend-row { display: flex; align-items: center; gap: .5rem; font-size: 0.75rem; color: var(--upsc-muted); }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

.palette-grid {
  display: grid; grid-template-columns: repeat(5,1fr); gap: 5px;
  margin-bottom: 1rem;
}
.p-item {
  aspect-ratio: 1; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 600;
  cursor: pointer; border: 2px solid transparent;
  transition: transform .1s;
}
.p-item:hover { transform: scale(1.1); }
.p-item.current    { border-color: var(--current-color); }
.p-item.answered   { background: var(--answered-color);   color: #fff; }
.p-item.marked     { background: var(--marked-color);     color: #fff; }
.p-item.unanswered { background: var(--unanswered-color); color: #fff; }
.p-item.unvisited  { background: var(--unvisited-color);  color: #fff; }

.palette-actions { display: flex; flex-direction: column; gap: .5rem; }
.palette-actions .nav-btn { width: 100%; text-align: center; }

/* ── Mobile Bottom Bar ─────────────────────────────────────────────────────── */
.mob-bar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--upsc-card);
  border-top: 1px solid var(--upsc-border);
  padding: 0.6rem 1rem;
  gap: .5rem; justify-content: space-between; align-items: center;
  z-index: 200;
  box-shadow: 0 -2px 10px rgba(0,0,0,.1);
}
@media(max-width:899px){ .mob-bar.visible { display: flex; } }

.mob-btn {
  padding: 8px 14px; border-radius: 8px; border: none;
  font-family: inherit; font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
}
.mob-btn:disabled { opacity: .4; cursor: not-allowed; }
.mob-btn.prev  { background: var(--upsc-border); color: var(--upsc-text); }
.mob-btn.mark  { background: #dbeafe; color: #2563eb; }
.mob-btn.mark.active { background: #2563eb; color: #fff; }
.mob-btn.next  { background: var(--upsc-saffron); color: #fff; }
.mob-palette-btn {
  background: var(--upsc-navy); color: #fff;
  border-radius: 8px; border: none;
  padding: 8px 12px; font-size: 0.8rem; font-weight: 600; cursor: pointer;
}

/* ── Mobile Palette Sheet ──────────────────────────────────────────────────── */
.sheet-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45); z-index: 300;
}
.sheet-backdrop.open { display: block; }

.palette-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--upsc-card);
  border-radius: 16px 16px 0 0;
  padding: 1.25rem 1.25rem 2rem;
  z-index: 400;
  transform: translateY(100%);
  transition: transform .3s ease;
  max-height: 70vh; overflow-y: auto;
}
.palette-sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--upsc-border); margin: 0 auto 1rem;
}
.sheet-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.sheet-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--upsc-muted); }

/* ── Submit Modal ──────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 500;
  align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--upsc-card);
  border-radius: var(--radius);
  padding: 2rem; max-width: 420px; width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.modal-box h3 { color: var(--upsc-navy); margin-bottom: .75rem; }
.modal-box p  { color: var(--upsc-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.modal-stats  {
  background: #f5f5f5; border-radius: 8px; padding: 1rem;
  margin-bottom: 1.25rem;
  display: flex; gap: 1rem;
}
[data-theme="dark"] .modal-stats { background: #2a2a2a; }
.modal-stat { flex: 1; text-align: center; }
.modal-stat-num  { font-size: 1.5rem; font-weight: 700; }
.modal-stat-lbl  { font-size: 0.75rem; color: var(--upsc-muted); }
.modal-stat.correct   .modal-stat-num { color: var(--answered-color); }
.modal-stat.incorrect .modal-stat-num { color: var(--unanswered-color); }
.modal-stat.skipped   .modal-stat-num { color: var(--upsc-muted); }
.modal-btns { display: flex; gap: .75rem; justify-content: flex-end; }
.modal-btns .nav-btn.cancel { background: var(--upsc-border); color: var(--upsc-text); }
.modal-btns .nav-btn.confirm{ background: var(--upsc-saffron); color: #fff; }

/* ── Results Screen ────────────────────────────────────────────────────────── */
#results-container {
  display: none;
  max-width: 860px; margin: 0 auto; padding: 2rem 1rem;
}

.score-card {
  background: var(--upsc-navy); color: #fff;
  border-radius: var(--radius); padding: 2rem;
  text-align: center; margin-bottom: 1.5rem;
}
.score-number { font-size: 3rem; font-weight: 800; }
.score-label  { font-size: 0.9rem; opacity: .8; }
.score-pct    { font-size: 1.1rem; font-weight: 600; margin-top: .25rem; }

.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--upsc-card);
  border: 1px solid var(--upsc-border);
  border-radius: var(--radius); padding: 1rem;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
}
.stat-card .num  { font-size: 2rem; font-weight: 700; }
.stat-card .lbl  { font-size: 0.8rem; color: var(--upsc-muted); }
.stat-card.correct   .num { color: var(--answered-color); }
.stat-card.incorrect .num { color: #c62828; }
.stat-card.skipped   .num { color: var(--upsc-muted); }

.result-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.result-btn {
  padding: 10px 22px; border-radius: 8px; border: none;
  font-family: inherit; font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
}
.result-btn.review  { background: var(--upsc-saffron); color: #fff; }
.result-btn.retake  { background: var(--upsc-navy); color: #fff; }
.result-btn.home    { background: var(--upsc-border); color: var(--upsc-text); }

/* Review Section */
.review-list { display: flex; flex-direction: column; gap: 1.25rem; }
.review-card {
  background: var(--upsc-card);
  border: 1px solid var(--upsc-border);
  border-radius: var(--radius); padding: 1.5rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
}
.review-card.correct   { border-left: 4px solid var(--answered-color); }
.review-card.incorrect { border-left: 4px solid #c62828; }
.review-card.skipped   { border-left: 4px solid var(--upsc-muted); }

.review-header { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.review-icon   { font-size: 1.3rem; }
.review-qnum   { font-weight: 700; font-size: 0.9rem; }
.review-qtext  { font-size: 0.92rem; line-height: 1.7; margin-bottom: 1rem; white-space: pre-line; }

.review-options { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.review-opt {
  padding: 7px 12px; border-radius: 6px;
  font-size: 0.88rem;
  background: var(--upsc-bg);
  border: 1px solid var(--upsc-border);
}
.review-opt.correct-ans { background: #e8f5e9; border-color: var(--answered-color); color: #1b5e20; font-weight: 600; }
.review-opt.user-wrong  { background: #fce4ec; border-color: #c62828; color: #b71c1c; }

.explanation-box {
  background: #fffde7;
  border: 1px solid #f9a825;
  border-radius: 8px; padding: 1rem;
  font-size: 0.88rem; line-height: 1.65;
  color: #333;
}
[data-theme="dark"] .explanation-box { background: #2a2800; border-color: #7a6000; color: #e0d080; }
.explanation-box strong { color: var(--upsc-saffron); }

/* ── Diagrams & images ──────────────────────────────────────────────────────── */
.question-img {
  max-width: 100%; height: auto;
  display: block; margin: .625rem auto;
  border-radius: 6px; border: 1px solid var(--upsc-border);
}

/* option button with diagram: stack letter+text row above the diagram */
.option-btn.has-diagram { flex-direction: column; align-items: stretch; }
.option-row { display: flex; align-items: flex-start; gap: .75rem; }

.option-diagram {
  margin-top: .375rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; background: var(--upsc-bg);
  padding: .2rem; overflow: hidden;
}
.option-diagram svg  { width: 100%; height: auto; min-height: 120px; display: block; }
.option-diagram img,
.option-img          { width: 100%; height: auto; display: block; border-radius: 6px; }

/* options-list 2-col grid when all options carry diagrams */
.options-list.has-diagrams { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

.explanation-diagram { margin-top: .625rem; text-align: center; }
.explanation-diagram svg { max-width: 100%; height: auto; display: inline-block; }
.explanation-img { max-width: 100%; height: auto; display: inline-block; border-radius: 6px; }

/* ── Footer ────────────────────────────────────────────────────────────────── */
.upsc-footer {
  text-align: center; padding: 1.5rem;
  font-size: 0.8rem; color: var(--upsc-muted);
  border-top: 1px solid var(--upsc-border);
  margin-top: 2rem;
}

/* ── Saved-result toast ────────────────────────────────────────────────────── */
.save-toast {
  font-size: 0.88rem; font-weight: 600;
  margin-top: .75rem; padding: 6px 12px;
  border-radius: 6px; display: inline-block;
}
.save-toast.ok  { background: #e8f5e9; color: #2e7d32; }
.save-toast.err { background: #fce4ec; color: #c62828; }
