:root {
  --color-bg: #0f0f10;
  --color-bg-map: #18181a;
  --color-bg-card: rgba(22,22,24,0.85);
  --color-bg-card-inner: rgba(255,255,255,0.03);

  --color-text: #f5f5f7;
  --color-text-body: #d8d8dc;
  --color-text-muted: #7a7a80;
  --color-text-hint: #6a6a70;

  --color-accent: #5dcaa5;
  --color-accent-light: #9fe1cb;
  --color-error: #e08080;

  --color-border: rgba(255,255,255,0.08);
  --color-border-subtle: rgba(255,255,255,0.06);

  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;

  /* 下部カード実高（map.js の ResizeObserver が上書き）。初期描画前のフォールバック */
  --card-height: 320px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ===== パスワード画面 ===== */
#password-screen {
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}
.password-wrap {
  width: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.password-title {
  font-size: 14px;
  letter-spacing: 0.14em;
  color: var(--color-accent-light);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.password-subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 24px;
}
#password-input {
  width: 260px;
  height: 44px;
  padding: 0 16px;
  background: rgba(255,255,255,0.05);
  border: 0.5px solid var(--color-border);
  border-radius: 12px;
  color: var(--color-text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  margin-bottom: 12px;
}
#password-input:focus { border-color: var(--color-accent); }
#password-submit {
  width: 260px;
  height: 44px;
  background: var(--color-accent);
  color: var(--color-bg);
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 150ms;
}
#password-submit:disabled { opacity: 0.4; pointer-events: none; }
#password-submit:active { opacity: 0.8; }
.password-error {
  font-size: 11px;
  color: var(--color-error);
  margin-top: 8px;
}

/* ===== メイン画面 ===== */
#main-screen {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
}

.top-bar {
  position: absolute;
  top: env(safe-area-inset-top, 12px);
  left: 16px;
  right: 16px;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
.chip {
  background: var(--color-bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 0.5px solid var(--color-border);
  border-radius: 14px;
  padding: 10px 14px;
  pointer-events: auto;
}
.chip-now {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 70%;
}
.chip-now .pin { width: 18px; height: 18px; flex-shrink: 0; }
.chip-count {
  text-align: center;
  min-width: 62px;
  padding: 10px 12px;
}
.chip-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  text-transform: uppercase;
  line-height: 1;
  margin-bottom: 3px;
}
.chip-value {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.2;
}
.chip-count .chip-value { font-size: 17px; }
.chip-unit {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-left: 2px;
}

.map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--card-height);
  background: var(--color-bg-map);
}
/* Mapbox のキャンバス背景（タイル読込前のちらつき防止） */
#map.mapboxgl-map,
#map .mapboxgl-canvas {
  background: var(--color-bg-map);
}
/* Mapbox の出典表記・ロゴは利用規約で必須なので非表示にしない。
   #map の下端は下部カードの上端（--card-height）に一致するため、
   コントロールはカードの直上に表示される。カードに隠れないよう前面に出す。 */
.mapboxgl-ctrl-bottom-left,
.mapboxgl-ctrl-bottom-right {
  z-index: 6;
}

.bottom-card {
  position: absolute;
  /* bottom は画面下端に張り付ける。home indicator 分（safe-area-inset-bottom）は
     padding-bottom で吸収する。bottom 側を env() で底上げすると card.offsetHeight に
     その分が含まれなくなり、--card-height（map の bottom）と食い違って
     iPhone 実機で地図領域が card 上端より下まで侵入し、muni-row の上半分が
     地図タイル（白系）に同化して見えなくなる事象が発生する。 */
  bottom: 0;
  left: 0;
  right: 0;
  /* 不透明境界を 44px 固定で打ち切り、muni-row top（card top + 92px）の手前で確実に opaque にする。
     旧設計の % 比率指定だとカード高さが大きいときに muni-row が透明グラデーション内に入り、
     後ろの淡色地図が透けて文字が見えなくなる事象を防ぐ。 */
  background: linear-gradient(180deg, rgba(15,15,16,0) 0px, var(--color-bg) 44px, var(--color-bg) 100%);
  padding: 28px 20px calc(20px + env(safe-area-inset-bottom, 0));
  z-index: 6;
}

