:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #161616;
  --bg-elevated: #1a1a2e;
  --bg-card-hover: #1a1a2e;
  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --text-muted: #555;
  --text-white: #fff;
  --border-color: #222;
  --border-light: #2a2a2a;
  --accent: #5a8af0;
  --accent-hover: #4a7ae0;
  --accent-bg: rgba(90, 138, 240, 0.15);
  --input-bg: #161616;
  --input-border: #2a2a2a;
  --badge-bg: rgba(90, 138, 240, 0.15);
  --btn-secondary-bg: #222;
  --btn-secondary-border: #333;
  --hero-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  --toast-bg: #1a1a2e;
  --toast-border: #5a8af0;
  --link-color: #5a8af0;
}

[data-theme="light"] {
  --bg-primary: #f5f3f0;
  --bg-secondary: #ffffff;
  --bg-elevated: #e8e4de;
  --bg-card-hover: #f0ede8;
  --text-primary: #1a1a1a;
  --text-secondary: #444;
  --text-muted: #666;
  --text-white: #000;
  --border-color: #d0cdc8;
  --border-light: #c0bdb8;
  --accent: #3a6ab0;
  --accent-hover: #2a5aa0;
  --accent-bg: rgba(58, 106, 176, 0.12);
  --input-bg: #ffffff;
  --input-border: #c0bdb8;
  --badge-bg: rgba(58, 106, 176, 0.12);
  --btn-secondary-bg: #e8e4de;
  --btn-secondary-border: #c0bdb8;
  --hero-bg: linear-gradient(135deg, #e8e4de 0%, #ddd8d0 100%);
  --toast-bg: #ffffff;
  --toast-border: #4a7ad0;
  --link-color: #4a7ad0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}
a { color: var(--link-color); text-decoration: none; }

.header {
  background: var(--bg-elevated);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: background 0.3s;
}
.header .logo { font-size: 1.2em; font-weight: 600; color: var(--text-white); letter-spacing: 2px; }
.header .logo span { color: var(--accent); }
.header .nav { display: flex; align-items: center; gap: 4px; }
.header .nav a {
  color: var(--text-muted);
  font-size: 0.85em;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s;
}
.header .nav a:hover, .header .nav a.active { color: var(--text-white); background: rgba(255,255,255,0.08); }
[data-theme="light"] .header .nav a:hover,
[data-theme="light"] .header .nav a.active { background: rgba(0,0,0,0.06); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.85em;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: 8px;
  line-height: 1;
}
.theme-toggle:hover { color: var(--text-white); border-color: var(--accent); }

.page { max-width: 800px; margin: 0 auto; padding: 20px; }

.footprint-grid { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.footprint-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px;
  transition: all 0.2s;
  cursor: pointer;
}
.footprint-card:hover { border-color: var(--accent); background: var(--bg-card-hover); }
.footprint-card .title { font-size: 1.15em; font-weight: 600; color: var(--text-white); margin-bottom: 6px; }
.footprint-card .preview { font-size: 0.85em; color: var(--text-secondary); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.footprint-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 0.75em; color: var(--text-muted); }
.footprint-card .meta .author { color: var(--accent); }
.footprint-card .meta .coords { font-family: monospace; }
.footprint-card .badge { display: inline-block; font-size: 0.7em; padding: 2px 8px; border-radius: 4px; background: var(--badge-bg); color: var(--accent); margin-top: 8px; }

.btn {
  display: inline-block;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 0.95em;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--text-primary); border: 1px solid var(--btn-secondary-border); }
.btn-secondary:hover { background: var(--border-color); }
.btn-block { display: block; width: 100%; }
.btn-lg { padding: 16px 32px; font-size: 1.1em; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 0.85em; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95em;
  font-family: inherit;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group textarea { min-height: 200px; resize: vertical; line-height: 1.6; }
.form-group select { cursor: pointer; }
.form-group .hint { font-size: 0.75em; color: var(--text-muted); margin-top: 4px; }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 20px; }
.template-option { background: var(--bg-secondary); border: 2px solid var(--border-light); border-radius: 10px; padding: 14px 12px; text-align: center; cursor: pointer; transition: all 0.2s; }
.template-option:hover { border-color: var(--text-muted); }
.template-option.selected { border-color: var(--accent); background: var(--bg-card-hover); }
.template-option .emoji { font-size: 1.8em; margin-bottom: 6px; }
.template-option .tname { font-size: 0.85em; font-weight: 600; color: var(--text-white); }
.template-option .tdesc { font-size: 0.7em; color: var(--text-muted); margin-top: 4px; }

.hero { text-align: center; padding: 60px 20px 40px; }
.hero .icon { font-size: 3em; margin-bottom: 16px; }
.hero h1 { font-size: 2em; font-weight: 700; color: var(--text-white); margin-bottom: 12px; letter-spacing: 3px; }
.hero h1 span { color: var(--accent); }
.hero p { color: var(--text-secondary); font-size: 1em; line-height: 1.6; max-width: 480px; margin: 0 auto 28px; }

.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 3em; margin-bottom: 12px; }
.empty-state p { font-size: 0.9em; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--toast-bg);
  border: 1px solid var(--toast-border);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.85em;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Left Drawer Nav ── */
