@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;700&display=swap');

/* ========================================
   CSS変数定義
======================================== */
:root {
  /* ライトモード */
  --bg-primary: linear-gradient(135deg, #f0f9ff 0%, #ffffff 50%, #fef2f2 100%);
  --bg-secondary: #ffffff;
  --bg-tertiary: #f9fafb;
  --bg-accent: #eff6ff;
  
  --text-primary: #333;
  --text-secondary: #666;
  --text-tertiary: #9ca3af;
  --text-inverse: #ffffff;
  
  --border-primary: #d1d5db;
  --border-secondary: #e5e7eb;
  
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 25px rgba(0,0,0,0.15);
  
  --footer-bg: #1f2937;
  --footer-text: #9ca3af;
}

/* ダークモード */
[data-theme="dark"] {
  --bg-primary: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #1f2937 100%);
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-accent: #1e3a5f;
  
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-tertiary: #94a3b8;
  --text-inverse: #1e293b;
  
  --border-primary: #475569;
  --border-secondary: #334155;
  
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 25px rgba(0,0,0,0.4);
  
  --footer-bg: #0f172a;
  --footer-text: #64748b;
}

/* ========================================
   リセット・ベーススタイル
======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'メイリオ', sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ========================================
   レイアウト
======================================== */
header {
  background: var(--bg-secondary);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 50;
  transition: background 0.3s ease;
}

header .container {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: inherit;
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: bold;
  background: linear-gradient(135deg, #2563eb, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

nav {
  display: flex;
  gap: 1.5rem;
}

nav a {
  text-decoration: none;
  color: var(--text-secondary);
  transition: color 0.2s;
}

nav a:hover {
  color: #2563eb;
}

.mobile-menu-button {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
}

.mobile-menu {
  display: none;
  padding-top: 1rem;
  border-top: 1px solid #eee;
  margin-top: 1rem;
}

.mobile-menu.show {
  display: block;
}

.mobile-menu a {
  display: block;
  padding: 0.5rem 0;
  text-decoration: none;
  color: var(--text-secondary);
}

main {
  padding: 2rem 0;
  min-height: calc(100vh - 200px);
}

footer {
  background: var(--footer-bg);
  color: var(--text-inverse);
  margin-top: 4rem;
  padding: 2rem 0;
  transition: background 0.3s ease;
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
  margin-bottom: 2rem;
}

.footer-section h3 {
  font-size: 1.125rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.footer-section p,
.footer-section a {
  color: var(--footer-text);
  font-size: 0.875rem;
  text-decoration: none;
  line-height: 1.8;
}

.footer-section a:hover {
  color: white;
}

.footer-section .share-btn {
  font-size: 0.75rem;
  padding: 0.5rem 0.75rem;
  margin: 0.25rem;
}

.footer-section .share-icon {
  width: 12px;
  height: 12px;
}

.footer-bottom {
  border-top: 1px solid var(--border-secondary);
  padding-top: 2rem;
  text-align: center;
  color: var(--footer-text);
  font-size: 0.875rem;
}

/* ========================================
   コンポーネント
======================================== */
.card {
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
  margin-bottom: 2rem;
  transition: background 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 1rem;
}

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

.btn-primary:hover {
  background: #1d4ed8;
  transform: translateY(-2px);
}

.btn-secondary {
  background: #e5e7eb;
  color: #374151;
}

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

.input-field {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border-primary);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.input-field:focus {
  outline: none;
  border-color: #2563eb;
}

/* ========================================
   学年表示
======================================== */
.hero {
  text-align: center;
  margin-bottom: 3rem;
}

.hero h1 {
  font-size: 2.5rem;
  font-weight: bold;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #2563eb, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.birth-form {
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
  margin-bottom: 3rem;
  transition: background 0.3s ease;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.info-box {
  background: var(--bg-accent);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1rem;
  margin: 1.5rem 0;
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: background 0.3s ease;
}

.current-age {
  background: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 2rem;
  text-align: center;
  margin-bottom: 2rem;
  transition: background 0.3s ease;
}

.current-age h2 {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.age-number {
  font-size: 3rem;
  font-weight: bold;
  color: #2563eb;
}

.school-section {
  margin-bottom: 2rem;
}

.school-header {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.school-elementary .school-header { color: #ea580c; }
.school-junior .school-header { color: #2563eb; }
.school-high .school-header { color: #db2777; }
.school-university .school-header { color: #7c3aed; }

.school-elementary { border-left: 4px solid #ea580c; }
.school-junior { border-left: 4px solid #2563eb; }
.school-high { border-left: 4px solid #db2777; }
.school-university { border-left: 4px solid #7c3aed; }

.grade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.grade-card {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 1rem;
  transition: background-color 0.2s;
}

.grade-card:hover {
  background: var(--bg-accent);
}

.grade-name {
  font-weight: bold;
  font-size: 1.125rem;
  margin-bottom: 0.5rem;
}

.grade-year {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--text-primary);
}

.grade-era {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-left: 0.5rem;
}

.grade-age {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* ========================================
   イベント表示
======================================== */
.events-section {
  background: linear-gradient(135deg, #faf5ff, #fce7f3);
  border-radius: 12px;
  padding: 2rem;
  margin: 2rem 0;
}

.events-section h3 {
  font-size: 1.5rem;
  font-weight: bold;
  text-align: center;
  margin-bottom: 1.5rem;
}

.event-card {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  border-left: 4px solid #7c3aed;
  box-shadow: var(--shadow-sm);
  transition: background 0.3s ease;
}

.event-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.event-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.event-year {
  font-weight: bold;
  color: #7c3aed;
  font-size: 0.875rem;
}

.event-title {
  color: var(--text-primary);
  font-weight: 500;
  margin: 0.25rem 0;
}

.event-category {
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 0.125rem 0.5rem;
  border-radius: 0.375rem;
  display: inline-block;
  margin-top: 0.25rem;
  transition: background 0.3s ease;
}

/* ========================================
   シェアボタン
======================================== */
.share-section {
  text-align: center;
  margin: 2rem 0;
}

.share-section h3 {
  font-size: 1.125rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.share-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.share-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.share-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.share-btn {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.share-btn:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.share-btn:active {
  transform: scale(0.95);
}

.share-twitter { background: #1da1f2; }
.share-twitter:hover { background: #0d8bd9; }

.share-facebook { background: #4267b2; }
.share-facebook:hover { background: #2d4373; }

.share-line { background: #00b900; }
.share-line:hover { background: #009600; }

.share-instagram { background: #e4405f; }
.share-instagram:hover { background: #c13584; }

.share-copy { background: #6b7280; }
.share-copy:hover { background: #4b5563; }

.share-print { background: #6b7280; }
.share-print:hover { background: #4b5563; }

/* ========================================
   機能紹介セクション
======================================== */
.features-section {
  margin: 4rem 0;
}

.features-section h2 {
  font-size: 1.5rem;
  font-weight: bold;
  text-align: center;
  margin-bottom: 2rem;
  color: var(--text-primary);
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.feature-card {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.feature-card:hover {
  background: var(--bg-accent);
  border-color: #2563eb;
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
  color: inherit;
}

.feature-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.feature-card h3 {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.feature-card p {
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

@media (max-width: 768px) {
  .features-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .feature-card {
    padding: 1.5rem;
  }
  
  .feature-icon {
    font-size: 2.5rem;
  }
}

/* ========================================
   使い方セクション
======================================== */
.howto-section {
  background: var(--bg-accent);
  border-radius: 12px;
  padding: 2rem;
  margin: 4rem 0;
  transition: background 0.3s ease;
}

.howto-section h2 {
  font-size: 1.5rem;
  font-weight: bold;
  text-align: center;
  margin-bottom: 1.5rem;
}

.howto-list {
  max-width: 600px;
  margin: 0 auto;
}

.howto-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.howto-number {
  background: #2563eb;
  color: white;
  border-radius: 50%;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: bold;
  flex-shrink: 0;
}

.hidden {
  display: none !important;
}

/* ========================================
   アニメーション
======================================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* 結果表示アニメーション */
#result-area:not(.hidden) {
  animation: fadeIn 0.6s ease-out;
}

.current-age {
  animation: scaleIn 0.5s ease-out;
}

.age-number {
  animation: pulse 2s ease-in-out infinite;
}

.school-section {
  animation: slideInLeft 0.6s ease-out;
  animation-fill-mode: both;
}

.school-elementary { animation-delay: 0.1s; }
.school-junior { animation-delay: 0.2s; }
.school-high { animation-delay: 0.3s; }
.school-university { animation-delay: 0.4s; }

.grade-card {
  opacity: 0;
  animation: fadeIn 0.4s ease-out forwards;
}

.grade-card:nth-child(1) { animation-delay: 0.05s; }
.grade-card:nth-child(2) { animation-delay: 0.1s; }
.grade-card:nth-child(3) { animation-delay: 0.15s; }
.grade-card:nth-child(4) { animation-delay: 0.2s; }
.grade-card:nth-child(5) { animation-delay: 0.25s; }
.grade-card:nth-child(6) { animation-delay: 0.3s; }

.event-card {
  animation: fadeIn 0.5s ease-out;
  animation-fill-mode: both;
}

.event-card:nth-child(1) { animation-delay: 0.5s; }
.event-card:nth-child(2) { animation-delay: 0.6s; }
.event-card:nth-child(3) { animation-delay: 0.7s; }
.event-card:nth-child(4) { animation-delay: 0.8s; }
.event-card:nth-child(5) { animation-delay: 0.9s; }

/* ボタンホバーアニメーション */
.btn {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:hover {
  box-shadow: 0 10px 20px rgba(0,0,0,0.15);
}

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

/* カードホバーアニメーション */
.card {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.grade-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

/* スムーススクロール */
html {
  scroll-behavior: smooth;
}

/* ========================================
   ダークモードトグル
======================================== */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 2px solid var(--border-primary);
  border-radius: 50px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  margin-right: 1rem;
}

.theme-toggle:hover {
  background: var(--bg-accent);
  transform: scale(1.05);
}

.theme-icon-light,
.theme-icon-dark {
  font-size: 1.25rem;
  transition: opacity 0.3s ease;
}

[data-theme="light"] .theme-icon-dark {
  display: none;
}

[data-theme="dark"] .theme-icon-light {
  display: none;
}

/* ダークモードでの色調整 */
[data-theme="dark"] .btn-primary {
  background: #3b82f6;
}

[data-theme="dark"] .btn-primary:hover {
  background: #2563eb;
}

[data-theme="dark"] .btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

[data-theme="dark"] .btn-secondary:hover {
  background: var(--bg-accent);
}

[data-theme="dark"] .age-number {
  color: #60a5fa;
}

[data-theme="dark"] .back-to-top {
  background: #3b82f6;
}

[data-theme="dark"] .back-to-top:hover {
  background: #2563eb;
}

/* ========================================
   キーボードナビゲーション
======================================== */
/* キーボードナビゲーション時のフォーカス表示 */
.keyboard-nav *:focus {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

[data-theme="dark"] .keyboard-nav *:focus {
  outline-color: #60a5fa;
}

/* フォーカス可能要素のスタイル */
.grade-card:focus,
.event-card:focus,
.history-item:focus {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

[data-theme="dark"] .grade-card:focus,
[data-theme="dark"] .event-card:focus,
[data-theme="dark"] .history-item:focus {
  outline-color: #60a5fa;
}

/* スキップリンク */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #2563eb;
  color: white;
  padding: 0.5rem 1rem;
  text-decoration: none;
  z-index: 100;
  border-radius: 0 0 8px 0;
}

.skip-link:focus {
  top: 0;
}

/* キーボードショートカットのヒント */
.keyboard-hints {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
  z-index: 90;
  max-width: 250px;
}

.keyboard-nav .keyboard-hints {
  opacity: 1;
  visibility: visible;
}

.keyboard-hints h4 {
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.keyboard-hints ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.keyboard-hints li {
  padding: 0.25rem 0;
}

.keyboard-hints kbd {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  padding: 0.125rem 0.375rem;
  font-family: monospace;
  font-size: 0.75rem;
  margin-right: 0.5rem;
}

/* ========================================
   トップへ戻るボタン
======================================== */
.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 50px;
  height: 50px;
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
}

.back-to-top.show {
  opacity: 1;
  visibility: visible;
}

.back-to-top:hover {
  background: #1d4ed8;
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.back-to-top:active {
  transform: translateY(-1px);
}

/* モバイルでの表示位置調整 */
@media (max-width: 768px) {
  .back-to-top {
    bottom: 20px;
    right: 20px;
    width: 45px;
    height: 45px;
  }
}

/* ========================================
   履歴セクション
======================================== */
.history-section {
  margin-bottom: 2rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.history-item:hover {
  background: var(--bg-accent);
  border-color: #2563eb;
  transform: translateX(5px);
}

.history-item-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-date {
  font-weight: 500;
  color: var(--text-primary);
}

.history-age {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.history-timestamp {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.history-favorite {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  transition: transform 0.2s;
}

.history-favorite:hover {
  transform: scale(1.2);
}

.history-favorite.active {
  color: #fbbf24;
}

/* ========================================
   友達比較ページ
======================================== */
.compare-form {
  margin-bottom: 3rem;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 2rem;
  align-items: start;
  margin-bottom: 2rem;
}

.person-input {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 1.5rem;
  transition: background 0.3s ease;
}

.person-input h3 {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 1rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.vs-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
}

.vs-text {
  background: linear-gradient(135deg, #2563eb, #ec4899);
  color: white;
  font-size: 1.5rem;
  font-weight: bold;
  padding: 1rem 1.5rem;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  animation: pulse 2s ease-in-out infinite;
}

.form-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* 比較結果表示 */
.age-diff-summary {
  text-align: center;
  margin-bottom: 2rem;
}

.age-diff-display {
  margin: 1.5rem 0;
}

.age-diff-number {
  font-size: 3rem;
  font-weight: bold;
  color: #2563eb;
  margin-bottom: 0.5rem;
}

.age-diff-detail {
  font-size: 1.125rem;
  color: var(--text-secondary);
}

.current-ages {
  margin-bottom: 2rem;
}

.ages-display {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 1rem;
}

.person-age {
  text-align: center;
  padding: 1.5rem;
  background: var(--bg-tertiary);
  border-radius: 12px;
  transition: background 0.3s ease;
}

.person-label {
  display: block;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.age-value {
  font-size: 2rem;
  font-weight: bold;
  color: #2563eb;
}

/* 学年比較表 */
.grade-comparison {
  margin-bottom: 2rem;
}

.comparison-table {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-primary);
}

.table-header,
.table-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.5fr;
  gap: 1rem;
  padding: 1rem;
  align-items: center;
}

.table-header {
  background: var(--bg-accent);
  font-weight: bold;
  color: var(--text-primary);
}

.table-row {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-secondary);
  transition: background 0.2s ease;
}

.table-row:hover {
  background: var(--bg-tertiary);
}

.school-column {
  font-weight: 500;
  color: var(--text-primary);
}

.person-column {
  text-align: center;
  font-size: 0.875rem;
}

.person-column small {
  color: var(--text-secondary);
}

.diff-column {
  text-align: center;
  font-weight: bold;
  font-size: 0.875rem;
  padding: 0.5rem;
  border-radius: 6px;
}

.same-grade {
  background: #dcfce7;
  color: #166534;
}

.person1-later {
  background: #dbeafe;
  color: #1d4ed8;
}

.person2-later {
  background: #fce7f3;
  color: #be185d;
}

[data-theme="dark"] .same-grade {
  background: #14532d;
  color: #bbf7d0;
}

[data-theme="dark"] .person1-later {
  background: #1e3a8a;
  color: #93c5fd;
}

[data-theme="dark"] .person2-later {
  background: #831843;
  color: #f9a8d4;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
  .compare-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  
  .vs-divider {
    min-height: auto;
    margin: 1rem 0;
  }
  
  .vs-text {
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
  }
  
  .ages-display {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .table-header,
  .table-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    text-align: left;
  }
  
  .table-header > div,
  .table-row > div {
    padding: 0.25rem 0;
  }
  
  .table-header > div:before,
  .table-row > div:before {
    content: attr(data-label) ': ';
    font-weight: bold;
    display: inline;
  }
  
  .diff-column {
    text-align: left;
  }
}

@media (max-width: 480px) {
  .person-input {
    padding: 1rem;
  }
  
  .age-diff-number {
    font-size: 2.5rem;
  }
  
  .age-value {
    font-size: 1.5rem;
  }
}

/* ========================================
   クイズページ
======================================== */
.quiz-menu {
  margin-bottom: 3rem;
}

.quiz-difficulty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.difficulty-card {
  background: var(--bg-tertiary);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.difficulty-card:hover {
  background: var(--bg-accent);
  border-color: #2563eb;
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}

.difficulty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.difficulty-card h3 {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.difficulty-card p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.difficulty-details {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-tertiary);
}

.quiz-stats {
  background: var(--bg-accent);
  border-radius: 12px;
  padding: 1.5rem;
  margin-top: 2rem;
}

.quiz-stats h3 {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
}

.stat-item {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: bold;
  color: #2563eb;
}

/* クイズゲーム画面 */
.quiz-game {
  max-width: 800px;
  margin: 0 auto;
}

.quiz-header {
  margin-bottom: 2rem;
}

.quiz-progress {
  margin-bottom: 1rem;
}

.progress-bar {
  background: var(--bg-tertiary);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  background: linear-gradient(90deg, #2563eb, #ec4899);
  height: 100%;
  transition: width 0.3s ease;
  width: 0%;
}

.question-counter {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.quiz-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.score-display,
.timer-display {
  font-weight: 500;
  color: var(--text-primary);
}

.score-value,
.timer-value {
  font-weight: bold;
  color: #2563eb;
}

.question-card {
  margin-bottom: 2rem;
}

.question-text {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2rem;
  line-height: 1.6;
}

.choices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.choice-btn {
  background: var(--bg-tertiary);
  border: 2px solid var(--border-primary);
  border-radius: 8px;
  padding: 1rem;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-primary);
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.choice-btn:hover:not(:disabled) {
  background: var(--bg-accent);
  border-color: #2563eb;
  transform: translateY(-2px);
}

.choice-btn:disabled {
  cursor: not-allowed;
}

.choice-btn.correct {
  background: #dcfce7;
  border-color: #16a34a;
  color: #166534;
}

.choice-btn.incorrect {
  background: #fef2f2;
  border-color: #dc2626;
  color: #991b1b;
}

[data-theme="dark"] .choice-btn.correct {
  background: #14532d;
  border-color: #22c55e;
  color: #bbf7d0;
}

[data-theme="dark"] .choice-btn.incorrect {
  background: #7f1d1d;
  border-color: #ef4444;
  color: #fecaca;
}

.question-feedback {
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
}

.feedback-result {
  font-size: 1.125rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

.feedback-result.correct {
  color: #16a34a;
}

.feedback-result.incorrect {
  color: #dc2626;
}

.feedback-result.timeout {
  color: #ea580c;
}

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

.quiz-controls {
  text-align: center;
  margin-top: 2rem;
}

/* クイズ結果画面 */
.quiz-result {
  max-width: 800px;
  margin: 0 auto;
}

.result-card {
  text-align: center;
  margin-bottom: 2rem;
}

.result-summary {
  margin: 2rem 0;
}

.final-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.score-display-large {
  font-size: 4rem;
  font-weight: bold;
  color: #2563eb;
}

.score-label {
  font-size: 1.5rem;
  color: var(--text-secondary);
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.result-stat {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 1rem;
}

.result-stat .stat-label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.result-stat .stat-value {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--text-primary);
}

.result-feedback {
  background: var(--bg-accent);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 2rem 0;
}

.performance-message {
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--text-primary);
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 2rem;
}

/* 復習セクション */
.review-section {
  margin-top: 2rem;
}

.review-item {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1rem;
  border-left: 4px solid #dc2626;
}

.review-question {
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.review-answers {
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.user-answer {
  color: #dc2626;
  margin-bottom: 0.25rem;
}

.correct-answer {
  color: #16a34a;
  font-weight: 500;
}

.review-explanation {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
  .quiz-difficulty-grid {
    grid-template-columns: 1fr;
  }
  
  .difficulty-card {
    padding: 1.5rem;
  }
  
  .quiz-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .choices-grid {
    grid-template-columns: 1fr;
  }
  
  .choice-btn {
    min-height: 50px;
    padding: 0.75rem;
  }
  
  .result-stats {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .score-display-large {
    font-size: 3rem;
  }
  
  .result-actions {
    flex-direction: column;
    align-items: center;
  }
  
  .result-actions .btn {
    width: 200px;
  }
}

@media (max-width: 480px) {
  .question-text {
    font-size: 1.125rem;
  }
  
  .difficulty-icon {
    font-size: 2.5rem;
  }
  
  .score-display-large {
    font-size: 2.5rem;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ========================================
   年表ページ
======================================== */
.timeline-form {
  margin-bottom: 3rem;
}

.timeline-summary {
  margin-bottom: 2rem;
}

.summary-info {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2rem;
  align-items: center;
  margin-top: 1rem;
}

.birth-info {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.birth-date {
  font-size: 1.25rem;
  font-weight: bold;
  color: var(--text-primary);
}

.current-age {
  font-size: 1rem;
  color: var(--text-secondary);
}

.timeline-stats {
  display: flex;
  gap: 2rem;
}

.timeline-nav {
  margin-bottom: 2rem;
}

.timeline-nav h3 {
  font-size: 1.125rem;
  font-weight: bold;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.nav-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav-btn {
  background: var(--bg-tertiary);
  border: 2px solid var(--border-primary);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-btn:hover {
  background: var(--bg-accent);
  border-color: #2563eb;
  transform: translateY(-2px);
}

.timeline-container {
  margin-bottom: 3rem;
}

.timeline-content {
  position: relative;
}

.timeline-section {
  margin-bottom: 3rem;
  position: relative;
}

.timeline-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-primary);
}

.section-title {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--text-primary);
  margin: 0;
}

.section-period {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.timeline-track {
  position: relative;
  padding-left: 2rem;
}

.timeline-track::before {
  content: '';
  position: absolute;
  left: 1rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, #e5e7eb, #d1d5db);
}

[data-theme="dark"] .timeline-track::before {
  background: linear-gradient(to bottom, #374151, #4b5563);
}

.timeline-item {
  position: relative;
  margin-bottom: 2rem;
  display: flex;
  gap: 1.5rem;
}

.timeline-item.current {
  background: linear-gradient(135deg, #fef3c7, #fed7aa);
  border-radius: 12px;
  padding: 1rem;
  margin: -1rem 0 1rem -1rem;
}

[data-theme="dark"] .timeline-item.current {
  background: linear-gradient(135deg, #451a03, #7c2d12);
}

.timeline-marker {
  position: relative;
  flex-shrink: 0;
}

.marker-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 3px solid #2563eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  position: relative;
  z-index: 2;
  box-shadow: var(--shadow-sm);
}

.timeline-item.current .marker-icon {
  border-color: #f59e0b;
  background: #fbbf24;
  animation: pulse 2s ease-in-out infinite;
}

.timeline-content-item {
  flex: 1;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.timeline-content-item:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.timeline-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.timeline-year {
  font-size: 1.125rem;
  font-weight: bold;
  color: #2563eb;
  background: var(--bg-accent);
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
}

.timeline-age {
  font-size: 0.875rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.timeline-wareki {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-style: italic;
}

.timeline-main {
  margin-bottom: 1rem;
}

.timeline-title {
  font-size: 1.125rem;
  font-weight: bold;
  color: var(--text-primary);
  margin: 0 0 0.5rem 0;
}

.timeline-description {
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0;
}

.timeline-events {
  background: var(--bg-tertiary);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
}

.timeline-events h5 {
  font-size: 0.875rem;
  font-weight: bold;
  color: var(--text-primary);
  margin: 0 0 0.75rem 0;
}

.events-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.event-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.event-icon {
  flex-shrink: 0;
  font-size: 1rem;
}

.event-title {
  line-height: 1.4;
}

.event-more {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-style: italic;
  padding: 0.25rem 0;
}

/* カテゴリ別のスタイリング */
.timeline-birth .timeline-section-header {
  border-bottom-color: #f59e0b;
}

.timeline-childhood .timeline-section-header {
  border-bottom-color: #10b981;
}

.timeline-elementary .timeline-section-header {
  border-bottom-color: #ea580c;
}

.timeline-junior .timeline-section-header {
  border-bottom-color: #2563eb;
}

.timeline-high .timeline-section-header {
  border-bottom-color: #db2777;
}

.timeline-university .timeline-section-header {
  border-bottom-color: #7c3aed;
}

.timeline-adult .timeline-section-header {
  border-bottom-color: #059669;
}

.timeline-current .timeline-section-header {
  border-bottom-color: #f59e0b;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
  .summary-info {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .timeline-stats {
    flex-direction: column;
    gap: 1rem;
  }
  
  .nav-buttons {
    justify-content: center;
  }
  
  .nav-btn {
    flex: 1;
    min-width: 120px;
    justify-content: center;
  }
  
  .timeline-item {
    flex-direction: column;
    gap: 1rem;
  }
  
  .timeline-track {
    padding-left: 0;
  }
  
  .timeline-track::before {
    display: none;
  }
  
  .timeline-item.current {
    margin: 0 0 2rem 0;
  }
  
  .timeline-marker {
    align-self: flex-start;
  }
  
  .timeline-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .section-title {
    font-size: 1.25rem;
  }
  
  .timeline-content-item {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .birth-date {
    font-size: 1.125rem;
  }
  
  .nav-btn {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
    min-width: 100px;
  }
  
  .timeline-year {
    font-size: 1rem;
  }
  
  .timeline-title {
    font-size: 1rem;
  }
  
  .marker-icon {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.875rem;
  }
}

/* 印刷スタイル */
@media print {
  .timeline-nav,
  .share-section,
  .howto-section {
    display: none !important;
  }
  
  .timeline-item {
    page-break-inside: avoid;
  }
  
  .timeline-section {
    page-break-inside: avoid;
  }
  
  .timeline-content-item {
    box-shadow: none !important;
    border: 1px solid #ddd;
  }
  
  .timeline-track::before {
    background: #ddd !important;
  }
  
  .marker-icon {
    border-color: #666 !important;
    background: white !important;
  }
}

/* ========================================
   モバイルタッチ最適化
======================================== */
/* タッチデバイス向け最適化 */
@media (pointer: coarse) {
  .btn,
  .share-btn,
  .input-field,
  select {
    min-height: 44px;
    font-size: 16px; /* iOSの自動ズームを防ぐ */
  }
  
  .grade-card {
    padding: 1.25rem;
  }
  
  .howto-number {
    width: 2rem;
    height: 2rem;
  }
}

/* スワイプ対応のためのスクロールコンテナ */
.school-section {
  -webkit-overflow-scrolling: touch;
}

/* タップハイライトを無効化 */
* {
  -webkit-tap-highlight-color: transparent;
}

/* フォーム要素のスタイルリセット */
input, select, button {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* ========================================
   レスポンシブ対応
======================================== */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 2rem;
  }
  
  nav {
    display: none;
  }
  
  .mobile-menu-button {
    display: block;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .age-number {
    font-size: 2.5rem;
  }
  
  .share-buttons {
    flex-direction: column;
    align-items: center;
  }
  
  .share-btn {
    width: 200px;
    justify-content: center;
  }
  
  .share-icon {
    width: 14px;
    height: 14px;
  }
}

@media (max-width: 480px) {
  .hero h1 {
    font-size: 1.75rem;
  }
  
  .card {
    padding: 1.5rem;
  }
  
  .birth-form {
    padding: 1.5rem;
  }
}