:root {
  --bg: #000;
  --panel: #1e293b;
  --text: #e5e7eb;
  --muted: #a0a0a0;
  --accent: #38bdf8;
  --border: #334155;
}

* { box-sizing: border-box; }

/* .panel等がdisplay:flexを持つため、UA既定の[hidden]スタイルより優先させる必要がある */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Kaku Gothic ProN", "游ゴシック Medium", メイリオ, meiryo, sans-serif;
}

/* ---- ページ全体の骨格 (モバイルファースト: 縦積み) ---- */

.app-shell {
  display: flex;
  flex-direction: column;
  /* iOS Safariはアドレスバー分だけ 100vh が実際の表示領域より大きくなるため、
     動的ビューポート高さ(100dvh)を使い、画面全体を縦スクロールさせず固定する。 */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.site-header {
  flex: none;
  background: #fefefe;
  border-bottom: 1px solid #d4d4d4;
}

.site-header-inner {
  padding: 8px 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

@media (max-width: 767px) {
  .site-header-inner { padding-left: 20px; padding-right: 20px; }
}

.site-logo {
  display: flex;
  align-items: center;
}

.site-logo-img {
  height: clamp(24px, 6vw, 34px);
  width: auto;
  display: block;
}

.site-lang {
  position: relative;
  display: flex;
  align-items: center;
  padding: 4px 6px;
}

.site-lang-icon {
  width: 24px;
  height: 24px;
  background-image: url("../../img/i_lang_select_sp.png");
  background-size: 24px 24px;
  background-repeat: no-repeat;
  background-position: center;
}

.site-lang-label {
  display: none;
}

.site-lang-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  border: none;
  /* 閉じている間は見えないが、開いたプルダウン一覧はこの背景/文字色で描画される */
  background-color: #fff;
  color: #000;
}

.app-header {
  flex: none;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  container-type: inline-size;
  container-name: app-header;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
}

.brand .subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  margin-left: auto;
}

.locate-status { font-size: 0.75rem; color: var(--muted); }

/* 「現在地に更新」ボタン: 従来の更新ボタンと同じ赤(#f0232d)を踏襲する */
.my-location-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  white-space: nowrap;
  background: #f0232d;
  color: #fff;
  border: none;
}

.my-location-btn:hover { background: #d81f28; border-color: transparent; }

.my-location-btn:disabled { opacity: 0.6; cursor: default; }

.my-location-icon { display: inline-flex; align-items: center; }
.my-location-icon svg { display: block; }

/* 折り返す直前の幅ではテキストを消してアイコンのみのボタンにする(天気予報アプリと同じ挙動) */
@container app-header (max-width: 480px) {
  .my-location-btn { gap: 0; padding: 6px 8px; }
  .my-location-text { display: none; }
}

select, button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

#playBtn,
#refreshBtn {
  background: #f0232d;
}

