/* ===== GUARDIÃO DA ÁGUA - RESPONSIVIDADE ===== */

/* ===== BREAKPOINTS ===== */
/* Mobile: 320px - 768px */
/* Tablet: 769px - 1024px */
/* Desktop: 1025px+ */

/* ===== MOBILE FIRST - BASE STYLES ===== */
@media screen and (max-width: 768px) {
    
    /* ===== MENU PRINCIPAL ===== */
    .menu-container {
        padding: 1rem;
        max-width: 90%;
    }
    
    .menu-header h1 {
        font-size: 2.5rem;
    }
    
    .subtitle {
        font-size: 1rem;
        margin-bottom: 2rem;
    }
    
    .menu-btn {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }
    
    .btn-icon {
        font-size: 1.2rem;
    }
    
    /* ===== HUD MOBILE ===== */
    .hud-top {
        height: 60px;
        padding: 0 1rem;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
    }

    

    .resource-item{
      padding: 0px;
      gap: 0px;
      width: 150px;
    }
    .resource-tooltip{
      display: none;
    }
    .resource-value{
      font-size: 0.9rem;
    }
    /* Show resource panel when active (opened via toggle) */
    .resource-panel.mobile-active {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        background: linear-gradient(180deg, rgba(45,53,97,0.98) 0%, rgba(26,31,58,0.98) 100%);
        padding: 1rem;
        z-index: 75;
        border-bottom: 4px solid var(--cartoon-blue);
        box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
        animation: slideInFromTop 0.3s ease-out;
    }

    .resource-panel.mobile-active .resource-item {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-width: 100px;
    }

    .resource-icon {
        font-size: 1.2rem;
    }

    .resource-label {
        display: none; /* Oculta labels em mobile */
    }
    
    /* ===== PAINÉIS LATERAIS MOBILE ===== */
    .hud-left {
        width: 100%;
        height: calc(100% - 60px);
        top: auto;
        bottom: 0px;
        left: 0;
        right: 0;
        background: linear-gradient(0deg, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.9) 100%);
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 60;
    }

    .hud-left.active {
        transform: translateY(0);
    }

    /* ===== ENHANCED MOBILE HUD-RIGHT WITH FULL-SCREEN SUPPORT ===== */
    .hud-right {
        display: flex !important;
        width: 100%;
        height: 100vh;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: linear-gradient(0deg, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.9) 100%);
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 70;
        backdrop-filter: blur(15px);
    }

    .hud-right.active {
        transform: translateX(0);
    }

    /* ===== MOBILE HUD-RIGHT HEADER WITH CLOSE BUTTON ===== */
    .hud-right .details-panel {
        padding: 1rem;
        position: relative;
    }

    .hud-right .mobile-panel-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1rem;
        padding-bottom: 0.5rem;
        border-bottom: 1px solid rgba(255,255,255,0.2);
    }

    .hud-right .mobile-panel-title {
        font-size: 1.2rem;
        color: #00FF88;
        font-weight: bold;
    }

    .hud-right .mobile-close-btn {
        background: rgba(255,255,255,0.1);
        border: 1px solid rgba(255,255,255,0.2);
        color: white;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .hud-right .mobile-close-btn:hover {
        background: rgba(255,255,255,0.2);
        transform: scale(1.1);
    }

    .hud-right .mobile-close-btn:active {
        transform: scale(0.95);
    }

    /* ===== MOBILE BUILDING DETAILS MODAL ===== */
    .hud-right .details-content {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        padding-bottom: 100px; /* Space for build button */
    }

    .hud-right .mobile-build-btn {
        position: fixed;
        bottom: 20px;
        left: 20px;
        right: 20px;
        padding: 1rem 2rem;
        background: linear-gradient(145deg, var(--cartoon-green), #00D470);
        color: white;
        border: 4px solid #00AA55;
        border-radius: 16px;
        font-size: 1.3rem;
        font-weight: bold;
        font-family: 'Fredoka', sans-serif;
        cursor: pointer;
        box-shadow: 0 8px 0 #008844;
        transition: all 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        z-index: 75;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
    }

    .hud-right .mobile-build-btn:hover {
        transform: translateY(-4px);
        box-shadow: 0 12px 0 #008844, 0 0 20px var(--cartoon-green);
    }

    .hud-right .mobile-build-btn:active {
        transform: translateY(-1px);
        box-shadow: 0 4px 0 #008844;
    }

    .hud-right .mobile-build-btn.disabled {
        background: linear-gradient(145deg, #666, #555);
        border-color: #444;
        box-shadow: 0 8px 0 #333;
        cursor: not-allowed;
        opacity: 0.6;
    }

    .hud-right .mobile-build-btn.disabled:hover {
        transform: none;
        box-shadow: 0 8px 0 #333;
    }

    /* Mobile building details content */
    .mobile-building-details {
        padding: 1rem 0;
    }

    .mobile-building-details .building-header {
        text-align: center;
        margin-bottom: 1.5rem;
    }

    .mobile-building-details .building-icon-large {
        font-size: 4rem;
        margin-bottom: 0.5rem;
    }

    .mobile-building-details h2 {
        font-size: 1.8rem;
        color: var(--cartoon-orange);
        margin: 0;
        font-family: 'Lilita One', cursive;
    }

    .mobile-building-details .building-description {
        background: rgba(0, 212, 255, 0.1);
        padding: 1rem;
        border-radius: 12px;
        border-left: 4px solid var(--cartoon-blue);
        margin-bottom: 1.5rem;
    }

    .mobile-building-details .building-description p {
        margin: 0;
        font-size: 1rem;
        line-height: 1.5;
        color: rgba(255, 255, 255, 0.9);
    }

    .mobile-building-details .building-stats-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.8rem;
        margin-bottom: 1.5rem;
    }

    .mobile-building-details .stat-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.8rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 10px;
        border: 2px solid rgba(255, 255, 255, 0.1);
    }

    .mobile-building-details .stat-label {
        font-weight: bold;
        font-size: 1rem;
        color: rgba(255, 255, 255, 0.8);
    }

    .mobile-building-details .stat-value {
        font-size: 1.1rem;
        color: var(--cartoon-green);
        font-weight: bold;
    }

    .mobile-building-details .stat-value.critical {
        color: var(--cartoon-red);
        animation: pulse-critical-cartoon 1s infinite;
    }

    .mobile-building-details .building-requirements {
        background: rgba(255, 140, 0, 0.1);
        padding: 1rem;
        border-radius: 12px;
        border-left: 4px solid var(--cartoon-orange);
    }

    .mobile-building-details .building-requirements h4 {
        margin: 0 0 0.5rem 0;
        color: var(--cartoon-orange);
        font-size: 1.1rem;
    }

    .mobile-building-details .building-requirements ul {
        margin: 0;
        padding-left: 1.5rem;
        list-style: none;
    }

    .mobile-building-details .building-requirements li {
        font-size: 0.95rem;
        margin-bottom: 0.3rem;
        color: rgba(255, 255, 255, 0.9);
    }

    .mobile-building-details .building-requirements li::before {
        content: '▸ ';
        color: var(--cartoon-orange);
        font-weight: bold;
    }

    .building-panel {
        padding: 1rem;
    }
    
    .building-panel h3 {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
    }
    
    .building-categories {
        gap: 0.3rem;
        margin-bottom: 0.5rem;
        flex-direction: column;
    }
    
    .category-btn {
        padding: 0.3rem;
        font-size: 1rem;
        font-weight: normal;
    }
    
    .building-items {
        gap: 0.3rem;
        overflow: visible;
    }
    
    .building-item {
        padding: 0.8rem;
        gap: 0.8rem;
        margin: 10px 0px;
    }
    
    .building-icon {
        font-size: 1.5rem;
        width: 40px;
        height: 40px;
    }
    
    .building-name {
        font-size: 1.4rem;
    }
    
    .building-cost {
        font-size: 1rem;
    }
    
    .building-description {
        font-size: 1rem;
    }
    
    /* ===== PAINEL INFERIOR MOBILE - COLLAPSIBLE REDESIGN ===== */
    .hud-bottom {
        height: 0px !important; /* Collapsed by default */
        padding: 0 !important;
        overflow: hidden;
        bottom: 0 !important;
        transition: height 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55),
                    padding 0.4s ease,
                    opacity 0.3s ease;
        opacity: 0;
        z-index: 50;
    }

    .hud-bottom.expanded {
        height: 200px !important; /* Expanded state */
        padding: 0.5rem 1rem !important;
        opacity: 1;
        z-index: 95 !important; /* FIX #4: Above mobile-toggle (85) and btn-missions (90) */
    }

    /* Toggle button for HUD bottom */
    .hud-bottom-toggle {
        position: fixed;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 60px;
        height: 30px;
        background: linear-gradient(135deg, rgba(0,212,255,0.9) 0%, rgba(0,168,204,0.9) 100%);
        border: 2px solid rgba(255,255,255,0.3);
        border-bottom: none;
        border-radius: 12px 12px 0 0;
        color: white;
        font-size: 1.2rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
        z-index: 100 !important; /* FIX #4: Above expanded hud-bottom (95) to remain clickable */
        box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.2);
    }

    .hud-bottom-toggle:hover {
        transform: translateX(-50%) translateY(-3px);
        box-shadow: 0 -6px 12px rgba(0, 0, 0, 0.3);
    }

    .hud-bottom-toggle:active {
        transform: translateX(-50%) translateY(-1px);
    }

    .hud-bottom-toggle.expanded {
        background: linear-gradient(135deg, rgba(255,193,7,0.9) 0%, rgba(255,152,0,0.9) 100%);
    }
    
    /* ===== MOBILE INFO PANEL OPTIMIZATION - FOCUS ON MISSION OBJECTIVE ===== */
    .info-panel {
        gap: 0.5rem;
        padding: 0.5rem 1rem;
        display: flex;
        flex-direction: column;
    }

    /* Hide resource info on mobile to maximize mission display space */
    .info-panel .resource-info {
        display: none !important;
    }

    /* Mission info takes full width */
    .mission-info {
        flex: 1;
        width: 100%;
        max-width: 100%;
    }

    .mission-info h4 {
        font-size: 0.9rem;
        margin-bottom: 0.3rem;
    }

    .mission-info p {
        font-size: 0.8rem;
        margin-bottom: 0.3rem;
    }

    /* Mission objective display - maximize space */
    .mission-objective-display {
        width: 100% !important;
        padding: 0.75rem !important;
        min-height: 60px !important;
    }

    .mission-objective-display .objective-content {
        flex: 1;
    }

    .mission-objective-display .objective-title {
        font-size: 0.95rem !important;
        line-height: 1.3;
    }

    .mission-objective-display .objective-action {
        font-size: 0.8rem !important;
    }
    
    .progress-text {
        font-size: 0.8rem;
    }
    
    /* ===== OVERLAYS MOBILE ===== */
    .overlay-content {
        padding: 2rem;
        margin: 1rem;
        max-width: 90%;
    }

    .overlay-content h2 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .overlay-btn {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }

    /* ===== BACK BUTTON MOBILE ===== */
    .back-btn {
        padding: 0.6rem 1.2rem;
        font-size: 0.85rem;
        gap: 0.4rem;
        min-height: 44px; /* Touch-friendly minimum */
    }

    .mission-details-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding-bottom: 1rem;
        margin-bottom: 1.5rem;
    }

    .mission-details-header h3 {
        font-size: 1.3rem;
        order: -1; /* Title first on mobile */
    }

    /* ===== MISSION CATEGORIES MOBILE ===== */
    .mission-categories-simplified {
        flex-direction: column;
        gap: 0.5rem;
    }

    .category-btn-large {
        max-width: none !important;
        min-width: auto !important;
        padding: 1rem 1.5rem !important;
        gap: 1rem !important;
    }

    .category-btn-large .category-info {
        opacity: 1 !important;
        transform: translateX(0) !important;
        width: auto !important;
        min-width: auto !important;
    }

    .category-btn-large .category-icon-large {
        font-size: 2rem !important;
    }

    /* Hide tooltips on mobile */
    .category-btn-large::before,
    .category-btn-large::after {
        display: none !important;
    }
    
    /* ===== BOTÕES DE TOGGLE MOBILE ===== */
    .mobile-toggle {
        position: fixed;
        bottom: 20px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: linear-gradient(135deg, #00D4FF, #00A8CC);
        border: none;
        color: white;
        font-size: 1.2rem;
        cursor: pointer;
        z-index: 60;
        box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3);
        transition: all 0.3s ease;
    }
    
    .mobile-toggle:hover {
        transform: scale(1.1);
    }
    
    .mobile-toggle.left {
        left: 20px;
    }
    
    .mobile-toggle.right {
        right: 20px;
    }
    
    /* ===== TUTORIAL MOBILE ===== */
    .tutorial-container {
        padding: 1rem;
        max-width: 95%;
        max-height: 90%;
    }
    
    .tutorial-header h2 {
        font-size: 1.3rem;
    }
    
    
    
    .tutorial-navigation {
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .tutorial-btn {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }
}