#drawer-handle {
  position: fixed; left: 8px; top: 50%; transform: translateY(-50%);
  z-index: 1000; width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,0.4); backdrop-filter: blur(4px);
  color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: left 0.3s ease; padding: 0;
  line-height: 1;
}
#drawer-handle.open { left: 72px; }

#drawer {
  position: fixed; left: 0; top: 50%; transform: translateY(-50%) translateX(-200%);
  z-index: 999; display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 14px 8px; transition: transform 0.3s ease;
}
#drawer.open { transform: translateY(-50%) translateX(0); }

.drawer-item {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; background: #000; color: #ccc;
  text-decoration: none; border: none; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3); transition: all 0.2s;
  font-family: inherit; padding: 0; line-height: 1;
  flex-shrink: 0;
}
.drawer-item:active { transform: scale(0.92); }
.drawer-item.active { background: #000; color: #fff; border: 1px solid rgba(255,255,255,0.2); }
[data-theme="light"] .drawer-item { background: #222; color: #ccc; }
[data-theme="light"] .drawer-item.active { background: #000; color: #fff; border: 1px solid rgba(255,255,255,0.3); }

.drawer-icon { font-size: 18px; line-height: 1; }
.drawer-label { font-size: 9px; line-height: 1; font-weight: 600; }

.drawer-divider { width: 24px; height: 1px; background: rgba(255,255,255,0.15); margin: 2px 0; }
[data-theme="light"] .drawer-divider { background: rgba(0,0,0,0.12); }

#drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.2);
  z-index: 998; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
#drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.loading { text-align: center; padding: 40px; color: var(--text-muted); }
.spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Emotion filter buttons */
.emo-filter {
  flex-shrink: 0; padding: 4px 10px; border-radius: 14px; border: 1px solid var(--border-color);
  background: var(--bg-secondary); color: var(--text-muted); font-size: 0.75em;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.emo-filter.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.emo-filter:hover { border-color: var(--accent); color: var(--text-white); }

/* Emotion grid (create page) */
.emotion-grid {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px;
}
.emotion-option {
  padding: 8px 14px; border-radius: 20px; border: 1px solid var(--border-color);
  background: var(--bg-secondary); color: var(--text-primary); font-size: 0.85em;
  cursor: pointer; transition: all 0.2s;
}
.emotion-option:hover { border-color: var(--accent); }
.emotion-option.selected { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

/* Letter envelope (create page) */
.letter-envelope {
  background: linear-gradient(135deg, rgba(160,100,50,0.08) 0%, rgba(120,80,40,0.04) 100%);
  border-radius: 20px; padding: 32px 28px;
  border: 1px solid rgba(160,100,50,0.2); position: relative;
  box-shadow: inset 0 0 60px rgba(120,80,40,0.06);
}
.letter-envelope::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0;
  height: 20px;
  background: linear-gradient(135deg, transparent 33%, rgba(160,100,50,0.08) 33%, rgba(160,100,50,0.08) 66%, transparent 66%);
  background-size: 30px 20px;
}
.letter-envelope::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0 70px 70px 0;
  border-color: transparent rgba(160,100,50,0.1) transparent transparent;
}
.letter-stamp {
  position: absolute; top: 12px; right: 12px;
  width: 52px; height: 52px; border: 2px solid rgba(180,80,60,0.35);
  border-radius: 50%; z-index: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6em;
  background: radial-gradient(circle at 40% 35%, rgba(180,80,60,0.1), transparent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.letter-postmark {
  position: absolute; top: 14px; right: 14px; font-size: 1.8em; z-index: 2;
  animation: postmark-spin 0.8s ease-out forwards;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.2));
}
@keyframes postmark-spin {
  0% { transform: rotate(-30deg) scale(0) translateY(20px); opacity: 0; }
  50% { transform: rotate(10deg) scale(1.3) translateY(-4px); opacity: 1; }
  100% { transform: rotate(-12deg) scale(1) translateY(0); opacity: 0.9; }
}
.letter-title { font-size: 1.3em; font-weight: 600; color: var(--text-white); margin-bottom: 4px; }
.letter-subtitle { font-size: 0.85em; color: var(--text-muted); margin-bottom: 24px; }

/* Visibility selector */
.vis-selector { display: flex; gap: 8px; flex-wrap: wrap; }
.vis-opt {
  padding: 8px 16px; border-radius: 20px; border: 1px solid var(--border-color);
  background: var(--bg-secondary); color: var(--text-primary); font-size: 0.85em;
  cursor: pointer; transition: all 0.2s;
}
.vis-opt:hover { border-color: var(--accent); }
.vis-opt.selected { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

/* Resonate button in popup */
.btn-rs {
  background: rgba(255,80,120,0.15); color: #ff5078; border: 1px solid rgba(255,80,120,0.3);
  border-radius: 6px; cursor: pointer; font-size: 0.85em; transition: all 0.2s;
}
.btn-rs:hover { background: rgba(255,80,120,0.25); }

/* Notification dot on drawer */
.drawer-item .notif-dot { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; position: absolute; top: 4px; right: 4px; }

/* Bottom panel scroll */
#emotionFilters::-webkit-scrollbar { height: 2px; }
#emotionFilters::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

/* SOS button global */
.drawer-sos { color: #fff !important; background: #e53e3e !important; border-top: 1px solid var(--border-color); margin-top: 4px; padding-top: 4px; border-radius: 6px; }
.drawer-sos .drawer-icon { color: #fff !important; }
.drawer-sos:hover { background: #c0392b !important; }

/* ── Media Search Modal (create footprint / route) ── */
.media-input-row { display: flex; gap: 6px; align-items: center; }
.media-input-row input { flex: 1; min-width: 0; }
.btn-media {
  flex-shrink: 0; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--border-color); background: var(--bg-elevated);
  color: var(--accent); cursor: pointer; font-size: 0.85em; transition: all 0.2s;
}
.btn-media:hover { border-color: var(--accent); background: rgba(90,138,240,0.12); }

#mediaSearchModal {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.7); align-items: center; justify-content: center; padding: 16px;
}
#mediaSearchModal.show { display: flex; }
.ms-modal-box {
  background: var(--bg-primary); border: 1px solid var(--border-color);
  border-radius: 16px; width: 100%; max-width: 440px; max-height: 85vh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.ms-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.ms-header h3 { font-size: 0.95em; margin: 0; }
.ms-close { background: none; border: none; color: var(--text-muted); font-size: 1.4em; cursor: pointer; padding: 0 4px; line-height: 1; }
.ms-tabs { display: flex; gap: 6px; padding: 10px 18px 0; flex-shrink: 0; flex-wrap: wrap; }
.ms-tab { padding: 6px 12px; border-radius: 16px; border: 1px solid var(--border-color); background: transparent; color: var(--text-muted); cursor: pointer; font-size: 0.8em; }
.ms-tab.active { border-color: var(--accent); color: var(--accent); background: rgba(90,138,240,0.1); }
.ms-search-row { display: flex; gap: 6px; padding: 10px 18px; flex-shrink: 0; }
.ms-search-row input {
  flex: 1; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--border-color); background: var(--input-bg); color: var(--text-primary); font-size: 0.85em;
}
.ms-results { flex: 1; overflow-y: auto; padding: 0 18px 4px; font-size: 0.8em; color: var(--text-muted); }
.ms-card { display: flex; gap: 10px; padding: 8px; margin-bottom: 8px; border: 1px solid var(--border-color); border-radius: 10px; cursor: pointer; transition: border-color 0.2s; }
.ms-card:hover { border-color: var(--accent); }
.ms-thumb { width: 72px; height: 54px; object-fit: cover; border-radius: 6px; background: #000; flex-shrink: 0; }
.ms-thumb-ph { display: flex; align-items: center; justify-content: center; font-size: 1.5em; background: linear-gradient(135deg, #5a8af0, #9b59b6); color: #fff; }
.ms-card-meta { min-width: 0; }
.ms-card-title { font-size: 0.8em; color: var(--text-primary); line-height: 1.4; max-height: 2.8em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ms-card-src { font-size: 0.7em; color: var(--text-muted); margin-top: 2px; }

/* ── 微交互反馈 (micro interactions) ── */
.btn, .btn-rs, .btn-media, .emo-filter, .vis-opt, .template-option, .ms-card, .footprint-card, .route-card, .stat-card, .ms-tab, .sp-style-btn, .sp-ghost {
  transition: all 0.2s ease;
}
.btn:active, .btn-rs:active, .btn-media:active, .emo-filter:active, .vis-opt:active, .template-option:active, .ms-card:active, .footprint-card:active, .route-card:active, .ms-tab:active, .sp-style-btn:active, .sp-ghost:active {
  transform: translateY(1px) scale(0.97);
}
.btn-primary:active, .btn-main:active { transform: translateY(1px) scale(0.97); box-shadow: 0 2px 8px rgba(90,138,240,0.35); }

/* hover lift */
.footprint-card:hover, .route-card:hover, .stat-card:hover, .ms-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.18); }

/* input focus glow */
input:focus, textarea:focus, select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(90,138,240,0.18);
}
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* toast 动效 */
.toast { transform: translate(-50%, -6px); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -14px); }
  to   { opacity: 1; transform: translate(-50%, -6px); }
}
.toast.show { animation: toast-in 0.25s ease both; }

/* 入场动画 */
@keyframes fpIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}
.footprint-card, .route-card, .stat-card, .ms-card { animation: fpIn 0.4s ease both; }

/* 按钮水波纹 */
.ripple { position: relative; overflow: hidden; }
.ripple-ink {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,0.5); transform: scale(0);
  animation: ripple 0.6s ease-out forwards; pointer-events: none;
}
@keyframes ripple { to { transform: scale(4); opacity: 0; } }

/* 数字滚动 */
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }
.num-pop { display: inline-block; animation: pop 0.3s ease; }

/* ── 连续足迹 Streak ── */
.streak-card {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  background: linear-gradient(135deg, rgba(255,153,51,0.16), rgba(255,87,34,0.08));
  border: 1px solid rgba(255,140,50,0.35); border-radius: 14px; margin: 12px 0;
}
.streak-flame { font-size: 2.4em; line-height: 1; animation: streak-flicker 1.6s ease-in-out infinite; }
@keyframes streak-flicker { 0%,100% { transform: scale(1) rotate(-3deg); } 50% { transform: scale(1.12) rotate(3deg); } }
.streak-info { flex: 1; min-width: 0; }
.streak-num { font-size: 1.15em; font-weight: 700; }
.streak-num span { color: #ff8c33; }
.streak-sub { font-size: 0.78em; color: var(--text-muted); margin: 4px 0 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.streak-cal { display: flex; gap: 4px; flex-wrap: wrap; }
.streak-dot { width: 16px; height: 16px; border-radius: 50%; font-size: 0.62em; line-height: 16px; text-align: center; flex-shrink: 0; }
.streak-dot.on { background: #ff8c33; color: #fff; }
.streak-dot.makeup { background: #2ecc71; color: #fff; }
.streak-dot.off { background: var(--bg-secondary); border: 1px solid var(--border-color); }
.streak-dot.today { box-shadow: 0 0 0 2px rgba(255,140,51,0.5); }
.streak-dot.today.off { box-shadow: 0 0 0 2px rgba(255,140,51,0.35); }

/* ── 勋章 ── */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.badge-item {
  text-align: center; padding: 12px 6px; border-radius: 12px;
  border: 1px solid var(--border-color); background: var(--bg-secondary);
  transition: all 0.2s ease;
}
.badge-item:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.18); }
.badge-item.earned { border-color: rgba(255,200,80,0.5); background: linear-gradient(160deg, rgba(255,200,80,0.14), rgba(255,150,50,0.06)); }
.badge-icon { font-size: 1.7em; line-height: 1; }
.badge-item:not(.earned) .badge-icon { filter: grayscale(1); opacity: 0.4; }
.badge-name { font-size: 0.74em; font-weight: 600; margin-top: 6px; color: var(--text-primary); }
.badge-item:not(.earned) .badge-name { color: var(--text-muted); }
.badge-desc { font-size: 0.66em; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.badge-prog { font-size: 0.62em; color: var(--text-secondary); margin-top: 4px; }
