:root {
  color-scheme: dark;
  --sky: #211738;
  --white: #fff8fb;
  --gold: #ffdfa2;
  --glass: #181128ae;
  --outline: #f4d9ff40;
  --serif: "Songti SC", "Noto Serif CJK SC", "STSong", SimSun, serif;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--white);
  background: var(--sky);
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { position: fixed; inset: 0; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { color: inherit; }
button:not(:disabled) { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.world {
  --edge: clamp(20px, 5vw, 76px);
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  container: sky-view / size;
  background: #432f65;
}
.sky, .sky-light, .vignette, .starfield, .effects { position: absolute; inset: 0; pointer-events: none; }
.sky {
  inset: -2%;
  background-color: #4a3566;
  background-image: url("assets/starfield.webp"), url("assets/cloud-room.webp");
  background-size: cover;
  background-position: center 55%;
  transform: translate3d(var(--sky-x, 0px), var(--sky-y, 0px), 0);
  transition: transform 450ms ease-out;
}
.sky-light {
  background:
    radial-gradient(ellipse at 56% 54%, #ffc58839, transparent 40%),
    radial-gradient(ellipse at 60% 15%, #bfb0ff50, transparent 63%);
  opacity: 0;
  transition: opacity 1800ms ease;
}
.world[data-lit] .sky-light { opacity: 1; }
.vignette {
  background:
    linear-gradient(90deg, #181027a1 0%, #2215363a 33%, transparent 61%),
    linear-gradient(180deg, #180f2a9a 0%, transparent 28%, transparent 59%, #160e28c4 100%);
}
.starfield { overflow: hidden; opacity: .66; transition: opacity 1400ms ease; }
.world[data-lit] .starfield { opacity: 1; }
.far-star {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--size);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #f7e7ff;
  box-shadow: 0 0 9px #dfb6ffba;
  opacity: var(--opacity);
}
.far-star.bright { animation: starlight var(--period) ease-in-out var(--delay) infinite alternate; }
@keyframes starlight { from { opacity: calc(var(--opacity) * .53); } to { opacity: var(--opacity); } }
.returned-stars { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.returned-stars i {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 38px;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, #ffe0b9aa 0%, #ffce7b38 29%, transparent 67%);
  opacity: 0;
  transition: opacity 850ms ease;
}
.returned-stars i::after {
  content: "";
  position: absolute;
  inset: 33%;
  background: #fff1d6;
  clip-path: polygon(50% 0%, 65% 34%, 100% 50%, 65% 66%, 50% 100%, 35% 66%, 0% 50%, 35% 34%);
}
.returned-stars i:nth-child(1) { --x: 70%; --y: 17%; }
.returned-stars i:nth-child(2) { --x: 80%; --y: 11%; width: 47px; }
.returned-stars i:nth-child(3) { --x: 89%; --y: 22%; }
.world[data-lit] .returned-stars i { opacity: 1; }

.world-header {
  position: absolute;
  z-index: 5;
  inset-inline: max(var(--edge), env(safe-area-inset-left)) max(var(--edge), env(safe-area-inset-right));
  top: max(clamp(15px, 3.8vh, 36px), calc(env(safe-area-inset-top) + 8px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; font-weight: 730; letter-spacing: .05em; }
.brand img { display: block; border-radius: 12px; box-shadow: 0 0 22px #eed1ff24; }
.world-actions { display: flex; gap: 8px; }
.viewport-button {
  min-height: 40px;
  padding: 7px 15px;
  border: 1px solid var(--outline);
  border-radius: 999px;
  color: var(--white);
  background: var(--glass);
  font-size: .8125rem;
  font-weight: 650;
  white-space: nowrap;
  transition: background-color 200ms ease, border-color 200ms ease;
}
.viewport-button:hover, .viewport-button[aria-pressed="true"] { background: #49365ee8; border-color: #f7e0ff80; }
.chat-toggle { background: #f1d9ff28; border-color: #f2d9ff78; }
.quest {
  position: absolute;
  z-index: 3;
  left: var(--edge);
  top: clamp(105px, 25%, 280px);
  max-width: min(40%, 430px);
  pointer-events: none;
}
.quest h1 {
  color: #fff5f4;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 5.1vw, 5.25rem);
  font-weight: 650;
  letter-spacing: .065em;
  line-height: 1.05;
  text-shadow: 0 4px 30px #1a0d2dbf;
}
.quest p {
  margin-top: clamp(10px, 2.3cqh, 20px);
  color: #fff0fa;
  font-size: clamp(.875rem, 1.38vw, 1.125rem);
  line-height: 1.7;
  text-shadow: 0 2px 7px #20122f;
}

.cloud-scene {
  position: absolute;
  z-index: 2;
  left: 54%;
  top: 51%;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: min(69vw, 80cqh, 800px);
  aspect-ratio: 1;
}
.cloud-scene::before, .cloud-scene::after {
  content: "";
  position: absolute;
  pointer-events: none;
  grid-area: 1 / 1;
}
.cloud-scene::before {
  bottom: 13%;
  width: 54%;
  height: 13%;
  border-radius: 50%;
  background: radial-gradient(ellipse, #2a173a60, transparent 64%);
  filter: blur(8px);
}
.cloud-scene::after {
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse, #ffc59055, transparent 61%);
  opacity: 0;
  transition: opacity 540ms ease;
}
.cloud-scene[data-state="happy"]::after { opacity: .8; }
.cloud-scene[data-state="curious"]::after { opacity: .35; }
.mascot-button {
  grid-area: 1 / 1;
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 30%;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.sprite { isolation: isolate; }
.sprite > img { width: 100%; height: auto; display: block; }
.sprite > svg, .sprite > canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
.sprite[data-rendered] > img, .sprite[data-renderer="3d"] > img { visibility: hidden; }
.sprite [data-part] { transform-box: view-box; }
.sprite [data-part="wave"] { transform-origin: 232px 733px; }
.sprite [data-part="star"] { transform-origin: 1035px 510px; }
.mascot-button[data-renderer="3d"] { cursor: grab; touch-action: none; }
.mascot-button[data-dragging] { cursor: grabbing; }

.star-targets { position: absolute; z-index: 4; inset: 0; pointer-events: none; }
.fallen-star {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: clamp(58px, 7.4vw, 105px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  pointer-events: auto;
  color: #ffd680;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fallen-star[data-star="0"] { --x: 23%; --y: 69%; --drift: 8px; --delay: -.9s; }
.fallen-star[data-star="1"] { --x: 79%; --y: 30%; --drift: 10px; --delay: -2.3s; }
.fallen-star[data-star="2"] { --x: 88%; --y: 63%; --drift: 7px; --delay: -1.5s; }
.world[data-round="1"] .fallen-star[data-star="0"] { --x: 30%; --y: 62%; }
.world[data-round="1"] .fallen-star[data-star="1"] { --x: 83%; --y: 32%; }
.world[data-round="1"] .fallen-star[data-star="2"] { --x: 79%; --y: 74%; }
.fallen-star span {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle, #ffd47862 0%, #ffca7634 28%, transparent 68%);
  animation: star-float 4.2s ease-in-out var(--delay) infinite;
}
.fallen-star span::before, .fallen-star span::after { content: ""; position: absolute; }
.fallen-star span::before {
  inset: 16%;
  border: 1px solid #ffd9a9a3;
  border-radius: 50%;
  box-shadow: 0 0 16px #ffd3873d, inset 0 0 15px #ffd38738;
  transition: transform 240ms ease, border-color 240ms ease;
}
.fallen-star span::after {
  width: 52%;
  aspect-ratio: 1;
  background: radial-gradient(circle at 50% 45%, #fffceb 11%, #fff0bc 33%, #ffd289 72%);
  clip-path: polygon(50% 0%, 62% 33%, 72% 40%, 100% 50%, 72% 61%, 63% 69%, 50% 100%, 37% 69%, 28% 61%, 0% 50%, 28% 40%, 38% 33%);
  transition: transform 230ms ease;
}
.fallen-star:hover span::before, .fallen-star:focus-visible span::before { transform: scale(1.2); border-color: #ffeabf; }
.fallen-star:hover span::after, .fallen-star:focus-visible span::after { transform: scale(1.14) rotate(9deg); }
.fallen-star[data-collected] { visibility: hidden; pointer-events: none; }
@keyframes star-float { 0%, 100% { transform: translateY(calc(-1 * var(--drift))); } 50% { transform: translateY(var(--drift)); } }
.effects { z-index: 3; width: 100%; height: 100%; }

.game-hud {
  position: absolute;
  z-index: 5;
  bottom: max(clamp(18px, 5cqh, 42px), calc(env(safe-area-inset-bottom) + 8px));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 9px;
  width: max-content;
  max-width: calc(100% - 22px);
  pointer-events: none;
}
.game-controls { display: flex; gap: 8px; align-items: center; min-height: 43px; pointer-events: auto; }
.star-progress {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 7px 13px;
  border: 1px solid #f7d3ff4d;
  border-radius: 999px;
  background: var(--glass);
  color: #fceefe;
  font-size: .8125rem;
  font-variant-numeric: tabular-nums;
}
.progress-stars { display: flex; gap: 5px; }
.progress-stars i {
  width: 17px;
  aspect-ratio: 1;
  background-color: #ceafd170;
  clip-path: polygon(50% 0%, 65% 34%, 100% 50%, 65% 66%, 50% 100%, 35% 66%, 0% 50%, 35% 34%);
  transition: background-color 300ms ease;
}
.progress-stars i[data-filled] { background-color: var(--gold); }
.replay { background: #fbdda9; color: #352144; border-color: #ffecbe; }
.replay:hover { background: #fff0cc; border-color: #ffecbe; }
.replay:focus-visible { outline-offset: 3px; }
.mascot-note, .controls-hint {
  text-align: center;
  color: #fff0fa;
  text-shadow: 0 1px 6px #130a23;
  font-size: .8125rem;
}
.mascot-note:empty { display: none; }
.mascot-note { color: #fff0cf; font-weight: 650; }
.controls-hint { color: #f3dff4; }
.controls-hint span { display: none; }
.world:has(.cloud-scene[data-mode="3d"]) .controls-hint span { display: inline; }
.no-script { position: absolute; bottom: 10px; left: var(--edge); }

.chat {
  --ink: #352344;
  --muted: #655470;
  --purple: #61388a;
  --edge: #eadff1;
  color-scheme: light;
  position: fixed;
  inset: max(68px, calc(var(--viewport-top, 0px) + 16px)) max(20px, 5vw) auto auto;
  width: min(422px, calc(100% - 28px));
  height: min(560px, calc(var(--viewport-height, 100dvh) - 94px));
  max-height: none;
  margin: 0;
  overflow: hidden;
  padding: 16px;
  border: 1px solid #fff5;
  border-radius: 22px;
  background: linear-gradient(155deg, #fff 12%, #f8eeff 100%);
  color: var(--ink);
  box-shadow: 0 16px 60px #16082080;
  scrollbar-width: none;
}
.chat[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat::backdrop { background: #140b24a3; }
.chat :focus-visible { outline-color: var(--purple); }
.chat-head { display: flex; min-width: 0; gap: 9px; align-items: center; border-bottom: 1px solid var(--edge); padding-bottom: 10px; }
.chat-head img { display: block; border-radius: 12px; background: #f4edfb; object-fit: contain; flex: none; }
.chat-head h2 { font-size: 1rem; line-height: 1.24; }
.chat-head p { color: var(--muted); font-size: .8125rem; margin-top: 3px; }
.text-button { margin-left: auto; flex: none; border: 0; background: transparent; padding: 7px 3px; font-size: .8125rem; color: var(--purple); font-weight: 650; white-space: nowrap; }
.text-button:hover { text-decoration: underline; }
.close-button { margin-left: auto; flex: none; width: 32px; height: 32px; padding: 0; font-size: 1.35rem; line-height: 1; border: 0; border-radius: 50%; background: #ebdef4; }
.text-button:not([hidden]) + .close-button { margin-left: 0; }
.welcome { align-content: center; min-height: 0; overflow: auto; scrollbar-width: none; text-align: center; padding: 7px 4px; }
.welcome h3 { margin-bottom: 13px; font-size: 1.24rem; }
.welcome .suggestions { justify-content: center; margin-bottom: 0; }
.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 3px;
}
.messages::-webkit-scrollbar, .welcome::-webkit-scrollbar { display: none; }
.messages:focus-visible { outline-offset: -2px; }
.bubble { flex: none; max-width: 92%; padding: 8px 11px; border-radius: 14px; font-size: .9375rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.from-wulumi { background: #efe2f9; border-top-left-radius: 5px; }
.from-visitor { align-self: flex-end; background: #fff0db; border-top-right-radius: 5px; }
.chat-compose { padding-top: 7px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.suggestions button { border: 1px solid #e4d4f0; background: white; color: #573279; border-radius: 100px; padding: 5px 9px; font-size: .8125rem; min-height: 32px; white-space: nowrap; }
.suggestions button:hover { background: #eee3f8; }
#chat-form { display: flex; gap: 7px; }
#message { min-width: 0; width: 100%; color: var(--ink); border: 1px solid #dfd2ea; background: #fdfbff; border-radius: 11px; padding: 8px 10px; }
#message::placeholder { color: #746680; }
.button { flex: none; min-height: 43px; padding: 7px 14px; border: 0; border-radius: 11px; font-weight: 660; }
.primary { background: #582a83; color: white; }
.primary:hover { background: #482269; }
.chat button:disabled { opacity: .6; }
.chat-error { color: #832b54; font-size: .8125rem; line-height: 1.4; margin-bottom: 6px; }
.local-note { color: var(--muted); font-size: .75rem; line-height: 1.4; margin-top: 6px; }

@media (max-width: 720px) and (orientation: portrait) {
  .world { --edge: 15px; }
  .sky { background-position: 59% 56%; }
  .vignette {
    background: linear-gradient(180deg, #190d2cc4 0%, #25153d4d 30%, transparent 54%, #190f2ccf 100%);
  }
  .world-header { top: max(13px, calc(env(safe-area-inset-top) + 8px)); }
  .brand { gap: 6px; }
  .brand img { width: 30px; height: 30px; border-radius: 9px; }
  .world-actions { gap: 5px; }
  .viewport-button { min-height: 35px; padding: 5px 10px; font-size: .75rem; }
  .quest { top: clamp(67px, 13cqh, 149px); left: 50%; transform: translateX(-50%); width: calc(100% - 28px); max-width: none; text-align: center; }
  .quest h1 { font-size: clamp(2.45rem, 10.4vw, 4rem); }
  .quest p { margin-top: 7px; line-height: 1.55; }
  .cloud-scene { top: 56%; left: 50%; width: min(99vw, 66cqh); }
  .returned-stars i:nth-child(1) { --x: 20%; --y: 30%; }
  .returned-stars i:nth-child(2) { --x: 50%; --y: 31%; }
  .returned-stars i:nth-child(3) { --x: 81%; --y: 27%; }
  .fallen-star[data-star="0"] { --x: 14%; --y: 45%; }
  .fallen-star[data-star="1"] { --x: 84%; --y: 38%; }
  .fallen-star[data-star="2"] { --x: 81%; --y: 72%; }
  .world[data-round="1"] .fallen-star[data-star="0"] { --x: 17%; --y: 68%; }
  .world[data-round="1"] .fallen-star[data-star="1"] { --x: 19%; --y: 38%; }
  .world[data-round="1"] .fallen-star[data-star="2"] { --x: 83%; --y: 63%; }
  .game-hud { gap: 6px; }
  .chat {
    --dialog-height: min(475px, calc(var(--viewport-height, 100dvh) - 34px));
    top: calc(var(--viewport-top, 0px) + var(--viewport-height, 100dvh) - var(--dialog-height) - max(10px, env(safe-area-inset-bottom)));
    right: 10px;
    left: 10px;
    width: auto;
    height: var(--dialog-height);
    padding: 12px;
    border-radius: 18px;
  }
  #message { font-size: 16px; }
}

@container sky-view (max-height: 540px) {
  .world-header { top: max(8px, env(safe-area-inset-top)); }
  .quest { top: max(64px, 21%); }
  .quest h1 { font-size: clamp(1.95rem, 5vw, 3.2rem); }
  .quest p { margin-top: 5px; }
  .game-hud { gap: 4px; bottom: max(7px, env(safe-area-inset-bottom)); }
  .star-progress { min-height: 34px; }
  .game-controls { min-height: 36px; }
}

@media (max-width: 720px) and (orientation: portrait) {
  @container sky-view (max-height: 540px) {
    .quest { top: max(49px, 12cqh); }
    .cloud-scene { top: 57%; width: min(90vw, 60cqh); }
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .chat { inset: max(8px, var(--viewport-top, 0px)) 12px auto auto; height: calc(var(--viewport-height, 100dvh) - 16px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