/* ===== TABLET ===== */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    
    .hud-left {
        width: 250px;
    }
    
    .hud-right {
        width: 250px;
    }
    
    .resource-panel {
        gap: 0.6rem;
    }
    
    .resource-item {
        padding: 0.4rem 0.8rem;
    }
    
    .building-panel {
        padding: 1.2rem;
    }
    
    .category-btn {
        min-width: 100px;
        font-size: 0.85rem;
    }
    
    .building-item {
        padding: 0.8rem;
    }
    
    .building-icon {
        font-size: 1.8rem;
        width: 45px;
        height: 45px;
    }
}

/* ===== DESKTOP LARGE ===== */
@media screen and (min-width: 1440px) {
    
    .hud-left {
        width: 350px;
    }
    
    .hud-right {
        width: 350px;
    }
    
    .resource-panel {
        gap: 0.6rem;
    }
    
    .resource-item {
        padding: 0.6rem 1.2rem;
    }
    
    .building-panel {
        padding: 2rem;
    }
    
    .building-item {
        padding: 0px 10px;
    }
    
    .building-icon {
        font-size: 2.2rem;
        width: 55px;
        height: 55px;
    }
    
    .hud-bottom {
        height: 140px;
    }
    
    .info-panel {
        padding: 1.5rem 2.5rem;
    }
}

