/* Keep the illustrated chase behind the live title and menu controls. */
#title {
  --title-height: var(--viewport-height, 100svh);
  --title-gutter: clamp(20px, 4.5vw, 86px);
  --title-top: max(20px, calc(var(--safe-top, 0px) + 8px));
  --title-bottom: max(20px, calc(var(--safe-bottom, 0px) + 8px));
  --title-wide-width: min(100cqw, calc(100cqh * 2.4));
  position: relative;
  display: flex;
  align-items: center;
  isolation: isolate;
  min-height: var(--title-height);
  padding: var(--title-top) max(var(--title-gutter), var(--safe-right, 0px))
    var(--title-bottom) max(var(--title-gutter), var(--safe-left, 0px));
  background: #101b27;
}
#title .title-scene {
  position: absolute;
  z-index: -1;
  inset: 0;
  display: block;
  container-type: size;
  overflow: hidden;
  pointer-events: none;
}
#title .title-scene::before {
  /* Fill spare space with the same art when the sharp illustration needs room. */
  content: '';
  position: absolute;
  inset: -24px;
  background: linear-gradient(#12253b7d, #0b1424b8), var(--story-scene) center / cover no-repeat;
  filter: blur(20px);
}
#title .title-scene img {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}
#title .title-atmosphere,
#title .title-spores { display: none; }
@media (prefers-reduced-motion: no-preference) {
  #app[data-view="title"] #title .title-atmosphere {
    position: absolute;
    inset: 0;
    z-index: -1;
    display: block;
    overflow: hidden;
    container-type: size;
    pointer-events: none;
  }
  #title .title-mist {
    /* Match the centered image crop so wisps stay over the painted pines. */
    --art-ratio: calc(1672 / 941);
    position: absolute;
    left: 50%;
    top: 50%;
    width: min(100cqw, calc(100cqh * var(--art-ratio)));
    aspect-ratio: var(--art-ratio);
    transform: translate(-50%, -50%);
    overflow: hidden;
  }
  #title .title-mist i {
    position: absolute;
    background: url('./title-mist.svg') center / 100% 100% no-repeat;
    animation: title-mist-drift var(--mist-duration) ease-in-out var(--mist-delay) infinite alternate;
  }
  #title .title-cloud {
    left: 27%; top: 7.3%; width: 25%; height: 6.9%; opacity: .37;
    --mist-dx: 9%; --mist-dy: -7%; --mist-duration: 26s; --mist-delay: -8s;
  }
  #title .title-fog-near {
    left: 2%; top: 22%; width: 39%; height: 16%; opacity: .33;
    --mist-dx: -7%; --mist-dy: 7%; --mist-duration: 30s; --mist-delay: -18s;
  }
  #title .title-fog-far {
    left: 8%; top: 42%; width: 31%; height: 16%; opacity: .26;
    --mist-dx: 9%; --mist-dy: -6%; --mist-duration: 34s; --mist-delay: -14s;
  }
  @media (orientation: portrait) {
    #title .title-mist { --art-ratio: calc(941 / 1671); }
    #title .title-cloud { left: 9%; top: 4.6%; width: 37%; height: 4.4%; }
    #title .title-fog-near { left: -9%; top: 13.4%; width: 69%; height: 9.8%; }
    #title .title-fog-far { left: 32%; top: 20%; width: 68%; height: 8.1%; }
  }
  #app[data-view="title"] #title .title-spores {
    position: absolute;
    display: block;
    inset: 0;
    z-index: -1;
    pointer-events: none;
  }
  #title .title-spores i {
    position: absolute;
    left: 68%;
    top: 40%;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #ffd08a;
    box-shadow: 0 0 6px 1px #ffa85b68;
    animation: title-spore-drift 6s ease-in-out -2s infinite;
  }
  #title .title-spores i:nth-child(2) {
    left: 73%;
    top: 44%;
    animation-duration: 7.3s;
    animation-delay: -4s;
  }
  #title .title-spores i:nth-child(3) {
    left: 80%;
    top: 55%;
    animation-duration: 8.2s;
    animation-delay: -1s;
  }
  @media (orientation: portrait) {
    #title .title-spores i { left: 39%; top: 47%; }
    #title .title-spores i:nth-child(2) { left: 54%; top: 52%; }
    #title .title-spores i:nth-child(3) { left: 62%; top: 65%; }
  }
}
@media (min-aspect-ratio: 3/2) and (max-aspect-ratio: 2/1),
       (min-aspect-ratio: 9/20) and (max-aspect-ratio: 3/5) {
  #title .title-scene img { object-fit: cover; }
  #title .title-mist { width: max(100cqw, calc(100cqh * var(--art-ratio))); }
}
@media (min-aspect-ratio: 16/9) {
  #title .title-scene img { width: var(--title-wide-width); margin-inline: auto; object-fit: fill; }
  #title .title-mist { width: var(--title-wide-width); height: 100cqh; aspect-ratio: auto; }
}
@media (min-aspect-ratio: 3/2) and (max-aspect-ratio: 12/5),
       (min-aspect-ratio: 9/20) and (max-aspect-ratio: 3/5) {
  #title .title-scene::before { content: none; }
}
@keyframes title-mist-drift {
  from { transform: translate(0, 0); }
  to { transform: translate(var(--mist-dx), var(--mist-dy)); }
}
@keyframes title-spore-drift {
  0%, 100% { opacity: 0; transform: translate(0, 4px); }
  40% { opacity: .48; }
  70% { opacity: .28; }
  95% { opacity: 0; transform: translate(8px, -12px); }
}
#title .title-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(35vw, 650px, 90dvh);
  max-width: none;
}
#title h1 {
  width: 100%;
  margin: 0;
  line-height: 0;
}
#title .title-wordmark {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 8px 17px #030d0ba3);
  pointer-events: none;
}
#title .title-drop-dust { opacity: 0; }
@media (scripting: enabled) and (prefers-reduced-motion: no-preference) {
  #title[data-title-intro="pending"] .title-drop-word { opacity: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  #title[data-title-intro="playing"] .title-drop {
    --drop-delay: 0ms;
    --drop-duration: 850ms;
    --drop-travel: calc(.6 * var(--drop-duration));
    --drop-spacing: calc(var(--drop-travel) + 190ms);
    --drop-baseline: 28%;
  }
  #title[data-title-intro="playing"] .title-drop--shrooms { --drop-delay: var(--drop-spacing); --drop-baseline: 72%; }
  #title[data-title-intro="playing"] .title-drop--attack { --drop-delay: calc(2 * var(--drop-spacing)); --drop-baseline: 97%; }
  #title[data-title-intro="playing"] .title-drop-dust {
    transform-box: fill-box;
    transform-origin: center bottom;
  }
  #title[data-title-intro="playing"] .title-drop-word {
    transform-box: view-box;
    transform-origin: center var(--drop-baseline);
    animation: title-drop var(--drop-duration) var(--drop-delay) both;
  }
  #title[data-title-intro="playing"] .title-drop-dust {
    animation: title-dust 620ms ease-out calc(var(--drop-delay) + var(--drop-travel)) both;
  }
}
@keyframes title-drop {
  0% {
    opacity: 0;
    transform: translateY(-230px);
    animation-timing-function: cubic-bezier(.46, .05, .77, .37);
  }
  12% { opacity: 1; }
  60% {
    transform: translateY(3px) scale(1.045, .91);
    animation-timing-function: ease-out;
  }
  78% { transform: translateY(-10px) scale(.99, 1.02); animation-timing-function: ease-in; }
  92% { transform: translateY(1px) scale(1.01, .99); animation-timing-function: ease-out; }
  100% { transform: none; }
}
@keyframes title-dust {
  0% { opacity: 0; transform: scale(.66, .24); }
  23% { opacity: .92; transform: translateY(-3px) scale(.98, .95); }
  100% { opacity: 0; transform: translateY(-25px) scale(1.14, 1.15); }
}
#title .title-actions {
  display: grid;
  gap: clamp(6px, 1dvh, 12px);
  width: min(100%, 360px);
  margin-top: clamp(12px, 3dvh, 36px);
}
#title .title-actions .btn {
  min-height: clamp(44px, 6.2dvh, 68px);
  padding: 4px 14px;
  border: 3px solid #091016;
  border-radius: 100px;
  background: linear-gradient(#38495d, #283746);
  box-shadow: inset 0 0 0 2px #b1b9c129, 0 4px 0 #080e13bc;
  color: #fff0d1;
  font-size: clamp(15px, 2.4dvh, 26px);
  font-weight: 900;
  line-height: 1.08;
  text-align: center;
  text-shadow: 0 2px #141d26;
}
#title .title-actions .btn svg { display: none; }
#title .title-actions #play {
  background:
    radial-gradient(ellipse at 8% 36%, #a4c83e 0 2%, transparent 2.4%),
    radial-gradient(ellipse at 13% 71%, #b9d94b 0 1.5%, transparent 1.9%),
    radial-gradient(ellipse at 90% 27%, #a7cb3c 0 2.5%, transparent 2.9%),
    radial-gradient(ellipse at 94% 70%, #a4c83e 0 1.8%, transparent 2.2%),
    linear-gradient(#eaff78, #c9ed4c 66%, #9cc439);
  box-shadow: inset 0 0 0 2px #f3ffba73, inset 0 -3px #6b961e73, 0 4px 0 #080e13bc;
  color: #101b0c;
  font-size: clamp(20px, 3.4dvh, 37px);
  text-shadow: none;
}
#title .title-actions .secondary:not(:disabled):hover { background: #475d72; }
#title .title-actions #play:not(:disabled):hover { background: linear-gradient(#f3ff9d, #d2f359); }
#title .btn:is(:focus-visible, [data-pad-focus]) {
  outline: 3px solid #f6ffb7;
  outline-offset: 2px;
}

@media (orientation: portrait) {
  #title {
    --title-gutter: clamp(14px, 6vw, 48px);
    --title-top: max(clamp(44px, 5.5dvh, 70px), calc(var(--safe-top, 0px) + 20px));
    --title-bottom: max(clamp(14px, 3.8dvh, 44px), calc(var(--safe-bottom, 0px) + 8px));
    align-items: stretch;
    justify-content: center;
  }
  #title .title-copy {
    justify-content: space-between;
    width: min(100%, 600px, 54dvh);
    min-height: calc(var(--title-height) - var(--title-top) - var(--title-bottom));
  }
  #title .title-actions { width: min(72%, 386px); }
  #title .title-actions .btn { min-height: clamp(44px, 6.4dvh, 69px); }
}
@media (max-height: 570px) and (orientation: landscape) {
  #title { --title-top: max(8px, var(--safe-top, 0px)); --title-bottom: max(8px, var(--safe-bottom, 0px)); }
  #title .title-copy { width: min(35vw, 68dvh); }
  #title .title-actions { margin-top: 10px; }
}
@media (max-height: 650px) and (orientation: portrait) {
  #title { --title-bottom: max(8px, calc(var(--safe-bottom, 0px) + 4px)); }
  #title .title-actions { gap: 5px; }
}

#arena .play-saves { flex-wrap: wrap; gap: 8px; margin-top: 14px; }
#arena .play-saves .btn { font-size: 13px; }
#play-notice { margin: 12px 0 0; }
