/* ==========================================================================
   关卡地图 · 星际冒险主题
   背景氛围参考「重返地球」，关卡节点造型参考「星际闯关」的星球球体。
   ========================================================================== */

:root {
  --bg0: #05071A;
  --bg1: #0C1030;
  --bg2: #191345;

  --star: #EAF2FF;
  --ink: #F4F7FF;
  --ink-dim: #B9C2E8;
  --ink-faint: #7C86B5;

  --path: #8B7CF6;
  --cyan: #5AD1FF;
  --orange: #FF9F45;
  --amber: #FFC46B;

  --card: #13193D;
  --ring: #8FA4FF;

  --title-grad: linear-gradient(115deg, #5AD1FF 5%, #8B7CF6 48%, #FF9F45 92%);
}

/* 标题字体：旁门正道标题体（文件缺失时自动回退系统字体） */
@font-face {
  font-family: 'PangMenZhengDao';
  src: url('../assets/fonts/pangmenzhengdao.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  color: var(--ink);
  /* 与 .sky 同款渐变做兜底，任何露出区域都不会是纯色块 */
  background:
    radial-gradient(120% 90% at 50% 0%, #1B1660 0%, transparent 55%),
    radial-gradient(90% 70% at 85% 90%, #141A52 0%, transparent 60%),
    linear-gradient(180deg, #05071A 0%, #0A0E2E 45%, #171144 100%);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* ---------------- 星空背景 ---------------- */
.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 0%, #1B1660 0%, transparent 55%),
    radial-gradient(90% 70% at 85% 90%, #141A52 0%, transparent 60%),
    linear-gradient(180deg, #05071A 0%, #0A0E2E 45%, #171144 100%);
}

.sky .star {
  position: absolute;
  border-radius: 50%;
  background: var(--star);
  opacity: .85;
  animation: twinkle var(--tw, 4s) ease-in-out var(--td, 0s) infinite;
}

.sky .nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .45;
}

@keyframes twinkle {
  0%, 100% { opacity: .22; transform: scale(.85); }
  50%      { opacity: .95; transform: scale(1.1); }
}

/* ---------------- 页面骨架 ---------------- */
.page {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 56px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

/* 星域页：内容在视口内垂直居中，地图宽度与章节页保持一致 */
.page.world-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  justify-content: safe center;
}

.world-page .map-wrap {
  margin-left: auto;
  margin-right: auto;
  flex: 0 0 auto;
}

/* ---------------- 标题区（左标题 / 右信息） ---------------- */
.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px 20px;
  flex-wrap: wrap;
  margin: 0 0 12px;
  text-align: left;
}

.hero-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 1.4px;
  color: var(--ink-dim);
  padding: 6px 14px;
  border: 1px solid rgba(143, 164, 255, .35);
  border-radius: 999px;
  background: rgba(19, 25, 61, .6);
  white-space: nowrap;
}

.brand b {
  color: var(--amber);
  font-weight: 700;
}

.brand .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-link:hover b {
  color: #9CC7FF;
}

.brand-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
  font-size: 12px;
  color: var(--amber);
  text-decoration: none;
  letter-spacing: 1.4px;
}

.brand-back:hover {
  color: #9CC7FF;
}

/* 星域页/章内页：重置进度放到进度条下方，右对齐 */
.world-page .hero-right,
.chapter-page .hero-right {
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.reset-inline {
  align-self: flex-end;
}

h1.title {
  margin: 0;
  font-size: clamp(20px, 3.2vw, 30px);
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: .06em;
  background: var(--title-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(90, 209, 255, .35));
  animation: rise .9s cubic-bezier(.2, .9, .25, 1.2) both;
}

.en-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(10px, 1.4vw, 12px);
  letter-spacing: .3em;
  color: var(--ink-dim);
  text-transform: uppercase;
  animation: rise .9s .12s cubic-bezier(.2, .9, .25, 1.2) both;
}

/* 星域页专属：标题与地图边框左右对齐，品牌名放到标题下方 */
.world-page .hero-left,
.chapter-page .hero-left {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding-left: 0;
}

.world-page .title-line,
.chapter-page .title-line {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.world-page .title-line .world-logo {
  display: block;
  width: clamp(200px, 22vw, 300px);
  height: auto;
}

.world-page h1.title,
.chapter-page h1.title {
  font-family: 'PangMenZhengDao', "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: clamp(28px, 4.2vw, 56px);
  font-weight: 400;
  letter-spacing: .04em;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(22px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

/* ---------------- 进度条 ---------------- */
.progress-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  white-space: nowrap;
}

.world-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--amber);
  text-shadow: 0 0 12px rgba(255, 196, 107, .45);
}

.progress-track {
  width: clamp(110px, 17vw, 190px);
  height: 8px;
  border-radius: 999px;
  background: rgba(99, 102, 241, .2);
  overflow: hidden;
  border: 1px solid rgba(143, 164, 255, .25);
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #7C8CF0, #A5B4FC, #FBBF24);
  box-shadow: 0 0 10px rgba(129, 140, 248, .75);
  transition: width .45s ease;
}

.progress-text {
  font-size: 13px;
  font-weight: 600;
  color: #C7D2FE;
  white-space: nowrap;
  letter-spacing: .04em;
}

/* ---------------- 地图 ---------------- */
.map-wrap {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(8, 11, 38, .45), rgba(16, 13, 58, .6));
  border: 1px solid rgba(143, 164, 255, .22);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .55), inset 0 0 80px rgba(90, 209, 255, .05);
}

.map-viewport {
  position: relative;
  width: 100%;
  height: auto;          /* 高度由缩放后的画布决定，保证星空背景铺满、不留空带 */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: contain;
}

.world-viewport {
  height: auto;
}

/* 缩放占位：尺寸跟随缩放后的画布，超出部分由 viewport 裁掉 */
.map-sizer {
  position: relative;
  margin: 0;
  flex: 0 0 auto;
}

.map-canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 960px;
  height: 530px;
  transform-origin: top left;
}

