:root {
  --accent: #2e8b57;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, var(--card));
  --bg: #f5f7f6;
  --card: #ffffff;
  --text: #1d2a24;
  --muted: #66756d;
  --line: #d5ddd8;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --board: #1a73e8;
  --alight: #d9480f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #5cc58a;
    --bg: #101513;
    --card: #1a211e;
    --text: #e8efeb;
    --muted: #98a79f;
    --line: #2f3a35;
    --warn: #fbbf24;
    --warn-bg: #3a2e0c;
    --board: #7ab0ff;
    --alight: #ff9a6b;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.6;
}
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px 48px; }

header.top {
  background: var(--accent);
  color: #fff;
  padding: 16px 0 14px;
}
header.top .wrap { padding-bottom: 0; }
.crumb { font-size: 13px; opacity: .85; }
.crumb a { color: #fff; }
h1 { margin: 2px 0 0; font-size: 22px; }
.sub { margin: 2px 0 0; font-size: 13px; opacity: .9; }
.source { margin: 8px 0 0; font-size: 12px; opacity: .9; line-height: 1.5; }
.source a { color: #fff; }
.source.disclaimer { margin-top: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 14px;
}
.card h2 { margin: 0 0 8px; font-size: 15px; color: var(--muted); font-weight: 600; }

/* 平日/土日祝 */
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 10px 0; font-size: 15px; font-weight: 600;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; cursor: pointer;
}
.seg button[aria-pressed="true"] {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.alert {
  font-size: 13px; margin-top: 10px; padding: 8px 10px; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn);
}

/* 手順バー */
.steps { display: flex; gap: 8px; align-items: stretch; }
.step {
  flex: 1; border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px;
  min-height: 62px;
}
.step .lbl { font-size: 12px; color: var(--muted); }
.step .val { font-size: 16px; font-weight: 700; word-break: break-all; }
.step.active { border-color: var(--accent); background: var(--accent-soft); }
.step.board .val { color: var(--board); }
.step.alight .val { color: var(--alight); }
.tools { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.tools .check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; margin-left: 4px; }
.tools .check input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.tools button {
  font-size: 14px; padding: 8px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.tools button:disabled { opacity: .4; cursor: default; }

/* 結果 */
#result:empty { display: none; }
.res-head { display: flex; justify-content: space-between; align-items: baseline; }
.res-head strong { font-size: 17px; }
.trip {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center;
  width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: transparent; border: 0; border-top: 1px solid var(--line);
  padding: 12px 0;
}
.trip:first-of-type { border-top: 0; }
.trip.sel { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 10px; border-top-color: transparent; padding-left: 10px; padding-right: 10px; }
.trip:hover:not(.sel) { background: var(--accent-soft); }
.legend { line-height: 1.7; }
.legend .lg { font-weight: 700; }   /* 色は経路と同じ(app.js rideColor をその場で指定) */
.legend .lg-bar {                    /* 経路の色の見本(乗車側の薄い色 → 降車側の濃い色) */
  display: inline-block; width: 64px; height: 8px; margin: 0 4px; border-radius: 4px; vertical-align: middle;
}

.course-select {
  width: 100%; font: inherit; font-size: 17px; font-weight: 700; padding: 12px 10px;
  border-radius: 10px; border: 2px solid var(--accent); background: var(--card); color: var(--text);
}
.card h2 label { font: inherit; }

/* 地図上: コースの線と経路。
   線の太さは「画面上のpx ÷ 拡大率(--z)」にして、拡大縮小しても画面上の太さが変わらないようにする */
.overlay {
  position: absolute; left: 0; top: 0; z-index: 1; pointer-events: none; overflow: visible;
  --casing: #fff;                      /* 線の縁取りの色 */
}
.overlay path { stroke-linecap: round; stroke-linejoin: round; }
.overlay .dim { fill: #fff; opacity: 0; transition: opacity .3s; }
.overlay .dim.on { opacity: .7; }
.overlay .course { transition: opacity .3s; }
.overlay .course.faded { opacity: .3; }
.overlay .casing { stroke: var(--casing); stroke-width: calc(10px / var(--z)); opacity: .9; }
.overlay .course .stroke { stroke-width: calc(6px / var(--z)); }
.overlay .r-casing { stroke: var(--casing); stroke-width: calc(10px / var(--z)); }
.overlay .r-line { stroke-width: calc(6px / var(--z)); }
.overlay .r-arrow { stroke: #fff; stroke-width: 2.4; }     /* 矢印は描くときに 1/z 倍している */
/* コース未選択時の全コースの線(押すとそのコースを選ぶ) */
.overlay .a-casing { stroke: var(--casing); stroke-width: calc(7.5px / var(--z)); opacity: .9; }
.overlay .a-stroke { stroke-width: calc(4.5px / var(--z)); }
.overlay .hit { stroke: rgba(0,0,0,0); stroke-width: calc(24px / var(--z)); pointer-events: stroke; cursor: pointer; }
.maplayer.has-course .overlay .all { display: none; }
/* コースの札(コース未選択時)。番号の丸の中心が札の位置(線の上)で、右下にコース名のカードが付く。拡大縮小しても大きさ一定。
   地図の地名と見分けがつくよう、コース色の枠と文字・「コース」の語を必ず付ける(地図にもともとある地名と区別するため)。
   --c / --cd はコース色(明るい表示/ダークモード)。丸の大きさ 30px とカードのずれ 12px は app.js の TAG_R / TAG_OFF と同じ値。 */
.ctag {
  position: absolute; z-index: 3; display: block; min-width: 30px; min-height: 30px;
  margin: 0; padding: 0; border: 0; background: none; cursor: pointer; text-align: left;
  pointer-events: none;                /* 押せるのは丸とカードだけ(札の箱の空いた角は、下の線を押せる) */
  font-family: "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  transform-origin: 0 0;
  transform: scale(calc(1 / var(--z))) translate(-15px, -15px);
}
.ctag .ct-no {
  position: absolute; left: 0; top: 0; z-index: 1; pointer-events: auto;
  width: 30px; height: 30px; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; border-radius: 50%; background: var(--c); color: #fff;
  font-weight: 700; font-size: 16px; line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
}
.ctag .ct-name {
  display: block; margin: 12px 0 0 12px; padding: 9px 10px 5px 18px; pointer-events: auto;
  border: 2px solid var(--c); border-radius: 10px; background: rgba(255,255,255,.94); color: var(--c);
  font-weight: 700; font-size: 14px; line-height: 1.25; text-align: center; white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.ctag .ct-name span { display: block; }
.ctag.compact .ct-name { display: none; }      /* 他の札と重なるときは丸だけ(app.js declutterTags) */
.ctag:hover, .ctag:focus-visible { transform: scale(calc(1.1 / var(--z))) translate(-15px, -15px); z-index: 4; }
.ctag:focus-visible { outline: none; }
.ctag:focus-visible .ct-no, .ctag:focus-visible .ct-name { outline: 2px solid var(--c); outline-offset: 2px; }
.maplayer.has-course .ctag { display: none; }
.mappick {                           /* 線が重なる所を押したときの、コースの選択肢 */
  position: absolute; z-index: 7; min-width: 180px; padding: 6px;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.3); cursor: default;
}
.mappick .mp-head { font-size: 12px; color: var(--muted); padding: 2px 6px 4px; }
.mappick button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px; text-align: left;
  font: inherit; font-size: 14px; font-weight: 700; color: var(--text);
  background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.mappick button:hover, .mappick button:focus-visible { background: var(--accent-soft); }
.mappick button i {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 22px; height: 22px; border-radius: 50%; color: #fff; font-style: normal; font-size: 13px;
}
.pin.on-ride:not(.is-board):not(.is-alight) .dot { opacity: 0; }   /* 途中停留所は印を消し、停車順の数字で示す */
.stepbadge {                         /* 停車順の数字(.n)と到着時刻の札(.t)。足元の点が停車位置 */
  position: absolute; z-index: 4; pointer-events: none; width: 0; height: 0;
  transform: scale(calc(1 / var(--z)));
}
.stepbadge .n {
  position: absolute; left: -10px; top: -10px; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center; box-sizing: border-box;
  border-radius: 50%; background: #fff; color: #2b2b2b; border: 2px solid var(--ride-edge, #5b3a8c);   /* 経路の濃い色 */
  font: 700 12px/1 inherit; font-style: normal; box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.stepbadge .t {
  position: absolute; left: 13px; top: -10px; height: 20px; padding: 0 6px; box-sizing: border-box;
  display: flex; align-items: center; white-space: nowrap;
  background: rgba(255,255,255,.94); color: #2b2b2b; border: 1px solid var(--ride-edge, #5b3a8c); border-radius: 6px;
  font: 700 12px/1 inherit; font-variant-numeric: tabular-nums; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.stepbadge.hide-t .t { display: none; }
.mapchip {
  position: absolute; left: 10px; top: 10px; z-index: 5; color: #fff; font-weight: 700;
  padding: 5px 14px; border-radius: 999px; box-shadow: 0 1px 4px rgba(0,0,0,.35); pointer-events: none;
}
.pin.off-ride { opacity: .4; }
.pin.on-ride .dot { border-width: 5px; }
.trip .no {
  grid-row: span 2; background: var(--accent); color: #fff; font-weight: 700;
  border-radius: 8px; padding: 2px 8px; font-size: 13px; white-space: nowrap;
}
.times { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.times .arrow { color: var(--muted); font-weight: 400; margin: 0 6px; }
.dur { font-size: 14px; color: var(--muted); text-align: right; }
.meta { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px;
  border-radius: 999px; margin-right: 4px;
}
.badge.next { background: var(--accent); color: #fff; }
.badge.detour { background: var(--warn-bg); color: var(--warn); }
.trip.past { opacity: .45; }
.trip.next { background: var(--accent-soft); margin: 0 -10px; padding-left: 10px; padding-right: 10px; border-radius: 10px; border-top-color: transparent; }
.empty { padding: 10px 0; color: var(--muted); }

/* バス停リスト(路線図風) */
ol.stops { list-style: none; margin: 4px 0 0; padding: 0; position: relative; }
ol.stops li { position: relative; padding-left: 30px; }
ol.stops li::before {          /* 縦線 */
  content: ""; position: absolute; left: 10px; top: 0; bottom: 0;
  width: 4px; background: var(--accent); opacity: .55;
}
ol.stops li:first-child::before { top: 50%; }
ol.stops li:last-child::before { bottom: 50%; }
ol.stops li::after {           /* 丸印 */
  content: ""; position: absolute; left: 5px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--accent);
}
ol.stops li.is-board::after { background: var(--board); border-color: var(--board); }
ol.stops li.is-alight::after { background: var(--alight); border-color: var(--alight); }
ol.stops button {
  width: 100%; text-align: left; min-height: 46px; padding: 8px 10px;
  font-size: 16px; color: var(--text); background: transparent;
  border: 0; border-radius: 10px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
ol.stops button:hover:not(:disabled) { background: var(--accent-soft); }
ol.stops button:disabled { color: var(--muted); opacity: .5; cursor: default; }
ol.stops .tag { font-size: 12px; font-weight: 700; }
li.is-board .tag { color: var(--board); }
li.is-alight .tag { color: var(--alight); }
/* ---------- 2列レイアウト(広い画面: 左=操作と結果 / 右=地図) ---------- */
.wrap.wide { max-width: 1240px; }
.layout { display: block; }
.mapcard { padding-bottom: 10px; }
.mapcard h2 .hint { font-weight: 400; font-size: 12px; margin-left: 6px; }
@media (min-width: 1000px) {
  .layout {
    display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr);
    column-gap: 20px; align-items: start;
  }
  .layout > * { grid-column: 1; }
  .layout > .mapcard {
    grid-column: 2; grid-row: 1 / span 10;
    position: sticky; top: 12px;
  }
  /* 地図の下端(出典の表示・注記)が、最初の画面からはみ出さない高さ。出典は常に見えるようにする必要がある */
  .layout .mapview { height: calc(100vh - 290px); min-height: 420px; }
}
#resultCard:has(#result:empty) { display: none; }

/* ---------- 地図 ---------- */
.mapview {
  position: relative; overflow: hidden; height: min(62vh, 480px);
  border-radius: 10px; border: 1px solid var(--line); background: #e8e4e1;
  touch-action: none; cursor: grab; user-select: none;
}
.mapview.grab { cursor: grabbing; }
.maplayer { position: absolute; left: 0; top: 0; transform-origin: 0 0; --z: 1; }
.maplayer.anim { transition: transform .3s ease; }
.maplayer .tiles { position: absolute; left: 0; top: 0; }     /* 背景の地図タイル(地理院タイル) */
.maplayer .tiles img { position: absolute; display: block; max-width: none; pointer-events: none; }
.attrib {                            /* 地図の出典。地図の表示中は常に見える位置に出す */
  position: absolute; left: 0; bottom: 0; z-index: 6; max-width: calc(100% - 56px);
  padding: 2px 8px; font-size: 11px; line-height: 1.5; color: #333;
  background: rgba(255,255,255,.88); border-top-right-radius: 6px; cursor: default;
}
.attrib a { color: #0b57d0; }
.maperr { color: var(--warn); }
/* 出典の「色調を…変更」は、今の表示で実際に色調を変えているときだけ出す(index.html #mapAttrib の注記を参照) */
.tone-dim, .dark-only { display: none; }
.mapview.has-course .tone-dim { display: inline; }   /* 白い半透明の覆い(コース選択中・明るい表示) */
/* ダークモード: 地図タイルの色調だけを暗く変える(地名・道路・境界などの中身は消さない・変えない) */
@media (prefers-color-scheme: dark) {
  .dark-only { display: inline; }
  .mapview.has-course .tone-dim { display: none; }   /* ダークモードの覆いは「暗く変更」に含める */
  .mapview { background: #2b302e; }
  .maplayer .tiles { filter: invert(1) hue-rotate(180deg) brightness(.82) contrast(.92); }
  .overlay { --casing: #1d2421; }
  .overlay .dim { fill: #101513; }
  .overlay .dim.on { opacity: .55; }
  .ctag .ct-name { background: rgba(29,36,33,.94); color: var(--cd); border-color: var(--cd); }
  .attrib { background: rgba(26,33,30,.9); color: #dfe7e3; }
  .attrib a { color: #8ab4f8; }
}
.pin {                               /* 地図上のバス停の印(拡大縮小しても大きさ一定) */
  position: absolute; z-index: 3; padding: 0; border: 0; background: transparent; cursor: pointer;
  width: 34px; height: 34px;
  transform: translate(-50%, -50%) scale(calc(1 / var(--z)));
}
.pin .dot {
  position: absolute; left: 50%; top: 50%; width: 18px; height: 18px;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: #fff; border: 4px solid var(--accent);
  box-shadow: 0 0 0 2px rgba(255,255,255,.9), 0 1px 4px rgba(0,0,0,.4);
  transition: width .12s, height .12s;
}
.pin:hover .dot, .pin:focus-visible .dot { width: 24px; height: 24px; }
.pin .lab {                          /* 名前ラベル: ホバー・選択時のみ表示 */
  display: none; position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  margin-bottom: -4px; white-space: nowrap; font-size: 13px; font-weight: 700;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  padding: 2px 8px; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.3);
  pointer-events: none; z-index: 2;
}
.pin:hover .lab, .pin:focus-visible .lab, .pin.is-board .lab, .pin.is-alight .lab { display: block; }
.pin.lab-off:not(:hover):not(:focus-visible) .lab { display: none; }   /* 同じ名前の印が2つあるとき、札は1つだけ(app.js markEnds) */
.pin:hover, .pin.is-board, .pin.is-alight { z-index: 3; }
.pin.is-board .dot { background: var(--board); border-color: #fff; width: 24px; height: 24px; }
.pin.is-alight .dot { background: var(--alight); border-color: #fff; width: 24px; height: 24px; }
.pin.is-board .lab { color: var(--board); border-color: var(--board); }
.pin.is-alight .lab { color: var(--alight); border-color: var(--alight); }
.pin:disabled { cursor: default; opacity: .35; }
.pin:disabled .dot { border-color: #888; }

.mapctl { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.mapctl button {
  min-width: 40px; height: 40px; font-size: 18px; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.mapctl button#zoomFit { font-size: 12px; }

/* 【仮】広告枠の位置確認用の赤枠。本番では消す(index.html の .ad-slot とセット) */
.ad-slot {
  box-sizing: border-box; margin: 14px 0; padding: 12px;
  border: 3px solid #e00; border-radius: 6px; background: rgba(238, 0, 0, .06);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-align: center; font-size: 13px; color: var(--text, inherit);
}
.ad-slot strong { color: #e00; font-size: 15px; }
.ad-1 { min-height: 100px; }   /* 上: 横長バナー */
.ad-2 { min-height: 250px; }   /* 下: 長方形 */
footer { margin-top: 24px; font-size: 12px; color: var(--muted); }
footer a { color: var(--accent); }

/* hide the ad slots until ads are placed */
.ad-slot { display: none !important; }
