/* ========================================
   リセット & 基本設定
   ======================================== */

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  line-height: 1.6;
  color: #1f2933;
  background: linear-gradient(135deg, #f9f8f6 0%, #f5f5f5 100%);
  min-height: 100vh;
}

/* ========================================
   ヘッダー
   ======================================== */

.header {
  background: linear-gradient(135deg, #f0f2f5 0%, #e8eaed 100%);
  padding: 3rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid #d4d7db;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.header-title {
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  color: #1a3a52;
  margin-bottom: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.header-subtitle {
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: #475569;
  font-weight: 400;
  font-style: italic;
}

/* ========================================
   メインコンテンツ
   ======================================== */

.main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem 1rem;
  flex: 1;
}

.screen {
  display: none;
  animation: fadeIn 0.3s ease-in;
}

.screen-active {
  display: block;
}

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

/* ========================================
   セットアップ画面
   ======================================== */

.setup-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 60vh;
}

.setup-card {
  background: white;
  border-radius: 12px;
  padding: 2.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  max-width: 500px;
  width: 100%;
  border: 1px solid #d4d7db;
}

.setup-card h2 {
  font-size: 1.5rem;
  color: #1a3a52;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ========================================
   フォーム要素
   ======================================== */

.setup-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group label,
.form-group legend {
  font-weight: 600;
  color: #1f2933;
  font-size: 0.95rem;
}

.form-group legend {
  padding: 0;
}

.form-hint {
  font-size: 0.85rem;
  color: #5a6c7d;
  font-weight: 400;
}

input[type="number"] {
  padding: 0.75rem;
  font-size: 1rem;
  border: 2px solid #cbd5e0;
  border-radius: 6px;
  background: #fafbfc;
  color: #1f2933;
  transition: border-color 0.2s, background-color 0.2s;
}

input[type="number"]:focus {
  outline: none;
  border-color: #2563eb;
  background: white;
}

input[type="number"]:invalid {
  border-color: #dc2626;
}

/* ========================================
   チェックボックスグループ
   ======================================== */

.checkbox-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  padding: 1rem 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.checkbox-label:hover {
  background-color: #eef2f5;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #2563eb;
}

.checkbox-label span {
  font-size: 0.95rem;
  color: #1f2933;
}

/* ========================================
   フィルターコンテナ
   ======================================== */

.filter-container {
  margin-bottom: 2rem;
  background: white;
  border-radius: 8px;
  border: 1px solid #d4d7db;
  padding: 1rem;
}

.filter-details {
  cursor: pointer;
}

.filter-summary {
  font-weight: 600;
  color: #1f2933;
  font-size: 0.95rem;
  padding: 0.5rem;
  user-select: none;
  list-style: none;
}

.filter-summary::-webkit-details-marker {
  display: none;
}

.filter-summary::before {
  content: "▼ ";
  display: inline-block;
  margin-right: 0.5rem;
  transition: transform 0.2s;
}

.filter-details[open] .filter-summary::before {
  transform: rotateZ(-180deg);
}

.filter-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #d4d7db;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  color: #1f2933;
}

.filter-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: #2563eb;
}

/* ========================================
   ボタン
   ======================================== */

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  transform: translateY(-2px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: #e8ecf1;
  color: #1f2933;
  border: 1px solid #cbd5e0;
}

.btn-secondary:hover {
  background: #dce4eb;
  border-color: #a0aec0;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  background: #e8ecf1;
  color: #1f2933;
  border: 1px solid #cbd5e0;
}

.btn-small:hover {
  background: #dce4eb;
  border-color: #a0aec0;
}

/* ========================================
   結果画面ヘッダー
   ======================================== */

.result-header {
  background: white;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  border: 1px solid #d4d7db;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.result-info {
  flex: 1;
  min-width: 200px;
}

.result-info h2 {
  font-size: 1.8rem;
  color: #1a3a52;
  margin-bottom: 0.5rem;
}

.result-subtitle {
  font-size: 1rem;
  color: #475569;
}

.result-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ========================================
   タイムライン
   ======================================== */

.timeline {
  position: relative;
  padding: 1rem;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(180deg, #cbd5e0 0%, #a0aec0 50%, #cbd5e0 100%);
  transform: translateX(-50%);
}

.age-marker {
  position: relative;
  background: transparent;
  padding: 0.5rem 0 0.25rem 0;
  margin: 0.75rem 0 0 0;
}

.age-marker-label {
  font-weight: 700;
  font-size: 0.8rem;
  color: white;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  padding: 0.3rem 0.6rem;
  border-radius: 3px;
  display: inline-block;
}

.timeline-event {
  position: relative;
  display: flex;
  gap: 1.5rem;
  margin: 0.5rem 0;
  align-items: stretch;
}

.timeline-event:nth-child(even) {
  flex-direction: row-reverse;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  background: #2563eb;
  border: 3px solid white;
  border-radius: 50%;
  position: absolute;
  left: 50%;
  top: 1rem;
  transform: translateX(-50%);
  z-index: 1;
  box-shadow: 0 0 0 2px #2563eb;
  flex-shrink: 0;
}

.timeline-content {
  flex: 1;
  background: transparent;
}

.timeline-event:nth-child(even) .timeline-content {
  text-align: left;
}

.event-details {
  background: white;
  border-radius: 8px;
  border: 1px solid #d4d7db;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  padding: 0.75rem 1rem;
}

.event-details[open] {
  padding: 1rem;
}

.event-details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
}

