* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #0B6346;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    max-width: 1554px;
    max-height: 1028px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #0B6346;
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#camera-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Prevent pull-to-refresh on mobile */
body {
    overscroll-behavior: none;
}

/* Center game-container when viewport exceeds max dimensions */
@media (min-width: 1555px) {
    #game-container {
        left: 50%;
        transform: translateX(-50%);
    }
}
@media (min-height: 1029px) {
    #game-container {
        top: 50%;
        transform: translateY(-50%);
    }
}
@media (min-width: 1555px) and (min-height: 1029px) {
    #game-container {
        transform: translate(-50%, -50%);
    }
}

/* ================================================
   WORLDMAP SCREEN — DOM-based level select
   ================================================ */

#worldmap-scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    isolation: isolate; /* Stacking context so negative z-index children stay visible */
    background: #0B6346;
    touch-action: none;
}

.wm-sprite {
    position: absolute;
    image-rendering: auto;
    pointer-events: none;
}

.wm-level-btn {
    pointer-events: auto;
    cursor: pointer;
}

.wm-tappable {
    pointer-events: auto;
    cursor: pointer;
}

#worldmap-snow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
}

/* Fade-to-white transition overlay */
#worldmap-fade {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 200;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease-in;
}

#worldmap-fade.wm-fade-active {
    opacity: 1;
}

/* Flower: anchor bottom-center, combined bounce + rotate */
.wm-flower {
    transform-origin: bottom center;
    will-change: transform;
}

.wm-flower-a1 {
    animation: wmFlowerBounce 1.0s ease-in-out infinite,
               wmFlowerRotate 2.0s ease-in-out infinite;
}

.wm-flower-a2 {
    animation: wmFlowerBounce 1.0s ease-in-out infinite 0.25s,
               wmFlowerRotate 2.0s ease-in-out infinite 0.4s;
}

.wm-flower-a3 {
    animation: wmFlowerBounce 1.0s ease-in-out infinite 0.5s,
               wmFlowerRotate 2.0s ease-in-out infinite 0.8s;
}

@keyframes wmFlowerBounce {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.75); }
}

@keyframes wmFlowerRotate {
    0%, 100% { transform: rotate(-25deg); }
    50% { transform: rotate(25deg); }
}

/* Elastic tap feedback for rainbow/trees */
@keyframes wmTapBounce {
    0%   { transform: scaleY(1); }
    10%  { transform: scaleY(0.3); }
    40%  { transform: scaleY(1.15); }
    60%  { transform: scaleY(0.95); }
    80%  { transform: scaleY(1.05); }
    100% { transform: scaleY(1); }
}

.wm-tap-effect {
    animation: wmTapBounce 0.8s ease-out;
}

/* Elastic bounce for level buildings on tap */
@keyframes wmLevelBounce {
    0%   { transform: scaleY(1); }
    15%  { transform: scaleY(0.85); }
    45%  { transform: scaleY(1.15); }
    70%  { transform: scaleY(0.97); }
    100% { transform: scaleY(1); }
}

.wm-level-bounce {
    animation: wmLevelBounce 0.3s ease-out;
}

/* ================================================
   ROTATE OVERLAY — shown in portrait during gameplay
   ================================================ */

#rotate-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.92);
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.rotate-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.rotate-icon {
    animation: rotateWiggle 2s ease-in-out infinite;
}

@keyframes rotateWiggle {
    0%, 100% { transform: rotate(0deg); }
    25%      { transform: rotate(90deg); }
    50%      { transform: rotate(90deg); }
    75%      { transform: rotate(0deg); }
}

.rotate-text {
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-align: center;
}

@media (orientation: portrait) {
    body.gameplay-active #rotate-overlay {
        display: flex;
    }

    body.gameplay-active #game-container {
        visibility: hidden;
    }
}

/* Sound toggle button on worldmap */
.wm-sound-btn {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 50;
    width: 48px;
    height: 48px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.wm-sound-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}
