/* =====================================================
   日本の人口動態予測 - メインスタイルシート（Day 11 完成版）
   ===================================================== */

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

:root {
  --color-primary:   #1a4a8a;
  --color-accent:    #e05c2b;
  --color-bg:        #f5f7fa;
  --color-surface:   #ffffff;
  --color-border:    #dde2ea;
  --color-text:      #1e2b3c;
  --color-muted:     #6b7a93;
  --color-decline:   #c0392b;
  --color-growth:    #2471a3;
  --shadow-sm:       0 1px 4px rgba(0,0,0,.08);
  --shadow-md:       0 4px 16px rgba(0,0,0,.12);
  --radius:          8px;
  --font-sans:       'Noto Sans JP', 'Hiragino Sans', 'Meiryo', sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---------- ヘッダー ---------- */
header {
  background: var(--color-primary);
  color: #fff;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.header-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-title span {
  font-size: .7rem;
  font-weight: 400;
  opacity: .75;
  margin-left: .5rem;
}

@media (max-width: 480px) {
  .header-title span { display: none; }
}

nav { display: flex; align-items: center; gap: .25rem; flex-shrink: 0; }

nav a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .82rem;
  padding: .3rem .65rem;
  border-radius: 4px;
  transition: background .15s, color .15s;
}
nav a:hover  { background: rgba(255,255,255,.15); color: #fff; }
nav a.active { background: rgba(255,255,255,.2);  color: #fff; font-weight: 600; }

/* ---------- ページコンテナ ---------- */
.page-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: .25rem;
}

.page-subtitle {
  font-size: .875rem;
  color: var(--color-muted);
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

/* ---------- カード ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* ---------- 地図ページ レイアウト ---------- */
.map-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 960px) {
  .map-layout { grid-template-columns: 1fr; }
}

/* ---------- 地図 SVG ---------- */
#map-card {
  position: relative;
  min-height: 440px;
}

#japan-map {
  width: 100%;
  height: 500px;
  display: block;
  touch-action: none; /* タッチ操作のズームを有効化 */
}

@media (max-width: 600px) {
  #japan-map { height: 360px; }
  #map-card  { min-height: 360px; }
}

.prefecture-path {
  stroke: #fff;
  stroke-width: .5;
  cursor: pointer;
  transition: opacity .15s, stroke-width .15s;
}
.prefecture-path:hover { opacity: .8; stroke-width: 1.5; stroke: #333; }

/* ---------- コントロールパネル ---------- */
.controls-card {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.control-section label {
  display: block;
  font-size: .75rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .45rem;
}

.year-display {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
  margin-bottom: .45rem;
  font-variant-numeric: tabular-nums;
}

.year-tag {
  display: inline-block;
  font-size: .68rem;
  padding: .15rem .55rem;
  border-radius: 99px;
  margin-left: .35rem;
  font-weight: 700;
}
.year-tag.historical { background: #e8f0fe; color: #1a4a8a; }
.year-tag.forecast   { background: #fce8d8; color: #c0392b; }

input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
  cursor: pointer;
  height: 4px;
}

.year-ticks {
  display: flex;
  justify-content: space-between;
  font-size: .62rem;
  color: var(--color-muted);
  margin-top: .3rem;
}

/* 再生ボタン */
.play-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: .5rem 1rem;
  font-size: .82rem;
  cursor: pointer;
  transition: background .2s;
  font-family: var(--font-sans);
  font-weight: 600;
}
.play-btn:hover  { background: #15387a; }
.play-btn.playing { background: var(--color-accent); }

/* モデルセレクター */
.model-selector {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.model-btn {
  padding: .4rem .7rem;
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  font-size: .82rem;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
  color: var(--color-text);
  font-family: var(--font-sans);
}
.model-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.model-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.model-btn .model-tag {
  font-size: .68rem;
  opacity: .75;
  margin-left: .3rem;
}

/* ---------- 凡例 ---------- */
.legend-wrap { display: flex; flex-direction: column; gap: .4rem; }
.legend-gradient { width: 100%; height: 12px; border-radius: 4px; }
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: .68rem;
  color: var(--color-muted);
}

/* ---------- 情報パネル ---------- */
#info-panel { min-height: 72px; }

.info-pref-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: .2rem;
}
.info-pop {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: .2rem;
  font-variant-numeric: tabular-nums;
}
.info-change { font-size: .875rem; font-weight: 600; }
.info-change.negative { color: var(--color-decline); }
.info-change.positive { color: var(--color-growth); }
.info-placeholder { font-size: .85rem; color: var(--color-muted); font-style: italic; }

/* ランキングリスト */
.ranking-list { list-style: none; font-size: .78rem; }
.ranking-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .3rem .2rem;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background .1s;
  border-radius: 3px;
}
.ranking-list li:hover { background: #f0f4fc; }
.ranking-list li .rank  { color: var(--color-muted); width: 1.4rem; flex-shrink: 0; }
.ranking-list li .pref  { flex: 1; }
.ranking-list li .val   { font-weight: 700; }
.ranking-list li .val.negative { color: var(--color-decline); }
.ranking-list li .val.positive { color: var(--color-growth); }

/* ---------- ツールチップ ---------- */
#tooltip {
  position: fixed;
  background: rgba(10,20,45,.92);
  color: #fff;
  padding: .6rem .9rem;
  border-radius: var(--radius);
  font-size: .8rem;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  display: none;
  line-height: 1.6;
}
#tooltip .tip-name { font-weight: 700; font-size: .9rem; margin-bottom: .15rem; }
#tooltip .tip-chg.neg { color: #f1948a; }
#tooltip .tip-chg.pos { color: #85c1e9; }

/* ---------- 都道府県詳細ページ ---------- */
.pref-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.pref-header h1 { font-size: 1.75rem; color: var(--color-primary); }

.back-link {
  font-size: .85rem;
  color: var(--color-primary);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  margin-bottom: .85rem;
  transition: opacity .15s;
}
.back-link:hover { opacity: .7; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

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

.chart-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: .85rem;
}
.chart-subtitle {
  font-size: .73rem;
  color: var(--color-muted);
  margin-left: .4rem;
  font-weight: 400;
}

/* ピラミッド年ボタン */
.pyramid-controls {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}

.pyramid-year-btn {
  padding: .2rem .55rem;
  border: 1.5px solid var(--color-border);
  border-radius: 4px;
  font-size: .76rem;
  cursor: pointer;
  background: var(--color-surface);
  transition: all .15s;
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--color-text);
}
.pyramid-year-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.pyramid-year-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.pyramid-year-btn.forecast-year { border-style: dashed; }
.pyramid-year-btn.forecast-year.active { border-style: solid; }

