* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: #0b0c16;
    font-family: 'Quicksand', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
    touch-action: none;
    overscroll-behavior: none;
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #1b162b 0%, #090a12 100%);
    overflow: hidden;
}

/* Canvas Wrapper - Perfectly contains the canvas without any clipping */
#canvas-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#gameCanvas {
    width: min(100vw, calc(100vh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    display: block;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.85);

    /* Pixel Art Crisp Rendering */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Floating Glass Menu Bar (Top-Right) */
#quick-bar {
    position: absolute;
    top: env(safe-area-inset-top, 14px);
    right: env(safe-area-inset-right, 18px);
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 200;
    pointer-events: auto;
}

.icon-btn {
    pointer-events: auto;
    background: rgba(22, 24, 42, 0.76);
    border: 1px solid rgba(255, 234, 167, 0.35);
    color: #ffeaa7;
    border-radius: 18px;
    height: 36px;
    padding: 0 14px;
    font-family: 'Quicksand', 'Trebuchet MS', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    vertical-align: middle;
}

.icon-circle {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    font-size: 15px;
    flex-shrink: 0;
}

.menu-pill {
    padding: 0 16px;
    height: 36px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.icon-btn.muted {
    opacity: 0.65;
    border-color: rgba(255, 118, 117, 0.45);
    background: rgba(36, 18, 28, 0.78);
    color: #ff7675;
}

.icon-btn:active, .icon-btn:hover {
    background: rgba(253, 121, 168, 0.45);
    border-color: #fd79a8;
    color: #ffffff;
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px rgba(253, 121, 168, 0.45);
}

@media (max-width: 600px) {
    #quick-bar {
        top: env(safe-area-inset-top, 8px);
        right: env(safe-area-inset-right, 8px);
        gap: 6px;
    }
    .icon-circle {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }
    .menu-pill {
        height: 32px;
        padding: 0 12px;
        font-size: 12px;
    }
}

/* Rotate to Landscape Overlay */
#rotate-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    background: radial-gradient(ellipse at center, #1e1936 0%, #080914 100%);
    z-index: 999999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    text-align: center;
    color: #ffffff;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Force Rotate Screen in Portrait Mode on Mobile/Tablet */
@media (orientation: portrait) and (max-width: 960px) {
    #rotate-overlay {
        display: flex !important;
    }
}

.rotate-card {
    background: rgba(22, 20, 40, 0.92);
    border: 1.5px solid rgba(255, 234, 167, 0.5);
    border-radius: 28px;
    padding: 34px 26px;
    max-width: 330px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.rotate-phone-anim {
    position: relative;
    width: 94px;
    height: 94px;
    margin-bottom: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.rotate-phone-body {
    width: 44px;
    height: 74px;
    border: 2.5px solid #ffeaa7;
    border-radius: 11px;
    background: rgba(14, 16, 30, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    animation: phoneRotate 3s infinite cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 20px rgba(255, 234, 167, 0.35);
}

.rotate-phone-notch {
    width: 14px;
    height: 3px;
    background: #ffeaa7;
    border-radius: 2px;
    margin-top: 4px;
}

.rotate-phone-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.rotate-circle-arrow {
    position: absolute;
    bottom: -6px;
    right: -6px;
    font-size: 28px;
    color: #fd79a8;
    animation: pulseSpin 3s infinite ease-in-out;
}

@keyframes phoneRotate {
    0%, 15% {
        transform: rotate(0deg);
    }
    50%, 75% {
        transform: rotate(-90deg);
    }
    100% {
        transform: rotate(0deg);
    }
}

@keyframes pulseSpin {
    0%, 100% {
        opacity: 0.65;
        transform: scale(0.95);
    }
    50% {
        opacity: 1;
        transform: scale(1.15) rotate(-30deg);
    }
}

.rotate-title {
    font-size: 21px;
    font-weight: 700;
    color: #ffeaa7;
    margin-bottom: 12px;
    font-family: 'Quicksand', 'Trebuchet MS', sans-serif;
    letter-spacing: 0.3px;
}

.rotate-text {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.88);
    line-height: 1.55;
    margin-bottom: 24px;
    font-family: 'Quicksand', sans-serif;
}

.rotate-btn {
    background: linear-gradient(135deg, #ff7675 0%, #fd79a8 100%);
    border: none;
    color: #ffffff;
    font-family: 'Quicksand', sans-serif;
    font-size: 14px;
    font-weight: 700;
    padding: 12px 22px;
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 4px 18px rgba(253, 121, 168, 0.45);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.rotate-btn:active {
    transform: scale(0.95);
}

/* ----------------------------------------------------
   MOBILE CONTROLLER (Widescreen Landscape Touch Layout)
---------------------------------------------------- */
#mobile-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    pointer-events: none;
    z-index: 250;
    transition: opacity 0.25s ease;
}

#mobile-controls.dimmed {
    opacity: 0.15;
    pointer-events: none;
}
#mobile-controls.dimmed * {
    pointer-events: none !important;
}

/* Show controls on touch devices */
@media (pointer: coarse) {
    #mobile-controls {
        display: block;
    }
}

