/* Fluent Design System Variables */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f3f3f3;
  --bg-tertiary: #fafafa;
  --bg-card: #ffffff;
  --text-primary: #201f1e;
  --text-secondary: #605e5c;
  --text-tertiary: #8a8886;
  --accent-primary: #0078d4;
  --accent-hover: #106ebe;
  --accent-pressed: #005a9e;
  --border-color: #e1dfdd;
  --shadow-sm: 0 1.6px 3.6px rgba(0, 0, 0, 0.13), 0 0.3px 0.9px rgba(0, 0, 0, 0.11);
  --shadow-md: 0 3.2px 7.2px rgba(0, 0, 0, 0.13), 0 0.6px 1.8px rgba(0, 0, 0, 0.11);
  --shadow-lg: 0 6.4px 14.4px rgba(0, 0, 0, 0.13), 0 1.2px 3.6px rgba(0, 0, 0, 0.11);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  /* Scrollbar tokens */
  --scrollbar-size: 10px;
  --scrollbar-radius: 8px;
  --scrollbar-track: rgba(0, 0, 0, 0.06);
  --scrollbar-thumb: rgba(0, 0, 0, 0.28);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.38);
  --scrollbar-thumb-active: rgba(0, 0, 0, 0.46);
}

/* Dark Theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #252525;
    --bg-card: #292929;
    --text-primary: #ffffff;
    --text-secondary: #d1d1d1;
    --text-tertiary: #a19f9d;
    --accent-primary: #60cdff;
    --accent-hover: #4db8e8;
    --accent-pressed: #3aa3d2;
    --border-color: #3d3d3d;
    --shadow-sm: 0 1.6px 3.6px rgba(0, 0, 0, 0.4), 0 0.3px 0.9px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 3.2px 7.2px rgba(0, 0, 0, 0.4), 0 0.6px 1.8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 6.4px 14.4px rgba(0, 0, 0, 0.4), 0 1.2px 3.6px rgba(0, 0, 0, 0.3);
    /* Dark auto theme scrollbar */
    --scrollbar-track: rgba(255, 255, 255, 0.06);
    --scrollbar-thumb: rgba(255, 255, 255, 0.24);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.32);
    --scrollbar-thumb-active: rgba(255, 255, 255, 0.40);
  }
}

/* Added manual theme override classes */
body.light-theme {
  --bg-primary: #ffffff;
  --bg-secondary: #f3f3f3;
  --bg-tertiary: #fafafa;
  --bg-card: #ffffff;
  --text-primary: #201f1e;
  --text-secondary: #605e5c;
  --text-tertiary: #8a8886;
  --accent-primary: #0078d4;
  --accent-hover: #106ebe;
  --accent-pressed: #005a9e;
  --border-color: #e1dfdd;
  --shadow-sm: 0 1.6px 3.6px rgba(0, 0, 0, 0.13), 0 0.3px 0.9px rgba(0, 0, 0, 0.11);
  --shadow-md: 0 3.2px 7.2px rgba(0, 0, 0, 0.13), 0 0.6px 1.8px rgba(0, 0, 0, 0.11);
  --shadow-lg: 0 6.4px 14.4px rgba(0, 0, 0, 0.13), 0 1.2px 3.6px rgba(0, 0, 0, 0.11);
  /* Light manual theme scrollbar */
  --scrollbar-track: rgba(0, 0, 0, 0.06);
  --scrollbar-thumb: rgba(0, 0, 0, 0.28);
  --scrollbar-thumb-hover: rgba(0, 0, 0, 0.38);
  --scrollbar-thumb-active: rgba(0, 0, 0, 0.46);
}

body.dark-theme {
  --bg-primary: #1e1e1e;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #252525;
  --bg-card: #292929;
  --text-primary: #ffffff;
  --text-secondary: #d1d1d1;
  --text-tertiary: #a19f9d;
  --accent-primary: #60cdff;
  --accent-hover: #4db8e8;
  --accent-pressed: #3aa3d2;
  --border-color: #3d3d3d;
  --shadow-sm: 0 1.6px 3.6px rgba(0, 0, 0, 0.4), 0 0.3px 0.9px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 3.2px 7.2px rgba(0, 0, 0, 0.4), 0 0.6px 1.8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 6.4px 14.4px rgba(0, 0, 0, 0.4), 0 1.2px 3.6px rgba(0, 0, 0, 0.3);
  /* Dark manual theme scrollbar */
  --scrollbar-track: rgba(255, 255, 255, 0.06);
  --scrollbar-thumb: rgba(255, 255, 255, 0.24);
  --scrollbar-thumb-hover: rgba(255, 255, 255, 0.32);
  --scrollbar-thumb-active: rgba(255, 255, 255, 0.40);
}

/* Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* Firefox */
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: var(--transition);
}

/* WebKit-based browsers (Chrome/Edge/Safari) */
*::-webkit-scrollbar {
  width: var(--scrollbar-size);
  height: var(--scrollbar-size);
}
*::-webkit-scrollbar-track {
  background: transparent; /* 使用透明轨道，避免大块底色显得厚重 */
}
*::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: var(--scrollbar-radius);
  border: 2px solid transparent; /* 让拇指更细，且有内边距效果 */
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}
*::-webkit-scrollbar-thumb:active {
  background-color: var(--scrollbar-thumb-active);
}

/* 让模态内容区的滚动条更精致一些（略窄） */
.modal-content::-webkit-scrollbar {
  width: 8px;
}
.modal-content {
  scrollbar-width: thin; /* Firefox */
}

.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.toilet-icon {
  width: 32px;
  height: 32px;
  color: var(--accent-primary);
  flex-shrink: 0;
}

.title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Section Title */
.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Selection Card */
.selection-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(40px);
}

/* Combo Group */
.combo-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

/* Map container styles */
.map-container {
  width: 100%;
  margin-bottom: 12px;
}

#map {
  width: 100%;
  height: min(60vh, 420px);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

/* Fluent-style map control (top-right) */
.map-control-card {
  /* Remove any visible card background so the button sits directly on the map */
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
  margin: 6px;
}

/* Stronger rule to override Leaflet or theme rules that add a backdrop/card */
.map-control-card.leaflet-bar {
  /* Acrylic effect: semi-transparent + blur + subtle border and shadow */
  background-color: rgba(255, 255, 255, 0.72) !important;
  background: linear-gradient(rgba(255,255,255,0.72), rgba(255,255,255,0.64)) !important;
  border: 1px solid rgba(0,0,0,0.06) !important;
  box-shadow: var(--shadow-sm) !important;
  padding: 6px !important;
  border-radius: var(--radius-md) !important;
  backdrop-filter: blur(8px) saturate(120%) !important;
}

/* Dark theme acrylic variant */
body.dark-theme .map-control-card.leaflet-bar {
  background-color: rgba(30, 30, 30, 0.64) !important;
  background: linear-gradient(rgba(30,30,30,0.64), rgba(30,30,30,0.56)) !important;
  border: 1px solid rgba(255,255,255,0.06) !important;
  box-shadow: 0 4px 10px rgba(0,0,0,0.36) !important;
  backdrop-filter: blur(10px) saturate(120%) !important;
  padding: 6px !important;
  border-radius: var(--radius-md) !important;
}
.map-control-card .map-control-btn {
  background: transparent;
  border: none;
  color: var(--accent-primary);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.map-control-card .map-control-btn:hover {
  background: rgba(0, 0, 0, 0);
}
.map-control-card .map-control-label { font-size: 13px }

/* Floor suggestions inside floor modal */
.floor-suggestions { border-radius: 8px; overflow: hidden; border: 1px solid rgba(0,0,0,0.04); background: var(--bg-card); box-shadow: var(--shadow-sm); }
.floor-suggestions .floor-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; }
.floor-suggestions .floor-row strong { margin-right: 8px; }
.restroom-sel-btn { background: transparent; border: 1px solid rgba(0,0,0,0.06); padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--text-primary); }
.restroom-sel-btn:hover { background: rgba(0,0,0,0.04); }

