/* Updated contents/HTML/extra/style.css
   Refactored, accessible, responsive, theme tokens, and dark-mode-ready.
   Replace your previous style.css with this file.
*/

/* ========== THEME / VARIABLES ========== */
:root {
  --bg-100: #eef5ff;
  --bg-200: #f4f7fb;
  --surface: #ffffff;
  --muted: #6b8aa8;
  --text-primary: #07203a;
  --text-secondary: #234;
  --accent-blue-600: #9d00ff;
  --accent-blue-400: #60a5fa;
  --success-100: #ecfccb;
  --success-text: #065f46;
  --danger-100: #fee2e2;
  --danger-text: #7f1d1d;
  --purple-100: #f5f3ff;
  --purple-600: #5d00ff;
  --glass-border: rgba(30, 60, 120, 0.04);
  --card-shadow: 0 20px 50px rgba(16, 24, 40, 0.06);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --transition-fast: 150ms cubic-bezier(0.2, 0.9, 0.25, 1);
  --max-width: 1200px;
  --grid-gap: 20px;
  --ui-padding: 16px;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, "Helvetica Neue", Arial;
  --qgrid-columns-desktop: 5;
  --qgrid-columns-mobile: 8;
}

/* Dark mode tokens (toggle by adding .dark to body) */
body.dark {
  --bg-100: #0b1220;
  --bg-200: linear-gradient(180deg, #071026 0%, #071427 100%);
  --surface: #071427;
  --muted: #9fb6d3;
  --text-primary: #e6eef8;
  --text-secondary: #cfe3fb;
  --glass-border: rgba(255, 255, 255, 0.04);
  --card-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

/* ========== RESET & BASE ========== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  height: 100%;
  margin: 0;
  font-family: var(--font-sans);
  background: linear-gradient(180deg, var(--bg-200), var(--bg-100));
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a {
  color: inherit;
  text-decoration: none;
}
img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

/* ========== TOPBAR ========== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  gap: 12px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.92),
    rgba(248, 252, 255, 0.7)
  );
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(4px);
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.topbar .meta {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Progress pill */
#progressText {
  background: linear-gradient(90deg, #fff, #f7fbff);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
  border: 1px solid rgba(34, 68, 120, 0.06);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.03);
}

/* ========== BUTTONS ========== */
.btn {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(34, 68, 120, 0.06);
  background: var(--surface);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  transition: transform var(--transition-fast),
    box-shadow var(--transition-fast), opacity 0.12s;
  box-shadow: 0 10px 26px rgba(16, 24, 40, 0.04);
}
.btn:active {
  transform: translateY(1px);
}
.btn.small {
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 10px;
}
.btn.primary {
  background: linear-gradient(
    90deg,
    var(--accent-blue-400),
    var(--accent-blue-600)
  );
  color: white;
  border: 0;
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.12);
}
.btn.ghost {
  background: transparent;
  border: 1px dashed rgba(34, 68, 120, 0.06);
}
.btn[disabled],
.btn.disabled {
  opacity: 0.56;
  cursor: not-allowed;
  transform: none;
}
.btn:focus {
  outline: 3px solid rgba(37, 99, 235, 0.08);
  outline-offset: 2px;
}

/* ========== LAYOUT ========== */
.quiz-wrap {
  display: flex;
  gap: var(--grid-gap);
  padding: 26px;
  max-width: 1400px;
  margin: 10px auto;
}
.sidebar {
  width: 350px;
  background: linear-gradient(180deg, var(--surface), #fbfdff);
  border-radius: var(--radius-lg);
  padding: var(--ui-padding);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--glass-border);
  flex-shrink: 0;
}
.content {
  flex: 1;
  min-height: 480px;
}

