:root {
  --bg: #0b0912;
  --bg-2: #120e1d;
  --card: rgba(255, 255, 255, 0.055);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #f2edf8;
  --muted: #a396b6;
  --pink: #ff5f9e;
  --pink-2: #ff8fb8;
  --violet: #8b5cf6;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #fb7185;
  --radius: 22px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 自定义 display 会覆盖浏览器默认的 [hidden]，必须显式压回 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(139, 92, 246, 0.28), transparent 60%),
    radial-gradient(900px 600px at 90% 5%, rgba(255, 95, 158, 0.22), transparent 55%),
    linear-gradient(180deg, #0b0912 0%, #0d0a15 55%, #0a0810 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}
.orb-a { width: 340px; height: 340px; background: #7c3aed; top: -120px; left: -80px; }
.orb-b { width: 300px; height: 300px; background: #ff4d8d; bottom: -140px; right: -90px; }

#app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 18px calc(56px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.view { animation: fade-up .35s ease both; }
.hidden { display: none !important; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 品牌区 ---------- */
.brand { text-align: center; padding: 46px 0 26px; }
.brand-mark {
  font-size: 46px;
  line-height: 1;
  filter: drop-shadow(0 10px 24px rgba(255, 95, 158, 0.45));
  animation: beat 2.4s ease-in-out infinite;
}
@keyframes beat {
  0%, 100% { transform: scale(1); }
  8% { transform: scale(1.09); }
  16% { transform: scale(1); }
  24% { transform: scale(1.06); }
}
.brand h1 {
  margin: 14px 0 6px;
  font-size: 27px;
  letter-spacing: 0.5px;
  background: linear-gradient(92deg, #fff 10%, var(--pink-2) 55%, #a78bfa 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub { margin: 0; color: var(--muted); font-size: 13.5px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.auth-card { padding: 18px 18px 22px; }

.tabs {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.28);
  padding: 5px;
  border-radius: 14px;
  margin-bottom: 18px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: .2s;
}
.tab.active {
  background: linear-gradient(120deg, var(--pink), var(--violet));
  color: #fff;
  box-shadow: 0 8px 20px rgba(255, 95, 158, 0.28);
}

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 7px;
  letter-spacing: .3px;
}
.field input, .field textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.32);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  border-color: rgba(255, 95, 158, 0.65);
  box-shadow: 0 0 0 4px rgba(255, 95, 158, 0.12);
}
.field input::placeholder { color: #6b5f7c; }

.err { color: var(--red); font-size: 13px; min-height: 18px; margin: 0 0 10px; }

/* ---------- 按钮 ---------- */
.btn {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s, filter .2s, opacity .2s;
  font-family: inherit;
}
.btn:active { transform: scale(0.985); }
.btn.primary {
  background: linear-gradient(120deg, var(--pink) 0%, #e0518f 45%, var(--violet) 100%);
  color: #fff;
  box-shadow: 0 12px 30px rgba(255, 95, 158, 0.3);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-top: 10px;
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn.small { width: auto; padding: 8px 14px; font-size: 12.5px; border-radius: 10px; }
.btn.wide { margin-top: 12px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 20px;
}
.topbar h2 { margin: 2px 0 0; font-size: 22px; }
.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: #8f7fa6;
}

/* ---------- 配对 ---------- */
.code-box {
  font-family: "SF Mono", Consolas, "Courier New", monospace;
  font-size: 34px;
  letter-spacing: 9px;
  text-align: center;
  padding: 18px 8px 18px 18px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px dashed rgba(255, 95, 158, 0.4);
  color: var(--pink-2);
  margin: 8px 0 12px;
  user-select: all;
}
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 8px 0; }
.hint.center { text-align: center; }
.divider {
  display: flex; align-items: center; gap: 12px;
  color: #6d6080; font-size: 12px; margin: 4px 0 16px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.08);
}
.card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 650; }

/* ---------- 主页头部 ---------- */
.home-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 6px 0 16px;
}
.me { display: flex; align-items: center; gap: 11px; }
.me strong { font-size: 15px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 19px;
  background: linear-gradient(135deg, rgba(255, 95, 158, .35), rgba(139, 92, 246, .35));
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.avatar.big { width: 52px; height: 52px; font-size: 24px; }

/* switch */
.switch { position: relative; width: 52px; height: 30px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 30px; cursor: pointer;
  background: rgba(255, 255, 255, .14); transition: .25s;
}
.slider::before {
  content: ""; position: absolute; width: 22px; height: 22px; left: 4px; top: 4px;
  border-radius: 50%; background: #fff; transition: .25s;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .4);
}
.switch input:checked + .slider {
  background: linear-gradient(120deg, var(--pink), var(--violet));
}
.switch input:checked + .slider::before { transform: translateX(22px); }

.share-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-radius: 16px; margin-bottom: 14px;
  background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .28);
}
.share-banner strong { display: block; font-size: 13.5px; color: #fde68a; }
.share-banner span { display: block; font-size: 12px; color: #cbb98a; margin-top: 2px; }

/* ---------- 对方卡片 ---------- */
.partner-card { position: relative; padding: 20px 18px 16px; }
.partner-top { display: flex; align-items: center; gap: 13px; }
.partner-meta { flex: 1; min-width: 0; }
.partner-meta h2 {
  margin: 0 0 4px; font-size: 18px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status-line { margin: 0; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5b5069; display: inline-block; }
.dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 128, .16); }
.dot.offline { background: #6b5f7c; }

/* 电量环 */
.battery-ring { position: relative; width: 74px; height: 74px; flex: 0 0 auto; }
.battery-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, .08); stroke-width: 8; }
.ring-fg {
  fill: none; stroke: var(--green); stroke-width: 8; stroke-linecap: round;
  stroke-dasharray: 264; stroke-dashoffset: 264;
  transition: stroke-dashoffset .7s ease, stroke .3s;
}
.ring-label {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
}
.ring-label strong { font-size: 17px; line-height: 1; }
.ring-label span { font-size: 10px; color: var(--muted); }

