:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-hover: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --correct: #22c55e;
  --wrong: #ef4444;
  --radius: 16px;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
}

.app {
  width: 100%;
  max-width: 640px;
}

.app-header {
  text-align: center;
  margin-bottom: 28px;
}

.app-header h1 {
  font-size: 2rem;
  margin-bottom: 6px;
}

.app-header p {
  color: var(--muted);
}

.screen {
  display: none;
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: block;
}

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

.screen-title {
  margin-bottom: 20px;
  font-size: 1.3rem;
}

/* --- Header layar pilih topik --- */
.topics-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.topics-header .screen-title {
  margin-bottom: 0;
  flex: 1;
}

.topics-header .btn {
  padding: 8px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* --- Layar pemilihan topik --- */
.quiz-list {
  display: grid;
  gap: 14px;
}

.quiz-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--card-hover);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  text-align: left;
  color: var(--text);
  font: inherit;
  width: 100%;
}

.quiz-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  background: #283548;
}

.quiz-card .quiz-icon {
  font-size: 2rem;
}

.quiz-card .quiz-info {
  flex: 1;
}

.quiz-card .quiz-info h3 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.quiz-card .quiz-info p {
  color: var(--muted);
  font-size: 0.9rem;
}

.quiz-card .quiz-best {
  font-size: 0.8rem;
  color: var(--primary-hover);
  font-weight: 600;
  white-space: nowrap;
}

/* --- Layar quiz --- */
.quiz-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px 16px;
  margin-bottom: 24px;
}

.quiz-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quiz-badge {
  background: var(--primary);
  color: #fff;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.quiz-progress {
  color: var(--muted);
  font-size: 0.9rem;
}

.timer-bar {
  grid-column: 1 / -1;
  height: 8px;
  background: #0b1220;
  border-radius: 999px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--correct);
  border-radius: 999px;
  transition: background 0.3s ease;
}

.timer-text {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.timer-text.low {
  color: var(--wrong);
}

.question-text {
  font-size: 1.25rem;
  margin-bottom: 22px;
  line-height: 1.4;
}

.options {
  display: grid;
  gap: 12px;
  margin-bottom: 24px;
}

.option {
  background: var(--card-hover);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 1rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.2s ease;
}

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

.option:disabled {
  cursor: not-allowed;
}

.option.selected {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.2);
}

.option.correct {
  border-color: var(--correct);
  background: rgba(34, 197, 94, 0.2);
}

.option.wrong {
  border-color: var(--wrong);
  background: rgba(239, 68, 68, 0.2);
}

/* --- Tombol --- */
.btn-row {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.btn {
  padding: 12px 22px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 2px solid var(--card-hover);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--card-hover);
}

/* --- Layar hasil --- */
.result-icon {
  font-size: 4rem;
  text-align: center;
  margin-bottom: 10px;
}

.result-title {
  text-align: center;
  margin-bottom: 6px;
}

.result-score {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--primary-hover);
  margin-bottom: 6px;
}

.result-message {
  text-align: center;
  color: var(--muted);
  margin-bottom: 12px;
}

.best-score {
  text-align: center;
  font-size: 0.9rem;
  color: var(--correct);
  font-weight: 600;
  margin-bottom: 24px;
}

.best-score.new {
  color: var(--primary-hover);
  font-size: 1rem;
}

/* --- Responsif --- */
@media (max-width: 480px) {
  body {
    padding: 12px;
  }

  .app-header h1 {
    font-size: 1.6rem;
  }

  .screen {
    padding: 20px;
  }

  .btn-row {
    flex-direction: column-reverse;
  }

  .btn {
    width: 100%;
  }
}