/* ========== リセット・基本 ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Nunito', 'Noto Sans JP', system-ui, -apple-system, sans-serif;
  background: #F9FAFB;
  color: #1F2937;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
button:disabled { cursor: not-allowed; opacity: 0.6; }

/* ========== レイアウト ========== */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  background: #FFFFFF;
}
.institution-bar {
  background: #F9FAFB;
  border-bottom: 1px solid #E5E7EB;
  padding: 6px 16px;
  text-align: center;
}
.institution-bar p {
  font-size: 12px;
  color: #6B7280;
  font-weight: 500;
}
.copyright {
  margin-top: auto;
  padding: 14px 16px;
  text-align: center;
  border-top: 1px solid #F3F4F6;
}
.copyright p {
  font-size: 11px;
  color: #9CA3AF;
}
.screen { flex: 1; display: flex; flex-direction: column; }

/* ========== ホーム画面 ========== */
.hero {
  background:
    radial-gradient(circle at 20% 20%, rgba(255,255,255,0.12), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(255,255,255,0.10), transparent 50%),
    linear-gradient(135deg, #2563EB 0%, #1D4ED8 60%, #1E40AF 100%);
  color: #FFFFFF;
  padding: 40px 24px 56px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.04) 0, rgba(255,255,255,0.04) 2px, transparent 2px, transparent 40px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,0.04) 0, rgba(255,255,255,0.04) 2px, transparent 2px, transparent 40px);
  pointer-events: none;
}
.hero-inner { position: relative; z-index: 1; }
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 20px;
}
.badge-star {
  display: inline-block;
  color: #FBBF24;
  font-size: 14px;
  line-height: 1;
}
.hero-title {
  font-size: 44px;
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}
.hero-title-accent { color: #FBBF24; }
.hero-sub { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.hero-caption { font-size: 13px; opacity: 0.85; }

.home-body { padding: 28px 20px 32px; }
.section-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 16px;
  color: #111827;
}
.howto { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.howto-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: #F3F4F6;
  border-radius: 12px;
}
.howto-icon {
  flex-shrink: 0;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  font-size: 20px;
}
.howto-icon--pink { background: #FCE7F3; }
.howto-icon--gray { background: #E5E7EB; }
.howto-icon--orange { background: #FED7AA; }
.howto-icon--green { background: #D1FAE5; }
.howto-title { font-size: 14px; font-weight: 700; color: #111827; }
.howto-desc { font-size: 12px; color: #6B7280; margin-top: 2px; }

.notice {
  margin-top: 20px;
  padding: 14px 16px;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: 12px;
}
.notice-title { font-size: 13px; font-weight: 700; color: #1E40AF; margin-bottom: 4px; }
.notice-body { font-size: 12px; color: #1E3A8A; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 20px;
}
.stat {
  padding: 16px 8px;
  border-radius: 12px;
  text-align: center;
}
.stat-blue { background: #DBEAFE; color: #1E40AF; }
.stat-orange { background: #FFEDD5; color: #C2410C; }
.stat-green { background: #D1FAE5; color: #047857; }
.stat-num { font-size: 28px; font-weight: 900; }
.stat-label { font-size: 12px; font-weight: 600; margin-top: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  transition: transform 0.1s ease, box-shadow 0.2s ease, background 0.2s ease;
  width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn-large { padding: 18px 24px; font-size: 17px; margin-top: 22px; }
.btn-primary {
  background: #2563EB;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}
.btn-primary:hover { background: #1D4ED8; }
.btn-secondary {
  background: #F3F4F6;
  color: #374151;
}
.btn-secondary:hover { background: #E5E7EB; }
.mic-caption {
  text-align: center;
  font-size: 12px;
  color: #9CA3AF;
  margin-top: 12px;
}

/* カテゴリ選択 */
.category-select {
  margin-top: 24px;
}
.category-select-label {
  font-size: 14px;
  font-weight: 800;
  color: #111827;
  margin-bottom: 10px;
}
.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.category-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.category-chip {
  flex: 1;
  text-align: left;
  padding: 12px 16px;
  border: 2px solid #E5E7EB;
  background: #FFFFFF;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  color: #374151;
  transition: all 0.15s ease;
}
.category-chip:hover { border-color: #93C5FD; color: #2563EB; }
.category-chip.is-selected {
  border-color: #2563EB;
  background: #2563EB;
  color: #FFFFFF;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}
.category-chip--all {
  font-weight: 800;
}
.qa-btn {
  flex-shrink: 0;
  padding: 10px 14px;
  border: 1px solid #FBBF24;
  background: #FFFBEB;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #B45309;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.qa-btn:hover { background: #FEF3C7; }

/* 問題と正解モーダル */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
body.modal-open { overflow: hidden; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  backdrop-filter: blur(2px);
}
.modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: #FFFFFF;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  animation: fadeInUp 0.2s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #F3F4F6;
}
.modal-title { font-size: 16px; font-weight: 800; color: #111827; }
.modal-close {
  font-size: 24px;
  line-height: 1;
  color: #9CA3AF;
  width: 32px; height: 32px;
  border-radius: 8px;
}
.modal-close:hover { background: #F3F4F6; color: #374151; }
.qa-list {
  list-style: none;
  overflow-y: auto;
  padding: 12px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.qa-item {
  padding: 12px 14px;
  background: #F9FAFB;
  border: 1px solid #F3F4F6;
  border-radius: 12px;
}
.qa-prompt { font-size: 14px; font-weight: 700; color: #111827; line-height: 1.4; }
.qa-answer {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px;
  font-weight: 600;
  color: #059669;
  margin-top: 6px;
  word-break: break-word;
}
.qa-explain { font-size: 12px; color: #6B7280; margin-top: 4px; }

/* ========== クイズ画面 ========== */
.quiz-header {
  padding: 14px 20px 8px;
  border-bottom: 1px solid #F3F4F6;
}
.quiz-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.quiz-progress-num { font-size: 13px; color: #6B7280; }
.quiz-progress-num strong { font-size: 18px; color: #111827; font-weight: 800; }
.quiz-score { font-size: 15px; font-weight: 800; color: #059669; }
.progress-bar {
  height: 6px;
  background: #E5E7EB;
  border-radius: 9999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2563EB, #3B82F6);
  width: 0%;
  transition: width 0.4s ease;
}

.quiz-body { padding: 20px; display: flex; flex-direction: column; gap: 20px; }

.category-badge {
  display: inline-block;
  align-self: flex-start;
  padding: 6px 14px;
  background: #DBEAFE;
  color: #1E40AF;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 700;
}

.question-card {
  background: #FFFFFF;
  border: 1px solid #E5E7EB;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.question-no { font-size: 12px; color: #9CA3AF; margin-bottom: 8px; font-weight: 500; }
.prompt-text {
  font-size: 22px;
  font-weight: 800;
  color: #111827;
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.question-card hr {
  border: none;
  border-top: 1px solid #F3F4F6;
  margin: 16px 0 12px;
}
.hint-label { font-size: 12px; color: #9CA3AF; margin-bottom: 4px; }
.hint-text {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 17px;
  color: #2563EB;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.mic-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.mic-ring {
  position: relative;
  width: 92px; height: 92px;
}
.mic-ring-svg {
  width: 100%; height: 100%;
  transform: rotate(-90deg);
}
.mic-ring-bg { fill: none; stroke: #E5E7EB; stroke-width: 6; }
.mic-ring-progress {
  fill: none;
  stroke: #9CA3AF;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 289.03;
  stroke-dashoffset: 289.03;
  transition: stroke-dashoffset 0.1s linear, stroke 0.2s ease;
}
.mic-ring.listening .mic-ring-progress { stroke: #F97316; }
.mic-ring.success .mic-ring-progress { stroke: #10B981; stroke-dashoffset: 0 !important; }
.mic-ring.fail .mic-ring-progress { stroke: #EF4444; stroke-dashoffset: 0 !important; }

.mic-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.mic-icon { font-size: 28px; color: #9CA3AF; }
.mic-count {
  font-size: 28px;
  font-weight: 900;
  color: #F97316;
}

.mic-status { font-size: 14px; color: #6B7280; font-weight: 600; min-height: 20px; }
.mic-substatus { font-size: 12px; color: #9CA3AF; min-height: 16px; }

.btn-mic {
  background: #EF4444;
  color: #FFFFFF;
  font-size: 17px;
  padding: 18px 24px;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}
.btn-mic:hover:not(:disabled) { background: #DC2626; }
.btn-mic.listening { background: #F87171; }
.btn-mic.disabled { background: #D1D5DB; color: #6B7280; box-shadow: none; }
.mic-btn-icon { font-size: 18px; }

.result-panel {
  background: #FFFFFF;
  border: 1px solid #E5E7EB;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  animation: fadeInUp 0.3s ease;
}
.result-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 14px;
}
.result-badge.correct { background: #D1FAE5; color: #047857; }
.result-badge.wrong { background: #FEE2E2; color: #B91C1C; }
.result-badge.timeout { background: #EFF6FF; color: #1D4ED8; }
.result-badge.unclear { background: #FEF3C7; color: #92400E; }

/* キーボードで答えるときの導線 */
.btn-type {
  background: #FFFFFF;
  color: #4B5563;
  border: 2px solid #D1D5DB;
  font-size: 14px;
  padding: 12px;
  margin-top: 10px;
}
.type-panel {
  background: #F9FAFB;
  border: 1px solid #E5E7EB;
  border-radius: 14px;
  padding: 16px;
  margin-top: 12px;
}
.type-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: #374151;
  margin-bottom: 8px;
}
.type-input {
  width: 100%;
  box-sizing: border-box;
  font-family: "IBM Plex Mono", monospace;
  font-size: 16px; /* iOS で入力時に拡大されないよう 16px 以上にする */
  padding: 12px;
  border: 2px solid #D1D5DB;
  border-radius: 10px;
  margin-bottom: 12px;
}
.type-input:focus {
  outline: none;
  border-color: #2563EB;
}
.type-panel .btn { margin-bottom: 8px; }
.type-panel .btn:last-child { margin-bottom: 0; }
.unclear-text {
  font-size: 14px;
  line-height: 1.8;
  color: #374151;
  margin: 0 0 16px;
}
.result-label {
  font-size: 11px;
  color: #9CA3AF;
  font-weight: 600;
  margin-top: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.result-user {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px;
  color: #374151;
  margin-top: 2px;
  word-break: break-word;
}
.result-answer {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 17px;
  color: #059669;
  font-weight: 600;
  margin-top: 2px;
  word-break: break-word;
}
.result-explain {
  font-size: 13px;
  color: #4B5563;
  margin-top: 2px;
}
.result-panel .btn { margin-top: 14px; }

.btn-retry {
  background: #F97316;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}
.btn-retry:hover { background: #EA580C; }

/* ========== 結果画面 ========== */
.result-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.result-hero {
  width: 100%;
  padding: 32px 24px 28px;
  text-align: center;
  color: #FFFFFF;
  background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 60%, #1E40AF 100%);
}
.result-trophy { font-size: 40px; line-height: 1; }
.result-title { font-size: 24px; font-weight: 900; margin-top: 8px; }
.result-subtitle { font-size: 13px; opacity: 0.9; margin-top: 4px; }

.result-grade {
  margin-top: -36px;
  width: 96px; height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #FFFFFF;
  border: 4px solid #F97316;
  color: #F97316;
  font-size: 44px;
  font-weight: 900;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}
.result-grade[data-grade="A"] { border-color: #10B981; color: #10B981; }
.result-grade[data-grade="B"] { border-color: #2563EB; color: #2563EB; }
.result-grade[data-grade="C"] { border-color: #F97316; color: #F97316; }

.result-score-line {
  margin-top: 16px;
  font-size: 36px;
  font-weight: 900;
  color: #111827;
}
.result-score-slash { font-size: 20px; color: #9CA3AF; font-weight: 700; }
.result-rate { font-size: 14px; color: #6B7280; margin-top: 2px; }

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  padding: 20px 20px 0;
}
.result-stat {
  padding: 14px 8px;
  border-radius: 12px;
  text-align: center;
}
.result-stat--correct { background: #ECFDF5; }
.result-stat--wrong { background: #FEF2F2; }
.result-stat--timeout { background: #F3F4F6; }
.result-stat-num { font-size: 24px; font-weight: 900; }
.result-stat--correct .result-stat-num { color: #059669; }
.result-stat--wrong .result-stat-num { color: #DC2626; }
.result-stat--timeout .result-stat-num { color: #6B7280; }
.result-stat-label { font-size: 12px; font-weight: 600; color: #4B5563; margin-top: 2px; }

.result-breakdown-wrap { width: 100%; padding: 20px 20px 0; }
.result-breakdown-title { font-size: 14px; font-weight: 800; color: #111827; margin-bottom: 10px; }
.result-breakdown {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}
.breakdown-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #F9FAFB;
}
.breakdown-item--correct { background: #ECFDF5; }
.breakdown-item--wrong { background: #FEF2F2; }
.breakdown-item--timeout { background: #F3F4F6; }
.breakdown-icon { flex-shrink: 0; font-weight: 900; font-size: 14px; line-height: 1.5; }
.breakdown-item--correct .breakdown-icon { color: #059669; }
.breakdown-item--wrong .breakdown-icon,
.breakdown-item--timeout .breakdown-icon { color: #DC2626; }
.breakdown-body { min-width: 0; }
.breakdown-prompt { font-size: 13px; color: #374151; line-height: 1.4; }
.breakdown-answer {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  color: #059669;
  font-weight: 600;
  margin-top: 2px;
  word-break: break-word;
}
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 24px 20px 8px;
}

/* ========== アニメーション ========== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45), 0 4px 14px rgba(239, 68, 68, 0.35); }
  50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0), 0 4px 14px rgba(239, 68, 68, 0.35); }
}
.btn-mic.listening { animation: micPulse 1.4s ease-in-out infinite; }

@keyframes soundWave {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

/* ========== ユーティリティ ========== */
[hidden] { display: none !important; }

/* ========== レスポンシブ ========== */
@media (max-width: 400px) {
  .hero { padding: 32px 20px 44px; }
  .hero-title { font-size: 36px; }
  .prompt-text { font-size: 19px; }
}
