body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000;
    overflow: hidden;
}

img {
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

#viewport {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color: #000;
}

#game-scale {
    /* 
       Enforce Fixed 16:9 Aspect Ratio 
       Width is optimized to fit within viewport bounds.
       177.777vh is 16/9 * 100vh. 
       If viewport is wider than 16:9, height limits width.
       If viewport is narrower than 16:9, width is 100vw.
    */
    width: min(100vw, 177.777vh);
    aspect-ratio: 16/9;

    /* Center in viewport */
    margin: auto;
    position: relative;

    /* Enable container queries for --px scaling */
    container-type: inline-size;
}

#game-wrapper {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: transparent;

    /* Force Mobile Interactions */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;

    /* 
       Scaling Magic:
       1920 logical pixels = 100cqw (Container Query Width)
       1 logical pixel = 100cqw / 1920
    */
    --px: calc(100cqw / 1920);

    /* Base font size scaling */
    font-size: calc(16 * var(--px));

    box-shadow: 0 0 calc(50 * var(--px)) rgba(0, 0, 0, 0.5);
}

.game-container {
    display: flex;
    width: 100%;
    height: 100%;
    position: relative;
    contain: layout paint;
}

/* Background Effect */
.bg-gradient {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 30% 50%, #4a3b2a 0%, #1a1510 100%);
    z-index: -1;
}

/* Main Area */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 2.1cqw;
    /* 40px */
    width: 100%;
}

.top-left-controls {
    position: absolute;
    top: 2.1cqw;
    left: 2.1cqw;
    display: flex;
    gap: 1.05cqw;
    /* 20px */
    z-index: 10;
}

.bottom-left-controls {
    position: absolute;
    bottom: 2.1cqw;
    left: 2.1cqw;
    display: flex;
    gap: 1.05cqw;
    z-index: 10;
    pointer-events: auto;
}

/* Sidebar */
.sidebar-right {
    width: 30cqw;
    /* 450px */
    min-width: 30cqw;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    box-shadow: calc(-5 * var(--px)) 0 calc(15 * var(--px)) rgba(0, 0, 0, 0.2);
    z-index: 10;
    border-left: calc(3 * var(--px)) solid rgba(255, 255, 255, 0.1);
    position: relative;
    height: 100%;
}

/* Loading Screen */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out, visibility 0.5s;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    width: calc(600 * var(--px));
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

.loading-content.ready {
    opacity: 1;
}

.loading-content h1 {
    font-family: var(--font-heading);
    color: var(--text-light);
    font-size: calc(5 * 1rem);
    /* rem scales with base font-size, so this is 5 * 16 * px */
    margin-bottom: 3rem;
    text-shadow: calc(4 * var(--px)) calc(4 * var(--px)) 0 #000;
}

.loader-container {
    width: 100%;
    height: calc(30 * var(--px));
    background: rgba(255, 255, 255, 0.1);
    border: calc(3 * var(--px)) solid #333;
    border-radius: calc(15 * var(--px));
    overflow: hidden;
    margin-bottom: calc(20 * var(--px));
    position: relative;
    box-shadow: inset 0 calc(2 * var(--px)) calc(5 * var(--px)) rgba(0, 0, 0, 0.5);
}

#loading-progress {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #ffbb00);
    transition: width 0.2s ease-out;
    box-shadow: 0 0 calc(10 * var(--px)) rgba(255, 159, 28, 0.5);
}

#loading-text {
    color: #fff;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 1.5rem;
    opacity: 0.8;
}