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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f4f6f9;
}

/* ===== HEADER ===== */
.site-header {
  background: linear-gradient(135deg, #1a3a6b 0%, #2563eb 100%);
  color: white;
  padding: 1.25rem 1rem;
  text-align: center;
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

.back-link {
  display: inline-block;
  color: rgba(255,255,255,0.8);
  font-size: 0.85rem;
  text-decoration: none;
  margin-bottom: 0.5rem;
  min-height: 44px;
  line-height: 44px;
}

.back-link:hover {
  color: white;
}

h1 {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.3;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 0.375rem;
}

/* ===== MAIN ===== */
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

/* ===== AD UNIT ===== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ===== CARD ===== */
.card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  margin-bottom: 1.25rem;
}

.card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1a3a6b;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e8edf5;
}

/* ===== DROP ZONE ===== */
.drop-zone {
  border: 2px dashed #93aed8;
  border-radius: 10px;
  padding: 2rem 1rem;
  text-align: center;
  background: #f0f4fb;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.drop-zone.drag-over {
  background: #dde8ff;
  border-color: #2563eb;
}

.drop-zone-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.drop-zone-text {
  font-size: 0.95rem;
  color: #444;
  margin-bottom: 0.375rem;
}

.drop-zone-sub {
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 0.75rem;
}

#file-input {
  display: none;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  min-height: 44px;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
}

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

.btn-primary {
  background: #2563eb;
  color: white;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-secondary {
  background: #e8edf5;
  color: #1a3a6b;
}

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

.file-btn {
  display: inline-block;
  font-size: 0.9rem;
  font-weight: 600;
  background: #2563eb;
  color: white;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  line-height: 44px;
  padding: 0 1.25rem;
  transition: opacity 0.15s;
}

.file-btn:hover {
  opacity: 0.85;
}

/* ===== IMPORT ACTIONS ===== */
.import-actions {
  margin-top: 1rem;
  text-align: center;
}

/* ===== FILE INFO ===== */
.file-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #edf7ed;
  border-radius: 6px;
  font-size: 0.9rem;
}

#file-name-display {
  font-weight: 600;
  color: #2e7d32;
}

#question-count-display {
  color: #555;
}

/* ===== MODE SETTINGS ===== */
.mode-settings {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e8edf5;
}

.mode-settings h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 0.75rem;
}

.mode-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.mode-row label {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.mode-row select {
  flex: 1;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: white;
  min-height: 44px;
}

#start-btn {
  width: 100%;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 6px;
  background: #e0e7ff;
  border-radius: 3px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #2563eb;
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ===== QUIZ META ===== */
.quiz-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  color: #555;
}

.counter {
  font-weight: 600;
  color: #1a3a6b;
}

.score {
  font-weight: 600;
  color: #2563eb;
}

/* ===== QUESTION BOX ===== */
.question-box {
  background: #f0f4fb;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.question-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.7;
  color: #1a1a2e;
}

/* ===== CHOICES GRID ===== */
.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  background: #f4f6f9;
  border: 2px solid #dde3ef;
  border-radius: 8px;
  cursor: pointer;
  min-height: 56px;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s;
  overflow-wrap: break-word;
  word-break: break-word;
  -webkit-tap-highlight-color: transparent;
}

.choice-btn:hover:not(:disabled) {
  background: #e0e7ff;
  border-color: #93aed8;
}

.choice-btn.correct {
  background: #edf7ed;
  border-color: #4caf50;
  color: #1b5e20;
}

.choice-btn.wrong {
  background: #fdecea;
  border-color: #ef5350;
  color: #7f0000;
}

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

.choice-key {
  display: inline-block;
  min-width: 1.4rem;
  height: 1.4rem;
  line-height: 1.4rem;
  text-align: center;
  background: #dde3ef;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.choice-btn.correct .choice-key {
  background: #4caf50;
  color: white;
}

.choice-btn.wrong .choice-key {
  background: #ef5350;
  color: white;
}

/* ===== FEEDBACK AREA ===== */
.feedback-area {
  margin-top: 0.75rem;
  padding: 1rem;
  background: #f9f9f9;
  border-radius: 8px;
  border-left: 4px solid #2563eb;
}

.feedback-text {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.feedback-text.correct-msg {
  color: #2e7d32;
}

.feedback-text.wrong-msg {
  color: #c62828;
}

.explanation-text {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 1rem;
  line-height: 1.6;
}

#next-btn {
  display: block;
  width: 100%;
}

/* ===== RESULT SECTION ===== */
.result-title {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 1.25rem;
}

.result-score-box {
  text-align: center;
  background: linear-gradient(135deg, #e0e7ff, #dde8ff);
  border-radius: 12px;
  padding: 2rem 1rem;
  margin-bottom: 1.5rem;
}

.result-score-num {
  font-size: 3rem;
  font-weight: 800;
  color: #2563eb;
  line-height: 1;
}

.result-score-label {
  font-size: 0.9rem;
  color: #444;
  margin-top: 0.25rem;
}

.result-detail {
  font-size: 0.95rem;
  color: #555;
  margin-top: 0.75rem;
}

.weak-list-area h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1a3a6b;
  margin-bottom: 0.75rem;
}

.weak-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.weak-list li {
  padding: 0.625rem 0.875rem;
  background: #fff5f5;
  border-left: 3px solid #ef5350;
  border-radius: 4px;
  font-size: 0.875rem;
  color: #333;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#retry-btn,
#retry-weak-btn,
#back-import-btn {
  width: 100%;
}

/* ===== HOWTO SECTION ===== */
.howto-section h2 {
  margin-top: 1.5rem;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-list {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
  color: #555;
  font-size: 0.95rem;
}

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

.code-block {
  background: #1e1e2e;
  color: #cdd6f4;
  font-size: 0.8rem;
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre;
  margin: 0.75rem 0;
  font-family: "Courier New", monospace;
  line-height: 1.5;
}

.howto-note {
  font-size: 0.875rem;
  color: #666;
  margin-top: 0.5rem;
}

.howto-section p {
  font-size: 0.95rem;
  color: #555;
  line-height: 1.7;
}

/* ===== FOOTER ===== */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #888;
}

.site-footer a {
  color: #666;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 640px) {
  h1 {
    font-size: 1.75rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .choices-grid {
    gap: 1rem;
  }

  .result-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  #retry-btn {
    flex: 1;
  }

  #retry-weak-btn,
  #back-import-btn {
    flex: 1;
  }
}

/* モバイル: 選択肢を縦1列 */
@media (max-width: 420px) {
  .choices-grid {
    grid-template-columns: 1fr;
  }
}
