:root {
  --bg: #FFF7ED;
  --card: #FFFFFF;
  --ink: #1F2937;
  --muted: #6B7280;
  --primary: #F97316;
  --primary-dark: #EA580C;
  --soft: #FFEDD5;
  --ok: #16A34A;
  --bad: #DC2626;
  --border: #FDBA74;
  --shadow: 0 10px 30px rgba(249, 115, 22, 0.15);
  --radius: 18px;
  font-family: "Segoe UI", "Nunito", "Comic Sans MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 10% 10%, #FED7AA 0, transparent 35%),
    radial-gradient(circle at 90% 0%, #FDE68A 0, transparent 30%),
    var(--bg);
  color: var(--ink);
}

button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* ===== HOME ===== */
#screen-home {
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#screen-home.active { display: flex; }

.home-card {
  width: min(920px, 100%);
  background: var(--card);
  border: 3px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 24px 32px;
  text-align: center;
}

.mascot {
  font-size: 64px;
  line-height: 1;
  animation: bounce 1.6s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

h1 {
  margin: 8px 0 4px;
  font-size: clamp(28px, 5vw, 42px);
  color: #C2410C;
}
.subtitle { margin: 0; color: var(--muted); font-size: 18px; }
.hint { margin: 18px 0 10px; font-size: 20px; font-weight: 700; }

.exam-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin: 18px 0 22px;
}

.exam-btn {
  border: 3px solid #FDBA74;
  background: linear-gradient(180deg, #FFF7ED, #FFEDD5);
  border-radius: 20px;
  padding: 18px 10px;
  font-size: 20px;
  font-weight: 800;
  color: #9A3412;
  transition: transform .15s ease, box-shadow .15s ease;
}
.exam-btn:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 8px 18px rgba(234, 88, 12, 0.25);
}
.exam-btn span {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.footer-note { color: var(--muted); margin: 0; }

/* ===== BUTTONS ===== */
.btn {
  border: none;
  border-radius: 14px;
  padding: 10px 16px;
  font-weight: 700;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(180deg, #FB923C, #F97316);
  color: white;
  box-shadow: 0 6px 0 #C2410C;
}
.btn.primary:active { box-shadow: 0 2px 0 #C2410C; transform: translateY(3px); }
.btn.soft {
  background: var(--soft);
  color: #9A3412;
  border: 2px solid #FDBA74;
}
.btn.ghost {
  background: white;
  border: 2px solid #FDBA74;
  color: #9A3412;
}
.btn.big { padding: 14px 22px; font-size: 18px; }

/* ===== EXAM ===== */
#screen-exam.active { display: flex; flex-direction: column; height: 100vh; }

.exam-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border-bottom: 3px solid #FED7AA;
  flex-wrap: wrap;
}
.exam-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 800;
  color: #9A3412;
}
.pill {
  background: #FFEDD5;
  color: #C2410C;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
}
.timer {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #FEF3C7;
  border: 2px solid #FCD34D;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.timer.warn {
  background: #FEE2E2;
  border-color: #FCA5A5;
  color: #B91C1C;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}

.exam-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  min-height: 0;
}

.pdf-pane, .answer-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.pdf-pane {
  border-right: 3px solid #FED7AA;
  background: #FFFBEB;
}
.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  flex-wrap: wrap;
  background: white;
  border-bottom: 2px solid #FED7AA;
}
#page-info { font-weight: 700; color: #9A3412; margin: 0 4px; }

.pdf-viewer {
  flex: 1;
  overflow: auto;
  position: relative;
  padding: 12px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
#pdf-canvas {
  max-width: 100%;
  height: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  border-radius: 8px;
  background: white;
}
.pdf-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,247,237,0.85);
  font-size: 22px;
  font-weight: 700;
  color: #C2410C;
}

.answer-pane {
  background: white;
  padding: 12px;
  overflow: hidden;
}
.progress-wrap { margin-bottom: 10px; }
.progress-label { font-weight: 700; margin-bottom: 6px; }
.progress-bar {
  height: 14px;
  background: #FFEDD5;
  border-radius: 999px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #FDBA74, #F97316);
  transition: width .2s ease;
}

