@import url('https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,500;0,700;0,800;1,700;1,800&display=swap');

*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: #05050a;
    font-family: 'Nunito', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none; 
}

#canvas-container {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
}

#canvas-container:active {
    cursor: grabbing;
}

#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #05050a;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #ffffff;
    z-index: 10;
}

#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#loading-screen.fade-out .loader-earth {
    transform: scale(1.5) translateZ(0);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#loading-screen.fade-out .spinner {
    transform: scale(1.5) rotate(180deg);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.loader-container {
    position: relative;
    width: 60vmin;
    height: 60vmin;
    max-width: 2048px;
    max-height: 2048px;
    container-type: inline-size;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 100vmin;
    transform-style: preserve-3d;
    margin-bottom: 5vmin;
}

.loader-earth {
    width: 55%;
    height: 55%;
    object-fit: contain;
    transform: scale(1) translateZ(0);
    display: block;
}

.orbit-tilt {
    position: absolute;
    width: 83%;
    height: 83%;
    transform-style: preserve-3d;
    transform: rotateX(70deg) rotateY(-12deg);
    pointer-events: none;
}

.spinner {
    width: 100%;
    height: 100%;
    border: 5.7cqw solid rgba(255, 255, 255, 0.1);
    border-top-color: #3D9BE9;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.instructions {
    position: absolute;
    bottom: 3vmin;
    left: 50%;
    transform: translateX(-50%) skewX(-5deg) translateY(0) rotate(0);
    color: #e8f4ff;
    background: linear-gradient(180deg, rgba(50, 75, 110, 0.75) 0%, rgba(20, 30, 50, 0.9) 100%);
    backdrop-filter: blur(1.5vmin);
    padding: 1.5vmin 3vmin;
    border-radius: 2vmin;
    pointer-events: none;
    font-size: 2.2vmin;
    font-weight: 800;
    letter-spacing: 0.1vmin;
    text-transform: uppercase;
    border: 0.3vmin solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 1vmin 3vmin rgba(0, 0, 0, 0.6), inset 0 0.5vmin 1vmin rgba(255, 255, 255, 0.2);
    text-align: center;
    z-index: 5;
    max-width: 90vw;
    opacity: 1;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
}

body.booting .instructions {
    transform: translateX(-50%) skewX(-5deg) translateY(20vmin);
    opacity: 0;
    transition: none;
    animation: none;
}

.instructions.hidden-hop, body.split-active .instructions {
    animation: hopLeave 0.6s ease-in forwards;
    pointer-events: none;
}

@keyframes hopLeave {
    0% { transform: translateX(-50%) skewX(-5deg) translateY(0) rotate(0); opacity: 1; }
    30% { transform: translateX(-50%) skewX(-5deg) translateY(-2.5vmin) rotate(4deg); opacity: 1; }
    100% { transform: translateX(-50%) skewX(-5deg) translateY(20vmin) rotate(-5deg); opacity: 0; }
}

.btn-dock {
    position: fixed;
    bottom: 3vmin;
    right: 3vmin;
    display: flex;
    gap: 2vmin;
    z-index: 6;
}

.action-btn {
    width: 8vmin;
    height: 8vmin;
    border-radius: 2vmin;
    background: linear-gradient(180deg, rgba(50, 75, 115, 0.75) 0%, rgba(15, 25, 45, 0.9) 100%);
    backdrop-filter: blur(1.5vmin);
    border: 0.3vmin solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 1vmin 2vmin rgba(0,0,0,0.6), inset 0 0.5vmin 1vmin rgba(255,255,255,0.25);
    color: #e8f4ff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    will-change: transform, box-shadow, border-color;
    backface-visibility: hidden;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, border-color 0.2s ease, filter 0.2s ease, opacity 0.4s ease;
}

/* Base default positions */
#random-button { transform: translateY(0) scale(1) translateZ(0); }
#map-button { transform: translateX(0) scale(1) translateZ(0); }

/* Off-screen states */
body.booting #random-button, body.split-active #random-button {
    transform: translateY(20vmin) scale(1) translateZ(0);
    opacity: 0;
    pointer-events: none;
}

body.booting #map-button, body.split-active #map-button {
    transform: translateX(20vmin) scale(1) translateZ(0);
    opacity: 0;
    pointer-events: none;
}

.action-btn.disabled {
    opacity: 0.35;
    border-color: rgba(255,255,255,0.1);
    color: #777777;
    box-shadow: none;
    cursor: not-allowed;
    pointer-events: none;
}

.action-btn:not(.disabled):hover {
    filter: brightness(1.15);
    border-color: #4FC3F7;
    color: #4FC3F7;
    box-shadow: 0 1.5vmin 3vmin rgba(61, 155, 233, 0.5), inset 0 0.5vmin 1vmin rgba(255,255,255,0.3);
}

