:root {
  --primary: #4F46E5;
  --primary-light: #EEF2FF;
  --primary-dark: #3730A3;
  --secondary: #06B6D4;
  --success: #10B981;
  --success-light: #D1FAE5;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --bg-app: #F8FAFC;
  --card-bg: #FFFFFF;
  --text-main: #0F172A;
  --text-muted: #64748B;
  --border-color: #E2E8F0;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --bottom-nav-height: 65px;
}

[data-theme="dark"] {
  --bg-app: #0F172A;
  --card-bg: #1E293B;
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --border-color: #334155;
  --primary-light: #312E81;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* Mobile Frame Wrapper for Android Look & Feel */
.app-viewport {
  width: 100%;
  max-width: 540px;
  min-height: 100vh;
  background-color: var(--card-bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
}

/* Header Area */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4F46E5, #06B6D4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: white;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}

.header-title h1 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.header-title span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  font-size: 12px;
  font-weight: 700;
}

.stat-fire { color: #F97316; }
.stat-xp { color: #8B5CF6; }

/* Main Content Views */
.app-main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--bottom-nav-height) + 20px);
  overflow-y: auto;
}

.view-section {
  display: none;
  animation: fadeIn 0.25s ease-in-out;
}

.view-section.active {
  display: block;
}

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

/* Banner Belajar */
.hero-banner {
  background: linear-gradient(135deg, #4338CA, #6366F1);
  color: white;
  padding: 20px;
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.25);
}

.hero-banner h2 {
  font-size: 19px;
  font-weight: 800;
  margin-bottom: 6px;
}

.hero-banner p {
  font-size: 13px;
  opacity: 0.9;
  line-height: 1.4;
  max-width: 80%;
}

.hero-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 8px;
}

.hero-deco {
  position: absolute;
  right: -10px;
  bottom: -15px;
  font-size: 70px;
  opacity: 0.25;
  user-select: none;
}

/* Section Titles */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-head h3 {
  font-size: 16px;
  font-weight: 700;
}

.section-head .see-all {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

/* Subject Grid Cards */
.subjects-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.subject-card {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.subject-card:hover, .subject-card:active {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.sub-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.sub-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}

.sub-topics-count {
  font-size: 11px;
  color: var(--text-muted);
}

/* Quick Action Banner */
.quick-quiz-banner {
  background: linear-gradient(135deg, #059669, #10B981);
  color: white;
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.quick-quiz-text h4 {
  font-size: 15px;
  font-weight: 700;
}

.quick-quiz-text p {
  font-size: 12px;
  opacity: 0.9;
}

.btn-white {
  background: white;
  color: #059669;
  border: none;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 20px;
  cursor: pointer;
}

/* Topic List Items */
.topics-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topic-item-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.topic-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topic-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
}

.topic-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

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

.btn-action {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-read {
  background: var(--primary-light);
  color: var(--primary);
}

.btn-quiz {
  background: var(--primary);
  color: white;
}

/* Topic Detail Modal / View */
.detail-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 100;
  justify-content: center;
  align-items: flex-end;
}

.detail-modal.show {
  display: flex;
}

.detail-sheet {
  background: var(--card-bg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.detail-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.close-sheet-btn {
  background: var(--bg-app);
  border: none;
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.materi-content {
  line-height: 1.6;
  font-size: 14px;
  color: var(--text-main);
}

.materi-content h4 {
  margin: 14px 0 6px 0;
  font-size: 15px;
  color: var(--primary);
}

.materi-content ul, .materi-content ol {
  padding-left: 20px;
  margin-bottom: 12px;
}

.materi-content li {
  margin-bottom: 6px;
}

.note-box {
  background: #FEF3C7;
  border-left: 4px solid #F59E0B;
  padding: 12px;
  border-radius: 8px;
  margin: 12px 0;
  font-size: 13px;
  color: #78350F;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 12px;
}

.data-table th, .data-table td {
  border: 1px solid var(--border-color);
  padding: 8px;
  text-align: left;
}

.data-table th {
  background: var(--bg-app);
  font-weight: 700;
}

/* Example Box */
.example-card {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 14px;
}

.example-card h5 {
  font-size: 13px;
  font-weight: 700;
  color: #059669;
  margin-bottom: 6px;
}

.example-card .example-soal {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.example-card .step-item {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.example-card .step-result {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #059669;
  background: #D1FAE5;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
}

/* Interactive Quiz Engine */
.quiz-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quiz-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.quiz-progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-app);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 12px;
}

.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4F46E5, #06B6D4);
  width: 0%;
  transition: width 0.3s ease;
}

.quiz-question-box {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
}

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

.option-btn {
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.15s ease;
}

.option-letter {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-muted);
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
  color: #065F46;
}

.option-btn.correct .option-letter {
  background: var(--success);
  color: white;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
  color: #991B1B;
}

.option-btn.wrong .option-letter {
  background: var(--danger);
  color: white;
}

.quiz-explanation-box {
  display: none;
  background: #F0FDF4;
  border: 1px solid #BBF7D0;
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #166534;
}

.quiz-explanation-box.show {
  display: block;
}

.btn-primary-block {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* Quiz Result Card */
.quiz-result-card {
  text-align: center;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.result-badge {
  font-size: 64px;
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.result-score {
  font-size: 40px;
  font-weight: 800;
  color: var(--primary);
}

/* Rapor Nilai & Riwayat */
.history-card {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.history-info h5 {
  font-size: 14px;
  font-weight: 700;
}

.history-info p {
  font-size: 11px;
  color: var(--text-muted);
}

.history-score-pill {
  font-size: 14px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 12px;
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  height: var(--bottom-nav-height);
  background: var(--card-bg);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 40;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  padding: 8px 0;
  transition: color 0.15s ease;
}

.nav-item.active {
  color: var(--primary);
}

.nav-icon {
  font-size: 20px;
}

/* Install PWA Prompt Bar */
.install-bar {
  display: none;
  background: #312E81;
  color: white;
  padding: 10px 14px;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
}

.install-bar.show {
  display: flex;
}

.install-btn {
  background: #22C55E;
  color: white;
  border: none;
  border-radius: 14px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