.event-details > summary::before {
  content: "▽";
  display: inline-flex;
  width: 1.2em;
  height: 1.2em;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #2563eb;
  font-weight: bold;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.event-details[open] > summary::before {
  transform: rotateZ(-180deg);
}

.event-summary-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  width: 100%;
}

.event-year {
  font-weight: 700;
  font-size: 0.9rem;
  color: #2563eb;
  flex-shrink: 0;
}

.event-age {
  font-size: 0.75rem;
  color: #5a6c7d;
  font-style: italic;
  flex-shrink: 0;
}

.event-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1f2933;
  flex: 1;
}

.event-summary {
  font-size: 0.95rem;
  color: #475569;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.event-region {
  font-size: 0.85rem;
  color: #5a6c7d;
  margin-bottom: 0.5rem;
}

.event-details-content {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #d4d7db;
  display: none;
}

.event-details[open] .event-details-content {
  display: block;
}

.event-category {
  display: inline-block;
  background: #f0f2f5;
  color: #1f2933;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 600;
  flex-shrink: 0;
}

.event-category[data-category="japan"] {
  background: #dbeafe;
  color: #1a3a52;
}

.event-category[data-category="world"] {
  background: #fee2e2;
  color: #7f1d1d;
}

.event-category[data-category="adachi"] {
  background: #dcfce7;
  color: #15803d;
}

.event-category[data-category="technology"] {
  background: #dbeafe;
  color: #1e40af;
}

.event-category[data-category="culture"] {
  background: #fed7aa;
  color: #9a3412;
}

.event-category[data-category="science"] {
  background: #e9d5ff;
  color: #6b21a8;
}

.event-sources {
  font-size: 0.85rem;
  color: #5a6c7d;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #d4d7db;
}

.event-source-link {
  color: #2563eb;
  text-decoration: none;
  word-break: break-word;
}

.event-source-link:hover {
  text-decoration: underline;
}


/* ========================================
   重要度別の視覚的フィードバック
   ======================================== */

.timeline-event.importance-high .timeline-dot {
  width: 14px;
  height: 14px;
  background: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
}

.timeline-event.importance-medium .timeline-dot {
  width: 12px;
  height: 12px;
  background: #a0aec0;
  box-shadow: 0 0 0 2px #a0aec0;
}

.timeline-event.sensitive .event-details {
  border-left: 3px solid #dc2626;
}

/* ========================================
   フッター
   ======================================== */

.footer {
  background: #e8ecf1;
  border-top: 1px solid #d4d7db;
  padding: 2rem 1rem;
  text-align: center;
  margin-top: 3rem;
  font-size: 0.9rem;
  color: #475569;
}

.footer p {
  margin-bottom: 0.5rem;
}

.footer-link {
  color: #2563eb;
  text-decoration: none;
  font-weight: 500;
}

.footer-link:hover {
  text-decoration: underline;
}

/* ========================================
   レスポンシブ対応
   ======================================== */