#pyramid-svg { width: 100%; display: block; }

/* ピラミッド凡例 */
.pyramid-legend {
  display: flex;
  gap: 1rem;
  font-size: .72rem;
  justify-content: center;
  flex-wrap: wrap;
  color: var(--color-muted);
}
.pyramid-legend span { display: flex; align-items: center; gap: .3rem; }
.legend-box {
  width: 11px; height: 11px; border-radius: 2px; display: inline-block; flex-shrink: 0;
}

/* 時系列グラフ */
#timeseries-chart-wrap { position: relative; }

/* モデル凡例 */
.model-legend {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  font-size: .75rem;
}
.model-legend-item { display: flex; align-items: center; gap: .3rem; }

/* ---------- About ページ ---------- */
.about-section { margin-bottom: 1.75rem; }
.about-section h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: .7rem;
  padding-bottom: .35rem;
  border-bottom: 2px solid var(--color-primary);
}
.about-section p  { font-size: .875rem; line-height: 1.85; margin-bottom: .7rem; }
.about-section ul { font-size: .875rem; line-height: 1.85; padding-left: 1.4rem; }

.data-source-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
  margin-top: .5rem;
}
.data-source-table th, .data-source-table td {
  text-align: left;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.data-source-table th { background: #f0f4fc; font-weight: 700; }

/* ---------- フッター ---------- */
footer {
  background: var(--color-primary);
  color: rgba(255,255,255,.7);
  text-align: center;
  font-size: .78rem;
  padding: 1.25rem;
  margin-top: 4rem;
  line-height: 1.8;
}
footer a { color: rgba(255,255,255,.9); }

/* ---------- ローディング ---------- */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.88);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  z-index: 50;
}
.spinner {
  width: 34px; height: 34px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- ユーティリティ ---------- */
.hidden { display: none !important; }

/* ---------- スマホ追加調整 ---------- */
@media (max-width: 600px) {
  .page-container { padding: 1rem .85rem 3rem; }
  .page-title     { font-size: 1.2rem; }
  .card           { padding: 1rem; }
  .year-display   { font-size: 1.6rem; }
  .controls-card  { gap: .85rem; }
  .pref-header h1 { font-size: 1.4rem; }
  .model-selector { flex-direction: row; flex-wrap: wrap; }
  .model-btn      { flex: 1 1 calc(50% - .2rem); }
  .pyramid-legend { gap: .5rem; }
  footer          { margin-top: 2.5rem; }
}

@media (max-width: 400px) {
  header { padding: 0 .85rem; }
  .header-title { font-size: .9rem; }
}

/* ---------- 印刷対応（ポートフォリオ提出用） ---------- */
@media print {
  header, footer, .play-btn, .model-selector, nav { display: none; }
  .card { box-shadow: none; border: 1px solid #ccc; }
  body  { background: #fff; }
}

/* ---------- フォーカス（アクセシビリティ） ---------- */
a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