.world-canvas {
  width: 1060px;
  height: 470px;
}

.map-canvas > svg.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* 星球节点层在航线之上 */
#worldLayer,
#nodesLayer {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ---------------- 关卡节点（星球） ---------------- */
.node {
  position: absolute;
  width: 168px;
  height: 140px;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  cursor: pointer;
  transition: transform .22s ease, filter .22s ease;
  z-index: 5;
}

.node:hover:not(:disabled) {
  transform: translateY(-5px) scale(1.06);
  filter: drop-shadow(0 0 16px rgba(90, 209, 255, .8));
  z-index: 7;
}

.node:active:not(:disabled) {
  transform: translateY(-1px) scale(1.01);
}

.node:disabled {
  cursor: not-allowed;
}

.planet {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

img.planet {
  object-fit: contain;
  user-select: none;
}

/* 章内关卡星球图整体放大，中心对齐球体 */
img.node-planet {
  transform: scale(1.35);
  transform-origin: 50% 50%;
}

/* 球体 / 大陆底纹 / 高光 / 光环 / 投影，颜色由状态变量驱动 */
.planet .sphere {
  fill: var(--c);
  stroke: rgba(255, 255, 255, .92);
  stroke-width: 3.5;
}

.planet .land {
  fill: var(--land);
  opacity: .5;
}

.planet .gloss {
  fill: #fff;
  opacity: .16;
}

.planet .ring {
  fill: none;
  stroke: var(--ring);
  stroke-width: 5;
  stroke-linecap: round;
}

.planet .shadow {
  fill: var(--shadow);
}

/* 三态 */
.node.locked,
.world-node.locked {
  --c: #3A4A8C;
  --land: #5C6CB0;
  --ring: #5668A8;
  --shadow: #1F2B5C;
}

.node.unlocked,
.world-node.unlocked {
  --c: #7C8CF0;
  --land: #C3CEFF;
  --ring: #A5B4FC;
  --shadow: #4D5CC4;
}

.node.passed,
.world-node.passed {
  --c: #FBBF24;
  --land: #FFF1C2;
  --ring: #FDE68A;
  --shadow: #B45309;
}

/* 当前可挑战：扩散脉冲 */
.node.unlocked .pulse {
  position: absolute;
  left: 84px;
  top: 68px;
  width: 104px;
  height: 104px;
  margin: -52px 0 0 -52px;
  border-radius: 50%;
  border: 3px solid rgba(124, 140, 240, .85);
  animation: pulse 2.2s ease-out infinite;
  pointer-events: none;
}

@keyframes pulse {
  0%   { transform: scale(.85); opacity: .85; }
  100% { transform: scale(1.75); opacity: 0; }
}

.node .num {
  position: absolute;
  left: 84px;
  top: 68px;
  transform: translate(-50%, -50%);
  font-size: 30px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .28);
  line-height: 1;
  z-index: 2;
  pointer-events: none;
}