.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px;
}
.stat {
  background: rgba(0, 0, 0, .26); border-radius: 14px; padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, .05);
}
.stat span { display: block; font-size: 11px; color: #8f7fa6; margin-bottom: 4px; }
.stat strong {
  display: block; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.locked {
  margin-top: 16px; padding: 22px; text-align: center;
  border-radius: 16px; background: rgba(0, 0, 0, .28);
  border: 1px dashed rgba(255, 255, 255, .12);
}
.lock-icon { font-size: 26px; margin-bottom: 6px; }
.locked p { margin: 0; color: var(--muted); font-size: 13px; }

.alert {
  background: rgba(251, 113, 133, .12); border: 1px solid rgba(251, 113, 133, .35);
  color: #fecdd3; border-radius: 14px; padding: 11px 14px; font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- 地图 ---------- */
.map-wrap {
  position: relative; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--card-border); box-shadow: var(--shadow);
  margin-bottom: 16px; background: #0d0a15;
}
#map { height: 260px; width: 100%; background: #0d0a15; }
.leaflet-container { background: #0d0a15; font-family: inherit; }
.leaflet-tile-pane {
  filter: invert(1) hue-rotate(190deg) brightness(0.72) contrast(1.05) saturate(0.55);
}
.map-legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 500;
  display: flex; align-items: center; gap: 12px;
  background: rgba(12, 9, 18, .82); backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 12px; padding: 7px 10px; font-size: 11.5px; color: #d9cfe8;
}
.swatch { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.swatch.me { background: var(--violet); }
.swatch.you { background: var(--pink); }
.chip {
  border: 1px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .06);
  color: #e7dcf5; border-radius: 999px; padding: 4px 10px; font-size: 11px;
  cursor: pointer; font-family: inherit;
}
.chip.active { background: linear-gradient(120deg, var(--pink), var(--violet)); border-color: transparent; }
.map-fallback {
  position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; gap: 6px; padding: 20px; background: #0d0a15;
}
.map-fallback p { margin: 0; color: var(--muted); font-size: 13px; }
.map-fallback a { color: var(--pink-2); font-size: 13px; }

.marker-pin {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  font-size: 16px; border: 2px solid #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .5);
}
.marker-pin.me { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.marker-pin.you { background: linear-gradient(135deg, #ff5f9e, #db2777); }

/* ---------- 操作区 ---------- */
.actions { display: flex; gap: 10px; }
.actions .btn { margin-top: 0; }
.actions .btn.primary { flex: 1.4; }
.actions .btn.ghost { flex: 1; }

/* ---------- 抽屉 ---------- */
.sheet-mask {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(4, 3, 8, .66); backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in .2s ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 520px; background: #16111f;
  border-radius: 24px 24px 0 0; padding: 12px 20px calc(26px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, .1);
  animation: slide-up .28s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes slide-up { from { transform: translateY(30px); } to { transform: none; } }
.sheet-handle {
  width: 38px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .18);
  margin: 0 auto 14px;
}
.sheet h3 { margin: 0 0 14px; font-size: 17px; }

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 20px);
  background: rgba(22, 17, 31, .96); color: #fff; padding: 12px 18px;
  border-radius: 14px; font-size: 13.5px; border: 1px solid rgba(255, 255, 255, .12);
  opacity: 0; pointer-events: none; transition: .25s; z-index: 3000;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55); max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.fineprint { color: #6f6382; font-size: 11.5px; text-align: center; line-height: 1.7; margin: 18px 0 0; }

@media (max-width: 380px) {
  .code-box { font-size: 27px; letter-spacing: 6px; }
  .battery-ring { width: 64px; height: 64px; }
}
