@import url('./tokens.css');

/* ==========================================================================
   轨道电梯主样式：固定图层 + 原生滚动输入
   图层（z-index 递增）：sky < stars < clouds < ground < landmarks
   < shaft < rain < cabin < hint < hud < footer
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --footer-h: 40px;
}

html {
  overscroll-behavior-y: none;
  overflow-anchor: none;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--ui-text-primary);
  background: #000;
  touch-action: pan-y;
  -webkit-font-smoothing: antialiased;
}

/* 输入层：空占位撑出滚动条，高度由 JS 设为 totalPx + 视口高 */
.track {
  width: 1px;
  pointer-events: none;
}

.layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

/* ---------- 天空（颜色由 JS 插值写入 CSS 变量） ---------- */
#sky {
  z-index: 0;
  background: linear-gradient(to bottom, var(--sky-top, #38bdf8), var(--sky-bottom, #bae6fd));
}

#sky::before {
  content: '';
  position: absolute;
  right: 14%;
  top: 14%;
  width: min(26vw, 200px);
  height: min(26vw, 200px);
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(254, 243, 199, 0.7) 0%,
    rgba(253, 224, 71, 0.22) 36%,
    rgba(253, 224, 71, 0) 70%
  );
  opacity: var(--sun-opacity, 0.85);
  pointer-events: none;
}

#sky::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42%;
  background: linear-gradient(
    to top,
    rgba(186, 230, 253, 0.5) 0%,
    rgba(125, 211, 252, 0.18) 42%,
    transparent 100%
  );
  opacity: var(--haze-opacity, 1);
  pointer-events: none;
}

/* ---------- 星星 ---------- */
#stars {
  z-index: 1;
  overflow: hidden;
  opacity: var(--stars-opacity, 0);
}

#stars-field {
  position: absolute;
  left: 0;
  right: 0;
  will-change: transform;
}

.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
}

.star-twinkle {
  animation: star-twinkle var(--tw, 3s) ease-in-out infinite;
  animation-delay: var(--td, 0s);
}

@keyframes star-twinkle {
  50% { opacity: 0.12; }
}

/* ---------- 云层（0–12 km，视差 0.6） ---------- */
#clouds {
  z-index: 2;
}

.cloud {
  position: absolute;
  top: 0;
  width: var(--cw, 160px);
  height: calc(var(--cw, 160px) * 0.4);
  will-change: transform;
}

.cloud-body {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: radial-gradient(ellipse at 50% 60%, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.5) 55%, rgba(255, 255, 255, 0) 78%);
  animation: cloud-drift 18s ease-in-out infinite;
}

.cloud-body::before {
  content: '';
  position: absolute;
  left: 16%;
  top: -42%;
  width: 44%;
  height: 95%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 65%, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.45) 60%, rgba(255, 255, 255, 0) 80%);
}

.cloud-body::after {
  content: '';
  position: absolute;
  right: 14%;
  top: -28%;
  width: 34%;
  height: 75%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 65%, rgba(255, 255, 255, 0.9) 0%, rgba(255, 255, 255, 0.4) 60%, rgba(255, 255, 255, 0) 80%);
}

@keyframes cloud-drift {
  0%, 100% { transform: translateX(-16px); }
  50% { transform: translateX(22px); }
}

#meteor-layer {
  z-index: 2;
  overflow: hidden;
  opacity: 0;
}

.meteor {
  position: absolute;
  width: 88px;
  height: 2px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), #e0f2fe 42%, #fff 100%);
  transform: rotate(-32deg);
  animation: meteor-fly 2.6s linear infinite;
  pointer-events: none;
}

@keyframes meteor-fly {
  0% { transform: translate(-24px, -36px) rotate(-32deg); opacity: 0; }
  14% { opacity: 0.95; }
  100% { transform: translate(48vw, 40vh) rotate(-32deg); opacity: 0; }
}

