:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #eef2ff;
  --success: #059669;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --warning: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== LAYOUT ===== */
#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px;
}

.screen { display: none; }
.screen.active { display: block; }

/* ===== HEADER ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.app-title span { color: var(--text-muted); font-weight: 400; }

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* ===== START SCREEN ===== */
.start-hero {
  text-align: center;
  padding: 20px 0 16px;
}

.start-hero h1 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

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

.app-branding {
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.app-branding a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.app-branding a:hover {
  text-decoration: underline;
}

.config-section {
  margin-top: 16px;
}

.config-section h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* Radio option group */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.radio-option {
  position: relative;
  cursor: pointer;
}

.radio-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.radio-option-label {
  display: block;
  padding: 4px 14px;
  border: 1.5px solid var(--border);
  border-radius: 100px;
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  transition: all 0.15s;
  cursor: pointer;
  user-select: none;
}

.radio-option input[type="radio"]:checked + .radio-option-label {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.radio-option:hover input[type="radio"]:not(:checked) + .radio-option-label {
  border-color: var(--accent);
  color: var(--accent);
}

.radio-option:hover input[type="radio"]:checked + .radio-option-label {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: white;
}

/* Read-only info list */
.info-list {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-top: 6px;
}

.btn-start {
  display: block;
  width: 100%;
  padding: 10px;
  margin-top: 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-start:hover { background: var(--accent-hover); }
.btn-start:active { transform: scale(0.98); }
.btn-start:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }

/* ===== QUIZ SCREEN ===== */
.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 4px;
}

.progress-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 100px;
  transition: width 0.4s ease;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-bottom: 10px;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 16px;
  margin-left: 6px;
}

.question-text {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 14px;
}

/* Answer options */
.answers-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.answer-item {
  position: relative;
}

.answer-item input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.answer-item label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 0.875rem;
  line-height: 1.4;
}

.answer-item label:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.answer-item input:checked + label {
  border-color: var(--accent);
  background: var(--accent-light);
}

.answer-letter {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  transition: all 0.15s;
}

.answer-item input:checked + label .answer-letter {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

/* Multi-response hint */
.multi-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Quiz buttons */
.quiz-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.btn-submit {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
  background: var(--accent);
  color: white;
}

.btn-submit:hover { background: var(--accent-hover); }
.btn-submit:active { transform: scale(0.97); }
.btn-submit:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }

/* ===== RESULTS SCREEN ===== */
.results-hero {
  text-align: center;
  padding: 16px 0 12px;
}

.score-ring {
  width: 110px;
  height: 110px;
  margin: 0 auto 12px;
  position: relative;
}

.score-ring svg {
  transform: rotate(-90deg);
}

.score-ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 10;
}

.score-ring-fill {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease;
}

.score-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.score-ring-text small {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
}

.results-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.results-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.pass-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pass-badge.pass { background: var(--success-bg); color: var(--success); }
.pass-badge.fail { background: var(--error-bg); color: var(--error); }

/* Category breakdown */
.breakdown-section {
  margin-top: 16px;
}

.breakdown-section h3 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.bar-chart {
  display: flex;
  gap: 6px;
  padding: 6px 0;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.bar-pct {
  font-size: 0.7rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.bar-track {
  width: 100%;
  max-width: 40px;
  height: 110px;
  background: var(--border);
  border-radius: 4px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  transition: height 0.6s ease;
}

.bar-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.bar-label {
  font-size: 0.65rem;
  color: var(--text);
  text-align: center;
  margin-top: 2px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Results actions */
.results-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn-restart, .btn-retake, .btn-retry-wrong, .btn-show-all, .btn-show-wrong {
  flex: 1;
  min-width: 110px;
  padding: 8px;
  border-radius: 8px;
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-restart { background: var(--accent); color: white; }
.btn-restart:hover { background: var(--accent-hover); }

.btn-retake, .btn-retry-wrong, .btn-show-all, .btn-show-wrong {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}

.btn-retake:hover, .btn-retry-wrong:hover, .btn-show-all:hover, .btn-show-wrong:hover {
  border-color: var(--accent); color: var(--accent);
}

.btn-retry-wrong:disabled, .btn-show-wrong:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== EMPTY / LOADING STATE ===== */
.empty-state {
  text-align: center;
  padding: 32px 20px;
}

.empty-icon { font-size: 2.5rem; margin-bottom: 10px; }

.empty-state h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
  max-width: 320px;
  margin: 0 auto 20px;
  font-size: 0.9rem;
}



/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: transform 0.3s ease;
  z-index: 100;
  white-space: nowrap;
}

.toast.visible { transform: translateX(-50%) translateY(0); }

/* ===== WRONG ANSWERS REVIEW ===== */
.review-item {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.35;
}

.review-item:last-child { border-bottom: none; }

.review-q {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.review-q-num {
  color: var(--text-muted);
  font-weight: 400;
  margin-right: 5px;
}

.review-correct-answers { margin-bottom: 4px; }

.review-correct-ans {
  color: var(--success);
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin-bottom: 2px;
}

.review-explanation {
  color: var(--text-muted);
  font-style: italic;
  margin-top: 3px;
}

.review-user-answers strong, .review-correct-answers strong {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

.review-user-ans {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin-bottom: 2px;
}

.review-user-ans.correct { color: var(--success); }
.review-user-ans.incorrect { color: var(--error); }

.review-status {
  font-weight: 700;
  margin-right: 4px;
}

.review-status.correct { color: var(--success); }
.review-status.incorrect { color: var(--error); }

.btn-print {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
  flex: 1;
  min-width: 110px;
  padding: 8px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-print:hover { border-color: var(--accent); color: var(--accent); }

.print-header, .print-footer { display: none; }

/* ===== PRINT ===== */
@media print {
  body { background: white; }

  #app { max-width: 100%; padding: 0; }

  .app-header,
  .results-actions,
  .toast { display: none !important; }

  .screen { display: none !important; }
  .screen#screen-wrong { display: block !important; }

  .card {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .print-header {
    display: block !important;
    text-align: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #4f46e5;
  }

  .print-brand {
    font-size: 22px;
    font-weight: 700;
    color: #4f46e5;
  }

  .print-url {
    font-size: 9px;
    color: #718096;
    margin-top: 4px;
  }

  .print-footer {
    display: block !important;
    text-align: center;
    margin-top: 24px;
    padding-top: 12px;
    border-top: 1px solid #ddd;
    font-size: 8px;
    color: #718096;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }

  #review-heading {
    font-size: 1.1rem;
    margin-bottom: 12px;
  }

  .review-item {
    page-break-inside: avoid;
    border-bottom: 1px solid #ddd;
    padding: 8px 0;
    font-size: 0.8rem;
  }

  .review-user-ans.correct { color: #059669; }
  .review-user-ans.incorrect { color: #dc2626; }
  .review-correct-ans { color: #059669; }
  .review-status.correct { color: #059669; }
  .review-status.incorrect { color: #dc2626; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 520px) {
  .card { padding: 14px; }
  .start-hero h1 { font-size: 1.3rem; }
  .score-ring { width: 90px; height: 90px; }
  .score-ring-text { font-size: 1.3rem; }
}