/* Controls */
.controls {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ========== QUESTION CARD ========== */
.question-card {
  background: linear-gradient(180deg, var(--surface), #fbfdff);
  padding: 22px;
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--glass-border);
  min-height: 420px;
  position: relative;
  overflow: hidden;
  transform-origin: center top;
  animation: cardEntrance 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
}
@keyframes cardEntrance {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.995);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.question-title {
  font-size: 20px;
  margin: 0 0 12px 0;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.28;
}
.question-sub {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Progress bar */
.progressbar-wrap {
  height: 8px;
  width: 100%;
  background: rgba(20, 40, 80, 0.04);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.progressbar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(
    90deg,
    var(--accent-blue-400),
    var(--accent-blue-600)
  );
  transition: width 0.6s cubic-bezier(0.2, 0.9, 0.25, 1);
}

/* ========== OPTIONS ========== */
.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid rgba(18, 36, 64, 0.06);
  background: linear-gradient(180deg, #fff, #fcfeff);
  transition: transform var(--transition-fast),
    box-shadow var(--transition-fast), border-color 0.12s, background 0.12s;
  position: relative;
}
.option:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 36px rgba(16, 24, 40, 0.06);
  border-color: rgba(37, 99, 235, 0.08);
}
.option:focus-within {
  outline: 3px solid rgba(37, 99, 235, 0.08);
  outline-offset: 2px;
}
.option input {
  transform: scale(1.02);
  accent-color: var(--accent-blue-600);
  margin-left: 4px;
}
.option.checked {
  border-color: rgba(37, 99, 235, 0.18);
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.04), #fff);
}

/* Option image */
.option-img {
  display: flex;
  gap: 14px;
  align-items: center;
}
.option-img img {
  width: 110px;
  height: auto;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(16, 24, 40, 0.06);
}

/* ripple (light & perf-friendly) */
.option:active::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(37, 99, 235, 0.06);
  animation: ripple 0.6s forwards;
}
@keyframes ripple {
  to {
    width: 500px;
    height: 500px;
    opacity: 0;
  }
}

/* ========== DRAG & DROP ========== */
.dnd-area {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  align-items: flex-start;
}
.dnd-choices,
.dnd-targets {
  background: linear-gradient(180deg, #fbfdff, #fff);
  padding: 14px;
  border-radius: 12px;
  min-height: 140px;
  border: 1px dashed rgba(37, 99, 235, 0.06);
  flex: 1;
  transition: box-shadow 0.12s, transform 0.12s;
}
.dnd-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid rgba(18, 36, 64, 0.04);
  margin: 10px 0;
  cursor: grab;
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.04);
  transition: transform 0.12s;
}
.dnd-item:active {
  cursor: grabbing;
  transform: scale(0.995);
}
.dnd-item.dragging {
  opacity: 0.78;
  transform: rotate(-2deg) scale(0.98);
  box-shadow: 0 30px 60px rgba(16, 24, 40, 0.08);
}
.target-drop {
  min-height: 44px;
  padding: 8px;
  margin-top: 8px;
  border-radius: 8px;
  background: transparent;
}
.dnd-target.over,
.dnd-target .target-drop.over {
  box-shadow: inset 0 0 0 3px rgba(59, 130, 246, 0.06);
  transform: translateY(-4px);
}
.dnd-item .hint {
  font-size: 12px;
  color: var(--muted);
}