#random-button:not(.disabled):hover { transform: translateY(-0.5vmin) scale(1.05) translateZ(0); }
#map-button:not(.disabled):hover { transform: translateX(-0.5vmin) scale(1.05) translateZ(0); }

.action-btn:not(.disabled):active,
.action-btn:not(.disabled).gamepad-pressed {
    transform: scale(0.95) translateZ(0) !important;
    border-color: #3D9BE9;
    box-shadow: inset 0 0.5vmin 1vmin rgba(0,0,0,0.8);
}

.action-btn svg {
    width: 4vmin;
    height: 4vmin;
    filter: drop-shadow(0 0.2vmin 0.4vmin rgba(0,0,0,0.7));
}

.bobbing-wrapper, .wiggle-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    transform-origin: center;
}

.action-btn:not(.disabled) .bobbing-wrapper {
    animation: bob 2.5s ease-in-out infinite;
}

.action-btn:not(.disabled) .wiggle-wrapper {
    animation: occasionalWiggle 4s ease-in-out infinite;
}

/* Wii U Soft Glassmorphic Panel Layout */
#info-panel {
    position: fixed;
    top: 50%; /* Vertically centers and allows content height to dictate bounds naturally */
    right: 3vmin;
    left: calc(50vw + 3vmin);
    max-height: calc(100vh - 6vmin);
    background: linear-gradient(180deg, rgba(45, 70, 105, 0.8) 0%, rgba(10, 20, 35, 0.95) 100%);
    backdrop-filter: blur(1.5vmin);
    border: 0.4vmin solid rgba(255, 255, 255, 0.35);
    border-radius: 3vmin;
    box-shadow: 0 2vmin 5vmin rgba(0, 0, 0, 0.8), inset 0 0.5vmin 1vmin rgba(255, 255, 255, 0.2);
    color: #e8f4ff;
    z-index: 8;
    padding: 3vmin;
    display: flex;
    flex-direction: column;
    gap: 2vmin;
    /* Base (hidden off-screen) */
    transform: translateY(-50%) skewX(-3deg) rotateY(15deg) scale(0.9);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease;
}

body.split-active #info-panel {
    transform: translateY(-50%) skewX(-3deg) rotateY(0deg) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.panel-card {
    display: flex;
    flex-direction: column;
    gap: 1.5vmin;
    position: relative;
    z-index: 4;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 1vmin; 
    
    /* Remove scrollbars */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.panel-card::-webkit-scrollbar {
    display: none;
    width: 0;
}

/* Staggered Animations inside Panel */
#info-panel .data-group,
#info-panel .data-group-row,
#info-panel .data-card-sub {
    opacity: 0;
    transform: translateY(3vmin);
    transition: opacity 0.4s ease, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

body.split-active #info-panel .data-group,
body.split-active #info-panel .data-group-row,
body.split-active #info-panel .data-card-sub {
    opacity: 1;
    transform: translateY(0);
}

/* Sequential Delays for Pop-in Polish */
body.split-active #info-panel .data-group.highlight { transition-delay: 0.1s; }
body.split-active #info-panel .data-group-row { transition-delay: 0.2s; }
body.split-active #info-panel .data-grid .data-card-sub:nth-child(1) { transition-delay: 0.3s; }
body.split-active #info-panel .data-grid .data-card-sub:nth-child(2) { transition-delay: 0.35s; }
body.split-active #info-panel .data-grid .data-card-sub:nth-child(3) { transition-delay: 0.4s; }
body.split-active #info-panel .data-grid .data-card-sub:nth-child(4) { transition-delay: 0.45s; }


.data-group {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.3);
    border: 0.2vmin solid rgba(255, 255, 255, 0.15);
    border-radius: 1.5vmin;
    padding: 1.5vmin 2vmin;
    box-shadow: inset 0 0.5vmin 1vmin rgba(0, 0, 0, 0.4), 0 0.5vmin 1vmin rgba(255,255,255,0.08);
    min-width: 0; 
}

.data-group.highlight {
    border-color: rgba(61, 155, 233, 0.7);
    background: linear-gradient(180deg, rgba(0, 100, 160, 0.4) 0%, rgba(0, 50, 100, 0.6) 100%);
    box-shadow: 0 1vmin 2vmin rgba(0, 154, 199, 0.3), inset 0 0.5vmin 1vmin rgba(255,255,255,0.15);
}

.data-group-row {
    display: flex;
    gap: 1.5vmin;
    width: 100%;
}

.data-group.half {
    flex: 1;
    min-width: 0; 
}

.data-label {
    font-size: 1.5vmin;
    font-weight: 800;
    color: #A0C2E0;
    text-transform: uppercase;
    letter-spacing: 0.1vmin;
    margin-bottom: 0.5vmin;
}

