:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e8edf4;
  --text-muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #334155;
  --radius: 12px;
}

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

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.app-header {
  background: linear-gradient(135deg, #4c1d95 0%, #0f1419 100%);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 2rem;
  padding-top: max(1.5rem, env(safe-area-inset-top));
}

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

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

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.card h2 {
  font-size: 1.35rem;
  margin-bottom: 1rem;
}

.card p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.card a {
  color: var(--accent);
}

.feature-list {
  margin: 1rem 0 1.5rem 1.25rem;
  color: var(--text-muted);
}

.feature-list li {
  margin-bottom: 0.5rem;
}

.info-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  margin: 1.25rem 0;
}

.info-item {
  flex: 1 1 0;
  min-width: 0;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 0.55rem 0.35rem;
  text-align: center;
}

.info-item .value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.info-item .label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  line-height: 1.25;
}

.shuffle-badge {
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: center;
}

.shuffle-badge .badge-short {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

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

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

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

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

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.progress-bar-wrap {
  background: var(--surface-2);
  border-radius: 999px;
  height: 8px;
  margin-bottom: 1.5rem;
  overflow: hidden;
}

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

.exam-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.score-tracker {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
}

.tracker-correct {
  color: var(--success);
}

.tracker-incorrect {
  color: var(--danger);
}

.question-number {
  font-weight: 600;
  color: var(--accent);
}

.question-content {
  margin-bottom: 1.5rem;
}

.question-text {
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.question-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.question-image,
.option-image {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1020;
}

.question-image {
  max-height: 320px;
  object-fit: contain;
}

.options-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option-btn {
  width: 100%;
  text-align: left;
  padding: 1rem 1.25rem;
  min-height: 44px;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #2a2540;
}

.option-btn.selected {
  border-color: var(--accent);
  background: #2e1065;
}

.option-btn.correct {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.15);
  color: var(--text);
}

.option-btn.incorrect {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
  color: var(--text);
}

.option-btn.correct-answer {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.15);
  color: var(--text);
}

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

.option-label {
  display: block;
  width: 100%;
}

.option-image {
  max-height: 180px;
  align-self: center;
}

.feedback-panel {
  margin-top: 1.25rem;
  padding: 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.feedback-panel.hidden {
  display: none;
}

.feedback-panel .feedback-status {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.feedback-panel .feedback-status.correct {
  color: var(--success);
}

.feedback-panel .feedback-status.incorrect {
  color: var(--danger);
}

.feedback-panel .correct-answer-block {
  color: var(--success);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.feedback-panel .your-answer {
  color: var(--danger);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.feedback-panel .explanation {
  background: var(--surface);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.feedback-panel .explanation strong {
  color: var(--text);
  display: block;
  margin-bottom: 0.25rem;
}

.manual-reference {
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.manual-reference strong {
  color: var(--accent);
  display: block;
  margin-bottom: 0.25rem;
}

.review-item .manual-reference {
  margin-top: 0.75rem;
}

.exam-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  gap: 1rem;
}

.score-display {
  text-align: center;
  padding: 2rem 0;
}

.score-circle {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  border: 6px solid var(--border);
}

.score-circle.pass {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

.score-circle.fail {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.score-circle .percent {
  font-size: 2.5rem;
  font-weight: 800;
}

.score-circle .label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.result-status {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.result-status.pass {
  color: var(--success);
}

.result-status.fail {
  color: var(--danger);
}

.result-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.review-header {
  margin-bottom: 1.5rem;
}

.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.review-item.correct-item {
  border-left: 4px solid var(--success);
}

.review-item.incorrect-item {
  border-left: 4px solid var(--danger);
}

.review-item h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.review-item .your-answer,
.review-item .correct-answer-block {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.review-item .your-answer {
  color: var(--danger);
}

.review-item .your-answer.correct-choice {
  color: var(--success);
}

.review-item .correct-answer-block {
  color: var(--success);
}

.review-item .explanation {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.review-item .explanation strong {
  color: var(--text);
  display: block;
  margin-bottom: 0.25rem;
}

.filter-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 0.5rem 1rem;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.filter-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.source-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.source-note a {
  color: var(--accent);
}

.topics-section,
.faq-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.topics-section h3,
.faq-section h3 {
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.topics-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  list-style: none;
}

.topics-list li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.faq-item dt {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.faq-item dd {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-left: 0;
  line-height: 1.55;
}

.btn-start {
  width: 100%;
  max-width: 320px;
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 2rem 2rem;
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-keywords {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.75;
}

@media (max-width: 768px) {
  .app-header {
    padding: 1rem 1.25rem;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

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

  .app-header p {
    font-size: 0.8rem;
    line-height: 1.4;
  }

  .container {
    padding: 1.25rem 1rem 3rem;
  }

  .card h2 {
    font-size: 1.2rem;
  }

  .question-text {
    font-size: 1.05rem;
  }

  .exam-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .score-tracker {
    width: 100%;
    justify-content: space-between;
  }

  .result-actions .btn {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 140px;
  }

  .filter-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.25rem;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  .filter-tabs::-webkit-scrollbar {
    display: none;
  }

  .review-header h2 {
    font-size: 1.2rem;
  }

  .score-circle {
    width: 140px;
    height: 140px;
  }

  .score-circle .percent {
    font-size: 2rem;
  }

  .result-status {
    font-size: 1.25rem;
  }
}

@media (max-width: 600px) {
  .container {
    padding: 1rem 0.85rem 3rem;
  }

  .card {
    padding: 1.25rem;
  }

  .info-grid {
    gap: 0.35rem;
  }

  .info-item {
    padding: 0.45rem 0.2rem;
  }

  .info-item .value {
    font-size: 1rem;
  }

  .info-item .label {
    font-size: 0.58rem;
  }

  .shuffle-badge .badge-long {
    display: none;
  }

  .shuffle-badge .badge-short {
    display: inline;
  }

  .shuffle-badge {
    font-size: 0.8rem;
    padding: 0.45rem 0.75rem;
  }

  .option-btn {
    padding: 0.9rem 1rem;
    font-size: 0.95rem;
  }

  .option-image {
    max-height: 140px;
  }

  .question-image {
    max-height: 220px;
  }

  .feedback-panel {
    padding: 1rem;
    font-size: 0.9rem;
  }

  .exam-nav {
    flex-direction: column;
    position: sticky;
    bottom: 0;
    background: var(--surface);
    margin: 1.5rem -1.25rem -1.25rem;
    padding: 1rem 1.25rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    z-index: 2;
  }

  .exam-nav .btn {
    width: 100%;
  }

  .btn-start {
    max-width: none;
    width: 100%;
  }

  .result-actions {
    flex-direction: column;
  }

  .result-actions .btn {
    width: 100%;
    flex: none;
  }

  .review-item {
    padding: 1.15rem;
  }

  .site-footer {
    padding: 1rem 1rem 1.5rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    font-size: 0.8rem;
  }
}

@media (max-width: 380px) {
  .app-header h1 {
    font-size: 1.1rem;
  }

  .info-item .value {
    font-size: 0.9rem;
  }

  .info-item .label {
    font-size: 0.52rem;
  }

  .tracker-correct,
  .tracker-incorrect {
    font-size: 0.82rem;
  }
}