/* Priority color markers for floor suggestion rows */
.floor-row.floor-priority-green { background: linear-gradient(90deg, rgba(16,185,129,0.06), rgba(16,185,129,0.02)); border-left: 4px solid #10b981; }
.floor-row.floor-priority-yellow { background: linear-gradient(90deg, rgba(234,179,8,0.06), rgba(234,179,8,0.02)); border-left: 4px solid #eab308; }
.floor-row.floor-priority-red { background: linear-gradient(90deg, rgba(239,68,68,0.06), rgba(239,68,68,0.02)); border-left: 4px solid #ef4444; }

/* Make the left label more prominent and add spacing for the colored badge */
.floor-row > div:first-child { display:flex; align-items:center; gap:10px; font-size:14px }

/* Big Toilet Info button to replace/augment the old confirm button */
.big-toilet-btn {
  display: inline-block;
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(180deg, #0078d4, #005a9e);
  border: none;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.big-toilet-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,0.22); }
.big-toilet-btn:active { transform: translateY(0); }

/* Adjust for dark theme */
body.dark-theme .big-toilet-btn { background: linear-gradient(180deg, #60cdff, #3aa3d2); color: #051923 }

/* Floor item (clickable) styles */
.floor-item { cursor: pointer; transition: background 0.12s ease, transform 0.06s ease; }
.floor-item:hover { background: rgba(0,0,0,0.04); transform: translateY(-2px); }
.floor-item .restroom-distance { font-weight: 600; color: var(--text-secondary); }

/* Hide the old floor match panel by default visual rule (JS also hides it) */
#floorMatchResult { display: none !important; }

/* Badge used as index when no baseline ("选择楼层") */
.floor-index-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  min-width: 20px;
  padding: 0 6px;
  margin-right: 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

@media (max-width: 480px) {
  #map {
    /* on small screens take most of viewport but leave room for lists */
    height: calc(100vh - 320px);
  }
}

/* Custom building div icon */
.custom-building-icon {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 4px 8px;
  backdrop-filter: blur(4px);
  white-space: nowrap;
}

/* Dark theme: make building labels blend and remain readable */
body.dark-theme .custom-building-icon {
  background: rgba(30, 30, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.building-icon-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.building-floors {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Tooltip small style override */
.leaflet-tooltip.building-tooltip {
  background: rgba(255,255,255,0.95);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 6px 8px;
  box-shadow: var(--shadow-sm);
  font-size: 13px;
}

/* tooltip in dark theme */
body.dark-theme .leaflet-tooltip.building-tooltip {
  background: rgba(24,24,24,0.92);
  color: var(--text-primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

/* Enter confirmation toast */
.enter-confirm-toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 18px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 6px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 1400;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.45);
}

body.light-theme .enter-confirm-toast {
  background: rgba(0,0,0,0.7);
  color: #fff;
}

body.dark-theme .enter-confirm-toast {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.06);
}

/* Circular progress inside enter-confirm-toast */
.enter-confirm-toast .progress-wrap { display:flex; align-items:center; justify-content:center; width:56px; height:56px }
.enter-confirm-toast .enter-progress { display:block }
.enter-confirm-toast .enter-progress .bg { stroke: rgba(255,255,255,0.12); }
.enter-confirm-toast .enter-progress .progress { stroke: var(--accent-primary); transition: stroke-dashoffset 0.12s linear; transform: rotate(-90deg); transform-origin: 50% 50%; }
body.dark-theme .enter-confirm-toast .enter-progress .bg { stroke: rgba(255,255,255,0.06); }
body.dark-theme .enter-confirm-toast .enter-progress .progress { stroke: var(--accent-primary); }
body.light-theme .enter-confirm-toast .enter-progress .bg { stroke: rgba(0,0,0,0.12); }
body.light-theme .enter-confirm-toast .enter-progress .progress { stroke: #fff; }

/* Visually hidden, accessible text */
.sr-only { position: absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0 }

/* Fluent control card in map top-right */
.map-control-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-md);
  padding: 8px;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(0, 0, 0, 0.04);
  z-index: 1200;
  backdrop-filter: blur(12px);
}

body.dark-theme .map-control-card {
  background: rgba(30, 30, 30, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.map-control-btn {
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}

.map-control-btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

.map-control-btn:active:not(:disabled) { transform: translateY(1px); }
.map-control-btn:disabled { cursor: not-allowed; opacity: 0.6; box-shadow: none; }

/* Modern user marker styles */
.user-marker-outer {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(240,240,240,0.95));
  display:flex; align-items:center; justify-content:center;
  box-shadow: var(--shadow-md);
  border: 2px solid rgba(0,0,0,0.06);
}
body.dark-theme .user-marker-outer { background: linear-gradient(180deg, rgba(30,30,30,0.95), rgba(40,40,40,0.95)); border: 2px solid rgba(255,255,255,0.06) }
.user-marker-arrow {
  width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-bottom: 12px solid var(--accent-primary);
  transform-origin: 50% 50%;
}
body.light-theme .user-marker-arrow { border-bottom-color: #0078d4 }
body.dark-theme .user-marker-arrow { border-bottom-color: #60cdff }

/* Map legend */
.map-legend {
  position: absolute;
  right: 12px;
  top: 12px;
  background: rgba(255,255,255,0.95);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: var(--shadow-md);
  z-index: 1200;
  font-size: 13px;
  color: var(--text-primary);
}
.map-legend .legend-item { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.map-legend .legend-item:last-child{ margin-bottom:0 }
.legend-icon { width:36px; height:36px; display:flex; align-items:center; justify-content:center }
.building-legend { background:linear-gradient(180deg,#60a5fa,#0078d4); color:white; border-radius:6px; padding:4px }
.building-legend-icon { font-size:16px }
.building-legend-badge { background:white; color:#111827; padding:2px 6px; border-radius:999px; font-weight:700; margin-left:6px }
.legend-text { font-size:12px; color:var(--text-secondary) }
.legend-swatch { width:28px; height:18px; border-radius:4px }

/* Floor match modal styling: center message, spacing, font sizes */
#floorMatchResult { text-align:center; }
#floorMatchResult #floorMatchMessage { font-size:15px; font-weight:700; color:var(--text-primary); margin-top:12px; margin-bottom:8px }
#floorMatchResult #floorMatchDetails { font-size:13px; color:var(--text-secondary); }

/* Make manual floor select fit the modal width nicely */
#manualFloorSelect { width: 100%; max-width: 100%; box-sizing: border-box; }

.combo-box {
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

.combo-box:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

.combo-box:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.2);
}

.readonly-label {
  grid-column: 1 / -1;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}

/* Details Card */
.details-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--border-color);
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.detail-item:last-child {
  margin-bottom: 0;
}

.detail-label {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 500;
}

.detail-value {
  font-size: 14px;
  color: var(--text-primary);
}

/* Restrooms Section */
.restrooms-section {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.count-badge {
  font-size: 13px;
  color: var(--text-tertiary);
  background: rgba(0,0,0,0.04);
  padding: 4px 8px;
  border-radius: 999px;
  margin-left: 8px;
  font-weight: 600;
}

/* choose restroom modal list buttons */
#chooseRestroomList .choose-btn {
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}

/* ensure choose modal adapts to dark theme */
body.dark-theme #chooseRestroomList .choose-btn {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-color);
}

#chooseRestroomList .choose-btn:hover {
  background: var(--bg-tertiary);
}

.restrooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.restroom-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.restroom-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
  transform: translateX(4px);
}

.restroom-btn:active {
  transform: translateX(2px);
}

.restroom-btn.selected {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.restroom-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.restroom-tag {
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

.restroom-btn.selected .restroom-tag {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

/* Added distance display styling */
.restroom-distance {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
  white-space: nowrap;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

.restroom-btn:hover .restroom-distance {
  background: var(--bg-card);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  /* 防止滚动链穿透到页面主体 */
  overscroll-behavior: contain;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* 当内容过长时，滚动模态内容，不穿透到背景 */
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Ensure modal text follows theme colors (fixes dark-mode modal text) */
.modal-content,
.modal-content h3,
.modal-content p,
.modal-content div,
.modal-content span,
.modal-content label {
  color: var(--text-primary);
}

.modal-content p { color: var(--text-secondary); }

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 当有模态窗口显示时，禁止页面主体滚动（防止触控穿透） */
body.modal-open {
  overflow: hidden;
}

/* Locating spinner and states */
.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border: 4px solid rgba(0, 0, 0, 0.08);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

/* When modal is shown, ensure locating/permission states are sized nicely */
#locatingState h3,
#permissionState h3 {
  margin-top: 8px;
}


.modal-content h3 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.modal-content p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.modal-buttons {
  display: flex;
  gap: 12px;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:active {
  background: var(--accent-pressed);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Responsive */
@media (max-width: 480px) {
  .container {
    padding: 12px;
  }

  .title {
    font-size: 18px;
  }

  .combo-group {
    grid-template-columns: 1fr;
  }
}

/* Added debug footer styles */
.debug-footer {
  margin-top: 24px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.debug-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.debug-item {
  display: flex;
  gap: 8px;
  font-size: 12px;
}

.debug-label {
  color: var(--text-tertiary);
  font-weight: 500;
}

.debug-value {
  color: var(--text-secondary);
  font-family: monospace;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-icon {
  width: 20px;
  height: 20px;
  color: var(--text-primary);
}

.sun-icon {
  display: none;
}

.moon-icon {
  display: block;
}

body.light-theme .sun-icon {
  display: block;
}

body.light-theme .moon-icon {
  display: none;
}

body.dark-theme .sun-icon {
  display: none;
}

body.dark-theme .moon-icon {
  display: block;
}

@media (max-width: 480px) {
  .debug-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .theme-toggle {
    align-self: flex-end;
  }
}
