* { touch-action: manipulation; }

:root {
  --blue: #00d4ff;
  --pink: #ff2d78;
  --green: #00ff88;
  --orange: #ff9500;
  --purple: #a855f7;
  --bg-dark: #0a0a1a;
  --bg-card: rgba(255,255,255,0.06);
  --bg-card-hover: rgba(255,255,255,0.1);
  --text: #ffffff;
  --text-dim: rgba(255,255,255,0.6);
  --radius: 16px;
  --safe-top: calc(env(safe-area-inset-top, 44px) + 12px);
  --safe-bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);
}

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #0a0a1a 0%, #1a0a2e 50%, #0a1628 100%);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  padding: var(--safe-top) 16px var(--safe-bottom);
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Bottom Nav */
#bottomNav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background: rgba(10,10,26,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px);
  z-index: 1000;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  padding: 6px 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.nav-btn.active {
  color: var(--blue);
}

.nav-btn .nav-icon {
  font-size: 22px;
}

.nav-btn .nav-label {
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Glass Card */
.glass {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 16px;
  transition: all 0.2s;
}

.glass:hover, .glass:active {
  background: var(--bg-card-hover);
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 24px;
}

.header h1 {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header .subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  text-align: center;
  padding: 14px 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
}

.stat-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Action Buttons */
.action-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  color: white;
  margin-bottom: 12px;
}

.action-btn.primary {
  background: linear-gradient(135deg, var(--blue), var(--purple));
}

.action-btn.secondary {
  background: linear-gradient(135deg, var(--pink), var(--orange));
}

.action-btn.exam {
  background: linear-gradient(135deg, var(--green), #00b4d8);
  color: #0a0a1a;
}

.action-btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

/* Topic Cards */
.topics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.topic-card {
  cursor: pointer;
  padding: 14px;
  position: relative;
  overflow: hidden;
}

.topic-card .topic-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.topic-card .topic-name {
  font-size: 13px;
  font-weight: 600;
  margin-top: 6px;
  line-height: 1.3;
}

.topic-card .topic-progress {
  margin-top: 10px;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.topic-card .topic-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

.topic-card.past-paper {
  grid-column: span 2;
}

/* Section Headers */
.section-header {
  font-size: 18px;
  font-weight: 700;
  margin: 24px 0 12px;
}

/* Quiz Screen */
.quiz-setup {
  text-align: center;
}

.quiz-setup .topic-select {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

.quiz-setup .topic-option {
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}

.quiz-setup .topic-option.selected {
  border-color: var(--blue);
  background: rgba(0,212,255,0.1);
}

.quiz-setup .topic-option .check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
}

.quiz-setup .topic-option.selected .check {
  background: var(--blue);
  border-color: var(--blue);
}

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.toggle {
  width: 50px;
  height: 28px;
  background: rgba(255,255,255,0.15);
  border-radius: 14px;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}

.toggle.on {
  background: var(--blue);
}

.toggle::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}

.toggle.on::after {
  transform: translateX(22px);
}

/* Quiz Active */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.quiz-header .q-count {
  font-size: 14px;
  color: var(--text-dim);
}

.quiz-header .q-timer {
  font-size: 14px;
  font-weight: 600;
  color: var(--orange);
}

.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  margin-bottom: 24px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  border-radius: 3px;
  transition: width 0.3s;
}

.question-card {
  margin-bottom: 20px;
  padding: 20px;
}

.question-type-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.badge-mc { background: rgba(0,212,255,0.15); color: var(--blue); }
.badge-tf { background: rgba(168,85,247,0.15); color: var(--purple); }
.badge-fill { background: rgba(255,149,0,0.15); color: var(--orange); }

.question-text {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 20px;
}

.difficulty-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  margin-left: 8px;
}

.diff-easy { background: rgba(0,255,136,0.15); color: var(--green); }
.diff-medium { background: rgba(255,149,0,0.15); color: var(--orange); }
.diff-hard { background: rgba(255,45,120,0.15); color: var(--pink); }

/* Answer Options */
.options-list {
  display: grid;
  gap: 10px;
}

.option-btn {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  color: white;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.option-btn:active {
  transform: scale(0.98);
}

.option-btn .option-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.option-btn.correct {
  background: rgba(0,255,136,0.15);
  border-color: var(--green);
}

.option-btn.correct .option-letter {
  background: var(--green);
  color: #0a0a1a;
}

.option-btn.wrong {
  background: rgba(255,45,120,0.15);
  border-color: var(--pink);
}

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

.option-btn.disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* Fill in blank */
.fill-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  color: white;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.fill-input:focus {
  border-color: var(--blue);
}

.fill-submit {
  margin-top: 10px;
}

/* TF buttons */
.tf-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tf-btn {
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--bg-card);
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.tf-btn:active { transform: scale(0.97); }
.tf-btn.correct { background: rgba(0,255,136,0.15); border-color: var(--green); }
.tf-btn.wrong { background: rgba(255,45,120,0.15); border-color: var(--pink); }

/* Explanation */
.explanation-box {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  background: rgba(168,85,247,0.1);
  border: 1px solid rgba(168,85,247,0.3);
  animation: fadeIn 0.3s;
}

.explanation-box .exp-header {
  font-weight: 700;
  font-size: 13px;
  color: var(--purple);
  margin-bottom: 6px;
}

.explanation-box .exp-text {
  font-size: 14px;
  line-height: 1.5;
  color: rgba(255,255,255,0.85);
}

/* Next button */
.next-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 16px;
  transition: all 0.2s;
}

