:root {
  --color-bg: #f4f5fb;
  --color-primary: #6d28f5;
  --color-primary-dark: #5417d6;
  --color-primary-light: #8b5cf6;
  --color-accent: #17c3b2;
  --color-warning: #e17055;
  --color-danger: #e74c3c;
  --color-text: #201a3a;
  --color-muted: #6b7280;
  --color-card: #ffffff;
  --color-border: #ececf5;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(76, 41, 196, 0.1);
  --font-heading: "Poppins", -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

/* Jaga-jaga: elemen dengan atribut [hidden] harus selalu benar-benar tersembunyi,
   walau ada class lain yang mengatur display (mis. display:flex pada .gambar-preview-wrap). */
[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg) url("../assets/pattern-doodle.svg") repeat;
  background-size: 340px 340px;
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}

.app-header, #app-main, .app-footer {
  position: relative;
  z-index: 1;
}

.app-header {
  background: linear-gradient(120deg, #7c3aed 0%, #6d28f5 45%, #4338ca 100%);
  color: white;
  padding: 22px 16px 46px;
  box-shadow: 0 6px 24px rgba(76, 41, 196, 0.28);
  border-radius: 0 0 26px 26px;
  position: relative;
  overflow: hidden;
}

.app-header-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.header-skyline {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 46px;
  opacity: 0.16;
  pointer-events: none;
  display: block;
}

.app-logo-group {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.app-logo {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 13px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.app-logo img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  display: block;
}

/* Logo sekolah punya margin putih bawaan di file aslinya -> di-zoom sedikit
   supaya lambangnya tampak lebih besar/penuh di dalam chip-nya. */
.app-logo img.logo-zoom {
  transform: scale(1.12);
}

.footer-logo-group {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.footer-logo-chip {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 10px;
}

.footer-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  display: block;
}

.footer-logo.logo-zoom {
  transform: scale(1.12);
}

.app-header h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: 0.1px;
}

.app-subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  opacity: 0.92;
}

#app-main {
  flex: 1;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
}

.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 0.8rem;
  color: var(--color-muted);
}

.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px 18px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #04795a;
  background: #e6fbf4;
  border: 1px solid #b7ebda;
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.center-card {
  text-align: center;
  padding: 40px 20px;
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 16px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error-icon {
  font-size: 2.5rem;
  margin: 0 0 8px;
}

.error-text {
  color: var(--color-danger);
  font-weight: 600;
}

.error-text.small-error {
  font-size: 0.8rem;
  font-weight: 500;
  display: inline-block;
  margin-top: 4px;
}

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

h2 {
  margin-top: 0;
  font-family: var(--font-heading);
  font-weight: 800;
}

.no-margin {
  margin: 0;
}

h3 {
  font-family: var(--font-heading);
}

.big-icon {
  font-size: 2.4rem;
  display: block;
  margin-bottom: 8px;
}

/* HOME */

.role-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 20px;
}

.role-button {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  color: white;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  text-align: left;
  box-shadow: 0 8px 18px rgba(76, 58, 156, 0.18);
}

.role-button:active {
  transform: scale(0.98);
}

.role-siswa {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
}

.role-guru {
  background: linear-gradient(135deg, #0f172a, #334155);
}

.role-menu-alt {
  background: #ffffff;
  color: var(--color-text);
  border: 2px solid var(--color-border);
  box-shadow: none;
}

.role-icon {
  font-size: 1.6rem;
}

.danger-button {
  background: #fdecea;
  color: #b3261e;
  border: 2px solid #f7c9c2;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
}

.link-button {
  background: none;
  border: none;
  color: var(--color-primary);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 0;
}

.center-link {
  display: block;
  width: 100%;
  text-align: center;
  margin: 4px 0 10px;
}

.badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* FORMS (nama siswa, pin guru, tambah soal) */

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
  text-align: left;
}

.stack-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-text);
}

.stack-form input,
.stack-form select,
.stack-form textarea {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 400;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
  background: white;
  color: var(--color-text);
}