.drag-handle {
  width: 36px;
  height: 4px;
  background: #3a3a3e;
  border-radius: 2px;
  /* margin-bottom は muni-row top を gradient 不透明境界（44px）より下に置くために確保。
     padding-top(28px) + drag-handle高さ(4px) + 20px = muni-row top 52px で 8px の安全マージン。 */
  margin: 0 auto 20px;
}

.muni-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 18px;
}
.muni-romaji {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--color-accent-light);
  text-transform: uppercase;
  margin-bottom: 6px;
  min-height: 14px;
}
.muni-name-big {
  font-size: 24px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.speed-wrap { text-align: right; }
.speed-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--color-text-hint);
  text-transform: uppercase;
  margin-bottom: 2px;
}
.speed-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  justify-content: flex-end;
}
.speed-value > span:first-child {
  font-size: 28px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.speed-unit {
  font-size: 12px;
  color: var(--color-text-muted);
}
.elevation-label {
  font-size: 9px;
  letter-spacing: 0.1em;
  color: var(--color-text-hint);
  text-transform: uppercase;
  margin-top: 8px;
}
.elevation-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
  justify-content: flex-end;
}
.elevation-value > span:first-child {
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.elevation-unit {
  font-size: 10px;
  color: var(--color-text-muted);
}

.tayori-card {
  background: var(--color-bg-card-inner);
  border: 0.5px solid var(--color-border-subtle);
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.tayori-label-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}
.tayori-line {
  width: 14px;
  height: 1px;
  background: var(--color-accent-light);
}
.tayori-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--color-accent-light);
  text-transform: uppercase;
}
.tayori-body {
  font-size: 14px;
  line-height: 1.75;
  color: var(--color-text-body);
  margin: 0;
  font-feature-settings: 'palt';
  min-height: 74px;
}
.tayori-body.muted {
  color: var(--color-text-muted);
  font-size: 12px;
  font-style: italic;
}
.tayori-skeleton {
  min-height: 74px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tayori-skeleton > div {
  height: 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  animation: skeleton 1.5s ease-in-out infinite;
}
.tayori-skeleton > div.short { width: 60%; }
@keyframes skeleton {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}
/* Plan E (6.5): スケルトン下に出るローディング段階表示の文言 */
.tayori-loading-text {
  margin-top: 6px;
  font-size: 11px;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  font-feature-settings: 'palt';
}

.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.disclaimer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--color-text-hint);
}
.disclaimer svg { width: 10px; height: 10px; }

.debug-toggle {
  font-size: 14px;
  text-decoration: none;
  color: var(--color-text-hint);
  margin-left: 8px;
  cursor: pointer;
  user-select: none;
  opacity: 0.4;
}
.debug-toggle:active { opacity: 0.6; }
.debug-toggle.debug-on { opacity: 1; }

.hillshade-toggle {
  font-size: 14px;
  text-decoration: none;
  color: var(--color-text-hint);
  margin-left: 8px;
  cursor: pointer;
  user-select: none;
  opacity: 0.4;
}
.hillshade-toggle:active { opacity: 0.6; }
/* Issue #48: 3 段階トグル。weak はやや濃く、strong は完全不透明 */
.hillshade-toggle.hillshade-weak { opacity: 0.7; }
.hillshade-toggle.hillshade-strong { opacity: 1; }

/* Plan E (6.5b): デバッグオーバーレイ。description のすぐ下に出す */
.debug-info {
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04);
  border-left: 2px solid var(--color-accent-light);
  border-radius: 3px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 10px;
  line-height: 1.6;
  color: var(--color-text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.gps-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 0.04em;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.dot-active {
  background: var(--color-accent);
  box-shadow: 0 0 0 0 rgba(93,202,165,0.6);
  animation: pulse 2s infinite;
}
.dot-inactive { background: var(--color-text-hint); }
.gps-status { color: var(--color-accent-light); }
.gps-status.inactive { color: var(--color-text-hint); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(93,202,165,0.6); }
  70% { box-shadow: 0 0 0 8px rgba(93,202,165,0); }
  100% { box-shadow: 0 0 0 0 rgba(93,202,165,0); }
}

/* ===== Leaflet 地図のダークテーマ調整 ===== */
.leaflet-container { background: var(--color-bg-map); }
.leaflet-control-attribution { display: none !important; }
