.game {
  max-width: min(100%, 106svh);
  margin-inline: auto;
}

.stage {
  height: auto;
  min-height: 0;
  aspect-ratio: 1.618 / 1;
}

.stage canvas {
  position: absolute;
  inset: 0;
}

.stage::after {
  background-color: transparent;
  transition: background-color 3s ease;
}

.stage.bedtime::after {
  background-color: rgb(40 29 55 / 30%);
}

@media (prefers-reduced-motion: reduce) {
  .stage::after {
    transition: none;
  }
}

/* Give the game and opening layers their own landscape viewport. */
@media (orientation: portrait) and (max-width: 650px) {
  .game-surface {
    --game-viewport-height: 100vw;
    position: fixed;
    top: 0;
    left: 100vw;
    width: 100svh;
    height: 100vw;
    min-height: 0;
    transform-origin: top left;
    transform: rotate(90deg);
  }
}

@media (orientation: portrait) and (max-width: 650px),
       (orientation: landscape) and (max-height: 600px) {
  body {
    --play-height: max(150px, calc(var(--game-viewport-height, 100svh) - 76px));
    padding: 12px max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
    overflow: auto;
  }

  .head, .intro, .footnote {
    display: none;
  }

  .game {
    max-width: min(100%, calc(var(--play-height) * 1.618 + 12px));
  }

  .gamebar {
    height: 40px;
  }
  .dialog {
    max-height: calc(var(--game-viewport-height, 100svh) - 24px);
  }
}
.rest-button {
  position: absolute;
  z-index: 2;
  width: 46px;
  height: 29px;
  padding: 0;
  border: 1px solid #d69a87;
  border-radius: 9px;
  background: #fff0d7;
  color: #70473b;
  box-shadow: 0 2px 5px #77553d38;
  font-size: 12px;
  font-weight: 700;
  touch-action: manipulation;
}
.rest-button.in-room {
  border-color: #e6ac9c;
  background: linear-gradient(#ffedba,#f6cfcb);
}
.rest-button[hidden] {
  display: none;
}
.stage.birthday-story .joystick,
.stage.birthday-story .hint,
.stage.birthday-story .notice {
  visibility: hidden;
}

.birthday-intro {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background-color: transparent;
  transition: background-color .85s ease-out;
}

.birthday-intro.is-ready {
  background-color: #000;
  transition: none;
}

.birthday-prologue {
  position: fixed;
  inset: 0;
  z-index: 100;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.birthday-prologue-curtain {
  display: grid;
  place-items: center;
}

.birthday-transition-title {
  margin: 0;
  padding: 0 1rem;
  color: #ffe4d6;
  font-family: "Songti SC", SimSun, serif;
  font-size: clamp(1.25rem, 5vw, 3.25rem);
  text-align: center;
}

.birthday-intro.is-dim {
  transition-duration: 2.6s;
  transition-timing-function: ease-in-out;
  background-color: rgb(49 30 36 / 58%);
}

.birthday-intro.is-revealing {
  transition-duration: 2.4s;
  transition-timing-function: ease-in-out;
}

.birthday-intro[hidden],
.birthday-intro [hidden] {
  display: none;
}

.birthday-intro button {
  justify-self: center;
  padding: .58em 1.75em;
  border: 1px solid #fff0cf;
  border-radius: 999px;
  background: linear-gradient(#fff3d6, #f6c9c5);
  box-shadow: 0 4px 12px #6d443549;
  color: #704336;
  font-size: 16px;
  font-weight: 700;
}

.birthday-intro .birthday-start {
  font-size: clamp(16px, 3vw, 24px);
  letter-spacing: .2em;
  text-indent: .2em;
}

.birthday-wish {
  align-self: end;
  width: min(360px, calc(100% - 20px));
  max-height: 100%;
  overflow: auto;
  margin-bottom: clamp(3px, 2%, 14px);
  padding: clamp(5px, 1.3%, 12px);
  display: grid;
  gap: 5px;
  text-align: center;
  color: #fff9e6;
  background: rgb(66 39 39 / 78%);
  border: 1px solid #ffd9b178;
  border-radius: 14px;
}

.birthday-wish:not([hidden]) {
  animation: birthday-wish-appear .65s ease-out both;
}

@keyframes birthday-wish-appear {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .birthday-wish:not([hidden]) { animation: none; }
}

.birthday-wish textarea {
  width: 100%;
  min-height: 36px;
  max-height: 56px;
  padding: 5px 9px;
  border: 1px solid #eac5b4;
  border-radius: 8px;
  background: #fff8eb;
  color: #613b33;
  resize: none;
  font: inherit;
  box-sizing: border-box;
}

.birthday-wish button {
  font-size: 14px;
  padding-block: .35em;
}

@media (prefers-reduced-motion: reduce) {
  .birthday-intro { transition: none; }
}

.chat-launcher {
  position: absolute;
  z-index: 2;
  left: 6px;
  bottom: 8px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  touch-action: manipulation;
}

.chat-launcher.is-visible {
  opacity: 1;
}

.chat-launcher img {
  width: 100%;
  height: 100%;
  transform: scale(1.38);
  pointer-events: none;
}

.stage.birthday-story .chat-launcher {
  visibility: hidden;
}

.overlay.chat-docked {
  --chat-floor: min(calc(clamp(22px, 9%, 60px) + 102px), calc(50% - 6px));
  position: absolute;
  z-index: 5;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 0;
  background: transparent;
}

.chat-docked .dialog {
  position: absolute;
  left: 0;
  bottom: var(--chat-floor);
  width: min(160px, 100%);
  height: 50%;
  max-height: calc(100% - var(--chat-floor) - 6px);
  display: flex;
  flex-direction: column;
  padding: 6px 7px;
  border-width: 2px;
  border-left: 0;
  border-radius: 0 14px 14px 0;
  box-shadow: 0 6px 22px #3f2b2838;
}

.chat-docked .dialog-kicker,
.chat-docked .dialog-options:empty {
  display: none;
}

.chat-docked .dialog h2 {
  margin: 0 24px 5px 0;
  font-size: 17px;
}

.chat-docked .close {
  right: 8px;
  top: 2px;
}

.chat-docked .dialog-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.chat-docked .chat-log {
  flex: 1;
  height: auto;
  min-height: 0;
  padding: 5px 7px;
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.chat-docked .empty-chat {
  padding: 8px 0;
  font-size: 11px;
}

.chat-docked .chat-form {
  flex: none;
  margin-top: 5px;
  gap: 4px;
}

.chat-docked .chat-form input,
.chat-docked .chat-form button {
  padding: 5px 7px;
  border-radius: 7px;
}


.chat-docked .chat-form button {
  white-space: nowrap;
}
.gift-button {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -100%);
  min-width: 34px;
  min-height: 26px;
  padding: 3px 6px;
  border: 1px solid #fff2d7;
  border-radius: 8px;
  background: #f8d6cb;
  color: #754940;
  box-shadow: 0 2px 5px #8b594b40;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  touch-action: manipulation;
}

.beach-heart {
  position: absolute;
  z-index: 2;
  width: 34px;
  height: 34px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  background: transparent url("assets/beach-heart.png") center / 142% no-repeat;
  cursor: pointer;
  touch-action: manipulation;
}

.beach-heart[hidden] {
  display: none;
}

.cottage-music {
  position: absolute;
  z-index: 7;
  top: 7px;
  right: 8px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 46px;
  align-items: center;
  gap: 2px 5px;
  width: clamp(125px, 27%, 225px);
  padding: 4px 6px;
  border: 1px solid #f9e6d3;
  border-radius: 10px;
  background: #fff8eef2;
  color: #754940;
  box-shadow: 0 2px 6px #66483129;
  font-size: clamp(9px, 1.4vmin, 12px);
}

.cottage-music .music-title {
  grid-column: 2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cottage-music button {
  display: grid;
  place-items: center;
  width: clamp(24px, 4vmin, 30px);
  height: clamp(24px, 4vmin, 30px);
  padding: 0;
  border: 1px solid #eac4ad;
  border-radius: 7px;
  background: #fae0d3;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}

.cottage-music .music-progress {
  grid-column: 1 / 3;
  width: 100%;
  min-width: 0;
  margin: 0;
  accent-color: #b87369;
  touch-action: none;
}

.cottage-music .music-skip {
  display: flex;
  justify-content: flex-end;
  gap: 3px;
}

.cottage-music .music-skip button {
  width: 21px;
  height: 24px;
  background: #fff1eb;
}

.cottage-music .music-add {
  justify-self: end;
  border-color: #f4ded4;
  background: #fff1eb;
}

.cottage-music .music-toggle::before {
  content: "";
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid currentColor;
}

.cottage-music .music-toggle.is-playing::before {
  box-sizing: border-box;
  width: 8px;
  height: 9px;
  border: 0;
  border-inline: 2px solid currentColor;
}

.cottage-music:not(.is-visible) {
  opacity: 0;
}

.cottage-music:not(.is-visible):not(:focus-within) > :not(.music-reveal) {
  visibility: hidden;
}

.cottage-music .music-reveal {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.cottage-music.is-visible .music-reveal {
  display: none;
}

.cottage-music:has(.music-reveal:focus-visible) {
  opacity: 1;
}

.cottage-music .music-reveal:focus-visible {
  background: transparent;
}

.beach-heart::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid transparent;
  border-top-color: #fff4bb99;
  border-radius: 50%;
  pointer-events: none;
  animation: beach-heart-glint 4s linear infinite;
}

@keyframes beach-heart-glint {
  to { transform: rotate(1turn); }
}

@media (prefers-reduced-motion: reduce) {
  .beach-heart::after { animation: none; }
}

.gift-dialogue {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 8px 7px;
}

.gift-dialogue[hidden] {
  display: none;
}

.gift-dialogue-frame {
  width: min(96%, 740px);
  display: grid;
  grid-template-columns: clamp(58px, 15%, 105px) 1fr;
  grid-template-rows: 1fr auto;
  gap: 4px clamp(8px, 3%, 24px);
  padding: clamp(7px, 2%, 16px);
  border: 3px solid #e8aa98;
  border-radius: 19px;
  background: linear-gradient(115deg,#ffe0bd,#fff0d6);
  box-shadow: inset 0 0 0 1px #fff5df, 0 3px 9px #75473233;
  color: #643d31;
}

.gift-dialogue-portrait {
  grid-row: span 2;
  align-self: center;
  width: 100%;
  aspect-ratio: 255 / 322;
  border-radius: 12px;
  background: #ffddba url('assets/gift-portrait-source.png') 7.34% 80.48% / 602.35% auto no-repeat;
}

.gift-dialogue-copy strong {
  display: inline-block;
  padding: 2px 12px;
  border: 1px solid #e8aa98;
  border-radius: 999px;
  background: #ffddbe;
  font-size: 13px;
}

.gift-dialogue-copy p {
  margin: 6px 0 0;
  font-size: clamp(14px, 2.4vw, 21px);
  font-weight: 650;
}

.gift-dialogue-frame button {
  justify-self: end;
  border: 1px solid #d39688;
  border-radius: 999px;
  background: #f9cfc0;
  color: inherit;
  padding: 5px 14px;
  font-weight: 700;
  touch-action: manipulation;
}
.gift-dialogue-frame.beach-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, 34px);
  gap: 5px;
  width: min(96%, 400px);
}

#beachSpeech[hidden], #beachChoices[hidden], .beach-end[hidden] {
  display: none;
}

.beach-choices button {
  justify-self: stretch;
  padding: 2px 4px;
  min-width: 0;
  font-size: clamp(11px, 2.5vw, 15px);
  white-space: nowrap;
}

.beach-end {
  position: absolute;
  z-index: 3;
  right: 10px;
  bottom: 10px;
  border: 1px solid #d39688;
  border-radius: 999px;
  background: #fff0d6;
  color: #643d31;
  padding: 6px 12px;
  font-weight: 700;
}

.dialogue-portrait-02 {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
.dialogue-portrait-02::before,
.dialogue-portrait-02::after {
  content: "";
  position: absolute;
  pointer-events: none;
}
.dialogue-portrait-02::before {
  inset: 4% 4% 5%;
  border-radius: 10% 10% 9% 9%;
  background: #ffdbb7 url('assets/boy-portrait-02.png') center bottom / 134% auto no-repeat;
}
.dialogue-portrait-02::after {
  inset: 0;
  background: inherit;
  clip-path: polygon(0 75%, 5% 75%, 11% 83%, 19% 88%, 25% 94%,
    34% 94%, 38% 91%, 61% 91%, 67% 94%, 76% 93%, 82% 87%,
    90% 81%, 95% 75%, 100% 75%, 100% 100%, 0 100%);
}
.beach-walk-curtain {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: #000;
}
.beach-walk-curtain[hidden] {
  display: none;
}

/* Let the game fill the visible viewport, including in mobile browsers. */
body {
  padding: 0;
  overflow: hidden;
}

.game-surface, .page, .game {
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
}

.game {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.gamebar, .footnote {
  display: none;
}

body {
  height: 100svh;
  height: 100dvh;
  min-height: 0;
}

.game-surface, .stage {
  height: var(--game-viewport-height, 100svh);
  height: var(--game-viewport-height, 100dvh);
  min-height: 0;
}

.stage {
  aspect-ratio: auto;
}

@media (orientation: portrait) and (max-width: 650px) {
  .game-surface,
  .birthday-prologue {
    width: 100svh;
    width: 100dvh;
  }

  .birthday-prologue {
    inset: 0 auto auto 100vw;
    height: 100vw;
    transform-origin: top left;
    transform: rotate(90deg);
  }
}
