/* ================= ROOT ================= */
:root {
  --bg-0: #f5f9ff;
  --bg-1: #e6f0ff;
  --bg-2: #ffffff;
  --card: rgba(255, 255, 255, 0.92);
  --card-strong: rgba(255, 255, 255, 0.98);
  --border: rgba(37, 99, 235, 0.18);
  --primary: #2563eb;
  --primary-2: #0ea5e9;
  --danger: #ef4444;
  --text-main: #0f172a;
  --text-muted: #475569;
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
  --field-bg: #ffffff;
  --field-text: #0f172a;
  --field-placeholder: #94a3b8;
  --header-bg: rgba(255, 255, 255, 0.8);
  --header-border: rgba(37, 99, 235, 0.12);
  --button-secondary-bg: rgba(37, 99, 235, 0.08);
  --button-secondary-border: rgba(37, 99, 235, 0.18);
  --button-secondary-text: #1e3a8a;
  --ghost-bg: rgba(37, 99, 235, 0.08);
  --ghost-border: rgba(37, 99, 235, 0.18);
  --ghost-text: #1e3a8a;
  --pill-bg: rgba(37, 99, 235, 0.12);
  --timer-bg: rgba(37, 99, 235, 0.18);
  --score-bg: rgba(37, 99, 235, 0.12);
  --grid-sheet-bg: rgba(255, 255, 255, 0.95);
  --legend-bg: rgba(37, 99, 235, 0.08);
  --review-card-bg: rgba(37, 99, 235, 0.06);
}

body.theme-dark {
  --bg-0: #0b1020;
  --bg-1: #0f172a;
  --bg-2: #09101f;
  --card: rgba(255, 255, 255, 0.08);
  --card-strong: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.12);
  --primary: #4f46e5;
  --primary-2: #22c55e;
  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --shadow: 0 24px 60px rgba(2, 6, 23, 0.55);
  --field-bg: rgba(15, 23, 42, 0.85);
  --field-text: #f9fafb;
  --field-placeholder: #9ca3af;
  --header-bg: rgba(4, 8, 23, 0.92);
  --header-border: rgba(255, 255, 255, 0.06);
  --button-secondary-bg: rgba(255, 255, 255, 0.08);
  --button-secondary-border: rgba(255, 255, 255, 0.06);
  --button-secondary-text: var(--text-main);
  --ghost-bg: rgba(255, 255, 255, 0.08);
  --ghost-border: rgba(255, 255, 255, 0.08);
  --ghost-text: var(--text-main);
  --pill-bg: rgba(255, 255, 255, 0.12);
  --timer-bg: rgba(79, 70, 229, 0.25);
  --score-bg: rgba(79, 70, 229, 0.15);
  --grid-sheet-bg: rgba(14, 19, 38, 0.96);
  --legend-bg: rgba(255, 255, 255, 0.08);
  --review-card-bg: rgba(255, 255, 255, 0.06);
}

/* ================= RESET ================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Sora", "Noto Sans Devanagari", sans-serif;
}

body {
  min-height: 100vh;
  color: var(--text-main);
  background:
    radial-gradient(1200px 600px at 10% -10%, #dbeafe, transparent 55%),
    radial-gradient(1000px 500px at 90% 10%, #bfdbfe, transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-2) 70%);
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(37, 99, 235, 0.12) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}

body.theme-dark {
  background:
    radial-gradient(1200px 600px at 10% -10%, #1e2b55, transparent 55%),
    radial-gradient(1000px 500px at 90% 10%, #133a3a, transparent 55%),
    linear-gradient(160deg, var(--bg-0), var(--bg-2) 70%);
}

body.theme-dark::before {
  background-image: radial-gradient(rgba(255,255,255,0.06) 1px, transparent 1px);
}

/* ================= LOADER ================= */
#loader {
  position: fixed;
  inset: 0;
  background: var(--bg-0);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeOut 1s ease 1.5s forwards;
}

.loader-circle {
  width: 60px;
  height: 60px;
  border: 4px solid var(--card);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

#loader p {
  margin-top: 15px;
  color: var(--text-muted);
}

/* ================= PAGES ================= */
.page {
  display: none;
  min-height: calc(100vh - 60px);
  padding: 96px 20px 80px;
  animation: slideUp 0.6s ease;
  position: relative;
  z-index: 1;
}

.page.active {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}

#testPage {
  padding-top: 74px;
}