/* ===== ORIENTAÇÃO LANDSCAPE MOBILE ===== */
@media screen and (max-width: 768px) and (orientation: landscape) {
    
    .hud-top {
        height: 50px;
    }
    
    .hud-bottom {
        height: 50px;
    }
    
    .hud-left,
    .hud-right {
        height: 150px;
        bottom: 50px;
    }
    
    .resource-item {
        padding: 0.2rem 0.6rem;
        font-size: 0.7rem;
    }
    
    .control-btn {
        width: 30px;
        height: 30px;
        font-size: 0.7rem;
    }
    
    .mission-info h4 {
        font-size: 0.8rem;
    }
    
    .mission-info p {
        font-size: 0.7rem;
    }
}

/* ===== TOUCH DEVICES ===== */
@media (hover: none) and (pointer: coarse) {
    
    
    
    .menu-btn:hover {
        transform: none;
    }
    
    .menu-btn:active {
        transform: scale(0.98);
    }
    
    .control-btn:hover {
        transform: none;
    }
    
    .control-btn:active {
        transform: scale(0.9);
    }
    
    /* Aumenta área de toque */
    .control-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .category-btn {
        min-height: 44px;
    }
    
    
}

/* ===== ENHANCED MOBILE TOGGLE BUTTONS (BOTTOM) ===== */
.mobile-toggle {
    position: fixed;
    bottom: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.4);
    background: linear-gradient(135deg, rgba(0,255,136,0.9) 0%, rgba(0,200,100,0.9) 100%);
    color: white;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 85;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
}

