/* 阶段 3：空间化视图层。只消费语义变量，兼容 day/night 与 5 种气泡样式。 */

.spatial-entry {
  display: block; width: 100%; margin-top: 10px; padding: 10px;
  border-radius: 12px; border: 1px solid var(--line, rgba(213,255,238,.16));
  background: rgba(127,127,127,.06); color: var(--ink, #edfaf4);
  font-size: 13px; text-align: center;
}
.spatial-entry:hover { border-color: var(--mint, #a9f5d3); }
#app.is-spatial .actionbar { display: none; }

.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;
}

:root {
  --sp-bg1: #061311;
  --sp-bg2: #020807;
  --sp-ink: #edfaf4;
  --sp-muted: #9db7ae;
  --sp-signal: #a9f5d3;
  --sp-warm: #ffd6b7;
  --sp-line: rgba(213, 255, 238, 0.16);
  --sp-panel: rgba(8, 28, 24, 0.82);
  --sp-map-filter: invert(1) hue-rotate(178deg) saturate(.46) brightness(.86) contrast(1.12);
  --sp-veil: rgba(2, 8, 7, .62);
  --sp-shadow: 0 30px 90px rgba(0, 0, 0, .55);
}

#app[data-theme="day"] {
  --sp-bg1: #e8e5da;
  --sp-bg2: #dcd9cc;
  --sp-ink: #1e2e28;
  --sp-muted: #5e746b;
  --sp-signal: #2f7e68;
  --sp-warm: #b07b45;
  --sp-line: rgba(30, 46, 40, 0.18);
  --sp-panel: rgba(244, 242, 233, 0.88);
  --sp-map-filter: saturate(.42) brightness(.98) contrast(.92) sepia(.08);
  --sp-veil: rgba(220, 217, 204, .55);
  --sp-shadow: 0 30px 90px rgba(46, 58, 52, .22);
}

.spatial-view {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(160deg, var(--sp-bg1), var(--sp-bg2));
  color: var(--sp-ink);
  transition: background-color .5s ease, color .5s ease;
  z-index: 5;
}

.spatial-view[hidden] { display: none !important; }

.spatial-map {
  position: absolute;
  inset: 0;
  background-color: #0d1c19;
  background-image:
    linear-gradient(rgba(120, 180, 160, .07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 180, 160, .07) 1px, transparent 1px),
    radial-gradient(circle at 50% 44%, rgba(60, 130, 110, .22), transparent 60%);
  background-size: 46px 46px, 46px 46px, 100% 100%;
  filter: var(--sp-map-filter);
  transition: filter .5s ease, transform .42s cubic-bezier(.22, 1, .36, 1), opacity .42s ease;
  transform-origin: 50% 60%;
}
.spatial-map--live { background-image: none; }
.spatial-map canvas { width: 100%; height: 100%; }

.spatial-focusing .spatial-map,
.spatial-focused .spatial-map {
  filter: var(--sp-map-filter) blur(3px) brightness(.82);
}

.spatial-veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 42%, transparent 30%, var(--sp-veil) 100%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .42s ease;
  z-index: 6;
}
.spatial-focused .sp-markers { opacity: 0; pointer-events: none; }
.spatial-focused .spatial-veil {
  opacity: 1;
  background:
    linear-gradient(rgba(0,0,0,.28), rgba(0,0,0,.28)),
    radial-gradient(circle at 50% 42%, transparent 22%, var(--sp-veil) 100%);
}
#app[data-theme="day"] .spatial-focused .spatial-veil {
  background:
    linear-gradient(rgba(30,46,40,.34), rgba(30,46,40,.34)),
    radial-gradient(circle at 50% 42%, transparent 22%, var(--sp-veil) 100%);
}

