* { box-sizing: border-box; }

/* Atribut hidden harus selalu menang atas display dari class (mis. .modal
   memakai display:flex). Tanpa ini, modal konfirmasi selalu tampil dan
   tombol Batal tidak bisa menutupnya. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: #1f2937;
  background: #f3f4f6;
}

h1 { font-size: 1.6rem; margin: 0 0 12px; color: #111827; }
h2 { font-size: 1.15rem; margin: 24px 0 10px; color: #111827; }
p { margin: 0 0 12px; }

/* ---------- Topbar & timer ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  background: #16283f; color: #fff;
  padding: 10px 16px;
}
.brand { font-weight: 700; font-size: 1.05rem; }
.timer {
  font-size: 1.5rem; font-weight: 700; letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  background: #0f1d2e; border: 1px solid #2d4a68;
  padding: 2px 14px; border-radius: 8px;
}
.timer.danger { color: #fca5a5; border-color: #b91c1c; }

/* ---------- Layout ---------- */
main { max-width: 1020px; margin: 0 auto; padding: 20px 16px 48px; }
.view { background: #fff; border-radius: 12px; padding: 22px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.lead { font-size: 1.05rem; color: #374151; }
.note { font-size: .92rem; color: #6b7280; }
.note.center { text-align: center; }

/* ---------- Pemilih sesi ---------- */
.session-picker {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0 6px;
}
.session-card {
  font: inherit; cursor: pointer; text-align: left;
  background: #f9fafb; border: 1.5px solid #d1d5db; border-radius: 10px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.session-card:hover { border-color: #1d4ed8; }
.session-card.selected { background: #dbeafe; border-color: #1d4ed8; }
.session-card .s-num { font-weight: 800; font-size: 1.05rem; color: #111827; }
.session-card .s-desc { font-size: .9rem; color: #4b5563; }
.session-card .s-progress {
  font-size: .82rem; font-weight: 700; color: #92400e;
  background: #fef3c7; border: 1px solid #f59e0b; border-radius: 999px;
  padding: 2px 10px; margin-top: 6px; align-self: flex-start;
}

/* ---------- Start view ---------- */
.notice {
  background: #fef9c3; border: 1px solid #eab308; border-radius: 8px;
  padding: 12px 14px; margin: 16px 0;
}
.info-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 18px 0;
}
.info-card {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 10px;
  padding: 12px 6px; text-align: center;
}
.info-card .num { display: block; font-size: 1.5rem; font-weight: 800; color: #1d4ed8; }
.info-card .lbl { font-size: .85rem; color: #374151; }
.pg-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.pg-table th, .pg-table td { border: 1px solid #d1d5db; padding: 8px 10px; text-align: left; }
.pg-table th { background: #f9fafb; }
.start-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 24px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; cursor: pointer; border-radius: 8px;
  border: 1px solid transparent; padding: 10px 18px;
  min-height: 44px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: #1d4ed8; color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1e40af; }
.btn.secondary { background: #e5e7eb; color: #111827; }
.btn.secondary:hover:not(:disabled) { background: #d1d5db; }
.btn.warn { background: #fef3c7; color: #92400e; border-color: #f59e0b; }
.btn.warn.active { background: #f59e0b; color: #fff; }
.btn.danger-outline { background: #fff; color: #b91c1c; border-color: #b91c1c; }
.btn.big { font-size: 1.05rem; padding: 12px 28px; }
.btn.block { width: 100%; margin-top: 10px; }
.btn.small { padding: 6px 14px; min-height: 38px; }
.btn.small.active { background: #1d4ed8; color: #fff; }
.link-btn {
  background: none; border: none; color: #1d4ed8; cursor: pointer;
  font: inherit; font-size: .9rem; padding: 4px 6px;
}

/* ---------- Exam view ---------- */
.exam-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.q-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
#q-number { font-weight: 700; }
.badge {
  display: inline-block; font-size: .8rem; font-weight: 700;
  padding: 2px 10px; border-radius: 999px; color: #fff;
}
.badge.cat-twk { background: #1d4ed8; }
.badge.cat-tiu { background: #047857; }
.badge.cat-tkp { background: #7c3aed; }
.q-sub { font-size: .9rem; color: #6b7280; }
.q-text { font-size: 1.08rem; font-weight: 600; color: #111827; white-space: pre-wrap; }

.options { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 20px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  font: inherit; cursor: pointer; width: 100%;
  background: #f9fafb; border: 1.5px solid #d1d5db; border-radius: 10px;
  padding: 12px 14px; min-height: 48px;
}
.option:hover { border-color: #1d4ed8; }
.option.chosen { background: #dbeafe; border-color: #1d4ed8; }
.opt-key {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
  background: #e5e7eb; color: #111827; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.option.chosen .opt-key { background: #1d4ed8; color: #fff; }
.opt-text { padding-top: 3px; }
.q-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.exam-side {
  background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 10px; padding: 14px;
  position: sticky; top: 64px;
}
.side-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; margin-bottom: 10px; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cell {
  font: inherit; font-size: .9rem; cursor: pointer; aspect-ratio: 1;
  border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: #374151;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.cell.answered { background: #dcfce7; border-color: #16a34a; color: #14532d; font-weight: 700; }
.cell.flagged { background: #fef3c7; border-color: #d97706; color: #92400e; }
.cell.flagged.answered { background: #dcfce7; border-color: #d97706; box-shadow: inset 0 -4px 0 #f59e0b; }
.cell.current { outline: 2px solid #1d4ed8; outline-offset: 1px; }
.grid-info { font-size: .88rem; color: #6b7280; margin: 10px 0 6px; }
.legend { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: #4b5563; margin-bottom: 6px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; border: 1px solid #d1d5db; }
.sw.answered { background: #dcfce7; border-color: #16a34a; }
.sw.flagged { background: #fef3c7; border-color: #d97706; }
.sw.plain { background: #fff; }

/* ---------- Result view ---------- */
.overall {
  border-radius: 10px; padding: 16px; text-align: center; margin-bottom: 16px;
}
.overall.pass { background: #dcfce7; border: 1px solid #16a34a; }
.overall.fail { background: #fee2e2; border: 1px solid #dc2626; }
.overall .big { font-size: 1.4rem; font-weight: 800; }
.overall .score { font-size: 2rem; font-weight: 800; }
.cat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.cat-card {
  border: 1px solid #d1d5db; border-radius: 10px; padding: 14px; text-align: center;
}
.cat-card.pass { border-color: #16a34a; background: #f0fdf4; }
.cat-card.fail { border-color: #dc2626; background: #fef2f2; }
.cat-card .cname { font-weight: 700; }
.cat-card .cscore { font-size: 1.6rem; font-weight: 800; }
.cat-card .cpg { font-size: .88rem; color: #6b7280; }
.pill {
  display: inline-block; margin-top: 6px; font-size: .8rem; font-weight: 700;
  padding: 2px 12px; border-radius: 999px; color: #fff;
}
.pill.pass { background: #16a34a; }
.pill.fail { background: #dc2626; }
.cat-detail { font-size: .95rem; margin-top: 14px; }
.cat-detail ul { margin: 6px 0; padding-left: 20px; }

.review-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 10px 0; }
.filter-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.chk { font-size: .95rem; display: flex; align-items: center; gap: 6px; }
.chk input { width: 18px; height: 18px; }

.review-item {
  border: 1px solid #d1d5db; border-radius: 10px; padding: 14px; margin-bottom: 12px;
}
.review-item .r-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.review-item .r-q { font-weight: 600; color: #111827; white-space: pre-wrap; }
.r-opt {
  border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px 10px; margin: 6px 0;
  display: flex; gap: 10px; align-items: flex-start;
}
.r-opt .opt-key { flex: 0 0 auto; }
.r-opt.correct { background: #dcfce7; border-color: #16a34a; }
.r-opt.user-wrong { background: #fee2e2; border-color: #dc2626; }
.r-opt.user-choice { background: #dbeafe; border-color: #1d4ed8; }
.r-opt.best { border-color: #16a34a; }
.r-opt .tag { margin-left: auto; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.tag.good { color: #15803d; }
.tag.bad { color: #b91c1c; }
.tag.info { color: #1d4ed8; }
.r-foot { font-size: .95rem; margin-top: 8px; }
.r-foot .ok { color: #15803d; font-weight: 700; }
.r-foot .no { color: #b91c1c; font-weight: 700; }
.r-disc { background: #f9fafb; border-left: 3px solid #9ca3af; padding: 8px 12px; margin-top: 8px; font-size: .95rem; }
.r-disc strong { display: block; margin-bottom: 2px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box { background: #fff; border-radius: 12px; padding: 22px; max-width: 440px; width: 100%; }
.modal-box h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Soal figural ---------- */
.q-gambar {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  padding: 10px; margin: 4px 0 6px; text-align: center;
}
.q-gambar svg { max-width: 100%; height: auto; max-height: 220px; }
.opt-svg { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 4px 0; }
.opt-svg svg { width: 84px; height: 84px; max-width: 100%; }
.r-fig { border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px; margin: 6px 0; text-align: center; }
.r-fig svg { max-width: 100%; height: auto; max-height: 200px; }
.r-opt .opt-svg svg { width: 64px; height: 64px; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .exam-layout { grid-template-columns: 1fr; }
  .exam-side { position: static; }
  .info-grid { grid-template-columns: repeat(3, 1fr); }
  .session-picker { grid-template-columns: 1fr; }
  .cat-cards { grid-template-columns: 1fr; }
  .view { padding: 16px; }
  h1 { font-size: 1.35rem; }
  .timer { font-size: 1.25rem; }
  .grid { grid-template-columns: repeat(5, 1fr); }
  .opt-svg svg { width: 68px; height: 68px; }
}