/* ========== EXPLANATIONS & BADGES ========== */
#explain {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff, #fff);
  border: 1px solid rgba(37, 99, 235, 0.06);
  box-shadow: 0 10px 26px rgba(16, 24, 40, 0.03);
}
.correct {
  color: var(--success-text);
  background: linear-gradient(90deg, #e6ffef, #eafaf0);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid rgba(15, 81, 50, 0.08);
}
.incorrect {
  color: var(--danger-text);
  background: linear-gradient(90deg, #fff1f2, #fff7f7);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  border: 1px solid rgba(127, 29, 29, 0.06);
}

/* ========== MODALS & FORM CONTROLS ========== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  background: linear-gradient(
    180deg,
    rgba(9, 14, 30, 0.42),
    rgba(9, 14, 30, 0.52)
  );
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.2, 0.9, 0.2, 1);
}
.modal-inner {
  width: 920px;
  max-width: calc(100% - 40px);
  background: linear-gradient(180deg, var(--surface), #fbfdff);
  border-radius: var(--radius-lg);
  padding: 20px;
  transform: translateY(12px);
  box-shadow: 0 40px 120px rgba(8, 12, 30, 0.5);
  transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.2, 1);
}
.modal.show {
  opacity: 1;
  pointer-events: auto;
}
.modal.show .modal-inner {
  transform: translateY(0);
}
.modal-inner label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.modal-inner input[type="text"],
.modal-inner input[type="number"],
.modal-inner select,
.modal-inner input[type="email"] {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(20, 40, 80, 0.06);
  font-size: 14px;
  background: linear-gradient(180deg, #fff, #fbfdff);
}
.modal-inner form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: rgba(10, 20, 40, 0.96);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  z-index: 100;
  transform: translateY(6px);
  opacity: 0;
  transition: transform 0.18s, opacity 0.18s;
}
.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* ========== SMALL HELPERS ========== */
.hidden {
  display: none !important;
}
.lead {
  color: #294;
  font-weight: 600;
}
.pop-in {
  animation: popIn 0.28s cubic-bezier(0.2, 0.9, 0.25, 1);
}
@keyframes popIn {
  0% {
    transform: scale(0.96);
    opacity: 0;
  }
  60% {
    transform: scale(1.02);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* subtle pulse for correct answers */
@keyframes correctPulse {
  0% {
    transform: scale(0.98);
    opacity: 0.9;
  }
  50% {
    transform: scale(1.03);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.pulse-correct {
  animation: correctPulse 0.5s ease-out;
}

/* ========== QUESTION GRID (1 - 100) ========== */
.question-grid {
  display: grid;
  grid-template-columns: repeat(var(--qgrid-columns-desktop), 1fr);
  gap: 8px;
  max-height: 540px;
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--surface), #fbfdff);
  border: 1px solid var(--glass-border);
}

/* number cell */
.qnum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 36px;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid rgba(18, 36, 64, 0.06);
  background: var(--surface);
  cursor: pointer;
  transition: transform var(--transition-fast),
    box-shadow var(--transition-fast), background 0.12s;
  font-size: 14px;
  color: var(--text-secondary);
}
.qnum:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 30px rgba(16, 24, 40, 0.04);
}
.qnum.disabled {
  opacity: 0.42;
  background: #fafafa;
  border: 1px dashed rgba(20, 40, 80, 0.03);
  cursor: default;
  color: #889;
}

/* answered = green */
.qnum.answered {
  background: linear-gradient(90deg, var(--success-100), #bbf7d0);
  border: 1px solid rgba(16, 185, 129, 0.12);
  color: var(--success-text);
}
/* unanswered = red */
.qnum.unanswered {
  background: linear-gradient(90deg, var(--danger-100), #fee2e2);
  border: 1px solid rgba(239, 68, 68, 0.08);
  color: var(--danger-text);
}
/* marked = purple (visual precedence) */
.qnum.marked {
  background: linear-gradient(90deg, var(--purple-100), #eef2ff);
  border: 1px solid rgba(124, 58, 237, 0.12);
  color: var(--purple-600);
  box-shadow: 0 6px 22px rgba(124, 58, 237, 0.04);
}

/* responsive grid tweaks */
@media (max-width: 1000px) {
  .quiz-wrap {
    flex-direction: column;
    padding: 16px;
    gap: 12px;
  }
  .sidebar {
    width: 100%;
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .question-grid {
    grid-template-columns: repeat(var(--qgrid-columns-mobile), 1fr);
    max-height: 220px;
  }
  .qnum {
    width: 36px;
    height: 30px;
    font-size: 13px;
  }
  .modal-inner {
    width: 100%;
    max-height: 80vh;
    overflow: auto;
  }
}

/* ========== ACCESSIBILITY FOCUS STATES ========== */
/* strong visible focus for keyboard users */
:focus {
  outline: none;
}
.qnum:focus {
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
  transform: translateY(-2px);
}

/* Reduce motion for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

.review-list {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 10px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 22px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
}

.modal-close:hover {
  color: var(--text-primary);
}

#timerDisplay {
  background: linear-gradient(90deg, #fff, #fbfdff);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-secondary);
  border: 1px solid rgba(34,68,120,0.06);
  box-shadow: 0 8px 20px rgba(16,24,40,0.03);
  font-weight: 700;
}
/* highlight active question number in grid */
.qnum.active {
  outline: 2px solid rgba(37, 99, 235, 0.12);
  box-shadow: 0 8px 26px rgba(37,99,235,0.06);
  transform: translateY(-4px);
}

/* selected dropdowns get subtle lift */
select.selected {
  box-shadow: 0 8px 20px rgba(16,24,40,0.04);
  border-color: rgba(37,99,235,0.12);
}

/* ensure checked option label visually different (if not already) */
.option.checked {
  border-color: rgba(37, 99, 235, 0.18);
  background: linear-gradient(180deg, rgba(37,99,235,0.03), #fff);
}
/* greyed-out state after clearing */
.option:not(.checked) {
  background: #ececec !important;
  border-color: #c2c2c2 !important;
  filter: grayscale(0.4);
}

/* ========== LEGACY / COMPAT HELPERS ========== */
/* keep small compatibility with older browsers for :has fallback (we used it in JS) */
