/* 色と形の決まり。車の計器盤ふうの暗い色調で、写真の地図の上に半透明で重ねる */
:root {
  --panel: rgba(14, 18, 26, 0.82); /* 重ねる枠の地 */
  --panel-solid: #141922; /* 透かさない枠 (シートなど) */
  --line: rgba(255, 255, 255, 0.14); /* 枠線 */
  --fill: rgba(255, 255, 255, 0.08); /* ボタンの地 */
  --fill-hover: rgba(255, 255, 255, 0.16);
  --text: #eef2f6;
  --text-dim: #9aa7b5;
  --accent: #35c8ff; /* 押している・選んでいる・速度の帯 */
  --warn: #ffb74d; /* 注意の文字 */
  --next: #1e88e5; /* 次に進む道の線 (app.js の nextLine と同じ色) */
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #10141c;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

button,
select,
input {
  font: inherit;
}

/* 進行方向が上になるように JS が回す。大きさ (画面の対角線) と回転角は app.js が入れる */
#map {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #1b1f24;
}

#credit {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 1000;
  max-width: 100vw;
  box-sizing: border-box;
  padding: 2px 8px;
  border-top-left-radius: 8px;
  background: rgba(14, 18, 26, 0.7);
  color: #c5cfda;
  font-size: 11px;
}

#credit a {
  color: #9fd8ff;
  text-decoration: none;
}

/* 左上の計器盤: 速度・ボタン・いまいる場所。? を開くと設定と説明が下に伸びる */
#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1000;
  width: 348px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
  pointer-events: none;
}

/* 速度とボタン類を1行に並べる */
#hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#speed {
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

#speed-value {
  display: inline-block;
  min-width: 3ch;
  font-size: 40px;
  font-style: italic;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: right;
}

#speed .unit {
  margin-left: 5px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* 速度計の帯。長さは app.js が速度に合わせて変える */
#speed-bar {
  height: 4px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
}

#speed-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, #35c8ff, #7cf0c8 55%, #ffd54f 80%, #ff7043);
  transform: scaleX(0);
  transform-origin: left;
}

/* いま走っている道と、近くの地名・駅 */
#where {
  margin-top: 6px;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#where:empty {
  display: none;
}

#status {
  color: var(--warn);
  font-weight: 600;
}

#status:empty {
  display: none;
}

/* 拡大縮小・開始位置・共有・メニューのボタン。HUD 自体はクリックを素通しするので、ここだけ受け取る */
#controls {
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: auto;
}

#controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--fill);
  color: var(--text);
  cursor: pointer;
}

#controls button[hidden] {
  display: none;
}

#controls button:hover {
  background: var(--fill-hover);
}

#controls svg,
#pad svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#help-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

/* メニューを開いたときに出る枠: 設定・操作説明・このサイトについて */
#panel[hidden],
#help[hidden],
#about[hidden] {
  display: none;
}

#panel {
  max-height: calc(100vh - 170px);
  max-height: calc(100dvh - 170px);
  margin-top: 8px;
  padding-top: 8px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  pointer-events: auto;
}

#settings {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-dim);
}

#settings select {
  max-width: 11.5em;
  height: 30px;
  margin-left: 4px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1c222c;
  color: var(--text);
  font-size: 12px;
}

/* 地名を出す / 消す の切り替え。右のつまみが入・切を示す */
#labels-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-dim);
  white-space: nowrap;
  cursor: pointer;
}

#labels-toggle .switch {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.15s;
}

#labels-toggle .switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

#labels-toggle[aria-pressed="true"] .switch {
  background: var(--accent);
}

#labels-toggle[aria-pressed="true"] .switch::after {
  transform: translateX(14px);
}

#help {
  margin: 10px 0 2px;
  padding: 0;
  list-style: none;
}

kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  font-family: inherit;
  font-size: 12px;
  text-align: center;
}

.next-swatch {
  display: inline-block;
  width: 22px;
  height: 6px;
  margin: 0 4px 2px 2px;
  border-radius: 3px;
  background: var(--next);
  vertical-align: middle;
}

/* このサイトについて (説明・作者・出典) */
#about {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  line-height: 1.6;
}

#about h1 {
  margin: 0;
  font-size: 15px;
  font-style: italic;
  font-weight: 800;
  letter-spacing: 0.02em;
}

#about p {
  margin: 2px 0 8px;
}

#about a {
  color: #9fd8ff;
}

#about .disclaimer {
  padding: 6px 10px;
  border: 1px solid rgba(255, 183, 77, 0.35);
  border-radius: 8px;
  background: rgba(255, 183, 77, 0.12);
  color: #ffe0b2;
  font-size: 12px;
}

