:root{
  --bg:#eef2f7;
  --card:#ffffff;
  --text:#0f172a;
  --muted:#64748b;
  --blue:#1d4ed8;
  --blue2:#2563eb;
  --green:#16a34a;
  --red:#dc2626;
  --border:#e2e8f0;
  --shadow: 0 12px 30px rgba(2, 6, 23, .12);
  --radius: 18px;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

*{ box-sizing:border-box; }
body{
  margin:0;
  background:
    radial-gradient(1200px 500px at 30% 20%, rgba(37,99,235,.12), transparent 55%),
    radial-gradient(900px 450px at 80% 60%, rgba(29,78,216,.10), transparent 55%),
    var(--bg);
  color:var(--text);
}

.hidden{ display:none !important; }
.screen{ min-height:100vh; }

.topbar{
  display:flex;
  justify-content:flex-end;
  padding:24px;
}
.admin-btn{
  border:2px solid rgba(29,78,216,.4);
  background:#fff;
  color:var(--blue);
  border-radius:12px;
  padding:10px 14px;
  font-weight:700;
  cursor:pointer;
  box-shadow: 0 6px 18px rgba(2,6,23,.08);
}
.admin-btn span{ margin-left:8px; }

.login-wrap{
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 24px;
}
.login-card{
  width:min(760px, 92vw);
  background:var(--card);
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 44px 40px;
}
.login-title h1{
  margin:0;
  font-size: 44px;
  letter-spacing: .2px;
}
.login-title .brand{ margin-left:10px; }
.subtitle{
  margin:10px 0 28px;
  color:var(--muted);
  font-size: 18px;
}
.field{
  display:block;
  margin: 18px 0 22px;
}
.label{
  display:block;
  color:var(--muted);
  margin-bottom:10px;
  font-weight:600;
}
input{
  width:100%;
  padding: 16px 18px;
  border:1px solid var(--border);
  border-radius: 14px;
  outline:none;
  font-size: 18px;
}
input:focus{
  border-color: rgba(37,99,235,.55);
  box-shadow: 0 0 0 4px rgba(37,99,235,.15);
}

.primary-btn{
  width:100%;
  border:none;
  cursor:pointer;
  font-weight:800;
  color:#fff;
  font-size: 22px;
  padding: 16px 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--blue2));
  box-shadow: 0 18px 30px rgba(29,78,216,.22);
}
.primary-btn:active{ transform: translateY(1px); }

.hint{
  margin:14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* EXAM */
.exam-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.user{
  display:flex; align-items:center; gap:12px;
}
.avatar{
  width:42px; height:42px;
  border-radius: 50%;
  background: rgba(37,99,235,.12);
  display:grid; place-items:center;
  font-size: 20px;
}
.user-name{ font-weight:900; }
.user-sub{ color:var(--muted); font-size: 13px; }

.timer{
  font-weight:900;
  padding: 10px 14px;
  border-radius: 12px;
  border:1px solid var(--border);
  background:#fff;
}

.danger-btn{
  border:none;
  cursor:pointer;
  font-weight:900;
  color:#fff;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--red);
  box-shadow: 0 12px 22px rgba(220,38,38,.18);
}

.exam-body{
  display:grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  padding: 18px;
}

/* Tablet/HP: jadikan 1 kolom agar soal + opsi muat rapi */
@media (max-width: 900px){
  .exam-body{
    grid-template-columns: 1fr;
    padding: 12px;
  }
  .nav-panel{
    height: auto;
    position: static;
    top: auto;
  }
  .question-grid{ grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); }
  .q-text{ font-size: 18px; }
}