/* ---------- 地球曲率暗示（上升后贴在视口底部，地面离开后可见） ---------- */
#earth-limb {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: -12vh;
  width: 190vw;
  height: 32vh;
  margin-left: -95vw;
  border-radius: 50% 50% 0 0;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(
      ellipse 70% 90% at 50% 115%,
      #14532d 0%,
      #166534 14%,
      #0f2744 38%,
      rgba(15, 23, 42, 0.35) 58%,
      transparent 74%
    );
  box-shadow: 0 -18px 48px rgba(8, 47, 73, 0.28);
}

/* ---------- 地面（0 m，随上升向下离开） ---------- */
#ground {
  position: fixed;
  z-index: 3;
  left: 0;
  right: 0;
  top: 0;
  height: 48vh;
  transform: translateY(84vh); /* JS 接管前的兜底位置 */
  pointer-events: none;
  background:
    linear-gradient(
      to bottom,
      #86efac 0%,
      #4ade80 7%,
      #22c55e 16%,
      #16a34a 38%,
      #166534 68%,
      #14532d 100%
    );
}

#ground::before {
  content: '';
  position: absolute;
  left: -28%;
  width: 156%;
  top: -22px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(to bottom, rgba(186, 230, 253, 0), #bbf7d0 46%, #4ade80 100%);
  box-shadow: 0 -16px 40px rgba(186, 230, 253, 0.32);
}

#ground::after {
  content: '';
  position: absolute;
  left: -2%;
  width: 104%;
  top: -38px;
  height: 42px;
  pointer-events: none;
  opacity: 0.92;
  background-repeat: no-repeat;
  background-image:
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#1e293b, #0f172a),
    linear-gradient(#334155, #1e293b),
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#1e293b, #0f172a),
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#334155, #1e293b),
    linear-gradient(#1e293b, #0f172a),
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#1e293b, #0f172a),
    linear-gradient(#334155, #1e293b),
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#1e293b, #0f172a),
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#334155, #1e293b),
    linear-gradient(#1e293b, #0f172a),
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#1e293b, #0f172a),
    linear-gradient(#0f172a, #0f172a),
    linear-gradient(#334155, #1e293b);
  background-size:
    22px 18px, 14px 28px, 36px 40px, 18px 22px, 28px 34px,
    12px 16px, 44px 38px, 20px 24px, 16px 30px, 32px 20px,
    24px 36px, 18px 14px, 40px 32px, 14px 26px, 22px 18px,
    30px 40px, 16px 22px, 26px 28px, 12px 18px, 34px 24px;
  background-position:
    2% 100%, 6% 100%, 10% 100%, 16% 100%, 21% 100%,
    26% 100%, 30% 100%, 37% 100%, 42% 100%, 47% 100%,
    52% 100%, 58% 100%, 62% 100%, 68% 100%, 73% 100%,
    78% 100%, 84% 100%, 89% 100%, 93% 100%, 97% 100%;
}

/* ---------- 地标 ---------- */
#landmarks {
  z-index: 4;
  overflow: hidden;
}

.landmark {
  position: absolute;
  top: 0;
  will-change: transform;
}

.side-left { left: clamp(110px, 16vw, 180px); }
.side-right { right: clamp(148px, 18vw, 220px); }
.side-center {
  left: clamp(110px, 16vw, 180px);
  right: clamp(148px, 18vw, 220px);
}
.side-center .landmark-inner {
  margin-inline: auto;
}

.landmark-inner {
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.45s ease;
  text-align: center;
}

.landmark.is-visible .landmark-inner {
  opacity: 1;
}

.landmark-img {
  display: block;
  margin: 0 auto;
  width: min(var(--w, 120px), 28vw);
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(2, 6, 23, 0.35));
  user-select: none;
}

.landmark-caption {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: rgba(9, 13, 22, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.22);
  font-size: clamp(13px, 3.4vw, 15px);
  line-height: 1.45;
  max-width: min(74vw, 22rem);
  text-align: left;
}

.landmark-caption strong {
  display: block;
  color: var(--ui-text-accent);
  font-weight: var(--fw-semibold);
  margin: 0 0 2px;
  font-size: 0.95em;
}

.caption-pill {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: rgba(9, 13, 22, 0.78);
  border: 1px solid rgba(148, 163, 184, 0.28);
  font-size: clamp(14px, 4vw, 18px);
  line-height: 1.55;
  max-width: min(78vw, 28rem);
}

.milestone-img {
  display: block;
  margin: 0 auto 10px;
  width: min(240px, 62vw);
}

.kind-milestone.side-center {
  left: clamp(108px, 15vw, 170px);
  right: clamp(168px, 22vw, 250px);
}

.kind-milestone .landmark-inner {
  transform: translateY(-58%);
}

.milestone-title {
  display: inline-block;
  padding: 6px 22px;
  border-top: 1px solid rgba(56, 189, 248, 0.55);
  border-bottom: 1px solid rgba(56, 189, 248, 0.55);
  font-size: clamp(26px, 7vw, 42px);
  font-weight: var(--fw-black);
  letter-spacing: 0.1em;
  text-indent: 0.1em;
  color: #fff;
  text-shadow: 0 2px 18px rgba(2, 6, 23, 0.85);
}

.milestone-text {
  display: table;
  margin: 12px auto 0;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  background: rgba(9, 13, 22, 0.75);
  font-size: clamp(13px, 3.8vw, 16px);
  line-height: 1.6;
  max-width: 78vw;
}

/* 地标微动效 */
.motion-hover { animation: lm-hover 1.8s ease-in-out infinite; }
@keyframes lm-hover {
  0%, 100% { transform: translateY(-5px); }
  50% { transform: translateY(5px); }
}

.motion-drift { animation: lm-drift 4.5s ease-in-out infinite; }
@keyframes lm-drift {
  0%, 100% { transform: translate(0, -6px); }
  50% { transform: translate(6px, 6px); }
}

.motion-burst {
  animation: lm-burst 1.5s ease-out infinite;
  transform-origin: 50% 50%;
}
@keyframes lm-burst {
  0% { transform: scale(0.55); opacity: 0.2; }
  35% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); opacity: 0.92; }
}

/* ---------- 电梯井 ---------- */
#shaft {
  position: fixed;
  z-index: 5;
  top: 0;
  bottom: 0;
  left: 18px;
  width: var(--shaft-width);
  background-image: url('../assets/shaft.svg');
  background-repeat: repeat-y;
  background-size: 100% auto;
  pointer-events: none;
}