/* ================= CARDS ================= */
.glass-card,
.question-card,
.result-card {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(
    145deg,
    rgba(255,255,255,0.12),
    rgba(255,255,255,0.04)
  );
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.center-title {
  text-align: center;
}

/* ================= START PAGE ================= */
.app-title {
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.4px;
}

.subtitle {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  margin: 8px 0 25px;
}

.input-group {
  margin-bottom: 18px;
}

label {
  font-size: 13px;
  color: var(--text-muted);
}

input,
select {
  width: 100%;
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--field-bg);
  color: var(--field-text);
  outline: none;
  font-size: 15px;
}

input::placeholder {
  color: var(--field-placeholder);
}

select option {
  background: var(--field-bg);
  color: var(--field-text);
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79,70,229,0.35);
}

/* ================= BUTTONS ================= */
.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn {
  padding: 14px 16px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.25s ease;
  letter-spacing: 0.2px;
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #fff;
  margin-top: 10px;
  box-shadow: 0 12px 24px rgba(79,70,229,0.45);
}

.primary-btn:hover {
  transform: translateY(-2px);
}

.secondary-btn {
  flex: 1;
  background: var(--button-secondary-bg);
  color: var(--button-secondary-text);
  border: 1px solid var(--button-secondary-border);
}

.secondary-btn:hover {
  background: rgba(37, 99, 235, 0.16);
}

.danger-btn {
  flex: 1;
  background: rgba(239,68,68,0.2);
  color: #fecaca;
}

.danger-btn:hover {
  background: rgba(239,68,68,0.35);
}

.ghost-btn {
  background: var(--ghost-bg);
  color: var(--ghost-text);
  border: 1px solid var(--ghost-border);
  padding: 8px 12px;
  font-size: 12px;
}

.ghost-btn:hover {
  background: rgba(37, 99, 235, 0.18);
}

/* ================= NOTE ================= */
.note {
  margin-top: 15px;
  font-size: 13px;
  text-align: center;
  color: var(--text-muted);
}

/* ================= TEST PAGE ================= */
.test-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 10;
  border-bottom: 1px solid var(--header-border);
}

.test-header .right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.timer-box {
  background: var(--timer-bg);
  padding: 6px 12px;
  border-radius: 18px;
  animation: pulse 1.4s infinite;
  font-weight: 600;
}

.progress-wrap {
  width: 100%;
  max-width: 520px;
  height: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  margin-top: 90px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #4f46e5);
  transition: width 0.3s ease;
}

.status-row {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
}

.pill {
  background: var(--pill-bg);
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-main);
  font-size: 12px;
}

.pill.marked {
  background: rgba(234,179,8,0.22);
  color: #fde68a;
}

/* ================= QUESTION ================= */
.question-card h2 {
  font-size: 17px;
  margin-bottom: 20px;
  line-height: 1.6;
}

.options button {
  width: 100%;
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid var(--border);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.options button:hover {
  background: rgba(37, 99, 235, 0.16);
  transform: translateY(-1px);
}

.options button.selected {
  background: rgba(34,197,94,0.2);
  border-color: rgba(34,197,94,0.6);
}

/* ================= ACTION BAR ================= */
.action-bar {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  width: 100%;
  max-width: 520px;
}

.review-actions {
  max-width: 900px;
}

.review-shell .glass-card {
  max-width: 520px;
}

.review-shell .review-page {
  margin-top: 10px;
}

/* ================= QUESTION GRID ================= */
.grid-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
}

.grid-overlay.hidden {
  display: none;
}

.grid-sheet {
  width: 100%;
  max-width: 640px;
  background: var(--grid-sheet-bg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: slideUp 0.35s ease;
}

.grid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.grid-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  font-size: 12px;
}

.legend-item {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--legend-bg);
}

.legend-item.answered {
  background: rgba(34,197,94,0.2);
  color: #bbf7d0;
}

.legend-item.marked {
  background: rgba(234,179,8,0.2);
  color: #fde68a;
}

.legend-item.empty {
  background: rgba(148,163,184,0.2);
  color: #e2e8f0;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 10px;
}

.grid-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: #e2e8f0;
  padding: 10px 0;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s ease;
}

.grid-btn:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,0.12);
}

.grid-btn.answered {
  background: rgba(34,197,94,0.24);
  border-color: rgba(34,197,94,0.6);
}

.grid-btn.marked {
  background: rgba(234,179,8,0.24);
  border-color: rgba(234,179,8,0.6);
}

.grid-btn.current {
  outline: 2px solid rgba(99,102,241,0.8);
}

/* ================= RESULT ================= */
.result-card h1 {
  text-align: center;
  margin-bottom: 15px;
}