/* ---------- HUD ---------- */
.sp-hud {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  font-size: 12px;
}
.sp-hud > * { pointer-events: auto; }
.sp-brand {
  position: absolute;
  left: 14px;
  top: calc(12px + var(--safe-top, 0px));
  letter-spacing: .12em;
  font-size: 11px;
  font-weight: 700;
  color: var(--sp-ink);
  text-shadow: 0 1px 8px rgba(0,0,0,.35);
  max-width: 44%;
}
.sp-brand small { display: block; font-size: 8px; font-weight: 400; opacity: .65; letter-spacing: .14em; margin-top: 2px; }
.sp-compass, .sp-weather, .sp-signalbar {
  position: absolute;
  background: var(--sp-panel);
  border: 1px solid var(--sp-line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--sp-ink);
  backdrop-filter: blur(8px);
  font-size: 11px;
  white-space: nowrap;
}
.sp-compass { right: 14px; top: calc(12px + var(--safe-top, 0px)); }
.sp-weather { left: 14px; top: calc(58px + var(--safe-top, 0px)); }
.sp-signalbar { right: 14px; top: calc(50px + var(--safe-top, 0px)); }
.sp-actions {
  position: absolute;
  right: 14px;
  bottom: calc(88px + var(--safe-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sp-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--sp-panel);
  border: 1px solid var(--sp-line);
  color: var(--sp-ink);
  display: grid; place-items: center;
  backdrop-filter: blur(8px);
  font-size: 15px;
}
.sp-btn[aria-expanded="true"] { border-color: var(--sp-signal); color: var(--sp-signal); }
.sp-theme-toggle {
  display: flex; gap: 2px; padding: 3px; border-radius: 999px;
  position: absolute; left: 14px; bottom: calc(88px + var(--safe-bottom, 0px));
  background: var(--sp-panel); border: 1px solid var(--sp-line);
  pointer-events: auto;
}
.sp-theme-toggle button {
  border: 0; background: none; color: var(--sp-muted);
  font-size: 11px; padding: 5px 8px; border-radius: 999px;
}
.sp-theme-toggle button[aria-pressed="true"] { background: var(--sp-signal); color: var(--sp-bg1); font-weight: 700; }

.sp-credit {
  position: absolute;
  left: 8px; bottom: calc(4px + var(--safe-bottom, 0px));
  font-size: 9px; color: var(--sp-muted); opacity: .7;
  pointer-events: none;
}
.sp-legal-note {
  position: absolute;
  right: 8px; bottom: calc(4px + var(--safe-bottom, 0px));
  font-size: 9px; color: var(--sp-muted); opacity: .6;
  max-width: 55%; text-align: right; pointer-events: none;
}

/* ---------- 玩家与圈层 ---------- */
.sp-player {
  position: absolute;
  left: 50%; top: 48%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--sp-signal);
  box-shadow: 0 0 0 4px rgba(169, 245, 211, .18), 0 0 22px var(--sp-signal);
  z-index: 8;
}
.sp-cone {
  position: absolute;
  left: 50%; top: 48%;
  width: 120px; height: 120px;
  margin: -60px 0 0 -60px;
  background: conic-gradient(from 0deg, rgba(169,245,211,.28), transparent 60deg);
  border-radius: 50%;
  transform: rotate(-20deg);
  z-index: 7;
  pointer-events: none;
}
.sp-ring {
  position: absolute;
  left: 50%; top: 48%;
  border: 1px dashed var(--sp-line);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 7;
  pointer-events: none;
}

/* ---------- 地图上的气泡 ---------- */
.sp-markers { position: absolute; inset: 0; z-index: 9; }
.sp-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 0; background: none; padding: 0;
  cursor: pointer;
  color: var(--sp-ink);
}
.sp-marker[data-band="far"] { cursor: default; }
.sp-bubble {
  --clarity: 1;
  --opacity: 1;
  --shell-blur: 0px;
  --text-fade: 1;
  --shell-a: rgba(169, 245, 211, .18);
  --shell-b: rgba(90, 200, 170, .06);
  --edge: rgba(215, 255, 237, .7);
  --glow: rgba(169, 245, 211, .5);
  --accent: #d7ffed;
  position: relative;
  border-radius: 50%;
  display: grid; place-items: center;
  text-align: center;
  opacity: var(--opacity);
  transition: opacity .5s ease, transform .3s ease;
}
.sp-bubble::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--shell-a), var(--shell-b));
  border: 1px solid var(--edge);
  box-shadow: inset 0 0 18px rgba(255,255,255,.12), 0 0 calc(22px * var(--clarity)) var(--glow);
  filter: blur(var(--shell-blur));
}
.sp-bubble__body { position: relative; z-index: 1; padding: 10px; max-width: 100%; }
.sp-bubble__mood { font-size: 11px; color: var(--accent); }
.sp-bubble__text { margin: 3px 0 0; font-size: 11px; line-height: 1.4; opacity: var(--text-fade); }
.sp-bubble__tail { margin-top: 3px; font-size: 9px; color: var(--sp-muted); opacity: var(--text-fade); }