.data-value {
    font-weight: 800;
    font-size: 2.5vmin;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 0.2vmin 0.5vmin rgba(0,0,0,0.9);
}

#val-location {
    white-space: normal;
    word-wrap: break-word;
    display: -webkit-box;
    line-clamp: 3;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.2;
    padding-right: 0.5vmin; 
}

.data-value.large {
    font-size: 3.5vmin;
}

.data-value.italic {
    font-style: italic;
    letter-spacing: 0.05vmin;
}

.data-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5vmin;
}

.data-card-sub {
    background: rgba(255, 255, 255, 0.08);
    border: 0.2vmin solid rgba(255, 255, 255, 0.15);
    border-radius: 1.5vmin;
    padding: 1.5vmin;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0.5vmin 1vmin rgba(0, 0, 0, 0.4), inset 0 0.5vmin 0.5vmin rgba(255,255,255,0.1);
    min-width: 0;
    overflow: hidden; 
}

.sub-label {
    font-size: 1.3vmin;
    font-weight: 800;
    color: #A0C2E0;
    margin-bottom: 0.5vmin;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sub-value {
    font-size: 2.8vmin;
    font-style: italic;
    font-weight: 800;
    white-space: nowrap;
    text-shadow: 0 0.2vmin 0.5vmin rgba(0,0,0,0.9);
}

.neon-blue { color: #4FC3F7; text-shadow: 0 0 1vmin rgba(79, 195, 247, 0.5), 0 0.2vmin 0.5vmin rgba(0,0,0,0.9); }
.neon-orange { color: #FFB733; text-shadow: 0 0 1vmin rgba(255, 183, 51, 0.5), 0 0.2vmin 0.5vmin rgba(0,0,0,0.9); }

.ios-back-btn {
    position: absolute;
    left: -3.5vmin;
    top: 4vmin;
    width: 6vmin;
    height: 6vmin;
    border-radius: 50%;
    background: linear-gradient(180deg, #4FC3F7 0%, #006A9E 100%);
    border: 0.3vmin solid #FFFFFF;
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 1vmin 2vmin rgba(0,0,0,0.6), inset 0 0.5vmin 1vmin rgba(255,255,255,0.4);
    z-index: 10;
    will-change: transform, filter;
    transform: scale(1) translateZ(0);
    backface-visibility: hidden;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), filter 0.2s ease;
}

.ios-back-btn:hover {
    transform: scale(1.1) rotate(-5deg) translateZ(0);
    filter: brightness(1.15);
}

.ios-back-btn:active, .ios-back-btn.gamepad-pressed {
    transform: scale(0.95) translateZ(0);
    filter: brightness(0.85);
}

.ios-back-btn svg {
    width: 3.5vmin;
    height: 3.5vmin;
    transform: translateX(-0.2vmin);
    filter: drop-shadow(0 0.2vmin 0.3vmin rgba(0,0,0,0.6));
}

@media (max-aspect-ratio: 1/1) {
    #info-panel {
        top: 75vh;
        left: 3vmin;
        right: 3vmin;
        max-height: calc(50vh - 6vmin);
        /* Portrait bottom-up tilt */
        transform: translateY(-50%) skewX(-3deg) rotateX(15deg) scale(0.9);
    }

    body.split-active #info-panel {
        transform: translateY(-50%) skewX(-3deg) rotateX(0deg) scale(1);
    }

    .ios-back-btn {
        left: 2.5vmin;
        top: -3.5vmin; 
        transform: scale(0.9) translateZ(0);
    }
}

/* ========================================= */
/* iiSU Embedded UI Logic */
/* ========================================= */
body.iiSU #info-panel,
body.iiSU .instructions,
body.iiSU #map-button {
    display: none !important;
}

body.iiSU .btn-dock {
    bottom: 3.5vmin;
    right: 3.5vmin;
}

body.iiSU .action-btn {
    width: 10vmin;
    height: 10vmin;
    border-radius: 2.5vmin;
}

body.iiSU .action-btn svg {
    width: 5vmin;
    height: 5vmin;
}

#iiSU-temp {
    display: block;
    position: absolute;
    bottom: 3.5vmin;
    left: 3.5vmin;
    font-size: 10vmin;
    line-height: 10vmin;
    font-weight: 800;
    color: #e8f4ff;
    text-shadow: 0 0.5vmin 1vmin rgba(0,0,0,0.8);
    font-style: italic;
    font-family: 'Nunito', sans-serif;
    pointer-events: none;
    z-index: 10;
    
    /* Animation base */
    opacity: 0;
    transform: translateX(-20vmin);
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
}

body.iiSU:not(.booting) #iiSU-temp {
    opacity: 1;
    transform: translateX(0);
}