/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: "Segoe UI", "Meiryo", "Hiragino Kaku Gothic ProN", sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== App Shell ===== */
#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
}

/* ===== Screen Transitions ===== */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn 0.4s ease;
}

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

/* ===== Loading Screen ===== */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 20px;
  color: #94a3b8;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #334155;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== App Header ===== */
.app-header {
  text-align: center;
  padding: 32px 0 16px;
}

.app-header h1 {
  font-size: 1.6rem;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.app-subtitle {
  color: #94a3b8;
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ===== Cards ===== */
.card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 24px;
  margin: 16px 0;
}

/* ===== Start Screen ===== */
.start-card h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
  color: #f1f5f9;
}

.start-card h3 {
  font-size: 0.9rem;
  color: #94a3b8;
  margin-bottom: 10px;
}

.category-checkbox {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.category-checkbox:hover {
  border-color: #60a5fa;
}

.category-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #3b82f6;
  cursor: pointer;
}

.category-name {
  flex: 1;
  font-size: 0.9rem;
}

.category-count {
  color: #64748b;
  font-size: 0.8rem;
}

.options {
  margin: 16px 0;
}

.option-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: #cbd5e1;
  cursor: pointer;
}

.option-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #3b82f6;
  cursor: pointer;
}

.question-count {
  text-align: center;
  font-size: 0.95rem;
  color: #94a3b8;
  margin: 16px 0;
}

.question-count strong {
  color: #60a5fa;
  font-size: 1.2rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

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

.btn-lg {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.05rem;
}

.btn-secondary {
  background: #334155;
  color: #e2e8f0;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-outline {
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
}

.btn-outline:hover {
  border-color: #60a5fa;
  color: #60a5fa;
}

/* ===== Progress Bar ===== */
.quiz-header {
  margin-bottom: 16px;
}

.progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.progress-count {
  font-size: 0.85rem;
  color: #94a3b8;
  white-space: nowrap;
  min-width: 60px;
}

.progress-bar-bg {
  flex: 1;
  height: 8px;
  background: #334155;
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #6366f1);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 600;
  margin-right: 6px;
}

.badge-category {
  background: #1e3a5f;
  color: #60a5fa;
}

.badge-basic {
  background: #166534;
  color: #4ade80;
}

.badge-intermediate {
  background: #78350f;
  color: #fbbf24;
}

.badge-advanced {
  background: #7f1d1d;
  color: #fca5a5;
}

.badge-type {
  background: #312e81;
  color: #a5b4fc;
}

/* ===== Question Card ===== */
.question-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 16px;
}

.question-meta {
  margin-bottom: 16px;
}

.question-text {
  font-size: 1.05rem;
  line-height: 1.8;
  color: #f1f5f9;
}

/* ===== Choice Buttons ===== */
.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 16px 20px;
  background: #0f172a;
  border: 2px solid #334155;
  border-radius: 10px;
  color: #e2e8f0;
  font-size: 0.95rem;
  line-height: 1.6;
  cursor: pointer;
  transition: all 0.2s;
}

.choice-btn:hover:not(.disabled) {
  border-color: #60a5fa;
  background: #172554;
}

.choice-btn.correct {
  border-color: #22c55e;
  background: #14532d;
}

.choice-btn.incorrect {
  border-color: #ef4444;
  background: #7f1d1d;
}

.choice-btn.disabled {
  cursor: default;
}

.choice-btn.disabled:not(.correct):not(.incorrect) {
  opacity: 0.5;
}

.choice-label {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.choice-btn.correct .choice-label {
  background: #22c55e;
  color: #052e16;
}

.choice-btn.incorrect .choice-label {
  background: #ef4444;
  color: #450a0a;
}

/* ===== Explanation Card ===== */
.explanation-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 24px;
  margin: 16px 0;
  animation: fadeIn 0.4s ease;
}

.explanation-card.result-correct {
  border-left: 4px solid #22c55e;
}

