/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --navy: #1a2a4a;
  --navy-light: #24365c;
  --warm-white: #f8f6f0;
  --gold: #c8a84b;
  --gold-soft: rgba(200, 168, 75, 0.16);
  --success: #2d6a4f;
  --danger: #c1121f;
  --text-on-navy: #f2efe6;
  --text-muted: #6b7280;
  --text-on-navy-muted: rgba(242, 239, 230, 0.72);

  --font: "Cairo", "Segoe UI", sans-serif;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;

  --radius: 14px;
  --radius-sm: 8px;
  --shadow-card: 0 20px 50px -20px rgba(26, 42, 74, 0.45);

  /* Girih-inspired lattice: a quiet nod to the subject, never used on the
     working exam screen — only on the calmer bookend moments. */
  --pattern:
    repeating-linear-gradient(45deg, rgba(200, 168, 75, 0.07) 0, rgba(200, 168, 75, 0.07) 1px, transparent 1px, transparent 34px),
    repeating-linear-gradient(-45deg, rgba(200, 168, 75, 0.07) 0, rgba(200, 168, 75, 0.07) 1px, transparent 1px, transparent 34px);
}

/* ==========================================================================
   Reset
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background-color: var(--navy);
  background-image: var(--pattern);
  color: var(--navy);
  min-height: 100vh;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p,
ul {
  margin: 0;
}

button {
  font-family: inherit;
}

input {
  font-family: inherit;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ==========================================================================
   Page shell + transitions
   ========================================================================== */
.page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  animation: fade-in 0.25s ease-out;
}

/* Author-origin display rules beat the UA [hidden] rule regardless of
   specificity, so every page needs its own display explicitly turned off
   when hidden — otherwise toggling the `hidden` attribute from JS no-ops. */
.page[hidden] {
  display: none;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.card {
  width: 100%;
  max-width: 640px;
  background: var(--warm-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  border-top: 4px solid var(--gold);
  padding: var(--space-7) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.card h1,
.card h2 {
  color: var(--navy);
}

.card > header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  text-align: center;
}

.card > header .exam-title {
  font-size: 1.75rem;
  font-weight: 800;
}

.card > header .exam-description {
  color: var(--text-muted);
  font-size: 1rem;
}

.card > header .exam-total-score {
  font-weight: 700;
  color: var(--gold);
}

/* ==========================================================================
   Loading
   ========================================================================== */
#page-loading {
  flex-direction: column;
  gap: var(--space-4);
  color: var(--text-on-navy);
}

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(242, 239, 230, 0.25);
  border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Status badges / countdowns
   ========================================================================== */
#page-not-started .card,
#page-expired-global .card {
  text-align: center;
  align-items: center;
}

.status-badge {
  display: inline-block;
  padding: var(--space-2) var(--space-5);
  border-radius: 999px;
  background: var(--gold-soft);
  color: #7a611f;
  font-weight: 700;
}

.status-badge.danger {
  background: rgba(193, 18, 31, 0.12);
  color: var(--danger);
}

.countdown {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--navy);
  letter-spacing: 0.02em;
}

/* ==========================================================================
   Landing
   ========================================================================== */
.exam-meta {
  background: rgba(26, 42, 74, 0.04);
  border-radius: var(--radius-sm);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 0.95rem;
}

.meta-row span {
  color: var(--text-muted);
}

.time-remaining-label {
  margin-top: var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px dashed rgba(26, 42, 74, 0.15);
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.instructions h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: var(--space-3);
}