.mobile-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3), 0 0 20px rgba(0,255,136,0.4);
}

.mobile-toggle:active {
    transform: scale(0.95) translateY(2px);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.mobile-toggle.left {
    left: 20px;
    background: linear-gradient(135deg, rgba(0,212,255,0.9) 0%, rgba(0,168,204,0.9) 100%);
    border-color: rgba(0,212,255,0.4);
}

.mobile-toggle.right {
    right: 20px;
    background: linear-gradient(135deg, rgba(0,255,136,0.9) 0%, rgba(0,200,100,0.9) 100%);
    border-color: rgba(0,255,136,0.4);
}

.mobile-toggle.active {
    background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(220,220,220,0.95) 100%);
    color: #333;
    border-color: rgba(0,255,136,0.8);
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3), 0 0 20px rgba(0,255,136,0.6);
}

/* ===== MISSIONS BUTTON REPOSITIONING (MOBILE) ===== */
@media screen and (max-width: 768px) {
    .missions-btn {
        position: fixed !important;
        bottom: 95px !important; /* 50px (toggle height) + 25px (spacing) + 20px (toggle bottom) */
        right: 20px !important;
        width: 50px !important;
        height: 50px !important;
        border-radius: 50% !important;
        background: linear-gradient(135deg, rgba(255,193,7,0.9) 0%, rgba(255,152,0,0.9) 100%) !important;
        border: 3px solid rgba(255,255,255,0.4) !important;
        color: white !important;
        font-size: 1.8rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer !important;
        transition: all 0.3s ease !important;
        z-index: 90 !important; /* Above mobile toggles (85) */
        box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3) !important;
        backdrop-filter: blur(10px) !important;
        padding: 0 !important;
        min-width: 50px !important;
        min-height: 50px !important;
    }

    .missions-btn:hover {
        transform: scale(1.1) !important;
        box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3), 0 0 20px rgba(255,193,7,0.6) !important;
    }

    .missions-btn:active {
        transform: scale(0.95) translateY(2px) !important;
        box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3) !important;
    }
}