/* D-Pad Zone (Left Thumb) */
.dpad-zone {
    position: absolute;
    bottom: max(14px, env(safe-area-inset-bottom, 14px));
    left: max(16px, env(safe-area-inset-left, 16px));
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    pointer-events: auto;
}

.dpad-arrows {
    display: flex;
    gap: 12px;
}

/* Action Zone (Right Thumb) */
.action-zone {
    position: absolute;
    bottom: max(14px, env(safe-area-inset-bottom, 14px));
    right: max(16px, env(safe-area-inset-right, 16px));
    display: flex;
    gap: 14px;
    align-items: flex-end;
    pointer-events: auto;
}

/* Mobile Control Buttons */
.ctrl-btn {
    border: 1.5px solid rgba(255, 234, 167, 0.7);
    background: rgba(22, 20, 42, 0.72);
    color: #ffeaa7;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    touch-action: none;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.55);
    transition: transform 0.08s ease, background-color 0.08s ease, border-color 0.08s ease;
    cursor: pointer;
}

/* Expanded invisible touch hit target for thumbs */
.ctrl-btn::after {
    content: '';
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
    border-radius: inherit;
    pointer-events: auto;
}

/* Arrow buttons (Left & Right) */
.arrow-btn {
    width: 64px;
    height: 64px;
    font-size: 24px;
    font-weight: bold;
}

.arrow-btn.active, .arrow-btn:active {
    background: rgba(255, 234, 167, 0.95);
    color: #121324;
    transform: scale(0.92);
    box-shadow: 0 0 16px #ffeaa7;
}

/* Run Toggle Pill */
.run-pill {
    width: 140px;
    height: 36px;
    border-radius: 18px;
    font-size: 13px;
    font-weight: 700;
    font-family: 'Quicksand', sans-serif;
    background: rgba(30, 32, 54, 0.85);
    border: 1.5px solid rgba(255, 118, 117, 0.8);
    color: #ff7675;
}

.run-pill.active {
    background: #ff7675;
    color: #ffffff;
    box-shadow: 0 0 14px #ff7675;
}

/* Action buttons (Jump & Interact) */
.action-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    font-weight: bold;
    font-family: 'Quicksand', sans-serif;
}

.btn-top, .btn-sub {
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.btn-top {
    font-size: 11px;
    letter-spacing: 0.5px;
}

.btn-sub {
    font-size: 14px;
    margin-top: 2px;
}

.jump-btn {
    width: 78px;
    height: 78px;
    background: rgba(108, 92, 231, 0.78);
    border-color: #a29bfe;
    color: #ffffff;
}

.jump-btn.active, .jump-btn:active {
    background: #a29bfe;
    color: #1a1c2b;
    transform: scale(0.92);
    box-shadow: 0 0 20px #a29bfe;
}

.interact-btn {
    background: rgba(253, 121, 168, 0.72);
    border-color: #fd79a8;
    color: #ffffff;
}

.interact-btn.active, .interact-btn:active {
    background: #fd79a8;
    color: #1a1c2b;
    transform: scale(0.92);
    box-shadow: 0 0 18px #fd79a8;
}
