:root {
  --leaf: #4f8a10;
  --leaf-dark: #3d6b0c;
  --panel-bg: rgba(255, 255, 255, 0.94);
  --panel-border: rgba(0, 0, 0, 0.1);
  --text: #1f2933;
  --text-dim: #64748b;
  --adbar-h: 90px; /* 下部広告バナーの高さ（他の下端要素はこの分だけ上げる） */
}

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

html, body {
  height: 100%;
  max-width: 100%;
  overflow-x: hidden; /* 横方向のはみ出し・シュリンク対策 */
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}

#map {
  position: fixed;
  inset: 0;
}

/* ---- HUD ---- */
.hud {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  min-width: 210px;
  padding: 12px 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.hud h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--leaf);
  letter-spacing: 0.02em;
}

.hud-sub {
  font-size: 10px;
  color: var(--text-dim);
  margin: 2px 0 8px;
  letter-spacing: 0.02em;
}

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  font-size: 13px;
  line-height: 1.8;
}

.hud-label {
  color: var(--text-dim);
}

.hud-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.hud-status {
  margin-top: 6px;
  font-size: 11px;
  color: #f0b429;
}

/* ---- credit footer ---- */
.credit {
  position: fixed;
  bottom: var(--adbar-h); /* 広告バナーの上に表示 */
  left: 0;
  right: 0;
  z-index: 31;
  padding: 6px 12px;
  background: var(--panel-bg);
  border-top: 1px solid var(--panel-border);
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.credit-links {
  margin-left: 8px;
  white-space: normal; /* リンク群は折り返し可（はみ出し防止） */
}

.credit-links a {
  color: var(--leaf-dark);
  text-decoration: none;
  margin: 0 4px;
  white-space: nowrap; /* 各リンクの文字は途中で折らない */
  display: inline-block;
}

.credit-links a:hover {
  text-decoration: underline;
}

.credit-links a + a {
  border-left: 1px solid var(--panel-border);
  padding-left: 8px;
}

/* ---- 現在地ボタン（右下の緑ピン） ---- */
.locate-btn {
  position: fixed;
  right: 14px;
  bottom: calc(var(--adbar-h) + 46px); /* 広告バナー＋クレジットの上 */
  z-index: 35;
  width: 52px;
  height: 52px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.locate-btn svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
  transition: transform 0.12s ease;
}

.locate-btn:hover svg {
  transform: scale(1.06);
}

.locate-btn:active svg {
  transform: scale(0.94);
}

/* 取得中はピンを点滅 */
.locate-btn.loading svg {
  animation: locate-pulse 0.9s ease-in-out infinite;
}

@keyframes locate-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---- 下部広告バナー（AdSense。地図とは別枠でポリシー準拠） ---- */
.adbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--adbar-h);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #ffffff;
  border-top: 1px solid var(--panel-border);
  padding-bottom: env(safe-area-inset-bottom);
}

.adbar .adsbygoogle {
  display: block;
  width: 100%;
  height: 100%;
}

/* AdSense未設定時のプレースホルダ */
.adbar.adbar-placeholder {
  background: #f1f5f9;
  color: #94a3b8;
  font-size: 12px;
  letter-spacing: 0.05em;
}

/* ---- bus marker ---- */
.bus-marker {
  /* MapLibreがマーカー位置を transform で制御する。position:absolute + top/left:0 を
     明示し、maplibregl-marker の指定を上書きしないようにする（relativeにするとズーム時に
     マーカーがドキュメントフロー上で積み上がって位置が崩れる）。ETAバッジ(.eta-badge)は
     この絶対配置要素を基準に配置される。 */
  position: absolute;
  top: 0;
  left: 0;
  width: 26px;
  height: 26px;
  cursor: pointer;
}

.bus-rot {
  width: 100%;
  height: 100%;
}

.bus-marker svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
}

/* ---- search panel ---- */
.search {
  position: fixed;
  top: 174px; /* HUD(サブタイトル付き)と重ならないよう隙間を確保 */
  left: 12px;
  z-index: 10;
  width: 250px;
  padding: 12px 16px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--text);
  /* backdrop-filter は使わない: 内部のfixed現在地ボタンの基準が狂うため（背景はほぼ不透明で影響なし） */
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* 開閉トグル兼タイトル（PCではボタンらしさを消してタイトル表示） */
.search-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  margin-bottom: 10px;
  background: none;
  border: none;
  cursor: default;
  font: inherit;
  text-align: left;
}

