/* ===== Theme Variables ===== */
:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: rgba(15, 23, 42, 0.08);
}

body.dark {
  --bg: #0f172a;
  --card: #111827;
  --primary: #3b82f6;
  --primary-dark: #1d4ed8;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #1f2937;
  --shadow: rgba(0, 0, 0, 0.25);
}

/* ===== Base ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: "Poppins", "Segoe UI", Tahoma, sans-serif;
  background: radial-gradient(circle at 20% 20%, #e8f0ff, transparent 50%),
              radial-gradient(circle at 80% 0%, #f7fbff, transparent 60%),
              var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
}

/* ===== Layout ===== */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 18px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 20px var(--shadow);
}

.title {
  font-weight: 700;
  font-size: 18px;
}

.subtitle {
  font-size: 13px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 10px;
}

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 15px 35px var(--shadow);
}

/* ===== Meta ===== */
.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-bar {
  width: 280px;
  height: 10px;
  border-radius: 8px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  transition: width 0.4s ease;
}

.progress-text {
  color: var(--muted);
  font-weight: 600;
}

.timer {
  text-align: right;
}

.timer-label {
  font-size: 12px;
  color: var(--muted);
}

.timer-value {
  font-size: 20px;
  font-weight: 700;
}

/* ===== Animated Circle ===== */
.circle-wrap {
  position: relative;
  width: 120px;
  height: 120px;
}

.progress-circle {
  transform: rotate(-90deg);
}

.progress-circle circle {
  fill: none;
  stroke-width: 10;
}

.progress-circle .bg {
  stroke: var(--border);
}

.progress-circle .fg {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset 0.4s ease;
}

.circle-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
}

/* ===== Quiz ===== */
.question-box {
  margin: 18px 0;
}

.question-text {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.5;
}

.options {
  display: grid;
  gap: 12px;
}

.option {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

body.dark .option {
  background: #0b1220;
}

.option:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.option.selected {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
}

.nav {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
}

/* ===== Buttons ===== */
.btn {
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== Result ===== */
.hidden { display: none !important; }

.result {
  padding-top: 10px;
}

.score-area {
  display: flex;
  align-items: center;
  gap: 26px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.score-circle {
  position: relative;
  width: 160px;
  height: 160px;
}

.score-ring {
  transform: rotate(-90deg);
}

.score-ring circle {
  fill: none;
  stroke-width: 12;
}

.score-ring .bg {
  stroke: var(--border);
}

.score-ring .fg {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 427;
  stroke-dashoffset: 427;
  transition: stroke-dashoffset 0.6s ease;
}

.score-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 700;
}

.score-title {
  font-size: 20px;
  font-weight: 700;
}

.score-desc {
  color: var(--muted);
  margin: 8px 0 12px;
}

.analysis h3 {
  margin-bottom: 10px;
}

.analysis-list {
  display: grid;
  gap: 12px;
}

.analysis-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.analysis-item .q {
  font-weight: 600;
  margin-bottom: 6px;
}

.analysis-item .answer {
  margin: 4px 0;
}

.correct {
  color: var(--success);
  font-weight: 600;
}

.wrong {
  color: var(--danger);
  font-weight: 600;
}

/* ===== Certificate ===== */
.field {
  display: grid;
  gap: 6px;
  margin: 8px 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.certificate {
  margin-top: 24px;
}

.certificate-container {
  width: min(100%, 920px);
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  padding: clamp(18px, 3.2vw, 38px) clamp(24px, 4.5vw, 52px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.2vw, 12px);
  text-align: center;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 38px rgba(15, 23, 42, 0.22);
  background-image:
    linear-gradient(to bottom, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.16)),
    url("quiz.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: #1f2937;
}

.certificate-header {
  font-family: "Cairo", sans-serif;
  font-size: clamp(11px, 1.3vw, 15px);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5b3a1b;
}

.certificate-title {
  font-family: "Pinyon Script", cursive;
  font-size: clamp(33px, 5.7vw, 72px);
  line-height: 1;
  color: #6b2f16;
  margin-top: clamp(2px, 0.6vw, 6px);
}

.certificate-name {
  display: inline-block;
  max-width: 90%;
  overflow-wrap: anywhere;
}

.certificate-subtitle {
  font-family: "Great Vibes", cursive;
  font-size: clamp(17px, 2.5vw, 32px);
  color: #7a5633;
  line-height: 1.08;
}

.certificate-content {
  font-family: "Cairo", sans-serif;
  font-size: clamp(15px, 2.1vw, 26px);
  color: #2d3748;
  line-height: 1.25;
}

.certificate-content strong {
  font-weight: 700;
}

.certificate-footer {
  margin-top: clamp(8px, 1.8vw, 18px);
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, 1.3vw, 16px);
  font-family: "Cairo", sans-serif;
  font-size: clamp(11px, 1.3vw, 15px);
  color: #5f3d1e;
}

.certificate-footer span {
  display: block;
  margin-top: 3px;
  font-size: clamp(12px, 1.5vw, 17px);
  font-weight: 700;
  color: #111827;
}

.certificate-card {
  position: relative;
  padding: 28px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: linear-gradient(140deg, rgba(37, 99, 235, 0.08), transparent 50%),
              linear-gradient(320deg, rgba(96, 165, 250, 0.12), transparent 50%),
              var(--card);
  overflow: hidden;
}

.cert-header {
  text-align: center;
  margin-bottom: 10px;
}

.cert-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 8px;
}

.cert-title {
  font-size: 24px;
  font-weight: 700;
}

.cert-sub {
  color: var(--muted);
  margin-top: 6px;
}

.cert-name {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  margin: 14px 0;
}

.cert-body {
  text-align: center;
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 16px;
}

.cert-course {
  font-weight: 700;
}

.cert-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.cert-sign {
  margin-top: 24px;
  text-align: right;
}

.cert-sign .line {
  height: 2px;
  background: var(--text);
  width: 200px;
  margin-left: auto;
  opacity: 0.5;
}

.cert-sign .label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.cert-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-18deg);
  font-size: 140px;
  font-weight: 700;
  color: var(--text);
  opacity: 0.06;
  pointer-events: none;
}

.cert-buttons {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: grid;
  place-items: center;
}

.modal-content {
  background: var(--card);
  padding: 20px;
  border-radius: 12px;
  width: min(92%, 360px);
  box-shadow: 0 15px 30px var(--shadow);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  justify-content: flex-end;
}

/* ===== RTL Support ===== */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] .nav {
  flex-direction: row-reverse;
}

[dir="rtl"] .progress-wrap {
  flex-direction: row-reverse;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .progress-bar { width: 180px; }
  .meta-right {
    display: flex;
    align-items: center;
    gap: 14px;
  }
  .timer { text-align: left; }
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .nav {
    flex-direction: column;
    gap: 10px;
  }
  .certificate-container {
    aspect-ratio: 3 / 4;
    padding: 16px 14px 18px;
    gap: 6px;
  }
  .certificate-footer {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-top: 6px;
  }
}

/* ===== Print ===== */
@media print {
  body {
    background: #fff;
  }
  .topbar,
  .meta,
  .quiz,
  .result,
  .analysis,
  .nav,
  .controls,
  .modal,
  .cert-buttons {
    display: none !important;
  }
  .card {
    box-shadow: none;
    padding: 0;
  }
  .certificate {
    display: block !important;
  }
  .certificate-card {
    border: 2px solid #000;
  }
}