@media (max-width: 768px) {
  .header {
    padding: 1.5rem 1rem;
  }

  .header-title {
    font-size: 1.3rem;
  }

  .main {
    padding: 0.75rem 0.5rem;
  }

  .setup-card {
    padding: 1.5rem;
  }

  .setup-card h2 {
    font-size: 1.2rem;
  }

  .checkbox-group {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .timeline {
    padding: 0.5rem 0;
  }

  .timeline::before {
    left: 15px;
  }

  .timeline-event {
    flex-direction: column;
    gap: 0;
    margin: 0.25rem 0;
    margin-left: 1.5rem;
  }

  .timeline-event:nth-child(even) {
    flex-direction: column;
  }

  .timeline-dot {
    left: 15px;
    top: 0.75rem;
  }

  .event-details {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d4d7db;
    border-radius: 6px;
  }

  .event-details[open] {
    padding: 0.75rem;
  }

  .event-summary-header {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .event-year {
    font-size: 0.8rem;
  }

  .event-age {
    font-size: 0.65rem;
  }

  .event-title {
    font-size: 0.85rem;
    flex-basis: 100%;
  }

  .event-category {
    font-size: 0.6rem;
    padding: 0.15rem 0.4rem;
  }

  .result-header {
    flex-direction: column;
    align-items: stretch;
  }

  .result-actions {
    justify-content: flex-start;
  }

  .result-info h2 {
    font-size: 1.3rem;
  }

  .filter-checkboxes {
    grid-template-columns: 1fr;
  }

  .age-marker {
    margin: 0.5rem 0 0.25rem 0;
  }

  .age-marker-label {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
  }
}

@media (max-width: 480px) {
  .header-title {
    font-size: 1.2rem;
  }

  .header-subtitle {
    font-size: 0.85rem;
  }

  .setup-card {
    padding: 1rem;
  }

  .btn {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
  }

  .timeline-event {
    margin-left: 1.2rem;
  }

  .timeline::before {
    left: 12px;
  }

  .timeline-dot {
    left: 12px;
  }

  .event-details {
    padding: 0.5rem 0.6rem;
  }

  .event-year {
    font-size: 0.75rem;
  }

  .event-age {
    font-size: 0.6rem;
  }

  .event-title {
    font-size: 0.8rem;
  }

  .event-category {
    font-size: 0.55rem;
  }

  .result-info h2 {
    font-size: 1.1rem;
  }

  .result-subtitle {
    font-size: 0.85rem;
  }
}

/* ========================================
   アクセシビリティ
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-color-scheme: dark) {
  body {
    background: linear-gradient(135deg, #1a1f2e 0%, #1e2636 100%);
    color: #e5e7eb;
  }

  .header {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    border-bottom-color: #4a5568;
    color: #e5e7eb;
  }

  .header-title {
    color: #93c5fd;
  }

  .header-subtitle {
    color: #cbd5e0;
  }

  .setup-card,
  .filter-container,
  .result-header,
  .event-details,
  .age-marker {
    background: #2d3748;
    border-color: #4a5568;
    color: #e5e7eb;
  }

  .setup-card h2 {
    color: #93c5fd;
  }

  .form-group label,
  .form-group legend {
    color: #f3f4f6;
    font-weight: 600;
  }

  .form-hint {
    color: #cbd5e0;
  }

  input[type="number"] {
    background: #1a202c;
    color: #f3f4f6;
    border-color: #4a5568;
  }

  input[type="number"]:focus {
    background: #2d3748;
    border-color: #60a5fa;
  }

  input[type="number"]::placeholder {
    color: #9ca3af;
  }

  .checkbox-label {
    color: #f3f4f6;
  }

  .checkbox-label span {
    color: #f3f4f6;
  }

  .checkbox-label:hover {
    background-color: #3d4659;
  }

  .filter-summary,
  .filter-label {
    color: #f3f4f6;
  }

  .filter-label span {
    color: #f3f4f6;
  }

  .btn-secondary,
  .btn-small {
    background: #3d4659;
    color: #f3f4f6;
    border-color: #4a5568;
  }

  .btn-secondary:hover,
  .btn-small:hover {
    background: #4a5568;
    color: #f3f4f6;
  }

  .result-info h2 {
    color: #93c5fd;
  }

  .result-subtitle {
    color: #cbd5e0;
  }

  .event-year {
    color: #60a5fa;
  }

  .event-age {
    color: #cbd5e0;
  }

  .event-title {
    color: #f3f4f6;
  }

  .event-summary {
    color: #d1d5db;
  }

  .event-region {
    color: #cbd5e0;
  }

  .event-details-content {
    border-top-color: #4a5568;
  }

  .event-details > summary::before {
    color: #60a5fa;
  }

  .event-category {
    background: #3d4659;
    color: #f3f4f6;
  }

  .event-category[data-category="japan"] {
    background: #1e3a8a;
    color: #93c5fd;
  }

  .event-category[data-category="world"] {
    background: #7f1d1d;
    color: #fca5a5;
  }

  .event-category[data-category="adachi"] {
    background: #15803d;
    color: #86efac;
  }

  .event-category[data-category="technology"] {
    background: #1e3a8a;
    color: #93c5fd;
  }

  .event-category[data-category="culture"] {
    background: #92400e;
    color: #fed7aa;
  }

  .event-category[data-category="science"] {
    background: #581c87;
    color: #e9d5ff;
  }

  .event-sources {
    color: #cbd5e0;
    border-top-color: #4a5568;
  }

  .event-source-link {
    color: #60a5fa;
  }

  .footer {
    background: #2d3748;
    border-top-color: #4a5568;
    color: #cbd5e0;
  }

  .footer-link {
    color: #60a5fa;
  }
}

/* ========================================
   フォーカス・活性状態のアクセシビリティ
   ======================================== */

input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.checkbox-label:focus-within {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 4px;
}

/* ========================================
   エラーメッセージ
   ======================================== */

.error-message {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #dc2626;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
  font-weight: 500;
  max-width: 90%;
  z-index: 1000;
  word-break: break-word;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  .error-message {
    background: #991b1b;
    color: #fee2e2;
  }
}

/* ========================================
   ローディング状態（フェッチ中）
   ======================================== */

.loading {
  opacity: 0.6;
  pointer-events: none;
}