.nav-panel{
  background:#fff;
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 22px rgba(2,6,23,.08);
  padding: 14px;
  height: calc(100vh - 110px);
  position: sticky;
  top: 86px;
  overflow:auto;
}
.nav-title{
  font-weight:900;
  margin-bottom: 12px;
}
.question-grid{
  display:grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.qbtn{
  border:1px solid var(--border);
  background:#fff;
  border-radius: 12px;
  padding: 10px 0;
  font-weight:900;
  cursor:pointer;
}
.qbtn.current{
  border-color: rgba(37,99,235,.75);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.qbtn.answered{
  background: rgba(22,163,74,.12);
  border-color: rgba(22,163,74,.35);
  color: var(--green);
}

.legend{
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  display:grid;
  gap: 8px;
}
.dot{
  display:inline-block;
  width:10px; height:10px;
  border-radius:50%;
  margin-right:8px;
  vertical-align: middle;
}
.dot-unanswered{ background:#cbd5e1; }
.dot-answered{ background: rgba(22,163,74,.85); }
.dot-current{ background: rgba(37,99,235,.85); }

.question-panel{
  background:#fff;
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 22px rgba(2,6,23,.08);
  padding: 18px 20px;
}
.q-meta{
  display:flex;
  justify-content:space-between;
  color: var(--muted);
  font-weight:700;
}
.q-text{
  margin: 12px 0 12px;
  font-size: 22px;
  line-height: 1.25;
}
.choices{
  display:grid;
  gap: 10px;
  margin: 14px 0 16px;
  /* 2 kolom agar A+C di atas, B+D di bawah (diatur oleh app.js) */
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.choice{
  display:flex;
  align-items:flex-start;
  gap:12px;
  padding: 12px 12px;
  border:1px solid var(--border);
  border-radius: 14px;
  cursor:pointer;
  min-height: 84px;
}
.choice input{ width:auto; }
.choice:hover{
  border-color: rgba(37,99,235,.45);
  background: rgba(37,99,235,.06);
}

.q-actions{
  display:flex;
  justify-content:space-between;
  gap:10px;
  margin-top: 8px;
}
.ghost-btn{
  border:1px solid var(--border);
  background:#fff;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight:900;
  cursor:pointer;
}
.ghost-btn:active{ transform: translateY(1px); }

/* RESULT */
.result-wrap{
  display:flex; justify-content:center; align-items:center;
  padding: 24px;
  min-height:100vh;
}
.result-card{
  width:min(980px, 94vw);
  background:#fff;
  border:1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.result-head h2{ margin:0; font-size: 28px; }
.score-box{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0 16px;
}
.score{
  border:1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: rgba(2,6,23,.02);
}
.score-label{ color: var(--muted); font-weight:800; }
.score-value{ font-size: 28px; font-weight:1000; margin-top: 6px; }

.review{
  margin-top: 14px;
  display:grid;
  gap: 12px;
}
.review-item{
  border:1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.review-item h4{ margin:0 0 6px; }
.badge{
  display:inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight:900;
  font-size: 12px;
  margin-left: 8px;
}
.badge.ok{ background: rgba(22,163,74,.12); color: var(--green); border:1px solid rgba(22,163,74,.25); }
.badge.no{ background: rgba(220,38,38,.10); color: var(--red); border:1px solid rgba(220,38,38,.25); }

/* ====== REVIEW DETAIL (SOAL + PILIHAN) ====== */
.review-qtext{ line-height: 1.45; font-weight: 700; }
.review-meta{ margin-top: 6px; color: var(--muted); font-weight: 800; }

.review-choices{
  display:grid;
  gap: 8px;
  margin-top: 10px;
}

.review-choice{
  display:grid;
  grid-template-columns: 30px 1fr 24px;
  gap: 10px;
  align-items:start;
  border:1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(2,6,23,.02);
}

.review-choice-label{ font-weight: 1000; color: var(--muted); }
.review-choice-text{ line-height: 1.45; }
.review-choice-mark{ text-align:right; font-weight: 1000; }

.review-choice.correct{
  border-color: rgba(22,163,74,.35);
  background: rgba(22,163,74,.08);
}
.review-choice.wrong{
  border-color: rgba(220,38,38,.35);
  background: rgba(220,38,38,.06);
}
.review-choice.picked .review-choice-label{ color: #0f172a; }

/* ====== FILTER BAR + COUNTER ====== */
.review-filter{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:12px;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:14px;
  background: rgba(2,6,23,.02);
}

.review-filter-title{
  font-weight:900;
  color: var(--muted);
}

.review-filter-group{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.review-filter-btn{
  border:1px solid var(--border);
  background:#fff;
  border-radius:12px;
  padding:8px 10px;
  font-weight:900;
  cursor:pointer;
}

.review-filter-btn.active{
  border-color: rgba(37,99,235,.35);
  background: rgba(37,99,235,.10);
}

.count-pill{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 26px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(2,6,23,.04);
  font-weight: 1000;
  font-size: 12px;
  margin-left: 8px;
}
.review-filter-btn.active .count-pill{
  border-color: rgba(37,99,235,.25);
  background: rgba(37,99,235,.12);
}

.result-actions{ margin-top: 18px; }
.result-actions .primary-btn{ width:auto; padding: 14px 18px; font-size:18px; }

/* MODAL */
.modal{
  position: fixed;
  inset:0;
  background: rgba(2,6,23,.55);
  display:grid;
  place-items:center;
  padding: 18px;
  z-index: 20;
}
.modal-card{
  width: min(520px, 92vw);
  background:#fff;
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  border:1px solid rgba(255,255,255,.25);
}
.modal-card h3{ margin:0 0 8px; }
.modal-actions{
  display:flex;
  gap: 10px;
  justify-content:flex-end;
  margin-top: 14px;
}
.modal-actions .primary-btn{ width:auto; font-size:16px; padding: 12px 14px; }


/* Tombol "Kosongkan Isian" */
.danger-ghost{
  border-color: rgba(220,38,38,.35);
  color: var(--red);
  background: rgba(220,38,38,.06);
}
.danger-ghost:hover{
  background: rgba(220,38,38,.10);
}


/* Select (dropdown) disamakan gaya dengan input */
select{
  width:100%;
  padding: 16px 18px;
  border:1px solid var(--border);
  border-radius: 14px;
  outline:none;
  font-size: 18px;
  background:#fff;
}
select:focus{
  border-color: rgba(37,99,235,.55);
  box-shadow: 0 0 0 4px rgba(37,99,235,.15);
}

/* gambar opsi jawaban (bulk upload) */
.choice-content { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.choice-letter{
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight: 900;
  background: rgba(15,23,42,.06);
  color: var(--text);
}
.choice-img { max-width: 100%; height: auto; margin-top: 8px; border-radius: 12px; }

/* ===========================
   RESPONSIVE IMAGE HANDLING
   - Menghindari gambar soal/opsi terlalu besar di HP
   - Menyesuaikan tinggi gambar dengan tinggi layar (vh) yang akurat di mobile
   =========================== */

/* --vh akan di-set oleh JS (app.js). Fallback: 1vh */
:root { --vh: 1vh; }

.q-image,
.choice-img{
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

/* Gambar pada stem soal */
.q-image{
  margin: 12px auto;
  border-radius: 12px;
  /* batasi tinggi agar tidak "menguasai" layar */
  max-height: calc(var(--vh, 1vh) * 35);
}

/* Gambar pada opsi jawaban */
.choice-img{
  margin-top: 8px;
  border-radius: 12px;
  max-height: calc(var(--vh, 1vh) * 22);
}

/* HP sangat kecil: jadikan 1 kolom agar tidak terlalu sempit */
@media (max-width: 360px){
  .choices{ grid-template-columns: 1fr; }
}

/* Desktop/tablet: batasi pakai pixel supaya konsisten */
@media (min-width: 768px){
  .q-image{ max-height: 360px; }
  .choice-img{ max-height: 220px; }
}


/* ===== MOBILE FIX: cegah panel Nomor Soal menutupi soal (override terakhir) ===== */
@media (max-width: 900px){
  .nav-panel{
    position: static !important;
    top: auto !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    margin-bottom: 12px;
  }
  .legend{ grid-template-columns: 1fr; }
}

/* ===== TABLET COMPACT MODE (biar 1 halaman) ===== */
@media (min-width: 900px) and (max-width: 1200px){

  /* rapatkan layout utama */
  .container,
  .main,
  .content{
    gap: 12px !important;
  }

  /* kecilkan panel kiri biar konten kanan lebih lega */
  .nav-panel{
    width: 260px !important;
  }

  /* rapatkan card soal */
  .question-card{
    padding: 14px !important;
  }

  /* judul/teks sedikit diperkecil */
  .question-title{
    font-size: 22px !important;
    line-height: 1.25 !important;
    margin-bottom: 10px !important;
  }

  /* gambar soal dibatasi agar tidak makan tinggi */
  .question-media img{
    max-height: 22vh !important;
    width: 100% !important;
    object-fit: contain !important;
  }

  /* grid jawaban tetap 2x2, tapi lebih rapat */
  .choices{
    gap: 10px !important;
  }
  .choice{
    padding: 12px !important;
  }

  /* gambar opsi dipaksa lebih pendek di tablet */
  .choice img{
    max-height: 13vh !important;
    width: 100% !important;
    object-fit: contain !important;
  }

  /* tombol bawah dirapatkan */
  .bottom-actions{
    margin-top: 10px !important;
    gap: 10px !important;
  }
}