#about .links a {
  margin-right: 12px;
}

#about .sources {
  margin: 0;
  color: var(--text-dim);
  font-size: 11px;
}

/* 車の印。上 (北) 向きに描いておき、進行方向の角度だけ回転させる */
.car {
  background: none;
  border: none;
}

.car-body {
  width: 24px;
  height: 44px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
}

.car-body svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* 画面上の操作ボタン。指で操作する端末 (スマホ・タブレット) でだけ出す */
#pad,
.touch-only {
  display: none;
}

@media (pointer: coarse) {
  #pad {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    padding: 0 16px calc(30px + env(safe-area-inset-bottom));
    pointer-events: none; /* ボタンの間は地図が見えるだけ */
  }

  .touch-only {
    display: list-item;
  }

  #map {
    touch-action: none; /* 走行中の地図は指で動かさない */
  }

  /* 操作中に画面が拡大されたり、文字が選択されたりしないようにする */
  html,
  body {
    touch-action: manipulation; /* 2回タップでの拡大を止める (一覧のスクロールは残す) */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}

.pad-group {
  display: flex;
  gap: 12px;
}

#pad button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 70px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: var(--panel);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  color: var(--text);
  touch-action: none;
  pointer-events: auto;
}

#pad svg {
  width: 30px;
  height: 30px;
  stroke-width: 2.4;
}

#pad button.held {
  border-color: var(--accent);
  background: var(--accent);
  color: #06202c;
}

/* 開始位置を選ぶ画面。走行中の地図の上に全面で重ねる */
#picker {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  background: var(--panel-solid);
  color: var(--text);
  font-size: 14px;
}

#picker[hidden] {
  display: none;
}

#picker-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

#picker-search {
  display: flex;
  gap: 6px;
}

#picker-query {
  width: 260px;
  max-width: 50vw;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1c222c;
  color: var(--text);
}

#picker-query::placeholder {
  color: var(--text-dim);
}

#picker-bar button,
#picker-results button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--fill);
  color: var(--text);
  cursor: pointer;
}

#picker-bar button {
  flex: none;
  white-space: nowrap;
}

#picker-bar button:hover,
#picker-results button:hover {
  background: var(--fill-hover);
}

#picker-search button {
  border-color: var(--accent);
  background: var(--accent);
  color: #06202c;
  font-weight: 700;
}

#picker-hint {
  flex: 1;
  color: var(--text-dim);
}

#picker-results {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 30vh;
  margin: 0;
  padding: 0 12px;
  overflow-y: auto;
  list-style: none;
  color: var(--text-dim);
}

#picker-results:not(:empty) {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

#picker-results button {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#picker-map {
  flex: 1;
  cursor: crosshair;
}

/* 狭い画面 (スマホの縦持ち) では、計器盤を画面の幅いっぱいに使う */
@media (max-width: 480px) {
  #hud {
    width: auto;
    right: 12px;
  }

  #speed-value {
    font-size: 34px;
  }

  /* 開始位置の画面: 検索欄と「閉じる」を1行に、案内文はその下の行に回す */
  #picker-search {
    flex: 1;
    min-width: 0;
  }

  #picker-query {
    flex: 1;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  #picker-hint {
    flex: none;
    order: 1;
    width: 100%;
    font-size: 12px;
  }

  #picker-results {
    max-height: 22vh;
  }
}

/* 共有先を選ぶシート。画面の中央に重ねる */
#share-sheet[hidden] {
  display: none;
}

#share-sheet {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  font-size: 14px;
}

#share-sheet .sheet-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(320px, calc(100vw - 48px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-solid);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  color: var(--text);
}

#share-sheet .sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
}

#share-sheet button {
  padding: 11px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

#share-sheet #share-close {
  padding: 2px 8px;
  background: none;
  color: var(--text-dim);
}

.share-x {
  background: #000;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.share-line {
  background: #06c755;
}

.share-fb {
  background: #1877f2;
}

#share-sheet .share-copy {
  background: var(--fill-hover);
  color: var(--text);
}

/* 写真の地図に重ねる駅と地名。地図が回ったぶん (--view-angle) 戻して、いつも正立させる */
.place-label span {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--view-angle, 0deg));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 6px #000;
  pointer-events: none;
}

/* 駅 */
.place-label.kind-0 span {
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(21, 101, 192, 0.85);
  text-shadow: none;
}

/* 市町村 */
.place-label.kind-2 span {
  font-size: 16px;
}