.app-main {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.map-surface {
  position: absolute;
  inset: 0;
}

.card {
  background: #f0f0f0;
  color: #000;
  border: 1px solid #999;
  border-radius: 10px;
}

.locate-btn {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #f0232d;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.locate-btn:hover {
  background: #d81f28;
}

.locate-btn svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

/* 「天気予報に戻る」ボタン: 凡例の行の下に横並びで配置し、左端に黒丸で表示する */
.overlay-btn-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.back-btn {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  text-decoration: none;
}

.back-btn:hover {
  background: rgba(0, 0, 0, 0.85);
}

.back-btn svg {
  width: 20px;
  height: 20px;
}

.overlay-stack {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.overlay-stack > * {
  pointer-events: auto;
}

/* 凡例+開閉トグルをひとまとめにし、凡例を閉じた時にトグルだけがその場に残るようにする。
   #legendBoxが元々持っていた幅の挙動(スマホは100%、PCはauto+max-width)をラッパー側に持たせる。
   トグルは独立した「ボタン」ではなく、カードの下端から突き出た「見出しタブ」に見せるため、
   隙間を無くしてカードと同じ色・枠線で融合させる。 */
.legend-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: 100%;
}

@media (min-width: 768px) {
  .legend-stack { width: auto; }
}

.collapse-toggle-btn {
  flex: none;
  width: 56px;
  height: 20px;
  padding: 0;
  border: 1px solid #999;
  background: #f0f0f0;
  color: #333;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  /* box-shadowは付けない: 影がどちらの方向でも、接している地図/カード/パネル側に
     うっすらと乗ってしまい境界線に見えるため、タブには影自体を使わない。 */
  /* flexアイテムはposition指定が無くてもz-indexが効くため、
     隣接するカード/パネルの境界線より手前に描画してタブとの継ぎ目を隠す */
  position: relative;
  z-index: 1;
}

.collapse-toggle-btn:hover { background: #fff; }

.collapse-toggle-btn svg { width: 16px; height: 16px; }

/* 凡例タブ: カードの下端に突き出る形。上辺はカードの下辺と重ねて段差を消す */
.legend-stack .collapse-toggle-btn {
  margin-top: -1px;
  border-top: none;
  border-radius: 0 0 10px 10px;
}

/* 再生パネル+開閉トグルをひとまとめにする(以前.panel自身が持っていた絶対配置をここへ移す) */
.panel-stack {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* 再生パネルタブ: パネルの上端に突き出る形。下辺はパネルの上辺と重ねて段差を消す。
   背景色は.panelの半透明度(0.85)と完全に一致させ、継ぎ目に色差の線が出ないようにする。 */
.panel-stack .collapse-toggle-btn {
  margin-bottom: -1px;
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  background: rgba(240, 240, 240, 0.85);
}

/* 閉じている間は、タブをヘッダー/フッターに直接くっつく「見出しラベル」として見せる。
   通常はカードの下端/パネルの上端に付くタブだが、カードやパネルが無い(hidden)間は
   overlay-stack/panel-stackの余白(top/bottom:12px)を打ち消す位置までタブ自身を
   絶対配置で動かし、ヘッダー/フッターと隙間なく接するようにする。
   フレックスフローから外すことで、戻る/現在地ボタンの位置には影響させない。 */
.overlay-stack:has(#legendBox[hidden]) #legendToggleBtn {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
}

.panel-stack:has(#radarPanel[hidden]) #panelToggleBtn {
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
}

/* 開閉トグルはレスポンシブ(768px未満)のみの機能。768px以上では常に展開状態で固定表示する */
@media (min-width: 768px) {
  .collapse-toggle-btn { display: none !important; }
  #legendBox[hidden] { display: block !important; }
  #radarPanel[hidden] { display: flex !important; }
}

@media (min-width: 1024px) {
  .panel-stack {
    left: 50%;
    right: auto;
    width: min(720px, calc(100% - 24px));
    transform: translateX(-50%);
  }
}

#updatedAtLabel {
  font-weight: bold;
}

.legend-card {
  padding: 10px 12px;
  font-size: 0.5rem;
  width: 100%;
}

.legend-card h2 {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: #000;
}

#legendScale {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: none;
}

.panel {
  width: 100%;
  /* カード共通の不透明な背景(.card)より、地図が透けて見える半透明の背景にする */
  background: rgba(240, 240, 240, 0.85);
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  flex-direction: column;
  gap: 10px;
}

/* スマホ幅では time-row 周りの上下の余白を詰める */
@media (max-width: 767px) {
  .panel {
    padding: 6px 14px;
    gap: 4px;
  }

  /* 降水強度の凡例はリスト(縦並び)だと縦幅を取るため、横並び+自動改行にする */
  #legendScale {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 12px;
  }
}

.time-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0px 5px;
}

.slider-wrap {
  position: relative;
  flex: 1 1 140px;
}

#timeSlider {
  width: 100%;
  display: block;
}

.slider-ticks {
  position: relative;
  height: 14px;
  margin-top: 2px;
}

.tick-label {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: #000;
  white-space: nowrap;
}

/* 英語のAM/PM表記など、幅の広い時刻表記でも目盛りが重ならないよう縮小する */
@media (max-width: 767px) {
  .tick-label {
    font-size: 0.58rem;
  }
}

.tick-label.tick-now {
  color: #000;
  font-weight: bold;
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-observed {
  background: #f0d025;
  color: #000;
}

.badge-forecast {
  background: #7c2d12;
  color: #fde7d0;
}


.opacity-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #000;
}

#timeSlider,
#opacitySlider {
  accent-color: #e41f35;
}

#opacitySlider {
  flex: 1 1 100px;
  max-width: 200px;
}

.app-footer {
  flex: none;
  padding: 6px 16px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
}

/* ---- タブレット/PC幅: 地図いっぱいに広げ、パネル類を地図上に浮かせる ---- */

@media (min-width: 768px) {
  .site-lang {
    flex-direction: column;
    padding: 4px 10px 2px;
    border-left: 1px solid #f7bbc2;
    border-right: 1px solid #f7bbc2;
  }

  .site-lang-icon {
    width: 32px;
    height: 32px;
    background-image: url("../../img/i_lang_select_pc.png");
    background-size: 32px 32px;
  }

  .site-lang-label {
    display: inline-block;
    color: #f0232d;
    font-size: 11px;
    line-height: 1.4;
  }

  /* PCは凡例を右上のコンパクトな幅に戻す(パネル幅への追従はスマホのみ) */
  .legend-card {
    width: auto;
    max-width: 190px;
    font-size: 0.8rem;
  }

  /* PCでは凡例の縦幅に引きずられないよう、戻るボタンを行から切り離して
     見出し直下(地図の左上)に独立配置する。現在地ボタンは凡例の下に残す。 */
  .overlay-btn-row {
    width: auto;
    justify-content: flex-end;
  }

  .back-btn {
    position: absolute;
    top: 0;
    left: 0;
  }
}