.explanation-card.result-incorrect {
  border-left: 4px solid #ef4444;
}

.result-label {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.result-label.correct {
  color: #4ade80;
}

.result-label.incorrect {
  color: #f87171;
}

.explanation-summary {
  font-size: 0.95rem;
  line-height: 1.8;
  color: #cbd5e1;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #334155;
}

.explanation-detail {
  font-size: 0.85rem;
  line-height: 1.7;
  color: #94a3b8;
  margin-bottom: 8px;
}

.explanation-detail strong {
  color: #cbd5e1;
}

.explanation-detail.is-correct strong {
  color: #4ade80;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #334155;
}

.keyword-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: #1e3a5f;
  color: #93c5fd;
  border-radius: 4px;
}

.btn-next {
  margin-top: 16px;
}

/* ===== Results Screen ===== */
.score-circle {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: 6px solid #334155;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
}

.score-circle.score-a { border-color: #22c55e; }
.score-circle.score-b { border-color: #3b82f6; }
.score-circle.score-c { border-color: #f59e0b; }
.score-circle.score-d { border-color: #ef4444; }

.score-number {
  font-size: 2rem;
  font-weight: 700;
  color: #f1f5f9;
}

.score-total {
  font-size: 0.85rem;
  color: #94a3b8;
}

.score-percentage {
  text-align: center;
  font-size: 1.2rem;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.score-grade {
  text-align: center;
  font-size: 0.95rem;
  margin-bottom: 24px;
  padding: 10px 16px;
  border-radius: 8px;
}

.score-grade.score-a { background: #14532d; color: #4ade80; }
.score-grade.score-b { background: #172554; color: #60a5fa; }
.score-grade.score-c { background: #451a03; color: #fbbf24; }
.score-grade.score-d { background: #450a0a; color: #f87171; }

.stats-section {
  margin: 20px 0;
}

.stats-section h3 {
  font-size: 0.9rem;
  color: #94a3b8;
  margin-bottom: 10px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: 0.85rem;
}

.stat-label {
  flex: 1;
  color: #cbd5e1;
}

.stat-value {
  color: #94a3b8;
  min-width: 60px;
  text-align: right;
}

.stat-bar-bg {
  width: 80px;
  height: 6px;
  background: #334155;
  border-radius: 3px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  background: #3b82f6;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

/* ===== App Info Section ===== */
.app-info h2 {
  font-size: 1.1rem;
  color: #f1f5f9;
  margin-bottom: 16px;
}

.info-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  font-size: 0.85rem;
}

.info-list dt {
  color: #94a3b8;
  font-weight: 600;
  white-space: nowrap;
}

.info-list dd {
  color: #cbd5e1;
}

.info-details {
  margin-top: 16px;
  border-top: 1px solid #334155;
  padding-top: 12px;
}

.info-details summary {
  font-size: 0.85rem;
  color: #60a5fa;
  cursor: pointer;
  font-weight: 600;
  padding: 4px 0;
}

.info-details summary:hover {
  color: #93c5fd;
}

.info-details-content {
  margin-top: 12px;
  font-size: 0.8rem;
  line-height: 1.8;
  color: #94a3b8;
}

.info-details-content h3 {
  font-size: 0.85rem;
  color: #cbd5e1;
  margin: 12px 0 6px;
}

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

.info-details-content ul {
  list-style: none;
  padding: 0;
}

.info-details-content li {
  padding-left: 16px;
  position: relative;
  margin-bottom: 6px;
}

.info-details-content li::before {
  content: '・';
  position: absolute;
  left: 0;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 24px 16px;
  color: #475569;
  font-size: 0.8rem;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  #app {
    padding: 12px;
  }

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

  .card {
    padding: 16px;
  }

  .question-card {
    padding: 16px;
  }

  .choice-btn {
    padding: 14px 16px;
    font-size: 0.9rem;
  }

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

  .score-number {
    font-size: 1.6rem;
  }
}