.node .stars {
  position: absolute;
  left: 50%;
  top: 116px;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  font-size: 15px;
  line-height: 1;
  white-space: nowrap;
  z-index: 3;
  pointer-events: none;
}

.node .stars .s {
  color: rgba(148, 163, 184, .35);
}

.node .stars .s.on {
  color: #FBBF24;
  text-shadow: 0 0 9px rgba(251, 191, 36, .9);
}

.node .stars .s svg,
.detail-stars svg {
  display: block;
  width: 1em;
  height: 1em;
}

.node .stars .s svg path,
.detail-stars svg path {
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.node .stars .s.on svg,
.detail-stars .on svg {
  filter: drop-shadow(0 0 4px rgba(251, 191, 36, .85));
}

.node .lock {
  position: absolute;
  right: 24px;
  bottom: 16px;
  width: 18px;
  height: 18px;
  z-index: 3;
  pointer-events: none;
  opacity: .8;
}

.node.locked img.planet {
  filter: saturate(.35) brightness(.72);
}

.node .lock svg {
  width: 100%;
  height: 100%;
  stroke: #C7D2FE;
  fill: none;
  stroke-width: 2;
}

/* 待开发槽位 */
.node.todo,
.world-node.todo {
  --c: #232B4E;
  --land: #333E68;
  --ring: #39446B;
  --shadow: #141A36;
  cursor: default;
  opacity: .55;
}

/* 星域页待开发星球保持不透明，避免航线透过来 */
.world-node.todo {
  opacity: 1;
}

.world-node.todo .planet {
  filter: saturate(.35) brightness(.72);
}

.world-node.todo .w-name,
.world-node.todo .w-meta {
  opacity: .65;
}

.node.todo .sphere,
.world-node.todo .sphere {
  stroke: rgba(255, 255, 255, .35);
}

.node .todo-mark {
  position: absolute;
  left: 84px;
  top: 68px;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .18em;
  color: #93A0CE;
  white-space: nowrap;
  z-index: 2;
  pointer-events: none;
}

/* ---------------- 路径 ---------------- */
#routeGlow,
#routeBase,
#routeDash {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#routeDash {
  animation: flow 4.5s linear infinite;
}

@keyframes flow {
  to { stroke-dashoffset: -120; }
}

/* ---------------- 图例（地图上方） ---------------- */
.legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--ink-dim);
  flex-wrap: wrap;
  align-items: center;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.legend .d {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .25);
}