/* ===== SELECTION COUNTER BADGE ===== */
.selection-counter-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF6B9D 0%, #FF4757 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: 'Fredoka', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), 0 0 15px rgba(255, 107, 157, 0.6);
    z-index: 10;
    animation: pulseBadge 1.5s ease-in-out infinite;
}

@keyframes pulseBadge {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), 0 0 15px rgba(255, 107, 157, 0.6);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), 0 0 25px rgba(255, 107, 157, 0.9);
    }
}

/* ===== MOBILE TOP TOGGLE BUTTONS (TOP HUD) ===== */
.mobile-top-toggle {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(100,100,255,0.9) 0%, rgba(80,80,200,0.9) 100%);
    border: 2px solid rgba(100,100,255,0.4);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 55;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    margin-left: 10px;
}

.mobile-top-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 0 15px rgba(100,100,255,0.4);
}

.mobile-top-toggle:active {
    transform: scale(0.95) translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

.mobile-top-toggle.resource-toggle {
    background: linear-gradient(135deg, rgba(255,165,0,0.9) 0%, rgba(200,130,0,0.9) 100%);
    border-color: rgba(255,165,0,0.4);
}

.mobile-top-toggle.control-toggle {
    background: linear-gradient(135deg, rgba(150,150,150,0.9) 0%, rgba(100,100,100,0.9) 100%);
    border-color: rgba(150,150,150,0.4);
}

.mobile-top-toggle.active {
    background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(220,220,220,0.95) 100%);
    color: #333;
    border-color: rgba(100,100,255,0.8);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 0 15px rgba(100,100,255,0.6);
}

/* ===== COMPACT RESOURCE INDICATORS (MOBILE) ===== */
.compact-resources {
    display: none; /* Hidden on desktop */
}

@media screen and (max-width: 768px) {
    .compact-resources {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 5px 10px;
        background: linear-gradient(135deg, rgba(45, 53, 97, 0.95) 0%, rgba(26, 31, 58, 0.95) 100%);
        border-radius: 20px;
        box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 0 15px rgba(100, 100, 255, 0.3);
        backdrop-filter: blur(10px);
        border: 2px solid rgba(100, 100, 255, 0.3);
        flex-wrap: wrap;
    }

    .compact-resource-item {
        display: flex;
        align-items: center;
        gap: 0;
        padding: 4px 2px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 12px;
        font-size: 0.85rem;
        font-weight: 600;
        color: #fff;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
        transition: all 0.3s ease;
        cursor: pointer;
    }

    .compact-resource-item:hover {
        background: rgba(255, 255, 255, 0.2);
        transform: scale(1.05);
    }

    .compact-resource-item:active {
        transform: scale(0.95);
        background: rgba(255, 255, 255, 0.25);
    }

    .compact-icon {
        font-size: 1rem;
        filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    }

    .compact-value {
        font-size: 0.75rem;
        letter-spacing: 0.5px;
    }
}

/* ===== MOBILE TOP HUD VISIBILITY ===== */
@media screen and (max-width: 768px) {
    .hud-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 10px;
    }

    .resource-panel,
    .control-buttons {
        height: 0px;
        overflow: hidden;
        transition: all 0.5s cubic-bezier(0.18, 0.89, 0.38, 1.49)
    }

    .resource-panel.mobile-visible,
    .control-buttons.mobile-visible {
        height: auto;
        flex-wrap: wrap;
        justify-content: space-evenly;
        padding: 10px;
        background: linear-gradient(180deg, #2D3561 0%, #1A1F3A 100%);
    }
}