/* ---------- 雨（1.3–6 km） ---------- */
#rain {
  z-index: 6;
  overflow: hidden;
  opacity: 0;
}

.rain-drop {
  position: absolute;
  top: -24px;
  width: 1.5px;
  height: var(--dh, 14px);
  background: linear-gradient(to bottom, rgba(224, 242, 254, 0), rgba(191, 226, 255, 0.85));
  animation: rain-fall var(--dd, 0.7s) linear infinite;
  animation-delay: var(--dl, 0s);
}

@keyframes rain-fall {
  to { transform: translate(-3vw, 110vh); }
}

/* ---------- 轿厢与小人 ---------- */
#cabin {
  position: fixed;
  z-index: 7;
  left: 29px;
  bottom: max(120px, 16vh);
  bottom: max(120px, 16dvh);
  width: var(--car-width-desktop);
  pointer-events: none;
}

.cabin-bob {
  position: relative;
  animation: cabin-bob 3.4s ease-in-out infinite;
  transform-origin: 50% 0%;
  will-change: transform;
}

@keyframes cabin-bob {
  0%, 100% { transform: translateY(-3px) rotate(-1.4deg); }
  50% { transform: translateY(3px) rotate(1.4deg); }
}

#cabin-img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

/* 宇航服覆盖层：精确罩住窗内主剪影 */
#suit {
  position: absolute;
  left: 54%;
  top: 33%;
  width: 27%;
  height: 43%;
  display: none;
  user-select: none;
}

#cabin.suited #suit {
  display: block;
}

/* 小人点击热区：11 km 后才有点击反应 */
#person-hit {
  position: absolute;
  left: 50%;
  top: 28%;
  width: 36%;
  height: 52%;
  pointer-events: auto;
  cursor: default;
  border-radius: 8px;
}

#cabin.suit-ready #person-hit,
#cabin.ground-egg #person-hit {
  cursor: pointer;
}