/* 五种外观：只改外壳变量，正文排版一致 */
.sp-bubble[data-style="mist"] { --shell-a: rgba(200,225,215,.20); --shell-b: rgba(120,160,150,.04); --edge: rgba(225,245,235,.55); --glow: rgba(190,220,210,.35); --accent: #eaf7f0; }
.sp-bubble[data-style="paper"] { --shell-a: rgba(255,248,230,.28); --shell-b: rgba(220,205,175,.10); --edge: rgba(255,250,235,.75); --glow: rgba(255,236,200,.4); --accent: #fff6e2; border-radius: 46% 54% 52% 48%; }
.sp-bubble[data-style="signal"] { --shell-a: rgba(90,230,210,.14); --shell-b: rgba(20,90,85,.10); --edge: rgba(120,255,230,.8); --glow: rgba(90,240,215,.55); --accent: #9dffe6; }
.sp-bubble[data-style="signal"]::after { content:""; position:absolute; inset:6px; border-radius:50%; background: repeating-linear-gradient(0deg, rgba(160,255,235,.10) 0 1px, transparent 1px 4px); pointer-events:none; }
.sp-bubble[data-style="vinyl"] { --shell-a: rgba(120,90,180,.30); --shell-b: rgba(20,16,40,.5); --edge: rgba(220,190,255,.7); --glow: rgba(170,120,255,.5); --accent: #e6d4ff; }
.sp-bubble[data-style="vinyl"]::after { content:""; position:absolute; inset:8px; border-radius:50%; background: repeating-radial-gradient(circle, transparent 0 3px, rgba(255,255,255,.06) 3px 4px); pointer-events:none; }
.sp-bubble[data-style="dew"] { --shell-a: rgba(180,255,220,.26); --shell-b: rgba(60,150,120,.08); --edge: rgba(220,255,240,.85); --glow: rgba(140,255,200,.55); --accent: #d8fff0; }

.sp-marker[data-band="near"] .sp-bubble { width: 132px; min-height: 132px; }
.sp-marker[data-band="mid"] .sp-bubble { width: 150px; min-height: 78px; border-radius: 40%; }
.sp-marker[data-band="cell"] .sp-bubble {
  width: 0; height: 0; border: 0; box-shadow: none;
}
.sp-marker[data-band="cell"] .sp-bubble::before {
  inset: -26px;
  background: radial-gradient(circle, rgba(169,245,211,.22), transparent 70%);
  border: 1px solid var(--sp-line);
  filter: none;
}
.sp-cell-label {
  position: absolute; left: 30px; top: -6px; white-space: nowrap;
  font-size: 9px; color: var(--sp-muted);
}
.sp-ambient {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: var(--sp-warm); opacity: .5; pointer-events: none;
  box-shadow: 0 0 8px var(--sp-warm);
}

/* ---------- 聚焦气泡 ---------- */
.sp-focus-layer { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.sp-focus-layer[hidden] { display: none; }
.sp-anchor {
  position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%; background: var(--sp-signal);
  box-shadow: 0 0 0 4px rgba(169,245,211,.2), 0 0 20px var(--sp-signal);
}
.sp-signal-line { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sp-focus-bubble {
  --clarity: 1;
  --opacity: 1;
  --shell-a: rgba(169, 245, 211, .34);
  --shell-b: rgba(60, 150, 128, .28);
  --edge: rgba(215, 255, 237, .85);
  --glow: rgba(169, 245, 211, .6);
  --accent: #d7ffed;
  position: absolute;
  width: min(86vw, 360px);
  min-height: min(86vw, 360px);
  left: 50%; top: 44%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: auto;
  display: grid; place-items: center;
  background: none; border: 0; color: var(--sp-ink);
  opacity: 0;
}
.sp-focus-bubble[data-style="mist"] { --shell-a: rgba(200,225,215,.22); --shell-b: rgba(120,160,150,.05); --edge: rgba(225,245,235,.6); --glow: rgba(190,220,210,.4); --accent: #eaf7f0; }
.sp-focus-bubble[data-style="paper"] { --shell-a: rgba(255,248,230,.30); --shell-b: rgba(220,205,175,.12); --edge: rgba(255,250,235,.8); --glow: rgba(255,236,200,.45); --accent: #fff6e2; }
.sp-focus-bubble[data-style="signal"] { --shell-a: rgba(90,230,210,.18); --shell-b: rgba(20,90,85,.12); --edge: rgba(120,255,230,.85); --glow: rgba(90,240,215,.6); --accent: #9dffe6; }
.sp-focus-bubble[data-style="vinyl"] { --shell-a: rgba(120,90,180,.34); --shell-b: rgba(20,16,40,.62); --edge: rgba(220,190,255,.75); --glow: rgba(170,120,255,.55); --accent: #e6d4ff; }
.sp-focus-bubble[data-style="dew"] { --shell-a: rgba(180,255,220,.28); --shell-b: rgba(60,150,120,.1); --edge: rgba(220,255,240,.9); --glow: rgba(140,255,200,.6); --accent: #d8fff0; }
.sp-focus-bubble::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, var(--shell-a), var(--shell-b));
  border: 1px solid var(--edge);
  box-shadow: inset 0 0 40px rgba(255,255,255,.14), 0 0 calc(60px * var(--clarity, 1)) var(--glow), var(--sp-shadow);
}
.sp-focus-bubble__content { position: relative; z-index: 1; padding: 34px 30px; max-width: 100%; }
.sp-focus-bubble__mood { font-size: 12px; color: var(--accent); letter-spacing: .1em; }
.sp-focus-bubble__text { font-size: 15px; line-height: 1.65; margin: 12px 0; opacity: var(--text-fade, 1); text-shadow: 0 1px 6px rgba(0,0,0,.35); }
.sp-focus-bubble__stats { display: flex; gap: 14px; justify-content: center; font-size: 11px; color: var(--sp-muted); }
.sp-focus-bubble__hint { margin-top: 16px; font-size: 10px; color: var(--sp-muted); opacity: .8; }
.sp-focus-close {
  position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%);
  background: var(--sp-panel); border: 1px solid var(--sp-line);
  color: var(--sp-ink); border-radius: 999px; padding: 8px 18px; font-size: 12px;
}
.sp-detail-btn {
  display: inline-block; margin-top: 10px; padding: 7px 16px;
  border-radius: 999px; border: 1px solid var(--sp-signal);
  color: var(--sp-signal); background: none; font-size: 12px;
}

/* ---------- 轻提示 ---------- */
.sp-reminders {
  position: absolute; left: 50%; top: calc(12px + var(--safe-top, 0px));
  transform: translateX(-50%);
  z-index: 30; width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.sp-reminder {
  background: var(--sp-panel); border: 1px solid var(--sp-line);
  border-radius: 12px; padding: 8px 14px; color: var(--sp-ink);
  font-size: 12px; text-align: center; backdrop-filter: blur(10px);
  animation: spReminderIn .3s ease both;
}
.sp-reminder--chip { border-color: var(--sp-warm); color: var(--sp-warm); }
@keyframes spReminderIn { from { opacity:0; transform: translateY(-8px); } to { opacity:1; transform:none; } }

.sp-nearby {
  position: absolute; left: 16px; bottom: calc(96px + var(--safe-bottom, 0px));
  width: min(88vw, 320px); max-height: 50vh; overflow: auto;
  background: var(--sp-panel); border: 1px solid var(--sp-line);
  border-radius: 16px; padding: 10px; z-index: 25;
}
.sp-nearby[hidden] { display: none; }
.sp-nearby h3 { margin: 4px 8px 10px; font-size: 12px; color: var(--sp-muted); font-weight: 500; }
.sp-nearby-item {
  display: block; width: 100%; text-align: left;
  border: 0; border-radius: 10px; padding: 10px;
  color: var(--sp-ink); background: rgba(127,127,127,.08);
  margin-bottom: 6px; font-size: 12px;
}

@media (min-width: 900px) {
  .sp-focus-bubble { width: min(38vw, 440px); min-height: min(38vw, 440px); }
  .sp-focus-bubble__text { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .spatial-map, .spatial-veil, .sp-bubble, .sp-focus-bubble { transition-duration: .01ms !important; animation: none !important; }
}