.legend .d.locked   { background: #3A4A8C; }
.legend .d.unlocked { background: #7C8CF0; }
.legend .d.passed   { background: #FBBF24; }

.legend-link {
  color: var(--cyan);
  text-decoration: none;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid rgba(90, 209, 255, .35);
  background: rgba(90, 209, 255, .08);
  transition: all .16s ease;
}

.legend-link:hover {
  background: rgba(90, 209, 255, .22);
  border-color: rgba(90, 209, 255, .7);
}

/* ---------------- 星域节点（大星球） ---------------- */
.world-node {
  position: absolute;
  width: 240px;
  height: 220px;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform .24s ease, filter .24s ease;
  z-index: 5;
}

.world-node .planet {
  left: 0;
  top: 0;
  width: 240px;
  height: 200px;
}

.world-node:hover:not(:disabled) {
  transform: translateY(-7px) scale(1.04);
  filter: drop-shadow(0 0 24px rgba(90, 209, 255, .75));
  z-index: 7;
}

.world-node:disabled {
  cursor: not-allowed;
  filter: saturate(.55);
}

.world-node .w-name {
  position: absolute;
  left: 0;
  right: 0;
  top: 168px;
  text-align: center;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: .08em;
  text-shadow: 0 3px 12px rgba(0, 0, 0, .6);
}

.world-node .w-meta {
  position: absolute;
  left: 0;
  right: 0;
  top: 196px;
  text-align: center;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--ink-dim);
  white-space: nowrap;
}

.world-node.passed .w-meta {
  color: var(--amber);
}

.world-node .w-lock {
  position: absolute;
  right: 30px;
  bottom: 26px;
  width: 28px;
  height: 28px;
  opacity: .9;
}

.world-node .w-lock svg {
  width: 100%;
  height: 100%;
  stroke: #C7D2FE;
  fill: none;
  stroke-width: 2;
}

.world-node.unlocked .pulse {
  position: absolute;
  left: 120px;
  top: 97px;
  width: 150px;
  height: 150px;
  margin: -75px 0 0 -75px;
  border-radius: 50%;
  border: 3px solid rgba(124, 140, 240, .8);
  animation: pulse 2.6s ease-out infinite;
  pointer-events: none;
}

/* ---------------- 底部 ---------------- */
.map-foot {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-faint);
  letter-spacing: .08em;
  flex-wrap: wrap;
}

.btn-ghost {
  border: 1px solid rgba(143, 164, 255, .4);
  background: rgba(19, 25, 61, .7);
  color: #C7D2FE;
  padding: 7px 16px;
  border-radius: 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .16s ease;
}

.btn-ghost:hover {
  background: rgba(99, 102, 241, .3);
  border-color: rgba(143, 164, 255, .75);
}

/* ---------------- 详情面板 ---------------- */
.panel-mask {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(4, 6, 22, .62);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

.panel-mask.show {
  opacity: 1;
  pointer-events: auto;
}

.detail-panel {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 31;
  transform: translate(-50%, 102%);
  width: min(96vw, 560px);
  max-height: 76vh;
  overflow: auto;
  padding: 26px 24px 28px;
  background: linear-gradient(180deg, #1A2152 0%, #10143A 100%);
  border: 1px solid rgba(143, 164, 255, .4);
  border-bottom: none;
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -18px 60px rgba(0, 0, 0, .6);
  transition: transform .34s cubic-bezier(.2, .85, .25, 1);
}

.detail-panel.show {
  transform: translate(-50%, 0);
}

@media (min-width: 900px) {
  .detail-panel {
    left: auto;
    right: 26px;
    bottom: 26px;
    transform: translateX(115%);
    width: 420px;
    border-radius: 24px;
    border-bottom: 1px solid rgba(143, 164, 255, .4);
  }

  .detail-panel.show {
    transform: none;
  }
}

.detail-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .08);
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-close:hover {
  background: rgba(255, 255, 255, .18);
}

.detail-no {
  font-size: 12px;
  letter-spacing: .3em;
  color: var(--cyan);
  font-weight: 700;
}

.detail-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .04em;
  margin-top: 2px;
}

.detail-tags {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.detail-tag {
  font-size: 12px;
  color: var(--amber);
  background: rgba(255, 159, 69, .14);
  border: 1px solid rgba(255, 159, 69, .4);
  padding: 3px 12px;
  border-radius: 999px;
  letter-spacing: .06em;
}

.detail-stars {
  display: inline-flex;
  gap: 3px;
  font-size: 16px;
  color: rgba(148, 163, 184, .4);
}

.detail-stars .on {
  color: #FBBF24;
  text-shadow: 0 0 9px rgba(251, 191, 36, .85);
}

.detail-block {
  margin-top: 18px;
}

.detail-block h4 {
  font-size: 12px;
  letter-spacing: .24em;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 8px;
}

.detail-block p {
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink-dim);
}

.detail-knowledge {
  background: rgba(90, 209, 255, .09);
  border-left: 3px solid var(--cyan);
  padding: 11px 14px;
  border-radius: 8px;
}

.detail-start {
  display: block;
  width: 100%;
  margin-top: 22px;
  padding: 13px 0;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .12em;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(145deg, #22D3EE, #6366F1);
  box-shadow: 0 4px 0 #3730A3, 0 0 22px rgba(99, 102, 241, .5);
}

.detail-start:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #3730A3;
}

.detail-start.is-locked {
  background: rgba(90, 100, 150, .5);
  box-shadow: none;
  cursor: not-allowed;
  color: #AAB6D8;
}

/* ---------------- 加载失败 ---------------- */
.load-error {
  padding: 40px 0;
  text-align: center;
  color: #FF8FC8;
  font-size: 14px;
}

/* ---------------- 响应式 ---------------- */
@media (max-width: 640px) {
  .node .num { font-size: 24px; }
  .node .stars { font-size: 13px; }
  .world-node .w-name { font-size: 17px; }
  .legend { gap: 12px; font-size: 12px; }
  .hero-right { gap: 8px; }
  .brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .001s !important;
    transition-duration: .001s !important;
  }
}