.section-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.section-tab {
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
  color: white;
  opacity: 0.75;
}
.section-tab.active { opacity: 1; outline: 3px solid #FED7AA; }

.answer-list {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}
.tip-box {
  background: #DBEAFE;
  border: 2px dashed #60A5FA;
  color: #1D4ED8;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.q-row {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 8px;
  align-items: center;
  background: #FFF7ED;
  border: 2px solid #FED7AA;
  border-radius: 14px;
  padding: 8px;
}
.q-num {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 18px;
}
.q-input {
  width: 100%;
  border: 2px solid #FDBA74;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 20px;
  font-weight: 700;
  outline: none;
  background: white;
}
.q-input:focus {
  border-color: #F97316;
  box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.18);
}
.q-row.filled { background: #ECFDF5; border-color: #6EE7B7; }
.q-row.filled .q-input { border-color: #34D399; }

.answer-actions {
  display: flex;
  gap: 10px;
  padding-top: 12px;
  border-top: 2px solid #FED7AA;
  margin-top: 10px;
}
.answer-actions .btn.primary { flex: 1; }

/* ===== RESULT ===== */
#screen-result.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.result-card {
  width: min(720px, 100%);
  background: white;
  border: 3px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 22px;
  text-align: center;
}
.result-emoji { font-size: 72px; line-height: 1; }
.score-box {
  background: linear-gradient(180deg, #FFF7ED, #FFEDD5);
  border-radius: 20px;
  padding: 18px;
  margin: 16px 0;
  border: 2px solid #FDBA74;
}
.score-main {
  font-size: 56px;
  font-weight: 900;
  color: #C2410C;
  line-height: 1;
}
.score-max { font-size: 28px; color: #9A3412; }
.score-detail { margin-top: 8px; font-size: 18px; font-weight: 700; }
.award-badge {
  display: inline-block;
  margin-top: 12px;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 18px;
}
.award-badge.gold { background: #FEF3C7; color: #92400E; border: 2px solid #F59E0B; }
.award-badge.silver { background: #F3F4F6; color: #374151; border: 2px solid #9CA3AF; }
.award-badge.bronze { background: #FFEDD5; color: #9A3412; border: 2px solid #F97316; }
.award-badge.merit { background: #DBEAFE; color: #1D4ED8; border: 2px solid #60A5FA; }
.award-badge.try { background: #FEE2E2; color: #991B1B; border: 2px solid #F87171; }

.result-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin: 14px 0 18px;
  text-align: left;
}
.break-item {
  background: #FFF7ED;
  border-radius: 12px;
  padding: 10px;
  border: 2px solid #FED7AA;
  font-size: 14px;
}
.break-item strong { display: block; font-size: 18px; }
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== REVIEW ===== */
#screen-review.active { display: flex; flex-direction: column; min-height: 100vh; }
.review-list {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.review-item {
  background: white;
  border-radius: 16px;
  border: 2px solid #FED7AA;
  padding: 12px;
}
.review-item.correct { border-color: #86EFAC; background: #F0FDF4; }
.review-item.wrong { border-color: #FCA5A5; background: #FEF2F2; }
.review-item.empty { border-color: #FCD34D; background: #FFFBEB; }
.review-q {
  font-weight: 800;
  font-size: 18px;
  margin-bottom: 6px;
}
.review-line { font-size: 15px; margin: 3px 0; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.tag.ok { background: #DCFCE7; color: #166534; }
.tag.bad { background: #FEE2E2; color: #991B1B; }
.tag.skip { background: #FEF3C7; color: #92400E; }

/* ===== MODAL ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-card {
  width: min(420px, 100%);
  background: white;
  border-radius: 22px;
  border: 3px solid #FDBA74;
  padding: 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 8px; font-size: 26px; color: #C2410C; }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .exam-body { grid-template-columns: 1fr; }
  .pdf-pane {
    border-right: none;
    border-bottom: 3px solid #FED7AA;
    max-height: 42vh;
  }
  #screen-exam.active { height: auto; min-height: 100vh; }
  .answer-pane { min-height: 55vh; }
}
