/**
 * Kingdom Quest - Game Styles
 * 
 * Mobile-first design with iOS notch support and responsive layout.
 */

/* WordPress wrapper - isolate game styles */
.kq-game-wrapper * {
    box-sizing: border-box;
}

.kq-game-wrapper {
    margin: 0;
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    z-index: 999999; /* Ensure game is above WordPress theme elements */
}

#gameContainer {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    opacity: 0;
    transition: opacity 0.8s ease-in;
}

#gameContainer.loaded {
    opacity: 1;
}

/* Top Bar - Resource Counters */
#topBar {
    position: relative;
    z-index: 100;
    background: linear-gradient(180deg, #2c2c2c 0%, #1a1a1a 100%);
    color: #fff;
    padding: 12px 15px;
    padding-top: calc(12px + env(safe-area-inset-top)); /* iOS notch support */
    border-bottom: 1px solid #444;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

#resources {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.resource {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: rgba(255,255,255,0.1);
    padding: 4px 8px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.resource-icon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

#menuButton {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 6px;
    border-radius: 5px;
    transition: background 0.2s;
}

#menuButton:hover {
    background: rgba(255,255,255,0.1);
}

.menu-line {
    width: 100%;
    height: 2px;
    background: #9bbc0f;
    border-radius: 2px;
}

/* Canvas Wrapper */
#canvasWrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color: #000;
    position: relative;
}

/* Loading Screen */
#loadingScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #001117;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-bottom: 10vh;
    z-index: 9999;
    transition: opacity 0.8s ease-out;
}

/* Background image layer */
#loadingScreen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('../img/kq-loading-bg.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0;
    animation: fadeInBackground 1s ease-in 0.3s forwards;
    z-index: 1;
}

/* Logo and text overlay */
#loadingFavicon,
#loadingText {
    position: relative;
    z-index: 2;
    opacity: 0;
    animation: fadeInContent 0.8s ease-in 1.5s forwards;
}

#loadingScreen.fade-out {
    opacity: 0;
    pointer-events: none;
}

#loadingFavicon {
    width: 128px;
    height: 128px;
    image-rendering: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Style the img tag inside (whether from WordPress logo or fallback) */
#loadingFavicon img {
    width: 128px;
    height: 128px;
    object-fit: contain;
    image-rendering: auto;
}

/* Remove default link styling if WordPress logo includes a link */
#loadingFavicon a {
    display: block;
    line-height: 0;
}

#loadingFavicon.loaded {
    animation: fadeInContent 0.8s ease-in 1.5s forwards, pulse 2s ease-in-out 2.5s infinite;
}

#loadingText {
    margin-top: 24px;
    color: #9bbc0f;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
}

@keyframes fadeInBackground {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

@keyframes fadeInContent {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: translateY(0) scale(1); }
    50% { opacity: 0.6; transform: translateY(0) scale(1.05); }
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: auto;
}

/* Prevent scrolling */
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Bottom Bar - Game Stats */
#bottomBar {
    position: relative;
    z-index: 100;
    background: linear-gradient(0deg, #2c2c2c 0%, #1a1a1a 100%);
    color: #ccc;
    padding: 10px 15px;
    border-top: 1px solid #444;
    flex-shrink: 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
}

#gameInfo {
    display: flex;
    justify-content: space-around;
    margin-bottom: 8px;
    font-size: 11px;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.info-label {
    color: #888;
    font-size: 10px;
}

.info-value {
    color: #9bbc0f;
    font-weight: 600;
    font-size: 13px;
}

#controls {
    text-align: center;
    font-size: 10px;
    color: #666;
    display: none; /* Hidden on mobile by default */
}

/* Show controls on desktop only */
@media (min-width: 768px) {
    #controls {
        display: block;
    }
}

/* Build Menu Modal (Mobile) */
#buildMenu {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(180deg, #1a1a1a 0%, #2c2c2c 100%);
    border-top: 2px solid #9bbc0f;
    padding: 20px 15px;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
}

#buildMenu.active {
    transform: translateY(0);
}

#buildMenuTitle {
    color: #9bbc0f;
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 15px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#buildOptions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.build-option {
    background: rgba(155, 188, 15, 0.1);
    border: 2px solid #555;
    border-radius: 8px;
    padding: 15px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.build-option.selected {
    background: rgba(155, 188, 15, 0.3);
    border-color: #9bbc0f;
}

.build-option:active {
    transform: scale(0.95);
}

.build-option-icon {
    font-size: 32px;
    margin-bottom: 5px;
}

.build-option-name {
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 3px;
}

.build-option-cost {
    color: #888;
    font-size: 9px;
}

#buildMenuClose {
    width: 100%;
    background: #9bbc0f;
    color: #1a1a1a;
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#buildMenuClose:active {
    background: #8aac0e;
}

/* Floating Build Mode Toggle Button */
#buildModeToggle {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom));
    left: calc(15px + env(safe-area-inset-left));
    width: 56px;
    height: 56px;
    background: rgba(44, 44, 44, 0.95);
    border: 3px solid #555;
    border-radius: 50%;
    color: #9bbc0f;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.3s;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
}

#buildModeToggle:active {
    transform: scale(0.9);
}

#buildModeToggle.active {
    background: #9bbc0f;
    color: #1a1a1a;
    border-color: #9bbc0f;
    transform: scale(1.1);
}

/* Floating Dice Roll Button */
#diceRollButton {
    position: fixed;
    bottom: calc(150px + env(safe-area-inset-bottom));
    left: calc(15px + env(safe-area-inset-left));
    width: 56px;
    height: 56px;
    background: rgba(44, 44, 44, 0.95);
    border: 3px solid #555;
    border-radius: 50%;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.3s;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
}

#diceRollButton:active {
    transform: scale(0.9);
}

#diceRollButton:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Zoom Controls (Desktop Only) */
#zoomControls {
    position: fixed;
    bottom: 100px;
    right: 20px;
    display: none;
    flex-direction: column;
    gap: 10px;
    z-index: 200;
}

@media (min-width: 768px) {
    #zoomControls {
        display: flex;
    }
    #buildMenu {
        display: none; /* Hide mobile build menu on desktop */
    }
    #buildModeToggle {
        display: none; /* Hide toggle button on desktop */
    }
}

.zoom-btn {
    width: 44px;
    height: 44px;
    background: rgba(44, 44, 44, 0.9);
    border: 2px solid #9bbc0f;
    border-radius: 50%;
    color: #9bbc0f;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.zoom-btn:hover {
    background: #9bbc0f;
    color: #1a1a1a;
    transform: scale(1.1);
}

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