.next-btn:active { transform: scale(0.97); }

/* Quiz Results */
.results-screen {
  text-align: center;
  padding-top: 20px;
}

.results-score {
  font-size: 72px;
  font-weight: 900;
  margin: 16px 0 4px;
}

.results-grade {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.results-detail {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 24px;
}

.wrong-review {
  text-align: left;
  margin-top: 20px;
}

.wrong-review .wrong-item {
  padding: 14px;
  margin-bottom: 10px;
}

.wrong-review .wrong-q {
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}

.wrong-review .wrong-answer {
  font-size: 13px;
  color: var(--green);
}

/* Flashcards */
.flashcard-container {
  perspective: 1000px;
  margin: 20px 0;
  min-height: 280px;
}

.flashcard {
  width: 100%;
  min-height: 280px;
  position: relative;
  transition: transform 0.5s;
  transform-style: preserve-3d;
  cursor: pointer;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  width: 100%;
  min-height: 280px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border-radius: var(--radius);
  text-align: center;
}

.flashcard-front {
  background: linear-gradient(135deg, rgba(0,212,255,0.12), rgba(168,85,247,0.12));
  border: 1px solid rgba(0,212,255,0.2);
}

.flashcard-back {
  background: linear-gradient(135deg, rgba(0,255,136,0.12), rgba(0,212,255,0.12));
  border: 1px solid rgba(0,255,136,0.2);
  transform: rotateY(180deg);
}

.flashcard-face .fc-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.flashcard-face .fc-text {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
}

.flashcard-face .fc-topic {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 16px;
}

.fc-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.fc-action-btn {
  padding: 14px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.fc-action-btn.got-it {
  background: rgba(0,255,136,0.15);
  color: var(--green);
  border: 1px solid rgba(0,255,136,0.3);
}

.fc-action-btn.review {
  background: rgba(255,149,0,0.15);
  color: var(--orange);
  border: 1px solid rgba(255,149,0,0.3);
}

.fc-action-btn:active { transform: scale(0.97); }

.fc-counter {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 12px;
}

/* Flashcard topic select */
.fc-topic-select {
  display: grid;
  gap: 8px;
  margin: 16px 0;
}

/* Progress Page */
.progress-topic {
  margin-bottom: 14px;
  padding: 14px;
}

.progress-topic .pt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.progress-topic .pt-name {
  font-weight: 600;
  font-size: 14px;
}

.progress-topic .pt-pct {
  font-weight: 700;
  font-size: 14px;
}

.progress-topic .pt-bar {
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-topic .pt-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-topic .pt-detail {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

.weak-area {
  border-color: var(--pink) !important;
}

.weak-badge {
  display: inline-block;
  background: rgba(255,45,120,0.15);
  color: var(--pink);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
}

/* Overall stats on progress */
.overall-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.overall-stat {
  text-align: center;
  padding: 16px;
}

.overall-stat .os-val {
  font-size: 28px;
  font-weight: 800;
}

.overall-stat .os-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  text-transform: uppercase;
}

/* Back button */
.back-btn {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Exam Practice */
.exam-section {
  margin-top: 16px;
}

.exam-card {
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
}

.exam-card .ec-label {
  font-size: 11px;
  color: var(--orange);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.exam-card .ec-title {
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
}

.exam-card .ec-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
  line-height: 1.4;
}

.exam-content {
  padding: 16px;
  line-height: 1.7;
  font-size: 14px;
  margin-bottom: 16px;
}

.exam-content h3 {
  color: var(--blue);
  font-size: 16px;
  margin: 16px 0 8px;
}

.exam-content h3:first-child { margin-top: 0; }

.exam-content ul {
  padding-left: 20px;
}

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

.exam-content .hint {
  background: rgba(255,149,0,0.1);
  border-left: 3px solid var(--orange);
  padding: 10px 14px;
  margin: 12px 0;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
}

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

.fade-in {
  animation: fadeIn 0.3s ease;
}

/* Shake for wrong */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.shake { animation: shake 0.3s; }

/* Module Selection */
.module-card {
  cursor: pointer;
  padding: 20px;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}

.module-card .module-emoji {
  font-size: 36px;
  margin-bottom: 10px;
}

.module-card .module-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.module-card .module-code {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.module-card .module-exam {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
}

.module-card .module-exam .exam-date {
  font-weight: 700;
  color: var(--orange);
}

.countdown-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.countdown-unit {
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 6px 10px;
  text-align: center;
  min-width: 52px;
}

.countdown-unit .cd-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--blue);
}

.countdown-unit .cd-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Case Study */
.case-study-box {
  background: rgba(0,212,255,0.05);
  border: 1px solid rgba(0,212,255,0.15);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  line-height: 1.7;
  font-size: 14px;
  white-space: pre-line;
}

/* Scrollbar */
::-webkit-scrollbar { width: 0; }
