/* ===========================
   リセット・基本設定
=========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1a56db;
  --primary-dark: #1e429f;
  --primary-light: #e8f0fe;
  --accent: #2563eb;
  --success: #057a55;
  --success-light: #def7ec;
  --error: #e02424;
  --error-light: #fde8e8;
  --warning: #c27803;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 6px;
  --radius-sm: 4px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ===========================
   レイアウト
=========================== */
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 16px;
}

main {
  flex: 1;
  padding: 24px 0 48px;
}

/* ===========================
   トップナビゲーションバー
=========================== */
.site-topbar {
  background: var(--primary);
  color: white;
  padding: 0;
}

.topbar-inner {
  display: flex;
  align-items: stretch;
  height: 52px;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: white;
  font-size: 1.15rem;
  font-weight: 800;
  padding: 0 20px 0 0;
  border-right: 1px solid rgba(255,255,255,0.2);
  white-space: nowrap;
  text-decoration: none;
}

.site-logo:hover {
  text-decoration: none;
  color: white;
}

.site-logo-icon {
  font-size: 1.3rem;
}

.topbar-nav {
  display: flex;
  align-items: stretch;
  padding: 0 8px;
  flex: 1;
}

.topbar-nav a {
  display: flex;
  align-items: center;
  color: rgba(255,255,255,0.85);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0 14px;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
  border-bottom: 3px solid transparent;
}

.topbar-nav a:hover {
  background: rgba(255,255,255,0.1);
  color: white;
  text-decoration: none;
}

.topbar-nav a.active {
  color: white;
  border-bottom-color: white;
}

/* ===========================
   サブヘッダー（パンくず）
=========================== */
.site-subheader {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--primary);
}

.breadcrumb-sep {
  color: var(--border-strong);
}

/* ===========================
   ページタイトルエリア
=========================== */
.page-hero {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  margin-bottom: 24px;
}

.page-hero-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.page-hero-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ===========================
   統計バー
=========================== */
.stats-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  gap: 0;
}

.stat-item {
  flex: 1;
  text-align: center;
  padding: 0 12px;
  border-right: 1px solid var(--border);
}

.stat-item:last-child {
  border-right: none;
}

.stat-number {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 旧stats-gridとの互換 */
.stats-section { display: none; }

/* ===========================
   クイックスタート
=========================== */
.quick-start-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

/* ===========================
   セクションタイトル
=========================== */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===========================
   カテゴリーグリッド
=========================== */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.category-card {
  background: var(--surface);
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.12s;
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
}

.category-card:hover {
  background: #f0f7ff;
  text-decoration: none;
  color: var(--text);
}

.category-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.category-info {
  flex: 1;
  min-width: 0;
}

.category-name {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--primary);
}

.category-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===========================
   ボタン
=========================== */
.btn-primary {
  display: block;
  background: var(--primary);
  color: white;
  padding: 13px 24px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
  width: 100%;
  text-decoration: none;
}

.btn-primary:hover {
  background: var(--primary-dark);
  color: white;
  text-decoration: none;
}

.btn-secondary {
  display: block;
  background: var(--surface);
  color: var(--primary);
  padding: 11px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  border: 1px solid var(--primary);
  transition: background 0.15s;
  width: 100%;
  text-decoration: none;
}

.btn-secondary:hover {
  background: var(--primary-light);
  text-decoration: none;
}

/* ===========================
   クイズヘッダー
=========================== */
.quiz-header {
  background: var(--primary-dark);
  color: white;
  padding: 12px 0;
}

.quiz-header .container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-home {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-home:hover {
  background: rgba(255,255,255,0.25);
  text-decoration: none;
  color: white;
}

.quiz-title-bar {
  font-size: 0.9rem;
  opacity: 0.85;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===========================
   クイズ画面
=========================== */
.progress-section {
  background: var(--surface);
  padding: 14px 16px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.progress-counter {
  font-weight: 700;
  color: var(--primary);
}

.progress-score {
  color: var(--text-muted);
}

.progress-bar-bg {
  background: var(--border);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  background: var(--primary);
  height: 100%;
  border-radius: 99px;
  transition: width 0.4s ease;
}

.question-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.question-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 3px;
}

.badge-year {
  background: var(--primary-light);
  color: var(--primary);
}

.badge-category {
  background: #ecfdf5;
  color: #065f46;
}

.question-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.7;
  color: var(--text);
}

/* ===========================
   選択肢
=========================== */
.choices-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.choice-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  text-align: left;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  line-height: 1.5;
  width: 100%;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}

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

.choice-num {
  font-weight: 700;
  min-width: 20px;
  color: var(--text-muted);
}

.choice-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
}

.choice-btn.correct .choice-num {
  color: var(--success);
}

.choice-btn.incorrect {
  border-color: var(--error);
  background: var(--error-light);
}

.choice-btn.incorrect .choice-num {
  color: var(--error);
}

/* ===========================
   フィードバック・解説
=========================== */
.feedback-section {
  display: none;
}

.feedback-section.visible {
  display: block;
}

.feedback-banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 12px;
  text-align: center;
}

.feedback-banner.correct {
  background: var(--success-light);
  color: var(--success);
}

.feedback-banner.incorrect {
  background: var(--error-light);
  color: var(--error);
}

.explanation-card {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 14px;
}

.explanation-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--warning);
  margin-bottom: 8px;
}

.explanation-text {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text);
}

.btn-next {
  background: var(--primary);
  color: white;
  border: none;
  padding: 13px 24px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}

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

/* ===========================
   結果画面
=========================== */
.result-screen {
  display: none;
}

.result-screen.visible {
  display: block;
}

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.result-trophy {
  font-size: 3.5rem;
  margin-bottom: 12px;
}

.result-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.result-score {
  font-size: 3rem;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
  margin: 16px 0;
}

.result-detail {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.result-message {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 20px;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===========================
   クイズ設定画面
=========================== */
.quiz-setup-screen {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.quiz-setup-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 18px;
}

.setup-option {
  margin-bottom: 18px;
}

.setup-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.setup-select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.setup-select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===========================
   フッター
=========================== */
.site-footer {
  background: #1f2937;
  color: rgba(255,255,255,0.6);
  padding: 24px 0;
  font-size: 0.75rem;
  line-height: 1.8;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.footer-links {
  display: flex;
  gap: 16px;
}

.footer-links a {
  color: rgba(255,255,255,0.6);
  text-decoration: none;
}

.footer-links a:hover {
  color: white;
  text-decoration: underline;
}

/* ===========================
   ローディング
=========================== */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* ===========================
   レスポンシブ
=========================== */
@media (max-width: 640px) {
  .categories-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-number {
    font-size: 1.2rem;
  }

  .topbar-nav {
    display: none;
  }

  .page-hero {
    padding: 14px 0;
  }

  .footer-inner {
    flex-direction: column;
    text-align: center;
  }
}

@media (max-width: 400px) {
  .categories-grid {
    grid-template-columns: 1fr;
  }

  .stats-bar {
    flex-wrap: wrap;
  }

  .stat-item {
    flex: 0 0 50%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
  }
}
