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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic",
               -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  background: #1a1a2e;
}

/* ===== ALERT BANNER ===== */
.alert-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 2000;
  background: #c0392b;
  color: white;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 10px;
  min-height: 48px;
  font-size: 15px;
  font-weight: bold;
  line-height: 1.3;
}

.alert-banner.warning { background: #e67e22; }
.alert-banner.emergency { background: #922b21; }
.alert-banner.hidden { display: none; }

#alert-text { flex: 1; }

.alert-close-btn {
  background: rgba(255,255,255,0.25);
  border: none;
  color: white;
  font-size: 20px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ===== MAP ===== */
#map {
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: 210px;
  z-index: 1;
  transition: top 0.2s ease, bottom 0.3s ease;
}

#map.banner-visible { top: 48px; }
#map.panel-expanded { bottom: 60vh; }

/* ===== INFO PANEL (bottom sheet on mobile) ===== */
.info-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1000;
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.25);
  height: 210px;
  overflow: hidden;
  transition: height 0.3s ease;
  padding: 0 20px 16px;
}

.info-panel.expanded {
  height: 60vh;
  overflow-y: auto;
}

.panel-handle {
  width: 100%;
  height: 28px; /* タッチ領域を拡大 */
  background: transparent;
  margin: 0 0 8px;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* 視覚的なバーは ::before で描画 */
.panel-handle::before {
  content: '';
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: #d5d5d5;
  transition: background 0.2s;
}
.panel-handle:hover::before { background: #aaa; }

/* ===== STATUS MESSAGE ===== */
.status-message {
  text-align: center;
  padding: 8px 0;
  color: #555;
}

.spinner {
  width: 30px; height: 30px;
  border: 3px solid #eee;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== MODE TOGGLE ===== */
.mode-toggle {
  display: flex;
  gap: 6px;
  background: #ecf0f1;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 12px;
}

.mode-btn {
  flex: 1;
  padding: 10px;
  background: transparent;
  color: #555;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s, color 0.2s;
}

.mode-btn.active {
  background: #2980b9;
  color: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ===== SEARCH (起点指定・学習用) ===== */
.search-section {
  margin-bottom: 12px;
}

.search-row {
  display: flex;
  gap: 6px;
}

.address-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid #ccc;
  border-radius: 8px;
  min-height: 44px;
}
.address-input:focus {
  outline: none;
  border-color: #2980b9;
}

.search-btn {
  flex-shrink: 0;
  width: 48px;
  min-height: 44px;
  background: #2980b9;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
}

.search-hint {
  font-size: 12px;
  color: #777;
  margin-top: 6px;
  line-height: 1.6;
}

.link-btn {
  background: none;
  border: none;
  color: #2980b9;
  font-size: 12px;
  font-weight: bold;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}
.link-btn.active {
  color: #c0392b;
}

/* ===== CANDIDATE LIST ===== */
.candidate-section { margin-bottom: 12px; }

.candidate-heading {
  font-size: 12px;
  color: #777;
  margin-bottom: 6px;
}

.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.candidate-card {
  width: 100%;
  text-align: left;
  background: #f4f6f8;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.candidate-card.selected {
  border-color: #2980b9;
  background: #eaf2f8;
}

.candidate-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.candidate-name {
  font-size: 14px;
  font-weight: bold;
  color: #2c3e50;
  line-height: 1.3;
}

.candidate-meta {
  font-size: 12px;
  color: #666;
}

.cand-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

.badge-safe { background: #d5f4e6; color: #1e8449; }
.badge-vertical { background: #d6eaf8; color: #2471a3; }
.badge-warn { background: #fdebd0; color: #b9770e; }

.route-safety {
  font-size: 12px;
  color: #555;
  line-height: 1.5;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #f8f9fa;
  border-left: 3px solid #2980b9;
  border-radius: 4px;
}

/* ===== ROUTE INFO ===== */
.shelter-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.shelter-name {
  font-size: 17px;
  font-weight: bold;
  color: #2c3e50;
  line-height: 1.3;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.info-item {
  background: #f4f6f8;
  border-radius: 8px;
  padding: 8px 10px;
}

.info-label {
  display: block;
  font-size: 11px;
  color: #777;
  margin-bottom: 2px;
}

.info-value {
  display: block;
  font-size: 18px;
  font-weight: bold;
  color: #2c3e50;
}

.shelter-address {
  font-size: 12px;
  color: #666;
  margin-bottom: 6px;
}

.shelter-note {
  font-size: 12px;
  color: #e67e22;
  margin-bottom: 6px;
}

/* ===== BUTTONS ===== */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  min-height: 48px;
  margin-top: 8px;
  transition: background 0.2s;
}
.btn-primary:active { background: #1e8449; }

.btn-secondary {
  width: 100%;
  padding: 12px;
  background: #ecf0f1;
  color: #2c3e50;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  min-height: 44px;
  margin-top: 8px;
}

/* ===== SAFE ===== */
.safe-box {
  padding: 8px 0;
}

.safe-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.safe-icon { font-size: 22px; }

.safe-title {
  font-size: 18px;
  font-weight: bold;
  color: #1e8449;
  line-height: 1.3;
}

.safe-text {
  font-size: 13px;
  color: #555;
  line-height: 1.5;
  margin-bottom: 6px;
}

/* ===== ERROR ===== */
.error-box {
  padding: 8px 0;
  color: #c0392b;
}

/* ===== FAB ===== */
.fab-container {
  position: fixed;
  right: 14px;
  bottom: 228px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: bottom 0.3s ease;
}

.fab {
  width: 50px; height: 50px;
  background: white;
  border: none;
  border-radius: 50%;
  box-shadow: 0 2px 12px rgba(0,0,0,0.28);
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.2s;
}
.fab:active { box-shadow: 0 1px 6px rgba(0,0,0,0.2); }

/* ===== USER MARKER ===== */
.user-dot {
  width: 16px; height: 16px;
  background: #2980b9;
  border-radius: 50%;
  border: 2px solid white;
  position: relative;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.user-dot.fallback { background: #e67e22; }

.user-pulse {
  position: absolute;
  top: -10px; left: -10px;
  width: 36px; height: 36px;
  background: rgba(41, 128, 185, 0.3);
  border-radius: 50%;
  animation: pulse 2s ease-out infinite;
}

.user-dot.fallback .user-pulse {
  background: rgba(230, 126, 34, 0.3);
}

@keyframes pulse {
  0%   { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* ===== AD CONTAINER ===== */
.ad-container {
  margin-top: 12px;
  border-top: 1px solid #eee;
  padding-top: 10px;
  text-align: center;
  min-height: 90px;
}

.ad-placeholder {
  background: #f4f6f8;
  color: #aaa;
  font-size: 12px;
  padding: 28px;
  border-radius: 6px;
  border: 1px dashed #ddd;
}

/* ===== LANGUAGE SWITCH ===== */
.lang-switch {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.lang-btn {
  flex: 1;
  padding: 7px 4px;
  background: #f0f2f5;
  color: #555;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  min-height: 36px;
  transition: background 0.2s, color 0.2s;
}

.lang-btn.active {
  background: #2980b9;
  color: white;
  border-color: #2980b9;
}

/* ===== OFFLINE NOTICE ===== */
.offline-notice {
  background: #636e72;
  color: white;
  font-size: 12px;
  text-align: center;
  padding: 6px 12px;
  border-radius: 6px;
  margin-bottom: 10px;
  line-height: 1.4;
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }

/* ===== NAVIGATION BAR ===== */
.nav-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1001;
  background: #154360;
  color: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
}

.nav-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 10px;
  min-height: 72px;
}

.nav-icon {
  font-size: 36px;
  flex-shrink: 0;
  width: 44px;
  text-align: center;
  line-height: 1;
}

.nav-text-group {
  flex: 1;
  min-width: 0;
}

.nav-direction {
  font-size: 18px;
  font-weight: bold;
  line-height: 1.3;
  margin: 0;
}

.nav-street {
  font-size: 12px;
  opacity: 0.75;
  margin: 2px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-dist {
  font-size: 22px;
  font-weight: bold;
  flex-shrink: 0;
  text-align: right;
}

.nav-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 14px;
  font-size: 13px;
  border-top: 1px solid rgba(255,255,255,0.15);
  gap: 8px;
}

.nav-remain {
  flex: 1;
  opacity: 0.85;
}

.nav-stop-btn {
  flex-shrink: 0;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35);
  color: white;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  min-height: 36px;
}

#map.nav-mode { bottom: 130px; }
.fab-container.nav-mode { bottom: 148px; }

/* ===== DESKTOP (≥768px) ===== */
@media (min-width: 768px) {
  .info-panel {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 320px;
    height: 100%;
    border-radius: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    overflow-y: auto;
    padding: 16px 20px 20px;
  }

  .info-panel.expanded { height: 100%; }

  .panel-handle { display: none; }

  #map {
    left: 320px;
    bottom: 0;
  }

  #map.panel-expanded { bottom: 0; }

  .fab-container {
    right: 16px;
    bottom: 24px;
  }

  .shelter-name { font-size: 18px; }

  .info-value { font-size: 20px; }

  /* Desktop ナビバー: 左サイドパネル */
  .nav-bar {
    top: 0; left: 0; bottom: 0; right: auto;
    width: 320px;
    border-radius: 0;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
  }
  .nav-main {
    flex: 1;
    flex-direction: column;
    align-items: flex-start;
    padding: 24px 20px 16px;
    gap: 8px;
  }
  .nav-icon { font-size: 52px; width: auto; }
  .nav-direction { font-size: 22px; }
  .nav-dist { font-size: 30px; }
  .nav-sub { padding: 12px 20px 20px; }

  #map.nav-mode {
    left: 320px;
    bottom: 0;
  }
  .fab-container.nav-mode {
    bottom: 24px;
  }
}