.stack-form input:focus,
.stack-form select:focus,
.stack-form textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-message {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
}

.form-message.success {
  background: #e6fbf4;
  color: #04795a;
}

.form-message.error {
  background: #fdecea;
  color: #b3261e;
}

.small-hint {
  margin: -8px 0 0;
  font-size: 0.78rem;
}

/* PENGATURAN LATIHAN (GURU) */

.pengaturan-tingkat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pengaturan-tingkat-item {
  flex: 1;
  min-width: 90px;
}

.small-button {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.gambar-preview-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
}

.gambar-preview-wrap img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

/* Foto pada soal (kuis, hasil, kunci jawaban) */

.soal-gambar {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: #f4f5fb;
  margin: 10px 0 16px;
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 12, 30, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.nama-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  background: #f0edff;
  padding: 5px 12px;
  border-radius: 999px;
  margin: -4px 0 10px;
  cursor: pointer;
}

/* BACK BUTTON */

.back-button {
  background: none;
  border: none;
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 4px 0 16px;
  cursor: pointer;
}

/* PILIH KELAS */

.pill-list {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.pill-button {
  flex: 1;
  min-width: 90px;
  padding: 22px 12px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: white;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-primary-dark);
  cursor: pointer;
}

.pill-button:active {
  background: #f0edff;
  border-color: var(--color-primary);
}

/* PILIH MAPEL */

.mapel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.mapel-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: white;
  cursor: pointer;
  text-align: left;
}

.mapel-card:active {
  border-color: var(--color-primary);
  background: #f7f6ff;
}

.mapel-card:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.mapel-icon {
  font-size: 1.3rem;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  margin-bottom: 2px;
}

.mapel-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.mapel-count {
  font-size: 0.78rem;
  color: var(--color-muted);
}

.mapel-badge {
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-accent);
  background: #e6fbf4;
  padding: 3px 8px;
  border-radius: 999px;
}

/* KUIS */

.quiz-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--color-muted);
  font-weight: 600;
}

.progress-track {
  height: 8px;
  background: var(--color-border);
  border-radius: 999px;
  margin: 8px 0 12px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: 999px;
  transition: width 0.25s ease;
}

.quiz-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.quiz-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  background: white;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-muted);
  cursor: pointer;
}

.quiz-dot.answered {
  background: #e6fbf4;
  border-color: var(--color-accent);
  color: #04795a;
}

.quiz-dot.current {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.quiz-bab {
  font-size: 0.8rem;
  color: var(--color-primary-dark);
  font-weight: 600;
  margin: 10px 0 0;
}

.quiz-question {
  font-size: 1.15rem;
  line-height: 1.5;
  margin: 8px 0 18px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: white;
  font-size: 0.98rem;
  text-align: left;
  cursor: pointer;
}

.option-button.selected {
  border-color: var(--color-primary);
  background: #f2effe;
}

.option-letter {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-border);
  font-weight: 700;
  font-size: 0.85rem;
}

.option-button.selected .option-letter {
  background: var(--color-primary);
  color: white;
}

.quiz-warning {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: #fff1ec;
  color: var(--color-warning);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid #ffd9c9;
}

.quiz-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}

.primary-button, .secondary-button {
  padding: 13px 20px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
}

.primary-button {
  background: var(--color-primary);
  color: white;
  flex: 1;
  box-shadow: 0 6px 16px rgba(108, 92, 231, 0.3);
}

.primary-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.secondary-button {
  background: white;
  color: var(--color-primary-dark);
  border: 2px solid var(--color-border);
}

.small-button {
  padding: 8px 14px;
  font-size: 0.82rem;
  flex: none;
}

/* HASIL */

.hasil-summary {
  text-align: center;
  padding-bottom: 12px;
}

.hasil-subject {
  color: var(--color-muted);
  font-weight: 600;
  margin: 0 0 4px;
}

