:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 10px 25px rgba(79, 70, 229, 0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic",
    "Meiryo", sans-serif;
  background: linear-gradient(135deg, #eef2ff 0%, #f5f7fb 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.hero {
  text-align: center;
  margin-bottom: 20px;
  padding: 24px 12px 8px;
}

.hero h1 {
  font-size: 26px;
  color: var(--primary-dark);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

.screen {
  display: none;
}

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

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

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card h2 {
  font-size: 20px;
  margin-bottom: 12px;
  color: var(--primary-dark);
}

.info-list {
  list-style: none;
  margin: 16px 0 20px;
  padding: 14px;
  background: #eef2ff;
  border-radius: 10px;
}

.info-list li {
  padding: 3px 0;
  font-size: 14px;
}

/* ボタン */
.primary-btn,
.secondary-btn,
.ghost-btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  font-family: inherit;
}

.primary-btn {
  background: var(--primary);
  color: white;
  width: 100%;
}

.primary-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.primary-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.secondary-btn {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
}

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

.ghost-btn {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 13px;
}

.ghost-btn:hover {
  background: #eef2ff;
  border-color: var(--primary);
}

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

.hidden {
  display: none !important;
}

/* ===== スマホ用タブ ===== */
.mobile-tabs {
  display: none;
  gap: 8px;
  margin-bottom: 12px;
}

.mobile-tab {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  font-family: inherit;
}

.mobile-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== スプリットレイアウト ===== */
.split-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.pane {
  background: white;
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid #eef2ff;
}

.passage-label {
  background: var(--primary);
  color: white;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

.passage-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary-dark);
}

.passage-text {
  font-size: 15px;
  line-height: 1.85;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 60vh;
  overflow-y: auto;
  padding: 8px 4px;
  -webkit-overflow-scrolling: touch;
}

.passage-text p {
  margin-bottom: 12px;
}

.passage-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  gap: 8px;
}

.passage-counter {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ===== 設問ペイン ===== */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding: 0 4px;
}

.progress {
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 16px;
}

.category {
  background: var(--primary);
  color: white;
  padding: 3px 12px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
}

.progress-bar {
  height: 5px;
  background: #e0e7ff;
  border-radius: 3px;
  margin-bottom: 14px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

.question-card {
  margin-bottom: 0;
  box-shadow: none;
  padding: 16px 4px;
}

.instruction {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.question {
  font-size: 17px;
  margin-bottom: 16px;
  line-height: 1.6;
  color: var(--text);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.option {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: white;
  font-size: 15px;
}

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

.option.selected {
  border-color: var(--primary);
  background: #eef2ff;
}

.option.correct {
  border-color: var(--success);
  background: #d1fae5;
}

.option.incorrect {
  border-color: var(--danger);
  background: #fee2e2;
}

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

.option-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #f3f4f6;
  color: var(--text-muted);
  font-weight: 700;
  margin-right: 10px;
  font-size: 13px;
  flex-shrink: 0;
}

.option.selected .option-marker {
  background: var(--primary);
  color: white;
}

.option.correct .option-marker {
  background: var(--success);
  color: white;
}

.option.incorrect .option-marker {
  background: var(--danger);
  color: white;
}

.quiz-actions {
  display: flex;
  gap: 8px;
}

.quiz-actions button {
  flex: 1;
}

.explanation {
  margin-top: 16px;
  padding: 14px;
  background: #fffbeb;
  border-left: 4px solid var(--warning);
  border-radius: 8px;
}

.explanation h3 {
  color: var(--warning);
  font-size: 15px;
  margin-bottom: 6px;
}

.explanation p {
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

.explanation.correct {
  background: #d1fae5;
  border-left-color: var(--success);
}

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

.explanation.incorrect {
  background: #fee2e2;
  border-left-color: var(--danger);
}

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

/* ===== 結果画面 ===== */
.score-display {
  text-align: center;
  padding: 16px 0;
}

.score-circle {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  font-size: 50px;
  font-weight: 700;
  margin: 0 auto 12px;
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.3);
}

.score-max {
  font-size: 20px;
  font-weight: 500;
  margin-left: 4px;
  opacity: 0.9;
}

.score-message {
  font-size: 17px;
  font-weight: 600;
  color: var(--primary-dark);
  margin-top: 10px;
}

.result-summary {
  margin-top: 24px;
}

.result-summary h3,
.result-details h3 {
  font-size: 17px;
  margin-bottom: 12px;
  color: var(--primary-dark);
}

#passage-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.passage-stat {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.passage-stat .name {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.passage-stat .value {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
}

#result-list {
  list-style: none;
  counter-reset: result;
  margin-bottom: 16px;
}

#result-list li {
  counter-increment: result;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: white;
}

#result-list li::before {
  content: counter(result);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--text-muted);
  color: white;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

#result-list li.correct::before {
  background: var(--success);
}

#result-list li.incorrect::before {
  background: var(--danger);
}

.result-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.5;
}

.result-text .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  margin-right: 6px;
}

.badge.correct {
  background: #d1fae5;
  color: #047857;
}

.badge.incorrect {
  background: #fee2e2;
  color: #b91c1c;
}

.result-text .your-answer {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.result-actions {
  margin-top: 16px;
}

footer {
  text-align: center;
  margin-top: 30px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ===== スマホ対応：タブ式 ===== */
@media (max-width: 768px) {
  .app {
    padding: 12px 10px 40px;
  }
  .hero h1 {
    font-size: 20px;
  }
  .subtitle {
    font-size: 12px;
  }
  .mobile-tabs {
    display: flex;
  }
  .split-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  /* スマホ：本文・設問をトグル */
  .pane {
    display: none;
  }
  .pane.active {
    display: block;
  }
  .card {
    padding: 16px;
  }
  .passage-text {
    max-height: none;
    font-size: 14px;
  }
  .question {
    font-size: 15px;
  }
  .option {
    font-size: 14px;
    padding: 10px 12px;
  }
  .score-circle {
    width: 120px;
    height: 120px;
    font-size: 42px;
  }
}

/* PC：本文を sticky にしてスクロールしても見える */
@media (min-width: 769px) {
  .passage-pane {
    position: sticky;
    top: 16px;
  }
  .passage-text {
    max-height: calc(100vh - 220px);
  }
}
