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

:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
  --radius: 8px;
  --top-bar-height: 52px;
  --sidebar-width: 320px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Microsoft YaHei', sans-serif;
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

/* Top bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-bar-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  gap: 16px;
}

.top-bar-left {
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: block;
}

.top-bar-right {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  align-items: center;
}

.search-box {
  position: relative;
  width: 220px;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--primary);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 4px;
  max-height: 300px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 1001;
}

.search-results.hidden { display: none; }

.search-group-label {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.search-result-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-secondary); }

.search-result-track strong {
  color: var(--primary);
}

.search-result-meta {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.search-result-location {
  display: block;
}

.top-bar-right {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.top-btn {
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: all 0.2s;
}

.top-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--primary-light);
}

/* Main content */
.main-content {
  position: fixed;
  top: var(--top-bar-height);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
}

/* Map area */
.map-area {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

#map {
  width: 100%;
  height: 100%;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: var(--bg);
  border-radius: 12px;
  width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

/* 设置对话框靠右 */
.modal.modal-right {
  justify-content: flex-end;
  align-items: stretch;
}

.modal.modal-right .modal-content {
  margin: 20px;
  max-height: calc(100vh - 40px);
  border-radius: 12px;
  width: 400px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  color: var(--text-secondary);
}

.modal-close:hover { background: var(--bg-secondary); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(79, 70, 229, 0.05);
}

.drop-icon { font-size: 40px; }
.drop-zone p { margin-top: 8px; color: var(--text-secondary); }
.drop-zone .hint { font-size: 13px; }

.upload-progress { text-align: center; padding: 20px 0; }

/* 全局 .hidden 兜底（之前只在特定元素上定义，容易漏） */
.hidden { display: none !important; }

/* 步骤列表 */
.howto-list {
  margin: 4px 0 0;
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}
.howto-list li { margin-bottom: 2px; }

/* About block */
.about-block { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 8px; }
.about-block .about-text {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: 6px 0;
}
.about-block .about-warn { color: #b45309; }
.about-block a { color: var(--primary); text-decoration: none; }
.about-block a:hover { text-decoration: underline; }
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: slideIn 0.3s ease;
  border-left: 4px solid var(--primary);
}

.toast.error { border-left-color: #ef4444; }
.toast.success { border-left-color: #22c55e; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Elevation chart */
.elevation-chart {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 500px;
  max-width: calc(100% - 40px);
  height: 150px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 800;
  padding: 4px 8px 8px;
  transition: transform 0.35s ease;
}

.elevation-chart.hidden { display: none; }

/* 移动端收起状态：向右滑出，只留 20px 可见 */
@media (max-width: 768px) {
  .elevation-chart {
    /* 移动端不居中，直接贴底部 */
    left: 10px;
    right: 10px;
    width: auto;
    max-width: none;
    transform: none;
  }

  .elevation-chart.collapsed {
    transform: translateX(calc(100% - 20px));
  }

  .elevation-chart.collapsed #chartInfo,
  .elevation-chart.collapsed #elevationCanvas {
    pointer-events: none;
    opacity: 0;
  }
}

#chartInfo {
  display: flex;
  justify-content: space-between;
  padding: 0 0 2px;
  font-size: 11px;
  color: var(--text-secondary);
}

#elevationCanvas {
  width: 100%;
  height: 126px;
  cursor: crosshair;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }

  /* 顶栏更紧凑 */
  .top-bar { padding: 0 8px; gap: 8px; }
  .top-bar-right { gap: 6px; }
  .top-btn { padding: 0 10px; height: 32px; font-size: 12px; }

  /* logo 改为竖排（emoji 上、文字下） */
  .logo {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    line-height: 1;
  }
  .logo-icon { width: 22px; height: 22px; }
  .logo-text { font-size: 11px; font-weight: 600; }

  .search-box { width: 130px; }
  .search-box input { height: 32px; font-size: 13px; }
}

/* Danger button */
.danger-btn {
  display: inline-block;
  padding: 6px 14px;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 6px;
}

.danger-btn:hover {
  background: #dc2626;
}

/* Storage bar */
.storage-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 6px;
}

.storage-fill {
  height: 100%;
  background: #22c55e;
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s, background 0.3s;
}

.storage-text {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Settings hint */
.settings-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}

/* iOS Shortcut guide */
.shortcut-install-btn {
  display: inline-block;
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

.shortcut-guide {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.shortcut-guide summary {
  cursor: pointer;
  color: var(--primary);
}
.shortcut-guide ol {
  margin-top: 6px;
  padding-left: 20px;
  line-height: 1.8;
}
.shortcut-guide code {
  background: var(--bg-secondary);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}