.hasil-score {
  font-size: 2.4rem;
  font-weight: 800;
  font-family: var(--font-heading);
  color: var(--color-primary);
  margin: 0;
}

.hasil-percentage {
  font-size: 1rem;
  color: var(--color-muted);
  margin: 2px 0 8px;
}

.hasil-label {
  font-weight: 600;
  font-size: 1rem;
}

.hasil-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.hasil-heading {
  border-top: 1px solid var(--color-border);
  padding-top: 16px;
  margin-bottom: 8px;
}

.hasil-heading.no-border {
  border-top: none;
  padding-top: 0;
}

.kunci-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.hasil-item, .kunci-item {
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  background: #fbfbfe;
}

.hasil-item.correct {
  border-color: #b7ebda;
  background: #f3fdf9;
}

.hasil-item.incorrect {
  border-color: #f7c9c2;
  background: #fef5f4;
}

.hasil-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-muted);
  margin-bottom: 6px;
}

.hasil-status {
  font-size: 0.85rem;
}

.hasil-question {
  font-weight: 600;
  margin: 4px 0 8px;
}

.hasil-answer-row {
  font-size: 0.92rem;
  margin: 4px 0;
}

.hasil-pembahasan {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px dashed var(--color-border);
}

/* KUNCI JAWABAN GURU */

.kunci-bab {
  font-size: 0.75rem;
  background: #f0edff;
  color: var(--color-primary-dark);
  padding: 2px 8px;
  border-radius: 999px;
}

.kunci-option {
  font-size: 0.92rem;
  margin: 4px 0;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.kunci-option.correct {
  background: #e6fbf4;
  color: #04795a;
  font-weight: 700;
}

.kunci-item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--color-border);
}

.empty-message {
  color: var(--color-muted);
  text-align: center;
  padding: 24px 0;
}

/* REKAP NILAI GURU */

.nilai-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.nilai-filters select,
.nilai-filters input {
  font-family: inherit;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--color-border);
  font-size: 0.85rem;
  flex: 1;
  min-width: 100px;
}

.nilai-table-wrap {
  overflow-x: auto;
}

.nilai-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.nilai-table th, .nilai-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.nilai-table th {
  color: var(--color-muted);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

@media (min-width: 520px) {
  .mapel-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

/* PILIH BAB */

.bab-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.bab-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: white;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.bab-button:active {
  border-color: var(--color-primary);
  background: #f7f6ff;
}

.bab-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.bab-count {
  font-size: 0.78rem;
  color: var(--color-muted);
  flex-shrink: 0;
}

/* IMPORT SOAL MASSAL */

.import-log-row {
  font-size: 0.82rem;
  color: #b3261e;
  background: #fdecea;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  margin: 6px 0;
}

/* STATISTIK SOAL */

.statistik-item {
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 12px;
  background: #fbfbfe;
}

.statistik-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.statistik-bar-track {
  flex: 1;
  height: 10px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.statistik-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
}

.statistik-bar-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

/* PAPAN PERINGKAT (LEADERBOARD) */

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.leaderboard-row.top {
  border-color: #f2d16b;
  background: #fffbea;
}

.leaderboard-rank {
  font-weight: 800;
  font-size: 1.1rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.leaderboard-nama {
  flex: 1;
  font-weight: 700;
  font-size: 0.92rem;
}

.leaderboard-rombel {
  font-weight: 400;
  color: var(--color-muted);
  font-size: 0.8rem;
}

.leaderboard-skor {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--color-primary-dark);
  flex-shrink: 0;
}

/* RIWAYAT NILAI SISWA */

.riwayat-row {
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.riwayat-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.92rem;
}

.riwayat-row-date {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--color-muted);
}

/* GRAFIK BATANG SEDERHANA (Rekap Nilai) */

.bar-chart {
  margin-bottom: 16px;
}

.bar-chart-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.bar-chart-label {
  width: 92px;
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
}

.bar-chart-track {
  flex: 1;
  height: 14px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.bar-chart-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.bar-chart-value {
  width: 40px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-primary-dark);
}
