.scene {
  position: relative;
  container-type: inline-size;
  width: min(100vw, calc(100vh * var(--scene-ratio)));
  width: min(100vw, calc(100dvh * var(--scene-ratio)));
}

.title-scene {
  --scene-ratio: 16 / 9;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

.harbor-water,
.title-breeze,
.title-tram {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: none;
  pointer-events: none;
}

.character-scene {
  --scene-ratio: 1024 / 580;
  color: #432210;
  font-family: system-ui, "Microsoft YaHei", sans-serif;
}

.scene-art {
  display: block;
  width: 100%;
  height: auto;
}

.title-scene > .scene-art {
  position: absolute;
  inset: 0;
  height: 100%;
}

/* Expand the art and its overlays together past the baked-in white border. */
.title-scene {
  --title-bleed: 1.006;
}

.title-scene > :is(.scene-art:first-child, canvas, .title-clouds) {
  scale: var(--title-bleed);
}

.title-scene nav {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}

.title-scene nav button {
  pointer-events: auto;
}

.character-scene > .scene-art:first-child {
  clip-path: inset(0.55%);
}

.art-button {
  position: absolute;
  top: var(--y);
  left: var(--x);
  width: var(--w);
  height: var(--h);
  box-sizing: border-box;
  padding: 0;
  border: 0;
  border-radius: 1cqw;
  background: transparent;
  touch-action: manipulation;
}

.art-button:focus-visible,
.back-button:focus-visible,
.profile-input:focus-visible {
  outline: max(2px, 0.3cqw) solid #215e88;
  outline-offset: max(1px, 0.15cqw);
}

/* The title buttons use individually cut pixel silhouettes on the original coordinates. */
.title-scene nav { scale: var(--title-bleed); }
.title-scene .art-button {
  --y: 55.2411%;
  --w: 11.8253%;
  --h: 18.1342%;
  background: var(--menu-art) center / 100% 100% no-repeat;
}
.menu-enter { --x: 31.0491%; --menu-art: url("../assets/title/menu-enter.png"); }
.menu-exit { --x: 43.2383%; --menu-art: url("../assets/title/menu-exit.png"); }
.menu-options { --x: 55.4275%; --menu-art: url("../assets/title/menu-options.png"); }
.title-scene .art-button:enabled:is(:hover, :focus-visible) { filter: brightness(1.12); }


.exit-scene {
  --scene-ratio: 960 / 544;
  --restart-width: 18%;
  --restart-left: calc((100% - var(--restart-width)) / 2);
  --exit-guide-width: 8.5%;
  color: #ffe6b0;
  text-align: center;
  font-family: system-ui, "Microsoft YaHei", sans-serif;
}

.exit-scene canvas {
  width: 100%;
  background: #538cc2 url("../assets/opening/00-loading-background.png") center / 100% 100% no-repeat;
}

.exit-scene h1 {
  position: absolute;
  top: 23%;
  left: 0;
  width: 100%;
  margin: 0;
  color: #fff2c8;
  font: 800 max(11px, 2.65cqw)/1.2 system-ui, "Microsoft YaHei", sans-serif;
  letter-spacing: 0.04em;
  text-shadow: 0 0.14em #2a4568, -0.06em 0 #2a4568, 0.06em 0 #2a4568;
}

.exit-guide {
  position: absolute;
  top: 39.9%;
  left: calc(var(--restart-left) - var(--exit-guide-width) + 0.2%);
  width: var(--exit-guide-width);
  height: 22.6%;
  object-fit: contain;
  object-position: right center;
  image-rendering: pixelated;
  pointer-events: none;
}

.exit-reaction {
  --bubble-edge: polygon(0 15%, 10% 15%, 10% 4%, 90% 4%, 90% 15%, 100% 15%,
    100% 72%, 90% 72%, 90% 82%, 60% 82%, 60% 91%, 50% 91%, 50% 100%,
    40% 100%, 40% 82%, 10% 82%, 10% 72%, 0 72%);
  position: absolute;
  left: calc(var(--restart-left) - var(--exit-guide-width) + 3.15%);
  bottom: 61.5%;
  width: 4.7cqw;
  aspect-ratio: 46 / 41;
  translate: -50% 0;
  transform-origin: 46% 100%;
  filter: drop-shadow(1px 2px #25395266);
  pointer-events: none;
}

.exit-reaction::before,
.exit-reaction::after {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: var(--bubble-edge);
  background: #362938;
}

.exit-reaction::after {
  inset: 5% 5% 6%;
  background: #fffcf4;
}

.pixel-heart {
  position: absolute;
  z-index: 1;
  top: 24%;
  left: 27%;
  width: 46%;
  height: 42%;
  background: #e93848;
  clip-path: polygon(0 19%, 11% 19%, 11% 0, 34% 0, 34% 15%, 45% 15%, 45% 28%, 55% 28%,
    55% 15%, 66% 15%, 66% 0, 89% 0, 89% 19%, 100% 19%, 100% 51%,
    89% 51%, 89% 64%, 78% 64%, 78% 77%, 67% 77%, 67% 89%, 56% 89%,
    56% 100%, 44% 100%, 44% 89%, 33% 89%, 33% 77%, 22% 77%, 22% 64%,
    11% 64%, 11% 51%, 0 51%);
}

@media (prefers-reduced-motion: no-preference) {
  .exit-scene:not([hidden]) .exit-reaction {
    animation: exit-reaction-pop 240ms ease-out 80ms both;
  }
}

@keyframes exit-reaction-pop {
  0% { transform: translateY(16%) scale(0.45); opacity: 0; }
  65% { transform: translateY(-4%) scale(1.1); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.restart-button {
  position: absolute;
  top: 43.3%;
  left: var(--restart-left);
  width: var(--restart-width);
  height: 20.4%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.55cqw;
  padding: 0.9cqw 0.65cqw;
  border: 0;
  background: transparent url("../assets/transitions/restart-frame.png") center / 100% 100% no-repeat;
  color: #602c11;
  font: 900 max(8px, 2.23cqw)/1.08 system-ui, "Microsoft YaHei", sans-serif;
  white-space: nowrap;
  image-rendering: pixelated;
}

.pixel-smile {
  display: block;
  width: max(13px, 4.6cqw);
  aspect-ratio: 1;
  object-fit: contain;
  image-rendering: pixelated;
}

.back-button {
  position: absolute;
  top: 3%;
  left: 3%;
  display: grid;
  width: max(26px, 4.2cqw);
  aspect-ratio: 1;
  place-content: center;
  padding: 0 0 0.4cqw;
  border: 2px solid #613619;
  border-radius: 19%;
  background: #ffe5ad;
  color: #673215;
  font: 700 max(22px, 3.5cqw)/1 system-ui, sans-serif;
}

.profile-input {
  position: absolute;
  left: 56%;
  width: 19.9%;
  height: 5.6%;
  box-sizing: border-box;
  padding: 0 0.7cqw;
  border: 0;
  border-radius: 0.4cqw;
  background: #ffedcf;
  color: #3c2215;
  font: 750 max(10px, 2.2cqw)/1.1 system-ui, "Microsoft YaHei", sans-serif;
}

.profile-input::placeholder {
  color: rgb(32 32 32 / 30%);
  opacity: 1;
}

.name-input { top: 35.3%; }
.home-input { top: 48.8%; }

[aria-label="选择形象"]::before {
  content: "";
  position: absolute;
  top: 68.1%;
  left: 20.9%;
  width: 17.75%;
  height: 13.7%;
  border-radius: 0.8cqw;
  background: #ffe1af;
}

.avatar-choice {
  --y: 69.8%;
  --w: 7.4%;
  --h: 10.5%;
  border: max(1px, 0.22cqw) solid #ae7750;
  background: #ffe2b2;
  color: #337fa4;
  font: 800 max(15px, 4.1cqw)/1 system-ui, sans-serif;
}

.avatar-choice > svg {
  display: block;
  width: max(15px, 4.1cqw);
  height: auto;
  margin: auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 6.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.avatar-male { --x: 21.35%; }
.avatar-female { --x: 30.15%; color: #a53033; }

.avatar-choice[aria-pressed="true"] {
  border-color: #bb721f;
  background: #fff1a8;
  box-shadow: inset 0 0 0 max(1px, 0.25cqw) #ffbb42;
}

.avatar-choice[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: -17%;
  right: -11%;
  width: 34%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid #627638;
  border-radius: 50%;
  background: #fff5cb;
  color: #447338;
  font-size: max(8px, 1.65cqw);
}

.avatar-preview {
  --ground-y: 92%;
  position: absolute;
  top: 27.6%;
  left: 20.15%;
  width: 18.5%;
  height: 39.7%;
  overflow: hidden;
  border-radius: 1.2cqw;
  background: radial-gradient(ellipse 33% 3.45% at 50% var(--ground-y), #bf9567 96%, transparent), #ffe2b5;
}

.avatar-portrait {
  position: absolute;
  top: var(--ground-y);
  left: 50%;
  width: auto;
  height: 88%;
  transform: translate(var(--shoe-midpoint-x), var(--shoe-sole-y));
  image-rendering: pixelated;
}

.male-preview .avatar-portrait {
  --shoe-midpoint-x: -49.1%;
  --shoe-sole-y: -97.8%;
}

.female-front {
  --shoe-midpoint-x: -40.4%;
  --shoe-sole-y: -99.8%;
  aspect-ratio: 156 / 282;
  background: none;
}

.reset-button { --x: 43.5%; --y: 69.4%; --w: 16.9%; --h: 11%; }
.confirm-button { --x: 61.6%; --y: 69.4%; --w: 18.8%; --h: 11%; }

.map-west { --x: 30%; --y: 22.2%; --w: 12.8%; --h: 8.3%; }
.map-east { --x: 69%; --y: 19.9%; --w: 12.8%; --h: 8.3%; }
.map-kowloon { --x: 55.4%; --y: 40.6%; --w: 13.7%; --h: 8.3%; }
.map-island { --x: 58.6%; --y: 71.2%; --w: 14.7%; --h: 8.3%; }
.map-lantau { --x: 11.9%; --y: 67.9%; --w: 19.5%; --h: 8.2%; }

.map-back-button {
  position: absolute;
  right: 2.4%;
  bottom: 3%;
  padding: 0.45em 0.8em;
  border: 2px solid #613619;
  border-radius: 0.65em;
  background: #ffe5ad;
  color: #673215;
  font: 800 max(8px, 1.25cqw)/1.1 system-ui, "Microsoft YaHei", sans-serif;
}

.map-back-button:focus-visible {
  outline: 2px solid #215e88;
  outline-offset: 2px;
}

button {
  cursor: inherit;
}

/* Native pixel cursors render above both the game and browser modal dialogs. */
html body, html body * {
  cursor: url("../assets/ui/cursor-arrow.png") 1 1, default !important;
}
html body :is(button:enabled, a[href], input[type="range"]:enabled, input[type="checkbox"]:enabled, [role="button"]:not([aria-disabled="true"])),
html body :is(button:enabled, a[href], [role="button"]:not([aria-disabled="true"])) * {
  cursor: url("../assets/ui/cursor-hand.png") 6 1, pointer !important;
}

@media (any-hover: hover) {
  button:enabled:hover,
  a[href]:hover {
    cursor: url("../assets/ui/cursor-hand.png") 6 1, pointer !important;
  }

  button:enabled:hover {
    filter: brightness(1.08);
  }

  button.art-button:enabled:not(.avatar-choice, .title-scene *, .journal-map *):hover {
    filter: none;
    -webkit-backdrop-filter: brightness(1.08);
    backdrop-filter: brightness(1.08);
  }
}

.title-clouds {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.title-cloud {
  position: absolute;
  top: var(--cloud-top);
  left: -18%;
  width: var(--cloud-width);
  height: auto;
  opacity: .92;
  image-rendering: pixelated;
  animation: title-cloud-drift var(--cloud-duration) linear var(--cloud-delay) infinite;
}

.title-cloud-broad {
  --cloud-top: 4%;
  --cloud-width: 10.6%;
  --cloud-duration: 54s;
  --cloud-delay: -12s;
}

.title-cloud-tall {
  --cloud-top: 8.2%;
  --cloud-width: 7.6%;
  --cloud-duration: 67s;
  --cloud-delay: -41s;
}

.title-cloud-low {
  --cloud-top: 13.6%;
  --cloud-width: 8.1%;
  --cloud-duration: 58s;
  --cloud-delay: -36s;
}

@keyframes title-cloud-drift {
  from { left: -18%; }
  to { left: 105%; }
}

@media (prefers-reduced-motion: reduce) {
  .title-cloud { animation: none; }
  .title-cloud-broad { left: 10%; }
  .title-cloud-tall { left: 58%; }
  .title-cloud-low { left: 76%; }
}

.title-logo-lettering {
  position: absolute;
  inset: 0;
  scale: var(--title-bleed);
  pointer-events: none;
}
.title-logo-lettering img {
  position: absolute;
  left: calc(490 / 1649 * 100%);
  top: calc(247 / 954 * 100%);
  width: calc(666 / 1649 * 100%);
  height: calc(175 / 954 * 100%);
}
