:root {
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --surface-alt: #F8FAFC;
  --text: #1E293B;
  --text-muted: #475569;
  --border: #E2E8F0;
  --primary: #2563EB;
  --primary-soft: #EFF6FF;
  --primary-dark: #1D4ED8;
  --green: #059669;
  --green-soft: #ECFDF5;
  --green-border: #6EE7B7;
  --red: #DC2626;
  --red-soft: #FEF2F2;
  --red-border: #FCA5A5;
  --amber: #D97706;
  --amber-soft: #FEF3C7;
  --amber-border: #FDE68A;
  --purple: #7C3AED;
  --purple-soft: #F5F3FF;
  --shadow: 0 4px 20px rgba(30, 41, 59, 0.05);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #273449;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.14);
  --primary-dark: #60a5fa;
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.14);
  --green-border: #059669;
  --red: #f87171;
  --red-soft: rgba(239, 68, 68, 0.14);
  --red-border: #dc2626;
  --amber: #fbbf24;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --purple: #a78bfa;
  --purple-soft: rgba(139, 92, 246, 0.14);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.main-nav {
  display: flex;
  gap: 6px;
  background: var(--surface-alt);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.18s;
}

.nav-btn:hover { color: var(--text); }
.nav-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--green-border);
}

.dot-green {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  cursor: pointer;
  font-size: 17px;
  display: grid;
  place-items: center;
}

/* Layout */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.2s ease; }

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

.section-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  margin-bottom: 4px;
}

.section-hero h2 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.section-hero p {
  margin: 0;
  color: var(--text-muted);
  max-width: 680px;
  font-size: 14.5px;
}

.search-box input {
  width: 300px;
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}

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

/* Summary Section */
.topic-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.topic-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.topic-pill.active, .topic-pill:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.summary-grid {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.chapter-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chapter-header {
  padding: 18px 22px;
  background: linear-gradient(135deg, var(--primary-soft), var(--purple-soft));
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.chapter-header h3 {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
}

.chapter-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
}

.chapter-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.visual-diagram-box {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 16px;
}

.visual-diagram-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mnemonic-banner {
  background: var(--amber-soft);
  border-left: 4px solid var(--amber);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
}

.mnemonic-banner strong { color: var(--amber); }

.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.concept-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--surface-alt);
}

.concept-item h4 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.concept-item p {
  margin: 0 0 10px;
  font-size: 13.5px;
  color: var(--text);
}

.analogy-box {
  background: var(--amber-soft);
  border: 1px solid var(--amber-border);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
}

.analogy-box strong {
  color: var(--amber);
}

.cc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-top: 8px;
}

.cc-table th, .cc-table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
}