.search-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--leaf);
  letter-spacing: 0.04em;
}

.search-caret {
  display: none; /* スマホでのみ表示 */
}

.search-field {
  display: block;
  margin-bottom: 10px;
}

.search-field > span {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.search-field input,
.search-field select {
  width: 100%;
  padding: 7px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  box-sizing: border-box;
}

.search-field input:focus,
.search-field select:focus {
  outline: none;
  border-color: var(--leaf);
  box-shadow: 0 0 0 2px rgba(79, 138, 16, 0.18);
}

.search-field select:disabled {
  background: #f1f5f9;
  color: #94a3b8;
}

.geo-btn {
  width: 100%;
  padding: 7px 10px;
  margin-bottom: 10px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  color: var(--leaf-dark);
  background: transparent;
  border: 1px solid var(--leaf);
  border-radius: 6px;
  cursor: pointer;
}

.geo-btn:hover {
  background: #f6faef;
}

.geo-btn:disabled {
  color: #94a3b8;
  border-color: #cbd5e1;
  cursor: default;
}

.geo-candidates {
  margin-bottom: 10px;
}

.geo-candidates:empty {
  margin-bottom: 0;
}

.geo-note {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.geo-error {
  color: #c0392b;
}

.geo-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  margin-bottom: 5px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
}

.geo-item:hover {
  border-color: var(--leaf);
  background: #f6faef;
}

.geo-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.geo-dist {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  white-space: nowrap;
}

/* 現在地マーカー */
.geo-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #2563eb;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4), 0 1px 4px rgba(0, 0, 0, 0.4);
}

.search-actions {
  display: flex;
  gap: 8px;
}

.search-actions button {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--leaf);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.search-actions button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.search-actions button.ghost {
  flex: 0 0 auto;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid #cbd5e1;
}

.search-results {
  margin-top: 12px;
}

.search-results:empty {
  margin-top: 0;
}

.result-summary {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  margin-bottom: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
}

.result-item:hover {
  border-color: var(--leaf);
  background: #f6faef;
}

/* 時刻表ベースの「次に来る予定」（走行中でないのでクリック不可・淡色） */
.result-item.is-scheduled {
  cursor: default;
  border-style: dashed;
  background: #fafafa;
}

.result-item.is-scheduled:hover {
  border-color: #e2e8f0;
  background: #fafafa;
}

.result-item.is-scheduled .result-eta {
  color: var(--text-dim);
}

.result-eta {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--leaf-dark);
  white-space: nowrap;
}

.result-eta small {
  font-size: 11px;
  font-weight: 600;
}

.result-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.result-route {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-id {
  font-size: 11px;
  color: var(--text-dim);
}

.result-origin {
  font-size: 11px;
  color: #c67d00;
  font-weight: 600;
}

.result-note {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-dim);
}

/* 絞り込み中に隠すバス */
.bus-marker.filtered-out {
  display: none;
}

/* 乗車バス停マーカー（緑） */
.board-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--leaf-dark);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* 目的地バス停マーカー（濃色の二重丸） */
.dest-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #1f2933;
  border: 4px solid #fff;
  box-shadow: 0 0 0 2px #1f2933, 0 1px 4px rgba(0, 0, 0, 0.4);
}

/* 次の予定便の始発地マーカー（琥珀色。未発車の便がどこから来るか）
   position はMapLibreの absolute に任せる（relativeにするとズーム時に崩れる）。
   絶対配置のマーカー要素が .origin-label の配置基準になる。 */
.origin-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #f0a020;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #c67d00, 0 1px 4px rgba(0, 0, 0, 0.4);
}