/* ===== MOBILE PANEL ANIMATIONS ===== */
@keyframes slideInFromBottom {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInFromTop {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.hud-left.active {
    animation: slideInFromBottom 0.3s ease-out;
}

.hud-right.active {
    animation: slideInFromRight 0.3s ease-out;
}

/* ===== HIGH DPI DISPLAYS ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    
    .resource-icon,
    .building-icon,
    .btn-icon {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .loading-progress {
        animation: none;
    }

    .menu-header h1 {
        animation: none;
    }
}

/* ===== STUDY BOOK SYSTEM ===== */

/* Locked building item styles */
.building-item.locked {
    position: relative;
    filter: grayscale(0.7);
    cursor: pointer;
}

.building-item.locked:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.building-item .study-icon {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1.5rem;
    background: rgba(255, 193, 7, 0.9);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    animation: pulse-study 2s infinite;
}

@keyframes pulse-study {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Study book overlay */
.study-book-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.study-book-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.study-book-container {
    width: 90%;
    max-width: 800px;
    max-height: 95vh;
    animation: bookOpen 0.5s ease;
}

@keyframes bookOpen {
    0% {
        transform: scale(0.8) rotateY(-15deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotateY(0deg);
        opacity: 1;
    }
}

.study-book {
    background: linear-gradient(135deg, #f5f5dc 0%, #fffef0 100%);
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    padding: 2rem;
    position: relative;
    border: 3px solid #8b4513;
}

.book-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #8b4513;
}

.book-header h2 {
    color: #4a2511;
    font-size: 1.8rem;
    margin: 0;
    font-family: 'Georgia', serif;
}

.book-close-btn {
    background: #d32f2f;
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.book-close-btn:hover {
    background: #b71c1c;
    transform: scale(1.1);
}

.book-progress {
    margin-bottom: 1.5rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #d7ccc8;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.9rem;
    color: #5d4037;
    font-weight: bold;
}

.book-content {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    min-height: 400px;
    max-height: 50vh;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
}

.page-number {
    text-align: center;
    color: #8b4513;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    font-style: italic;
}

.page-title {
    color: #2c1810;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    font-family: 'Georgia', serif;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0.5rem;
}

.page-text {
    color: #333;
    line-height: 1.8;
    font-size: 1rem;
}

.page-text h3 {
    color: #4a2511;
    font-size: 1.3rem;
    margin-top: 1.5rem;
    margin-bottom: 0.8rem;
}

.page-text h4 {
    color: #5d4037;
    font-size: 1.1rem;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.page-text ul, .page-text ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.page-text li {
    margin-bottom: 0.5rem;
}

.page-text p {
    margin-bottom: 1rem;
}

.page-text .highlight {
    background: #fff9c4;
    padding: 1rem;
    border-left: 4px solid #fbc02d;
    margin: 1rem 0;
    border-radius: 4px;
}

.page-text .warning {
    background: #ffebee;
    padding: 1rem;
    border-left: 4px solid #f44336;
    margin: 1rem 0;
    border-radius: 4px;
}

.page-text .tip {
    background: #e8f5e9;
    padding: 1rem;
    border-left: 4px solid #4caf50;
    margin: 1rem 0;
    border-radius: 4px;
}

.page-text .success {
    background: #e3f2fd;
    padding: 1rem;
    border-left: 4px solid #2196f3;
    margin: 1rem 0;
    border-radius: 4px;
}

.book-navigation {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.nav-btn {
    flex: 1;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.prev-btn {
    background: #757575;
    color: white;
}

.prev-btn:hover:not(:disabled) {
    background: #616161;
    transform: translateX(-3px);
}

.next-btn {
    background: #2196f3;
    color: white;
}

.next-btn:hover {
    background: #1976d2;
    transform: translateX(3px);
}

.complete-btn {
    background: linear-gradient(135deg, #4caf50, #8bc34a);
    color: white;
}

.complete-btn:hover {
    background: linear-gradient(135deg, #388e3c, #689f38);
    transform: scale(1.05);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.book-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: #5d4037;
    padding-top: 1rem;
    border-top: 1px solid #d7ccc8;
}

/* Mobile responsive */
@media screen and (max-width: 768px) {
    .study-book-container {
        width: 95%;
    }

    .study-book {
        padding: 1rem;
    }

    .book-header h2 {
        font-size: 1.3rem;
    }

    .book-content {
        padding: 1rem;
        min-height: 300px;
    }

    .page-title {
        font-size: 1.2rem;
    }

    .page-text {
        font-size: 0.95rem;
    }

    

    .nav-btn {
        width: 100%;
    }
}

/* ===== DESKTOP: Building categories accordion ===== */
@media screen and (min-width: 769px) {
    .building-categories {
        flex-direction: column;
        flex-wrap: nowrap;
        margin-bottom: 0;
    }

    .category-btn {
        min-width: unset;
        width: 100%;
        text-align: left;
    }

    /* Items drawer — hidden by default, shown when .accordion-open is added by JS */
    #building-items {
        display: none;

        overflow: visible;
        margin: 0.4rem 0 0.2rem 0;
        border-radius: 16px;
    }

    #building-items.accordion-open {
        display: flex;
    }
}