.cc-table th {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

/* Quiz Toolbar */
.quiz-toolbar {
  margin-bottom: 18px;
  padding: 16px 20px;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.filter-group select {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 15px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-danger-outline {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red-border);
}
.btn-danger-outline:hover { background: var(--red-soft); }

.progress-bar-wrap { display: flex; flex-direction: column; gap: 6px; }
.progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-track {
  height: 9px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
}

.progress-fill-correct { background: var(--green); transition: width 0.3s ease; }
.progress-fill-wrong { background: var(--red); transition: width 0.3s ease; }

/* Jump Grid */
.jump-grid-wrap {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.jump-grid-wrap.hidden { display: none; }

.jump-legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
}
.s-neutral { background: var(--surface-alt); border: 1px solid var(--border); }
.s-correct { background: var(--green); }
.s-wrong { background: var(--red); }
.s-active { background: var(--primary); }

.jump-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 6px;
}

.jump-num {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.jump-num.is-correct { background: var(--green-soft); color: var(--green); border-color: var(--green-border); }
.jump-num.is-wrong { background: var(--red-soft); color: var(--red); border-color: var(--red-border); }
.jump-num.is-active { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Question Card */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.q-num-badge {
  font-size: 13px;
  font-weight: 800;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 12px;
  border-radius: 999px;
}

.q-topic-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.q-text {
  font-size: 17.5px;
  font-weight: 700;
  margin: 0 0 18px;
  line-height: 1.5;
}

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

.option-btn {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.15s;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.option-btn:disabled { cursor: default; }

.opt-key {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  flex-shrink: 0;
}

.option-btn.opt-correct {
  background: var(--green-soft);
  border-color: var(--green);
}
.option-btn.opt-correct .opt-key {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.option-btn.opt-wrong {
  background: var(--red-soft);
  border-color: var(--red);
}
.option-btn.opt-wrong .opt-key {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

/* Instant Feedback Banner & Per-Option Explanations */
.feedback-panel {
  margin-top: 20px;
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  animation: fadeIn 0.2s ease;
}

.feedback-banner {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  font-size: 15px;
}

.feedback-banner.is-correct {
  background: var(--green-soft);
  color: var(--green);
  border-bottom: 1px solid var(--green-border);
}

.feedback-banner.is-wrong {
  background: var(--red-soft);
  color: var(--red);
  border-bottom: 1px solid var(--red-border);
}

.explanations-box {
  padding: 16px 18px;
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.explanations-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.exp-item {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13.5px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.exp-item.exp-right {
  border-left: 4px solid var(--green);
  background: var(--green-soft);
}

.exp-item.exp-wrong {
  border-left: 4px solid var(--red);
}

.exp-badge {
  font-size: 11.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}

.exp-right .exp-badge { background: var(--green); color: #fff; }
.exp-wrong .exp-badge { background: var(--red-soft); color: var(--red); border: 1px solid var(--red-border); }

.quiz-nav-bar {
  margin-top: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.quiz-counter {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-muted);
}

.keyboard-hint {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 12px;
}

/* Evaluation Tab */
.eval-summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.stat-card .stat-value { font-size: 28px; font-weight: 800; margin-top: 4px; }

.eval-topic-breakdown { margin-bottom: 20px; }
.eval-topic-breakdown h3, .wrong-list-header h3 { margin: 0 0 14px; font-size: 17px; }

.breakdown-list { display: flex; flex-direction: column; gap: 12px; }
.breakdown-row { display: flex; flex-direction: column; gap: 6px; }
.breakdown-top { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 600; }

.wrong-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.badge-wrong {
  background: var(--red-soft);
  color: var(--red);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
}

.wrong-list { display: flex; flex-direction: column; gap: 12px; }
.wrong-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--surface-alt);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
}

@media (max-width: 680px) {
  .topbar {
    padding-top: env(safe-area-inset-top);
  }
  .topbar-inner {
    padding: 10px 14px;
    gap: 10px;
  }
  .brand {
    flex: 1;
    min-width: 0;
  }
  .brand > div:last-child {
    min-width: 0;
    overflow: hidden;
  }
  .brand-badge {
    width: 36px;
    height: 36px;
    font-size: 14px;
    border-radius: 10px;
  }
  .brand h1 {
    font-size: 14.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .brand-sub {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-actions {
    gap: 6px;
  }
  .score-pill {
    padding: 5px 10px;
    font-size: 12px;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
  }
  .main-nav {
    order: 3;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .nav-btn {
    justify-content: center;
    padding: 9px 6px;
    font-size: 12px;
    min-height: 40px;
    text-align: center;
  }
  .nav-icon {
    font-size: 13px;
  }

  .container {
    padding: 16px 14px calc(28px + env(safe-area-inset-bottom));
  }
  .section-hero h2 {
    font-size: 20px;
  }
  .search-box, .search-box input {
    width: 100%;
    font-size: 16px; /* Cegah auto-zoom iOS Safari */
  }
  .topic-pills {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .topic-pill {
    flex-shrink: 0;
    min-height: 38px;
  }
  .chapter-header, .chapter-body {
    padding: 14px 16px;
  }
  .chapter-header h3 {
    font-size: 16.5px;
  }
  .concept-grid {
    grid-template-columns: 1fr;
  }

  /* Quiz mobile (iPhone XR 414px) */
  .quiz-toolbar {
    padding: 14px;
  }
  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .filter-group {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }
  .filter-group select {
    width: 100%;
    min-height: 44px;
    font-size: 16px; /* Cegah auto-zoom iOS Safari */
  }
  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 6px;
  }
  .toolbar-actions .btn {
    justify-content: center;
    min-height: 42px;
    padding: 8px 10px;
    font-size: 12.5px;
  }
  .jump-num {
    height: 40px;
    font-size: 13px;
  }

  .question-card {
    padding: 16px;
  }
  .q-text {
    font-size: 16px;
  }
  .option-btn {
    padding: 13px 12px;
    min-height: 48px;
    font-size: 14.5px;
  }
  .feedback-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
    font-size: 14px;
  }
  .explanations-box {
    padding: 12px 14px;
  }
  .exp-item {
    flex-direction: column;
    gap: 6px;
    font-size: 13.5px;
  }

  .quiz-nav-bar {
    position: sticky;
    bottom: calc(8px + env(safe-area-inset-bottom));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px 10px;
    box-shadow: 0 6px 24px rgba(30, 41, 59, 0.12);
    z-index: 30;
  }
  .quiz-nav-bar .btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 13.5px;
  }
  .quiz-counter {
    font-size: 12.5px;
    text-align: center;
  }
  .keyboard-hint {
    display: none;
  }

  /* Evaluasi mobile */
  .eval-summary-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card {
    padding: 14px;
  }
  .stat-card .stat-value {
    font-size: 22px;
  }
  .breakdown-top {
    flex-direction: column;
    gap: 2px;
    font-size: 12.5px;
  }
  .wrong-item .btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
}
