/* The 3D planet's own bits of interface. Everything else (speech boxes, quiz, HUD) uses play/game.css. */
.world3d { position: absolute; inset: 0; display: none; background: #0b0f24; }
body.planet-3d .world3d { display: block; }
body.planet-3d #world, body.planet-3d #touch { display: none; }
.w3d-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.w3d-veil { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; background: #0b0f24; font: 400 var(--fs-pixel) / 1 var(--font-pixel); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); transition: opacity .5s; }
.w3d-veil.off { opacity: 0; pointer-events: none; }
.w3d-veil i { display: block; width: 14cqw; height: .5cqw; margin-top: 1cqw; background: linear-gradient(90deg, var(--brand-blue), var(--brand-pink), var(--brand-green), var(--brand-orange)); background-size: 200% 100%; animation: w3dLoad 1.2s linear infinite; }
@keyframes w3dLoad { to { background-position: -200% 0; } }
/* touch joystick, bottom left */
.w3d-joy { position: absolute; z-index: 6; left: 2.5cqw; bottom: 3cqw; width: max(96px, 13cqw); aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--box); display: none; touch-action: none; user-select: none; -webkit-user-select: none; }
.w3d-joy i { position: absolute; left: 30%; top: 30%; width: 40%; height: 40%; border-radius: 50%; background: rgba(255,255,255,.75); box-shadow: 0 0 0 2px #000; }
body.touch-ui.planet-3d .w3d-joy { display: block; }
body.in-dialog .w3d-joy { display: none !important; }
/* keyboard hint, bottom left on desktop */
.w3d-keys { position: absolute; z-index: 5; left: 1.5cqw; bottom: 1.5cqw; padding: .5cqw .9cqw; font-size: var(--fs-small); transition: opacity .3s; }
.w3d-keys b { color: var(--brand-orange); font-weight: 400; }
body.touch-ui .w3d-keys, body.in-dialog .w3d-keys { display: none; }
/* debug: mock-up camera label (press C with ?debug=1) */
.w3d-mock { position: absolute; z-index: 5; left: 50%; top: 1.5cqw; transform: translateX(-50%); padding: .5cqw .9cqw; font-size: var(--fs-small); }
/* arrival fly-in: the planet's title over the wide orbit of the island (hidden again as the camera swoops down) */
.w3d-title { position: absolute; z-index: 5; left: 50%; bottom: 6cqw; transform: translate(-50%, 1cqw); text-align: center; color: #fff; opacity: 0; transition: opacity .7s, transform .7s; pointer-events: none; text-shadow: 0 .25cqw 0 #000, 0 0 1.5cqw rgba(0,0,0,.6); }
.w3d-title.on { opacity: 1; transform: translate(-50%, 0); }
.w3d-title small { display: block; font: 400 var(--fs-pixel) / 1 var(--font-pixel); letter-spacing: .3em; text-transform: uppercase; color: var(--brand-orange); }
.w3d-title b { display: block; margin-top: .8cqw; font: 400 5cqw / 1 var(--font-pixel); letter-spacing: .02em; font-weight: 400; }
.w3d-title span { display: block; margin-top: 1.4cqw; font-size: var(--fs-small); opacity: .7; }
body.w3d-intro .w3d-keys, body.w3d-intro #planetHud, body.w3d-intro .w3d-joy, body.w3d-intro #talkBtn { visibility: hidden; }
.w3d-title em { display: block; margin-top: 1cqw; font: 400 clamp(14px, 1.4cqw, 42px) / 1.2 var(--font-pixel); font-variant-ligatures: none; letter-spacing: .08em; text-transform: uppercase; font-style: normal; color: #fff; }   /* same as the loading text */
/* v2 planet: a marker over each person (round face badge in a coloured ring, a bobbing arrow under it, a tick when done).
   Positioned every frame by world3d.js (translate3d to the point above the person's head). */
.w3d-markers { position: absolute; inset: 0; z-index: 3; pointer-events: none; overflow: hidden; }
.w3d-mark { --s: clamp(24px, 3.6cqw, 84px); position: absolute; left: 0; top: 0; width: 0; height: 0; padding: 0; border: 0; background: none; pointer-events: auto; cursor: pointer; will-change: transform; }
.w3d-mark img { position: absolute; left: calc(var(--s) / -2); bottom: calc(var(--s) * .42); width: var(--s); height: var(--s); border-radius: 50%; box-sizing: border-box; border: max(3px, calc(var(--s) * .08)) solid var(--c); background: #111; box-shadow: 0 0 0 2px #000, 0 .3cqw .8cqw rgba(0,0,0,.45); image-rendering: pixelated; object-fit: cover; transition: transform .15s; }
.w3d-mark:hover img, .w3d-mark:focus-visible img { transform: scale(1.1); }
.w3d-mark:focus-visible { outline: none; }
.w3d-mark:focus-visible img { box-shadow: 0 0 0 2px #000, 0 0 0 5px #fff; }
.w3d-arrow { position: absolute; left: calc(var(--s) * -.16); bottom: 0; width: calc(var(--s) * .32); height: calc(var(--s) * .34); background: #fff; clip-path: polygon(30% 0, 70% 0, 70% 45%, 100% 45%, 50% 100%, 0 45%, 30% 45%); filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 1px #000); animation: w3dBob 1s ease-in-out infinite alternate; }
@keyframes w3dBob { from { transform: translateY(-20%); } to { transform: translateY(15%); } }
.w3d-mark.done .w3d-arrow { animation: none; left: calc(var(--s) * -.19); width: calc(var(--s) * .38); height: calc(var(--s) * .38); border-radius: 50%; background: #00bd8c; clip-path: none; box-shadow: 0 0 0 2px #fff; filter: none; }
.w3d-mark.done .w3d-arrow::after { content: ''; position: absolute; left: 30%; top: 22%; width: 22%; height: 38%; border: solid #fff; border-width: 0 3px 3px 0; transform: rotate(45deg); }
.w3d-mark.off { visibility: hidden; }
body.w3d-intro .w3d-markers, body.in-dialog .w3d-markers { visibility: hidden; }
@media (prefers-reduced-motion: reduce) { .w3d-arrow { animation: none; } }
.portrait.face { width: clamp(44px, 4.6cqw, 130px); height: auto; aspect-ratio: 1; border-radius: 50%; object-fit: cover; }

/* phones held upright: the 3D planet uses the whole screen instead of a 16:9 strip (the camera frames the island to
   the screen's width), the joystick sits below the island above the power bar, and the map button moves under the
   sound button so the two never overlap */
@media (max-aspect-ratio: 1/1) {
  body.planet-3d[data-screen="planet"] #stage { width: 100vw; height: 100dvh; }
  body.touch-ui.planet-3d .w3d-joy { left: 14px; bottom: 76px; width: 104px; }
  body.planet-3d[data-screen="planet"] .planet-map { right: 1.5cqw; top: calc(1.5cqw + 48px); }
  body.planet-3d[data-screen="planet"] .debug { top: 104px; width: 62vw; max-height: 40dvh; }
}

/* follow camera: a marker for someone off screen is pinned to the screen edge, a smaller badge centred on the pin with
   an arrow pointing their way (--rot is set by world3d.js) */
.w3d-mark.edge { --s: clamp(22px, 2.8cqw, 64px); }
.w3d-mark.edge img { bottom: auto; top: calc(var(--s) / -2); opacity: .92; }
.w3d-mark.edge .w3d-arrow, .w3d-mark.edge.done .w3d-arrow { animation: none; left: calc(var(--s) * -.16); top: calc(var(--s) * -.17); bottom: auto; width: calc(var(--s) * .32); height: calc(var(--s) * .34); border-radius: 0; background: #fff; box-shadow: none; clip-path: polygon(30% 0, 70% 0, 70% 45%, 100% 45%, 50% 100%, 0 45%, 30% 45%); filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 1px #000); transform: rotate(var(--rot, 0deg)) translateY(calc(var(--s) * .78)); }
.w3d-mark.edge.done .w3d-arrow::after { display: none; }

/* the Overview button (back to the aerial view of the whole planet), beside the map button; hidden while in it */
.planet-overview { position: absolute; z-index: 5; right: calc(12cqw + max(26px, 2.9cqw) + 2.4cqw); top: 1.5cqw; }
body:not(.planet-3d) .planet-overview, body.w3d-aerial .planet-overview, body.w3d-intro .planet-overview { display: none; }
@media (max-aspect-ratio: 1/1) {
  body.planet-3d[data-screen="planet"] .planet-overview { right: 1.5cqw; top: calc(1.5cqw + 96px); }
  body.planet-3d.w3d-aerial[data-screen="planet"] .debug, body.planet-3d[data-screen="planet"] .debug { top: 150px; }
}

/* round 4: "You" over the Visitor in the overview; bigger pinned waypoint badges and arrows */
.w3d-you { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.w3d-you b { position: absolute; left: 0; bottom: 18px; transform: translateX(-50%); padding: 2px 8px; font: 700 13px/1.2 var(--font-pixel, monospace); letter-spacing: .06em; text-transform: uppercase; color: #111; background: #ffd633; border: 2px solid #000; border-radius: 4px; white-space: nowrap; }
.w3d-you i { position: absolute; left: -9px; bottom: 2px; width: 18px; height: 14px; background: #ffd633; clip-path: polygon(0 0, 100% 0, 50% 100%); filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 1px #000); animation: w3dBob .8s ease-in-out infinite alternate; }
.w3d-you.off { visibility: hidden; }
body.w3d-intro .w3d-you { visibility: hidden; }
.w3d-mark.edge { --s: 42px; }
.w3d-mark.edge .w3d-arrow, .w3d-mark.edge.done .w3d-arrow { left: -12px; top: -13px; width: 24px; height: 26px; transform: rotate(var(--rot, 0deg)) translateY(36px); }
/* phones: the debug pill only when it is open (closed it sat in the middle of the screen) */
@media (max-aspect-ratio: 1/1) { body.planet-3d[data-screen="planet"] .debug:not(:has(details[open])) { display: none; } }

/* v3 loading veil (GeoQuest style): a small picture of the planet floating in space while the 3D world loads; when it
   is ready (.off) the planet zooms towards the camera as the veil fades, straight into the 3D fly-in round the island */
.w3d-veil { display: block; background: #000 url('../play/figma/galaxy/galaxy-frame-bg.jpg') center / cover; transition: opacity .9s ease-in; }
.w3d-veil > div { position: absolute; left: 0; right: 0; top: 33cqw; display: flex; flex-direction: column; align-items: center; color: #fff; font: 400 clamp(14px, 1.4cqw, 42px) / 1.2 var(--font-pixel); font-variant-ligatures: none; letter-spacing: .08em; text-transform: uppercase; transition: opacity .3s; }
.w3d-veil > div i { width: max(240px, 18cqw); height: max(8px, .45cqw); margin-top: max(12px, 1.1cqw); border-radius: 99px; }
.w3d-veil.off > div { opacity: 0; }
body.w3d-intro .w3d-veil > div { opacity: 0; transition: none; }   /* the big "Now landing" heading takes over: never both on screen at once */
.w3d-veil-planet { position: absolute; left: 50%; top: 9cqw; width: 34cqw; margin-left: -17cqw; image-rendering: pixelated; filter: drop-shadow(0 0 2.5cqw rgba(140, 170, 255, .3)); animation: veilBob 3s ease-in-out infinite alternate; transition: scale 1.1s cubic-bezier(.5, 0, .8, .4); }
.w3d-veil.off .w3d-veil-planet { scale: 5; }
@keyframes veilBob { from { translate: 0 -.6cqw; } to { translate: 0 .6cqw; } }
@media (prefers-reduced-motion: reduce) { .w3d-veil-planet { animation: none; transition: none; } }

/* v3: the planet fills the whole window, not just the 16:9 box. The 3D view and its loading screen's starry background
   reach the window edges; the hint box and the landing title are pulled back to where they sit in the box, and pop-up
   backdrops cover the whole window too. (% here is the box's size, 100vw / 100dvh the window's.) */
body[data-screen="planet"] #stage, #s-planet { overflow: visible; }
.world3d { inset: calc((100% - 100dvh) / 2) calc((100% - 100vw) / 2); }
.w3d-veil { inset: calc((100% - 100cqh) / 2) calc((100% - 100cqw) / 2); }
.w3d-veil::before { content: ''; position: absolute; z-index: -1; top: calc((100% - 100dvh) / 2); bottom: calc((100% - 100dvh) / 2); left: calc((100% - 100vw) / 2); right: calc((100% - 100vw) / 2); background: inherit; }
.w3d-keys { left: calc(1.5cqw + (100vw - 100cqw) / 2); bottom: calc(1.5cqw + (100dvh - 100cqh) / 2); }
.w3d-title { bottom: calc(6cqw + (100dvh - 100cqh) / 2); }
.modal, .chat-card { inset: calc((100% - 100dvh) / 2) calc((100% - 100vw) / 2); }

/* the loading bar (2 Dec): a dim track with one glowing bar that fills 0 to 100% (--p is set by play/game.js) */
.w3d-veil > div i { position: relative; overflow: hidden; background: rgba(255, 255, 255, .14); animation: none; }
.w3d-veil > div i::after { content: ''; position: absolute; inset: 0 auto 0 0; width: var(--p, 0%); transition: width .25s ease-out;
  background: linear-gradient(90deg, var(--brand-blue), var(--brand-pink), var(--brand-green), var(--brand-orange)); background-size: max(240px, 18cqw) 100%;
  box-shadow: 0 0 .8cqw rgba(140, 170, 255, .9); }

/* HQ storm (game.js stormSync): the sky and clouds darken (world3d.js storm()) and lightning flashes now and then; clears
   over 3 s once you meet Jaimy */
.w3d-rain { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.w3d-rain b { position: absolute; inset: 0; background: #dfe8ff; opacity: 0; }
.w3d-rain.flash b { animation: w3dFlash .9s ease-out; }
@keyframes w3dFlash { 0% { opacity: 0; } 8% { opacity: .45; } 16% { opacity: .05; } 24% { opacity: .3; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .w3d-rain.flash b { animation: none; } }

/* BugHerd 24: a small pixel label always floats over each object (world/js/objects.js placeLabels sets the position):
   Cause, Highlight and Fun fact in white on the black see-through box; the Quiz one orange with a play arrow, because it
   is the one you play. Hidden (.off) in the overview, during dialogs and when it would sit on a HUD box or the talk box. */
.w3d-olbl { position: absolute; left: 0; top: 0; translate: -50% -100%; padding: .32em .55em .26em; background: rgba(0, 0, 0, .75); border: 2px solid #fff; border-radius: 4px;
  color: #fff; font: 400 clamp(11px, .9cqw, 26px) / 1 var(--font-pixel, monospace); font-variant-ligatures: none; letter-spacing: .06em; text-transform: uppercase; white-space: nowrap;
  pointer-events: none; will-change: transform; }
.w3d-olbl.off { visibility: hidden; }
.w3d-olbl.is-quiz { display: inline-flex; align-items: center; gap: .4em; background: var(--brand-orange, #fcb24f); border-color: #000; color: #000; box-shadow: 0 0 0 1px rgba(255, 255, 255, .7); animation: w3dQuizPulse 1.1s ease-in-out infinite alternate; }
.w3d-olbl.is-quiz::after { content: ''; width: .5em; height: .62em; background: currentColor; clip-path: polygon(0 0, 100% 50%, 0 100%); }
@keyframes w3dQuizPulse { from { box-shadow: 0 0 0 1px rgba(255, 255, 255, .7); } to { box-shadow: 0 0 0 1px rgba(255, 255, 255, .7), 0 0 .9em .15em rgba(252, 178, 79, .85); } }   /* a glow, not a scale: scale would multiply the position transform */
@media (prefers-reduced-motion: reduce) { .w3d-olbl.is-quiz { animation: none; } }
body.in-chat .w3d-olbl, body.wk-open .w3d-olbl { visibility: hidden; }
@media (orientation: landscape) and (max-height: 500px) {
  body.touch-ui .w3d-olbl { font-size: 9px; padding: 3px 4px 2px; border-width: 1.5px; border-radius: 3px; }
}