#person-hit:focus-visible {
  outline: 2px solid var(--ui-text-accent);
  outline-offset: 2px;
}

/* ---------- 「向上滚动」提示 ---------- */
#hint {
  position: fixed;
  z-index: 8;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

#hint.hidden,
#hint[hidden] {
  display: none;
}

.hint-text {
  display: inline-block;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  background: rgba(9, 13, 22, 0.72);
  border: 1px solid rgba(186, 230, 253, 0.45);
  font-size: clamp(17px, 4.4vw, 22px);
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  box-shadow: 0 4px 24px rgba(2, 6, 23, 0.35);
}

.hint-sub {
  margin-top: 8px;
  font-size: clamp(12px, 3.2vw, 14px);
  letter-spacing: 0.08em;
  color: var(--ui-text-primary);
  text-shadow: 0 1px 6px rgba(2, 6, 23, 0.7), 0 0 2px rgba(2, 6, 23, 0.9);
}

.hint-arrow {
  margin-top: 10px;
  font-size: 26px;
  text-shadow: 0 1px 8px rgba(2, 6, 23, 0.6);
  animation: hint-bounce 1.5s ease-in-out infinite;
}

@keyframes hint-bounce {
  0%, 100% { transform: translateY(6px); }
  50% { transform: translateY(-10px); }
}

/* ---------- HUD：只有高度与气温 ---------- */
#hud {
  position: fixed;
  z-index: 9;
  right: 18px;
  bottom: calc(var(--footer-h) + var(--safe-bottom) + 14px);
  text-align: right;
  pointer-events: none;
  min-width: 8.5em;
  padding: 8px 14px 10px;
  border-radius: var(--radius-md);
  background: rgba(9, 13, 22, 0.48);
  border: 1px solid rgba(248, 250, 252, 0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* 数字与单位是同一个 inline-flex 行，基线对齐、禁止换行，任何宽度下都不会拆开 */
#hud-alt {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.18em;
  max-width: 100%;
  font-family: var(--font-mono);
  font-weight: var(--fw-bold);
  font-size: clamp(34px, 7.4vw, 56px);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 1px 12px rgba(2, 6, 23, 0.85);
}

#hud-alt-num,
.hud-unit {
  flex: 0 0 auto;
  white-space: nowrap;
}

.hud-unit {
  font-size: 0.5em;
  font-weight: var(--fw-semibold);
  letter-spacing: 0;
  color: var(--ui-text-secondary);
}

#hud-temp {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.22em;
  font-family: var(--font-mono);
  font-size: clamp(16px, 3.6vw, 22px);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-shadow: 0 1px 8px rgba(2, 6, 23, 0.75);
}

/* ℃ 在等宽栈里常落到 CJK 回退字形，改走系统无衬线栈，颜色跟随气温色 */
.hud-unit-temp {
  font-family: var(--font-sans);
  font-size: 0.78em;
  font-weight: var(--fw-medium);
  color: inherit;
}

#hud-temp.t-warm { color: var(--temp-warm); }
#hud-temp.t-mild { color: var(--temp-mild); }
#hud-temp.t-chilly { color: var(--temp-chilly); }
#hud-temp.t-freezing { color: var(--temp-freezing); }
#hud-temp.t-cryo { color: var(--temp-cryo); }

#hud-layer {
  margin-top: 6px;
  font-size: clamp(11px, 2.3vw, 13px);
  line-height: 1.2;
  letter-spacing: 0.16em;
  color: var(--ui-text-secondary);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}

/* ---------- 路过 toast：单节点复用，避开井与 HUD ---------- */
#pass-toast {
  position: fixed;
  z-index: 8;
  left: 0;
  right: 0;
  top: 16%;
  bottom: auto;
  width: max-content;
  max-width: min(22rem, 42vw);
  margin-inline: auto;
  padding: 8px 14px 10px;
  border-radius: var(--radius-md);
  background: rgba(9, 13, 22, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.28);
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.4);
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

#pass-toast.is-on {
  opacity: 1;
  transform: translateY(0);
}