.result-card p {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.score-box {
  margin: 20px 0;
  padding: 20px;
  border-radius: 14px;
  background: var(--score-bg);
  text-align: center;
}

.score-box h2 {
  font-size: 30px;
}

.score-box p {
  font-size: 18px;
  color: var(--text-muted);
}

.result-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.breakdown-item {
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.breakdown-item strong {
  display: block;
  font-size: 18px;
  color: var(--text-main);
  margin-top: 4px;
}

body.theme-dark .options button {
  background: rgba(255, 255, 255, 0.08);
}

body.theme-dark .options button:hover {
  background: rgba(79, 70, 229, 0.2);
}

body.theme-dark .breakdown-item {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.06);
}

body.theme-dark .grid-sheet {
  border-color: rgba(255, 255, 255, 0.08);
}

html {
  scroll-behavior: smooth;
}

button,
.glass-card,
.question-card,
.result-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* ================= REVIEW PAGE ================= */
.review-page {
  width: 100%;
  max-width: 900px;
  margin: 20px auto;
  padding: 20px;
  box-sizing: border-box;
}

.review-card {
  width: 100%;
  background: var(--review-card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
  box-sizing: border-box;
}

.review-card h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.review-option {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 14px;
}

.review-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(234,179,8,0.2);
  color: #fde68a;
}

.correct {
  background: rgba(34,197,94,0.25);
  border: 1px solid rgba(34,197,94,0.6);
}

.wrong {
  background: rgba(239,68,68,0.25);
  border: 1px solid rgba(239,68,68,0.6);
}

.right-answer {
  background: rgba(59,130,246,0.25);
  border: 1px dashed rgba(59,130,246,0.7);
}

.not-attempted {
  background: rgba(107,114,128,0.25);
  border: 1px dashed rgba(156,163,175,0.6);
}

/* ================= FOOTER ================= */
footer {
  text-align: center;
  padding: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ================= APP HEADER ================= */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 12;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.app-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18);
}

.app-name {
  font-size: 14px;
  color: var(--text-main);
}

.app-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

body.in-test .app-header {
  display: none;
}

/* ================= THEME TOGGLE ================= */
.theme-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-strong);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.theme-switch input {
  display: none;
}

.switch-track {
  width: 42px;
  height: 22px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.25);
  position: relative;
  transition: background 0.2s ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
  transition: transform 0.2s ease, background 0.2s ease;
}

.theme-switch input:checked + .switch-track {
  background: rgba(100, 116, 139, 0.5);
}

.theme-switch input:checked + .switch-track::after {
  transform: translateX(20px);
  background: #0b1020;
}

.switch-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.theme-switch.compact {
  background: transparent;
  border: none;
  padding: 0;
}

.theme-switch.compact .switch-label {
  display: none;
}

/* ================= PRINT ================= */
@media print {
  body {
    background: #ffffff;
    color: #000000;
  }

  #loader,
  .app-header,
  footer,
  .test-header,
  #gridOverlay {
    display: none !important;
  }

  .page {
    display: none !important;
    padding: 0 !important;
  }

  #resultPage {
    display: block !important;
  }

  body[data-page="review"] .page {
    display: block !important;
  }

  .result-card {
    max-width: 100% !important;
    box-shadow: none !important;
    border: 1px solid #d1d5db !important;
    background: #ffffff !important;
  }

  .action-bar button {
    display: none !important;
  }
}

/* ================= ANIMATIONS ================= */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(79,70,229,0.5); }
  70% { box-shadow: 0 0 0 12px rgba(79,70,229,0); }
  100% { box-shadow: 0 0 0 0 rgba(79,70,229,0); }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* ================= RESPONSIVE ================= */
@media (max-width: 600px) {
  body {
    font-size: 15px;
  }

  .page {
    padding: 20px 14px 80px;
  }

  .glass-card,
  .question-card,
  .result-card {
    max-width: 100%;
    border-radius: 16px;
    padding: 22px 18px;
  }

  .app-title {
    font-size: 20px;
  }

  .subtitle {
    font-size: 13px;
  }

  input,
  select {
    font-size: 16px;
    padding: 14px;
    border-radius: 12px;
  }

  .primary-btn,
  .secondary-btn,
  .danger-btn {
    padding: 15px;
    font-size: 15px;
    border-radius: 14px;
  }

  .test-header {
    height: 58px;
    padding: 0 14px;
  }

  .timer-box {
    padding: 6px 10px;
    font-size: 13px;
  }

  .progress-wrap,
  .status-row,
  .action-bar {
    max-width: 100%;
  }

  .question-card h2 {
    font-size: 16px;
  }

  .options button {
    padding: 15px;
    font-size: 15px;
  }

  .action-bar {
    flex-direction: column;
  }

  .score-box h2 {
    font-size: 24px;
  }

  .score-box p {
    font-size: 16px;
  }

  .app-header {
    height: 58px;
    padding: 0 14px;
  }

  footer {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