.instructions ul {
  padding-inline-start: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  font-size: 0.92rem;
  color: var(--navy);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn-primary,
.btn-secondary {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

.btn-primary {
  background: var(--navy);
  color: var(--warm-white);
  padding: var(--space-3) var(--space-5);
}

.btn-primary:hover {
  background: var(--navy-light);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-large {
  padding: var(--space-4) var(--space-5);
  font-size: 1.05rem;
}

.btn-secondary {
  background: transparent;
  color: var(--navy);
  border: 1.5px solid rgba(26, 42, 74, 0.25);
  padding: var(--space-3) var(--space-5);
}

.btn-secondary:hover {
  border-color: var(--navy);
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-icon {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 1.25rem;
  cursor: pointer;
  display: none;
  padding: var(--space-2);
}

/* ==========================================================================
   Registration form
   ========================================================================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-group label,
.form-group-label {
  font-weight: 700;
  font-size: 0.92rem;
}

.form-group input {
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid rgba(26, 42, 74, 0.2);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: #fff;
  color: var(--navy);
}

.form-group input:focus {
  border-color: var(--gold);
}

.gender-options {
  display: flex;
  gap: var(--space-3);
}

.gender-option {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid rgba(26, 42, 74, 0.2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: #fff;
  font-weight: 400;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.gender-option:has(input:checked) {
  border-color: var(--navy);
  background: var(--gold-soft);
}

.gender-option input[type="radio"] {
  accent-color: var(--navy);
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  flex-shrink: 0;
}

.field-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.error-message {
  background: rgba(193, 18, 31, 0.08);
  color: var(--danger);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
}

/* ==========================================================================
   EXAM_IN_PROGRESS
   ========================================================================== */
#page-exam {
  flex-direction: column;
  min-height: 100vh;
  padding: 0;
  align-items: stretch;
  justify-content: flex-start;
}

.exam-header {
  background: var(--navy);
  color: var(--text-on-navy);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.exam-header-title {
  font-size: 1rem;
  font-weight: 700;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exam-timer {
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: rgba(242, 239, 230, 0.1);
  padding: var(--space-2) var(--space-4);
  border-radius: 999px;
  letter-spacing: 0.03em;
}

.exam-timer.timer-warning {
  background: var(--danger);
  color: #fff;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.exam-candidate-name {
  font-size: 0.9rem;
  color: var(--text-on-navy-muted);
}

.exam-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 280px;
  align-items: start;
  background: var(--warm-white);
}

.sidebar {
  order: 2;
  background: rgba(26, 42, 74, 0.03);
  border-inline-start: 1px solid rgba(26, 42, 74, 0.1);
  padding: var(--space-5);
  min-height: 100%;
}

.sidebar h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: var(--space-4);
}

.sidebar-section {
  margin-bottom: var(--space-5);
}

.sidebar-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.sidebar-circles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.q-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid rgba(26, 42, 74, 0.25);
  background: #fff;
  color: var(--navy);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.q-circle:hover {
  transform: scale(1.08);
}

.q-circle.q-answered {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--navy);
}

.q-circle.q-current {
  border-color: var(--navy);
  border-width: 2.5px;
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.sidebar-overlay {
  display: none;
}

.question-area {
  order: 1;
  padding: var(--space-6) var(--space-6);
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.section-title {
  color: var(--gold);
  font-weight: 700;
  font-size: 0.9rem;
}

.question-progress {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.question-text {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: var(--space-2);
}

.answers-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.answer-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1.5px solid rgba(26, 42, 74, 0.15);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: #fff;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}

.answer-option:hover {
  border-color: var(--gold);
}

.answer-option.selected {
  border-color: var(--navy);
  background: var(--gold-soft);
}

.answer-option input[type="radio"] {
  accent-color: var(--navy);
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.answer-option span {
  font-size: 1rem;
}

.question-nav {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-5);
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 42, 74, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-4);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--warm-white);
  border-radius: var(--radius);
  padding: var(--space-6);
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  box-shadow: var(--shadow-card);
}

.modal p {
  font-size: 1rem;
  color: var(--navy);
  line-height: 1.8;
}

.modal-actions {
  display: flex;
  gap: var(--space-3);
}

.modal-actions button {
  flex: 1;
}

/* ==========================================================================
   Toast / offline banner
   ========================================================================== */
.toast {
  position: fixed;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: var(--text-on-navy);
  padding: var(--space-3) var(--space-5);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
}

.toast[hidden] {
  display: none;
}

.offline-banner {
  position: fixed;
  top: 0;
  inset-inline: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: var(--space-2) var(--space-4);
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 200;
}

.offline-banner[hidden] {
  display: none;
}

/* ==========================================================================
   Completion pages
   ========================================================================== */
#page-completed .card,
#page-time-up .card {
  text-align: center;
  align-items: center;
}

.completion-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  background: rgba(45, 106, 79, 0.12);
  color: var(--success);
}

.completion-icon.clock {
  background: rgba(26, 42, 74, 0.08);
  color: var(--navy);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1024px) {
  .exam-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: -1;
    position: fixed;
    top: 0;
    bottom: 0;
    inset-inline-end: 0;
    width: min(320px, 85vw);
    transform: translateX(100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
    z-index: 50;
    background: var(--warm-white);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.15);
  }

  html[dir="rtl"] .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(26, 42, 74, 0.4);
    z-index: 40;
  }

  .btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 640px) {
  .card {
    padding: var(--space-6) var(--space-4);
  }

  .question-area {
    padding: var(--space-5) var(--space-4);
  }

  .exam-header {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-2);
  }

  .exam-header-title {
    font-size: 0.85rem;
  }

  .exam-timer {
    font-size: 1rem;
    padding: var(--space-1) var(--space-3);
  }

  .exam-candidate-name {
    display: none;
  }

  .meta-row {
    flex-direction: column;
    gap: var(--space-1);
  }

  .question-nav {
    flex-direction: column-reverse;
    gap: var(--space-3);
  }

  .question-nav button {
    width: 100%;
  }
}