.toast-title {
  color: var(--ui-text-accent);
  font-weight: var(--fw-semibold);
  font-size: clamp(14px, 3.4vw, 16px);
  letter-spacing: 0.04em;
}

.toast-flavor {
  margin-top: 2px;
  color: var(--ui-text-primary);
  font-size: clamp(12px, 3vw, 13px);
  line-height: 1.4;
}

.toast-flavor:empty {
  display: none;
}

/* ---------- 页脚 ---------- */
#footer {
  position: fixed;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: var(--footer-h);
  padding: 4px 14px calc(4px + var(--safe-bottom));
  background: var(--ui-bottom-bar-bg);
  border-top: 1px solid var(--ui-bottom-bar-border);
  backdrop-filter: var(--ui-bottom-bar-blur);
  -webkit-backdrop-filter: var(--ui-bottom-bar-blur);
  font-size: 12px;
  color: var(--ui-text-secondary);
  pointer-events: auto;
}

#footer a {
  color: var(--ui-text-accent);
  text-decoration: none;
  white-space: nowrap;
}

.footer-left {
  min-width: 0;
  white-space: nowrap;
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
}

.footer-right a {
  color: var(--ui-text-secondary);
}

.footer-right .footer-home {
  color: var(--ui-text-accent);
}

#footer a:hover {
  text-decoration: underline;
}

/* ---------- 降级提示 ---------- */
#boot-note,
.noscript-note {
  position: fixed;
  z-index: 99;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: rgba(9, 13, 22, 0.92);
  border: 1px solid var(--ui-panel-card-border);
  color: var(--ui-text-primary);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
}

#boot-note code {
  color: var(--ui-text-accent);
  font-family: var(--font-mono);
}

.noscript-note a {
  color: var(--ui-text-accent);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  :root { --footer-h: 52px; }

  #shaft { left: 10px; width: 44px; }
  #cabin { left: 19px; width: var(--car-width-mobile); }
  .side-left { left: 132px; }
  .side-right { right: 8.5rem; }
  .side-center {
    left: 132px;
    right: 8.5rem;
  }
  .kind-object.side-left .landmark-img {
    width: min(var(--w, 120px), 20vw);
  }
  .kind-milestone.side-center {
    left: 100px;
    right: 12px;
  }
  .kind-milestone .landmark-inner {
    transform: translateY(-76%);
  }
  #hud {
    right: 10px;
    padding: 6px 10px 8px;
    min-width: 0;
    max-width: 48vw;
  }
  #hud-alt { font-size: clamp(22px, 6vw, 28px); }
  #hud-temp { font-size: clamp(14px, 3.4vw, 16px); }
  #hud-layer { font-size: 10px; letter-spacing: 0.12em; }

  #pass-toast {
    left: auto;
    right: 12px;
    top: 16px;
    bottom: auto;
    width: auto;
    max-width: min(62vw, 16rem);
    margin-inline: 0;
  }

  .kind-object.side-right .landmark-inner {
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
  }
  .kind-object.side-right .landmark-caption {
    margin-top: 0;
    margin-bottom: 6px;
    text-align: right;
    max-width: min(34vw, 10.5rem);
  }

  .landmark-caption,
  .caption-pill,
  .milestone-text {
    max-width: 100%;
  }
  .milestone-title {
    font-size: clamp(22px, 6vw, 32px);
    letter-spacing: 0.06em;
  }

  #footer {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    font-size: 10.5px;
    padding: 6px 10px calc(6px + var(--safe-bottom));
  }
  .footer-left {
    white-space: normal;
    line-height: 1.35;
  }
  .footer-right {
    gap: 10px;
    flex-wrap: wrap;
  }
}

/* ---------- 减少动态效果：雨与烟花等全部静态化 ---------- */
@media (prefers-reduced-motion: reduce) {
  #rain { display: none; }

  .cabin-bob,
  .hint-arrow,
  .star-twinkle,
  .motion-hover,
  .motion-drift,
  .motion-burst,
  .cloud-body,
  .meteor {
    animation: none !important;
  }

  .landmark-inner,
  #hint,
  #pass-toast {
    transition: none !important;
  }

  #pass-toast {
    transform: none !important;
  }
}