.origin-label {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 3px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  color: #fff;
  background: #c67d00;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* ETAバッジ（絞り込み中のバスに表示）*/
.eta-badge {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 2px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  color: #fff;
  background: var(--leaf-dark);
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* ---- route popup ---- */
.bus-popup .maplibregl-popup-content {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.bus-popup .maplibregl-popup-tip {
  border-top-color: var(--panel-bg);
  border-bottom-color: var(--panel-bg);
}

.popup-route {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

.popup-vehicle {
  color: var(--text-dim);
  white-space: nowrap;
}

.hud-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

/* MapLibre attribution is duplicated in our footer; keep it compact */
.maplibregl-ctrl-attrib {
  font-size: 10px;
}

/* ---- responsive (スマホ最適化: 検索パネルをボトムシート化) ----
   幅だけでなく「ホバー不可＋粗いポインタ＝タッチ端末」でも適用する。
   一部のアプリ内ブラウザで width=device-width が効かず幅が広く判定される対策。 */
@media (max-width: 640px), (hover: none) and (pointer: coarse) {
  :root {
    --adbar-h: 60px; /* スマホは320x50バナー想定で低め */
  }

  /* ===== スマホUI: 上部アプリバー（緑・白文字） ===== */
  .hud {
    top: 0;
    left: 0;
    right: 0;
    min-width: 0;
    border: none;
    border-radius: 0;
    background: var(--leaf);
    color: #fff;
    backdrop-filter: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .hud-brand { min-width: 0; }

  .hud h1 {
    color: #fff;
    font-size: 21px;
    margin: 0;
    letter-spacing: 0.01em;
  }

  .hud-sub {
    color: rgba(255, 255, 255, 0.9);
    font-size: 12px;
    margin: 2px 0 0;
  }

  .hud-stats {
    flex: 0 0 auto;
    text-align: right;
  }

  .hud-row {
    justify-content: flex-end;
    gap: 6px;
    font-size: 12px;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.85);
  }

  .hud-label { color: rgba(255, 255, 255, 0.7); }
  .hud-value { color: #fff; font-size: 15px; }

  .hud-hint { display: none; }

  /* 通知（現在地エラー等）はアプリバー直下にオーバーレイ表示 */
  .hud-status {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 100%;
    margin-top: 6px;
    padding: 9px 12px;
    font-size: 13px;
    color: #7a4f00;
    background: #fff3cd;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  /* 地図のズーム操作はアプリバーの下に出す */
  .maplibregl-ctrl-top-right {
    top: 74px;
  }

  /* ===== スマホUI: 下部ボトムシート（検索） ===== */
  .search {
    top: auto;
    bottom: var(--adbar-h);
    left: 0;
    right: 0;
    width: auto;
    padding: 22px 16px calc(72px + env(safe-area-inset-bottom));
    border: none;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    max-height: 72dvh;
  }

  /* ドラッグハンドル風のつまみ */
  .search::before {
    content: "";
    position: absolute;
    top: 9px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 5px;
    border-radius: 3px;
    background: #d1d5db;
  }

  .search-toggle {
    cursor: pointer;
    margin-bottom: 12px;
    padding: 6px 2px;
    min-height: 44px;
  }

  .search-title { font-size: 20px; }

  .search-caret {
    display: block;
    width: 14px;
    height: 14px;
    border-right: 2.5px solid var(--text-dim);
    border-bottom: 2.5px solid var(--text-dim);
    transform: rotate(-135deg);
    transition: transform 0.2s;
    margin-right: 6px;
  }

  .search.collapsed .search-caret { transform: rotate(45deg); }

  .search-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .search.collapsed .search-body { display: none; }

  /* 現在地ボタン: シート上端の少し上に固定（メニューと重ならない＝地図エリア右下） */
  .locate-btn {
    position: absolute;
    top: -64px;
    right: 14px;
    bottom: auto;
  }

  /* 入力・ボタン: 大きく・タップしやすく */
  .search-field { margin-bottom: 16px; }

  .search-field > span {
    font-size: 15px;
    margin-bottom: 8px;
  }

  .search-field input,
  .search-field select {
    padding: 16px 14px;
    font-size: 17px;
    border-radius: 10px;
  }

  .geo-btn {
    padding: 16px 12px;
    font-size: 16px;
    border-radius: 10px;
    margin-bottom: 16px;
  }

  .search-actions { gap: 10px; }

  .search-actions button {
    padding: 17px 12px;
    font-size: 18px;
    border-radius: 10px;
  }

  .result-summary {
    font-size: 15px;
    margin-bottom: 10px;
  }

  .result-item,
  .geo-item {
    padding: 16px 14px;
    gap: 14px;
    border-radius: 10px;
    margin-bottom: 8px;
  }

  .result-eta { font-size: 24px; }

  .result-route,
  .geo-name { font-size: 17px; }

  .result-id,
  .result-origin,
  .geo-note,
  .result-note { font-size: 14px; }

  .geo-dist { font-size: 15px; }

  /* クレジット（省スペースに保つ） */
  .credit {
    z-index: 30;
    font-size: 10px;
    padding: 4px 10px calc(4px + env(safe-area-inset-bottom));
    background: var(--panel-bg);
  }

  .credit-links a {
    display: inline-block;
    padding: 3px 6px;
    font-size: 11px;
  }
}
