:root {
  --space-ink: #211B38;
  --space-ink-deep: #171225;
  --cream: #FFF1C7;
  --broccoli: #63C96B;
  --signal: #FF8B45;
  --comet: #78E3E8;
  --berry: #EA5D7D;
  --paper: #FFF8E8;
  --muted: #B9AFCF;
  --border: rgba(255, 241, 199, 0.22);
  --shadow: 0 18px 50px rgba(7, 4, 16, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--space-ink-deep);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--cream);
  background: linear-gradient(160deg, #2A2146 0%, var(--space-ink) 46%, #171326 100%);
  font-family: "HarmonyOS Sans SC", "MiSans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  content: "";
  pointer-events: none;
  opacity: 0.3;
  background-image:
    radial-gradient(circle, rgba(255, 241, 199, 0.75) 0 1px, transparent 1.5px),
    radial-gradient(circle, rgba(120, 227, 232, 0.55) 0 1px, transparent 1.6px);
  background-position: 0 0, 19px 27px;
  background-size: 42px 42px, 71px 71px;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  flex-direction: column;
  overflow: hidden;
}

.mission-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.73rem;
  letter-spacing: 0.04em;
}

.mission-code,
.recipient {
  margin: 0;
}

.recipient {
  color: var(--cream);
  font-weight: 700;
}

.progress-track {
  height: 3px;
  margin-top: 12px;
  overflow: hidden;
  background: rgba(255, 241, 199, 0.12);
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background: var(--comet);
  transition: width 520ms ease;
}

.delivery-stage {
  display: flex;
  min-height: 0;
  padding-top: clamp(12px, 3dvh, 32px);
  flex: 1;
  flex-direction: column;
}

.space-window {
  position: relative;
  width: min(100%, 360px);
  height: clamp(150px, 27dvh, 250px);
  margin: 0 auto;
  overflow: hidden;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.planet {
  position: absolute;
  top: 18%;
  left: 7%;
  width: 58px;
  aspect-ratio: 1;
  border: 1px solid rgba(120, 227, 232, 0.42);
  border-radius: 50%;
  box-shadow: inset -12px -7px 0 rgba(120, 227, 232, 0.1);
}

.route-line {
  position: absolute;
  top: 49%;
  left: 13%;
  width: 74%;
  border-top: 1px dashed rgba(255, 241, 199, 0.22);
}

.broccoli-guide {
  position: absolute;
  right: 2%;
  bottom: -10px;
  width: min(52vw, 190px);
  overflow: visible;
  filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.25));
  animation: gentle-float 4.8s ease-in-out infinite;
}

.helmet {
  fill: rgba(120, 227, 232, 0.13);
  stroke: var(--comet);
  stroke-width: 3;
}

.head {
  fill: var(--broccoli);
}

.crown {
  fill: var(--broccoli);
  stroke: #2E7C45;
  stroke-width: 3;
}

.stem {
  fill: #A9E36B;
}

.scanner {
  fill: var(--signal);
}

.scanner-light {
  fill: var(--cream);
}

.capsule {
  fill: var(--cream);
  stroke: var(--space-ink);
  stroke-width: 3;
}

.scan-beam {
  position: absolute;
  top: 54%;
  right: 31%;
  width: 28%;
  height: 2px;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--comet), transparent);
  animation: scan 3.8s ease-in-out infinite;
}

.message-panel {
  display: grid;
  width: min(100%, 420px);
  margin: clamp(18px, 3.5dvh, 34px) auto 0;
  gap: 12px;
  text-align: left;
}

.system-label,
.letter-kicker {
  margin: 0;
  color: var(--comet);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

h1 {
  max-width: 11ch;
  margin: 0;
  color: var(--cream);
  font-size: clamp(2rem, 10.5vw, 3.55rem);
  line-height: 1.05;
  letter-spacing: 0;
  text-wrap: balance;
}

.narration,
.notice-response {
  max-width: 32em;
  margin: 0;
  color: #E7DDED;
  font-family: "STKaiti", "KaiTi", "FangSong", serif;
  font-size: clamp(1rem, 4.2vw, 1.16rem);
  line-height: 1.72;
}

.notice-response {
  padding-left: 13px;
  border-left: 3px solid var(--signal);
  color: var(--cream);
}

.actions {
  display: grid;
  width: min(100%, 420px);
  margin: auto auto 0;
  padding-top: 22px;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button {
  min-height: 52px;
  padding: 13px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  line-height: 1.25;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 3px solid var(--comet);
  outline-offset: 3px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.button-primary {
  color: #2A180C;
  background: var(--signal);
}

.button-secondary {
  color: var(--cream);
  border-color: var(--border);
  background: transparent;
}

.letter {
  position: relative;
  z-index: 1;
  width: min(100%, 430px);
  min-height: calc(100dvh - 132px);
  margin: 0 auto;
  padding: clamp(26px, 5dvh, 46px);
  border-radius: 8px;
  color: #33263C;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.letter h1 {
  max-width: none;
  color: #33263C;
  font-size: clamp(2rem, 9vw, 3rem);
}

.letter-kicker {
  color: #6D3A75;
}

.letter-copy {
  display: grid;
  margin: 26px 0 28px;
  gap: 18px;
}

.letter-copy p,
.letter-signature {
  margin: 0;
  font-family: "STKaiti", "KaiTi", "FangSong", serif;
  font-size: clamp(1.05rem, 4.5vw, 1.22rem);
  line-height: 1.88;
}

.letter-signature {
  color: #6D5A70;
  font-size: 0.94rem;
}

.replay-button {
  width: 100%;
  margin-top: 30px;
}

.fallback-letter {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 40px 24px;
  color: #33263C;
  background: var(--paper);
  font-family: "STKaiti", "KaiTi", "FangSong", serif;
  line-height: 1.8;
}

.fallback-letter h1 {
  color: #33263C;
}

.fallback-kicker {
  color: #6D3A75;
  font-family: "HarmonyOS Sans SC", "PingFang SC", sans-serif;
  font-weight: 700;
}

html:not(.js) .app-shell {
  display: none;
}

@keyframes gentle-float {
  0%, 100% {
    transform: translateY(0) rotate(-1deg);
  }

  50% {
    transform: translateY(-8px) rotate(1deg);
  }
}

@keyframes scan {
  0%, 100% {
    opacity: 0.25;
    transform: scaleX(0.62);
  }

  50% {
    opacity: 1;
    transform: scaleX(1);
  }
}

@media (max-width: 360px) {
  .app-shell {
    padding-right: 14px;
    padding-left: 14px;
  }

  .mission-header {
    font-size: 0.66rem;
  }

  .space-window {
    height: 150px;
  }

  .message-panel {
    margin-top: 16px;
  }

  h1 {
    font-size: 1.85rem;
  }

  .actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
