body {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        margin: 0;
        padding: 5px;
        background-color: #f0f0f0;
        font-family: 'Press Start 2P', cursive;
        box-sizing: border-box;
        overflow: hidden;
    }

    .grid-container {
        display: grid;
        grid-template-columns: repeat(11, minmax(20px, 45px));
        grid-template-rows: repeat(11, minmax(20px, 45px));
        gap: 2px;
        margin-bottom: 10px;
        border: 2px solid #333;
        padding: 5px;
        background-color: #444;
        width: auto;
        max-width: 600px;
        box-sizing: border-box;
    }

    .grid-cell {
        width: 100%;
        height: 100%;
        aspect-ratio: 1/1;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        border: 1px solid #666;
        background-color: #777;
        user-select: none;
        transition: background-color 0.2s;
        position: relative;
        overflow: hidden;
        box-sizing: border-box;
    }
	
/* Styling for the Cookiebot button in the Settings tab */
.cookie-settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    background: linear-gradient(45deg, #8B4513, #D2691E);
    color: white;
    border: 2px solid #DAA520;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    font-size: 12px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    transition: all 0.2s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.cookie-settings-btn:hover {
    background: linear-gradient(45deg, #A0522D, #F4A460);
    transform: translateY(-2px) scale(1.05);
}

.cookie-settings-btn .cookiebot-icon {
    width: 24px;
    height: 24px;
}
    .grid-cell img {
        width: 80%;
        height: 80%;
        object-fit: contain;
        transition: transform 0.3s;
    }

    .grid-cell:hover img {
        transform: scale(1.1);
    }
    
    .grid-cell:active {
        background-color: #aaa;
    }
    
    /* Add more visible active state styling specifically for touch devices */
    @media (hover: none) {
        .grid-cell:active {
            background-color: gold !important;
            border-color: red !important;
        }
    }

    .selected {
        background-color: gold;
        box-shadow: inset 0 0 0 2px red, 0 0 0 1px red;
        border: 1px solid red;
        z-index: 1;
        position: relative;
    }

    #message-box {
        margin-top: 20px;
        font-size: 14px;
        color: #333;
        background-color: rgba(255, 220, 150, 0.8);
        padding: 10px;
        border-radius: 5px;
        border: 2px solid #996600;
        position: fixed;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 100;
        width: 90%;
        max-width: 300px;
        text-align: center;
    }

    #attempts-display {
    margin: 0;
    font-size: 14px;
    color: #fff;
    background: linear-gradient(45deg, #8B4513, #D2691E);
    border: 3px solid #DAA520;
    border-radius: 15px;
    padding: 8px 15px;
    height: 40px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    top: 3px;
    font-family: 'Press Start 2P', cursive;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    white-space: nowrap;
    min-width: 120px;
}

#attempts-display::after {
    content: "";
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, transparent, rgba(218, 165, 32, 0.2), transparent);
    border-radius: 18px;
    z-index: -1;
}

    .explode {
        animation: explode 0.5s ease-in-out, fadeOut 0.5s ease-in-out 0.5s forwards;
    }

    @keyframes explode {
        0% {
            transform: scale(1);
        }

        50% {
            transform: scale(1.2);
        }

        100% {
            transform: scale(0);
        }
    }

    @keyframes fadeOut {
        from {
            opacity: 1;
        }

        to {
            opacity: 0;
        }
    }
	
	 /* NEW: Screen shake animation */
    .screen-shake {
        animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
    }
    
    @keyframes shake {
      10%, 90% { transform: translate3d(-1px, 0, 0); }
      20%, 80% { transform: translate3d(2px, 0, 0); }
      30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
      40%, 60% { transform: translate3d(4px, 0, 0); }
    }

    .fall {
        animation: fall 0.5s ease-in-out;
    }

    @keyframes fall {
        0% {
            transform: translateY(-50px);
        }
        100% {
            transform: translateY(0);
        }
    }

    
	#attempts-display {
		margin-bottom: 10px;
		font-size: 16px;
		color: #333;
		text-align: center;
	}
    #victory-screen {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.8);
        display: flex;
        justify-content: center;
        align-items: center;
        color: white;
        font-size: 24px;
        z-index: 1000;
        display: none;
        text-align: center;
        padding: 20px;
    }

    .remove {
        background-color: red;
    }

    .symbol-icons {
        display: flex;
        justify-content: center;
        gap: 10px;
        flex-wrap: wrap;
        max-width: 100%;
        padding: 0 10px;
    }

    .symbol-icon {
        font-size: 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
        background-color: #555;
        border: 2px solid #333;
        border-radius: 5px;
        padding: 6px 8px;
        cursor: pointer;
        transition: transform 0.2s, background-color 0.2s;
    }

    .symbol-icon img {
        width: 20px;
        height: 20px;
        object-fit: contain;
    }
	
	#game-area {
	  position: relative;      /* parent for absolute children */
	  display: inline-block;   /* shrink-wrap to grid size */
	}


	#top-bar {
		display: flex; 
		justify-content: space-between;
		align-items: center; 
		margin-bottom: 10px; 
		position: relative;
		width: 100%;
	}	

	#coin-icon {
		z-index: 10;
		width: 100px;
		height: 40px;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		padding: 0 10px;
		background-color: #333;
		border: 2px solid gold;
		border-radius: 20px;
		box-sizing: border-box;
		cursor: pointer;
	}

	#coin-icon img {
		width: 30px;
		height: 30px;
		object-fit: contain;
	}

	#coin-icon .symbol-score {
		font-size: 16px;
		color: white;
		margin-top: 0;
		margin-left: auto;
		font-weight: bold;
	}

	#pirate-icon {
    z-index: 10;
    width: 80px;
    height: 40px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: 0 10px;
    background-color: #333;
    border: 2px solid gold;
    border-radius: 20px;
    box-sizing: border-box;
    cursor: pointer;
}

#pirate-icon img {
  width: 30px; 
  height: 30px; 
  object-fit: contain;
}

#pirate-icon .symbol-score { 
  font-size: 16px; 
  color: white;
  margin-top: 0; 
  margin-left: auto; 
  font-weight: bold;
}

/* Main container for tab system */
    .tab-container {
        position: relative;
        width: 100%;
        height: 100vh;
        overflow: hidden;
    }
    
    /* Tab content screens */
    .tab-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease-in-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 60px;
    padding-bottom: 80px; /* Reduced from 120px */
    box-sizing: border-box;
    overflow-y: auto; /* Add this line */
}
    
    /* Game screen (default) */
    .tab-content.game-screen {
        transform: translateX(0);
    }
    
    /* Shop screen */
    .tab-content.shop-screen {
        transform: translateX(-100%);
        background: linear-gradient(135deg, #8B4513, #D2691E);
		padding-left: 0;
    padding-right: 0;
    }
    
    /* Treasures screen */
	.tab-content.treasures-screen {
		transform: translateX(-200%);
		background: linear-gradient(135deg, #FFD700, #FFA500);
		padding-left: 0;
	padding-right: 0;
	}

	/* Map screen */
	.tab-content.map-screen {
		transform: translateX(-300%);
		background: linear-gradient(135deg, #2F4F4F, #708090);
		padding-left: 0;
	padding-right: 0;
	}

	/* Settings screen */
	.tab-content.settings-screen {
		transform: translateX(-400%);
		background: linear-gradient(135deg, #6c757d, #343a40);
		padding-left: 0;
	padding-right: 0;
	}
    
    /* Active tab content positioning */
    .tab-content.active {
        transform: translateX(0) !important;
    }
	
	.bottom-navigation {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    background: transparent;
    backdrop-filter: none;
    padding: 8px 0;
}


.top-message {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    background: rgba(240, 240, 240, 0.9);
    backdrop-filter: blur(5px);
    padding: 10px 0;
}
    
    /* Active navigation button styling */
    .nav-icon.active {
        background: linear-gradient(45deg, #DAA520, #FFD700);
        box-shadow: 0 0 15px rgba(218, 165, 32, 0.8);
        transform: translateY(-2px);
    }
    
    /* Shop content styling */
    .shop-content {
    width: 80%; /* CHANGED: Was 60% */
    max-width: 450px; /* CHANGED: Was 350px */
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 20px;
    border: 3px solid #8B4513;
    box-shadow: 0 0 20px rgba(0,0,0,0.3);
    margin: 0 auto; /* Center the content */
    /* NEW: Add height constraints and scrolling */
    max-height: 70vh; /* Limit height to 70% of viewport */
    overflow-y: auto; /* Enable vertical scrolling */
    display: flex;
    flex-direction: column;
}
    
    .shop-title {
        text-align: center;
    margin-bottom: 20px;
    font-size: 20px;
    color: #8B4513;
    font-family: 'Press Start 2P', cursive;
    /* NEW: Make title sticky */
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.95);
    padding: 10px 0;
    margin: -20px -20px 20px -20px;
    padding-left: 20px;
    padding-right: 20px;
    z-index: 10;
    }
	
	.shop-items-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px; /* Space for scrollbar */
}
    
    .shop-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 15px;
        padding: 15px;
        border: 2px solid #DAA520;
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.8);
        transition: transform 0.2s;
    }
    
    .shop-item:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    }
    
    ..shop-item-info {
        display: flex;
        align-items: center;
        flex-shrink: 1; /* ADDED: Allow this container to shrink */
        min-width: 0; /* ADDED: Allow shrinking below its content's natural width */
    }
    
    .shop-item img {
        width: 40px;
        height: 40px;
        margin-right: 15px;
        border-radius: 5px;
    }
    
    .shop-item-name {
        font-size: 14px;
        font-weight: bold;
        color: #333;
        white-space: normal; /* ADDED: Ensure name can wrap if needed */
        word-break: break-word; /* ADDED: Allow long names to break */
    }
    
    .shop-item-price {
        display: flex;
        align-items: center;
        gap: 15px;
        flex-shrink: 0; /* ADDED: Prevent this container (price + button) from shrinking */
    }
    
    .shop-price {
        display: flex; /* ADDED: Makes this a flex container */
        align-items: center; /* ADDED: Vertically aligns the number and coin */
        gap: 4px; /* ADDED: Adds a small space between number and coin */
        font-size: 16px;
        font-weight: bold;
        color: #DAA520;
        white-space: nowrap; /* ADDED: Prevents this "price + coin" block from wrapping */
    }
    
    .shop-buy-btn {
        padding: 8px 16px;
        background: linear-gradient(45deg, #8B4513, #D2691E);
        color: white;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        font-family: 'Press Start 2P', cursive;
        font-size: 10px;
        transition: all 0.2s;
    }
    
    .shop-buy-btn:hover {
        background: linear-gradient(45deg, #A0522D, #F4A460);
        transform: scale(1.05);
    }
    
    .shop-buy-btn:disabled {
        background: #999;
        cursor: not-allowed;
        transform: none;
    }
    
    /* Treasures content styling */
    .treasures-content {
        width: 80%;
        max-width: 450px;
        background: rgba(255, 255, 255, 0.95);
        border-radius: 15px;
        padding: 20px;
        border: 3px solid #DAA520;
        box-shadow: 0 0 20px rgba(0,0,0,0.3);
        text-align: center;
		margin: 0 auto; /* Center the content */
    }
    
    .treasures-title {
        font-size: 20px;
        color: #DAA520;
        font-family: 'Press Start 2P', cursive;
        margin-bottom: 20px;
    }
    
    /* Map content styling */
    .map-content {
        width: 80%;
        max-width: 450px;
        background: rgba(255, 255, 255, 0.95);
        border-radius: 15px;
        padding: 20px;
        border: 3px solid #2F4F4F;
        box-shadow: 0 0 20px rgba(0,0,0,0.3);
        text-align: center;
		margin: 0 auto; /* Center the content */
    }
    
    .map-title {
        font-size: 20px;
        color: #2F4F4F;
        font-family: 'Press Start 2P', cursive;
        margin-bottom: 20px;
    }
    
    /* Hide original shop modal */
    #shop-modal {
        display: none !important;
    }
    
	
    /* Add styling for the flying symbols */
    .flying-symbol {
        position: fixed;
        z-index: 1000;
        pointer-events: none; /* So it doesn't interfere with clicks */
    }
    
    .symbol-icon:hover {
        background-color: #666;
        transform: translateY(-3px);
    }

    .symbol-icon:active {
        transform: translateY(0);
    }

    .symbol-score {
        font-size: 12px;
        color: white;
        margin-top: 5px;
        font-weight: bold;
    }

    @keyframes spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(1440deg); }
    }
    
    #wheel-overlay {
        display: none !important;
    }

    @keyframes pulse {
        0% { transform: scale(1); }
        50% { transform: scale(1.3); }
        100% { transform: scale(1); }
    }

    .symbol-score-update {
        animation: pulse 0.5s ease-in-out;
        font-weight: bold;
        color: gold;
    }
    
    /* Special styling for interactive symbols */
    .symbol-icon[data-symbol="pistol"], 
    .symbol-icon[data-symbol="goblet"], 
    .symbol-icon[data-symbol="ship"],
    .symbol-icon[data-symbol="sword"],
	.symbol-icon[data-symbol="flag"], 
    .symbol-icon[data-symbol="hat"]	{
        border: 2px solid gold;
        box-shadow: 0 0 8px rgba(255, 215, 0, 0.7);
        position: relative;
    }

    /* Add an indicator that these symbols have special abilities */
    .symbol-icon[data-symbol="pistol"]:after, 
    .symbol-icon[data-symbol="goblet"]:after, 
    .symbol-icon[data-symbol="ship"]:after,
    .symbol-icon[data-symbol="sword"]:after,
	.symbol-icon[data-symbol="flag"]:after,
    .symbol-icon[data-symbol="hat"]:after	{
        content: "✨";
        position: absolute;
        top: -10px;
        right: -5px;
        font-size: 16px;
        animation: pulse 1.5s infinite;
    }

    /* Hover tooltips - hide on mobile */
    @media (hover: none) and (pointer: coarse) {
    .symbol-icon[data-symbol]:before,
    .symbol-icon[data-symbol]:hover:before {
        display: none !important;
        content: none !important;
    }
}


/* Only show tooltips on devices with hover capability */
@media (hover: hover) and (pointer: fine) {
        .symbol-icon[data-symbol="pistol"]:hover:before {
            content: "Click to remove symbols";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }
		
		.symbol-icon[data-symbol="coin"]:hover:before {
            content: "Golden Coin - Your treasure";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="goblet"]:hover:before {
            content: "Click to shuffle the board";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="ship"]:hover:before {
            content: "Need 5+ symbols for your journey";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="wheel"]:hover:before {
            content: "Helps you maneveur in battle";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="pirate"]:hover:before {
            content: "Your lives but you can sacrifice it for 5 moves";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="rum"]:hover:before {
            content: "Easy with the rum pirate!";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="cannon"]:hover:before {
            content: "Yeah, you fire with it";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="ball"]:hover:before {
            content: "Gift for the enemy";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="hat"]:hover:before {
            content: "Clears a 3x3 area of symbols from the board, collecting any coins within that area";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="flag"]:hover:before {
            content: "Allows you to remove a single symbol from the board and instantly add it to your inventory count";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }

        .symbol-icon[data-symbol="sword"]:hover:before {
            content: "Get rid of one symbol from the playing field";
            position: absolute;
            bottom: -30px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(0,0,0,0.8);
            color: white;
            padding: 5px;
            border-radius: 5px;
            font-size: 10px;
            white-space: nowrap;
            z-index: 100;
        }
    }

.navigation-section {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 8px; /* Reduced gap from 10px */
    margin-top: 15px;
    flex-wrap: nowrap;
    max-width: 100%;
    padding: 0 5px; /* Reduced side padding */
    position: relative;
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1; /* ADDED: Makes the button square */
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(2px);
    border-radius: 8px;
    margin: 0 2px;
    border: 3px solid #DAA520;
    padding: 0;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    font-family: 'Press Start 2P', cursive;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    flex-grow: 1;
    flex-basis: 0;
    max-width: 75px;
    overflow: hidden;
    /* REMOVED 'position: relative;' as it's no longer needed */
}

.nav-icon:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
    background: linear-gradient(45deg, #A0522D, #F4A460);
}

.nav-icon:active {
    transform: translateY(0);
}

.nav-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* This makes the image fill the button, cropping if needed */
    /* REMOVED opacity and transition */
}


.statistics-grid {
        display: grid;
        grid-template-columns: 1fr; /* Single column on small screens */
        gap: 15px;
        margin-top: 20px;
    }

    .stat-item {
        display: flex;
        align-items: center;
        background: rgba(255, 255, 255, 0.8);
        border: 2px solid #daa520;
        border-radius: 10px;
        padding: 10px 15px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }

    .stat-item img {
        width: 30px;
        height: 30px;
        object-fit: contain;
        margin-right: 10px;
    }

    .stat-label {
        font-size: 12px;
        color: #8b4513;
        font-weight: bold;
        flex-grow: 1;
        text-align: left;
    }

    .stat-value {
        font-size: 16px;
        color: #333;
        font-family: 'Press Start 2P', cursive;
    }
	
	.coin-icon {
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin-left: 2px;
}

	.flying-chest {
    /* This ensures it starts hidden if you want to control visibility purely with JS */
    opacity: 0;
    /* Basic transition is handled by JS, but you can add more here */
}

.shop-items-container::-webkit-scrollbar {
    width: 8px;
}

.shop-items-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.shop-items-container::-webkit-scrollbar-thumb {
    background: #8B4513;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.shop-items-container::-webkit-scrollbar-thumb:hover {
    background: #D2691E;
}

   /* Responsive adjustments */
@media (max-width: 768px) {

/* ADD THIS NEW RULE to precisely control spacing around the top bar */
    #top-bar {
        margin-top: 20px;  /* Pushes counters down from the top edge */
        margin-bottom: 5px; /* Reduces space between counters and grid */
    }
	
    /* Grid adjustments */
    .grid-container {
        grid-template-columns: repeat(11, 1fr);
        grid-template-rows: repeat(11, 1fr);
        width: 100%;      /* Changed from 95vw */
        max-width: 100%;  /* Changed from 95vw */
        gap: 1px;
        padding: 3px;
    }
    
    .grid-cell {
        border-width: 1px;
    }

    .selected {
        box-shadow: inset 0 0 0 3px red, 0 0 0 1px red !important;
        background-color: gold !important;
        border-color: red !important;
    }
    
    /* KEEP DESKTOP SIZE FOR COIN AND PIRATE ICONS - THIS IS THE FIX */
    #coin-icon {
        width: 100px; /* Maintain desktop width */
        min-width: 100px; /* Ensure it doesn't shrink */
        height: 40px; /* Maintain desktop height */
        flex-shrink: 0; /* Prevent shrinking */
    }

    #pirate-icon {
        width: 80px; /* Maintain desktop width */
        min-width: 80px; /* Ensure it doesn't shrink */
        height: 40px; /* Maintain desktop height */
        flex-shrink: 0; /* Prevent shrinking */
    }

    #coin-icon img, #pirate-icon img {
        width: 30px !important; /* Force desktop image size */
        height: 30px !important; /* Force desktop image size */
    }
    
    /* Symbol icons adjustments */
    .symbol-icons {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        grid-template-rows: repeat(2, 1fr);
        gap: 3px;
        width: 100%;
        max-width: 100%;
        justify-items: center;
        align-items: center;
        margin-top: 5px;
        box-sizing: border-box; /* Add this line to fix the wrapping */
    }
    
    .symbol-icon {
        font-size: 14px;
        padding: 3px 4px;
        width: 100%;
        max-width: 60px;
        box-sizing: border-box;
    }
    
    .symbol-icon img {
        width: 16px;
        height: 16px;
    }
    
    .symbol-score {
        font-size: 8px;
    }

    #message-box {
        font-size: 12px;
    }
    
    #victory-screen {
        font-size: 18px;
    }
    
	/* Navigation adjustments */
	.navigation-section {
		gap: 5px; /* Reduced gap */
		margin-top: 10px;
	}

	.nav-icon {
		padding: 0; /* CHANGED: Remove padding to let the image fill */
		min-width: 0; /* Removed min-width, ensuring flexibility */
	}
    
    .nav-icon-symbol {
        font-size: 20px;
        margin-bottom: 6px;
    }
    
    /* Tab content adjustments */
    .map-content { /* Kept map styles separate */
        width: 80%;
        max-width: 320px;
        padding: 15px;
        margin: 0 auto;
    }
    
    /* NEW rule for treasures-content to match shop */
    .treasures-content {
        width: 70%;
        max-width: 70vw;
        padding: 15px;
        margin: 0 auto;
        max-height: 50vh; /* Match shop */
        
        /* Added from shop to enable scrolling */
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }
    
    .shop-content {
        width: 70%;
        max-width: 70vw;
        padding: 15px;
        margin: 0 auto;
        max-height: 50vh;
    }
        
    .shop-title {
        font-size: 16px;
        margin: -15px -15px 15px -15px;
        padding-left: 15px;
        padding-right: 15px;
    }
    
    .map-title { /* Kept map title separate */
        font-size: 16px;
    }
    
    /* NEW rule for treasures-title to match shop */
    .treasures-title {
        font-size: 16px;
        color: #8B4513; /* Match shop title */

        /* Added properties to make title sticky */
        text-align: center;
        position: sticky;
        top: 0;
        background: rgba(255, 255, 255, 0.95);
        padding: 10px 0;
        margin: -15px -15px 15px -15px; /* Match shop title mobile margins */
        padding-left: 15px;
        padding-right: 15px;
        z-index: 10;
    }
    
    .shop-item {
        padding: 10px;
        margin-bottom: 10px;
    }
    
    .shop-item img {
        width: 30px;
        height: 30px;
        margin-right: 10px;
    }
    
    .shop-item-name {
        font-size: 12px;
    }
    
    .shop-price {
        font-size: 14px;
    }
    
    .shop-buy-btn {
        font-size: 8px;
        padding: 6px 12px;
    }
    
    .tab-content {
        padding-left: 0;
        padding-right: 0;
    }
    
    /* Hide tooltips on mobile - CONSOLIDATED FROM YOUR SCATTERED BLOCKS */
    .symbol-icon[data-symbol]:before,
    .symbol-icon[data-symbol]:hover:before {
        display: none !important;
        content: none !important;
    }
}

@media (max-width: 500px) {
     .grid-container {
        grid-template-columns: repeat(11, 1fr);
        grid-template-rows: repeat(11, 1fr);
        width: 100%;      /* Changed from 98vw */
        max-width: 100%;  /* Changed from 98vw */
        gap: 1px;
        padding: 2px;
    }
    body {
        padding: 2px;
    }
    /* KEEP DESKTOP SIZE FOR COIN AND PIRATE ICONS EVEN ON VERY SMALL SCREENS */
    #coin-icon {
        width: 100px; /* Keep desktop width */
        min-width: 100px; /* Ensure it doesn't shrink */
        height: 40px; /* Keep desktop height */
        flex-shrink: 0; /* Prevent shrinking */
    }
    #pirate-icon {
        width: 80px; /* Keep desktop width */
        min-width: 80px; /* Ensure it doesn't shrink */
        height: 40px; /* Keep desktop height */
        flex-shrink: 0; /* Prevent shrinking */
    }
    #coin-icon img, #pirate-icon img {
        width: 30px; /* Keep desktop image size */
        height: 30px; /* Keep desktop image size */
    }
    .symbol-icons {
        width: 100%;      /* Changed from 98vw */
        max-width: 100%;  /* Changed from 98vw */
        gap: 2px;
    }
    .symbol-icon {
        font-size: 12px;
        padding: 2px 3px;
        max-width: 55px;
    }
    .symbol-icon img {
        width: 14px;
        height: 14px;
    }
    .symbol-score {
        font-size: 7px;
    }
    .grid-cell {
        min-width: 0;
        min-height: 0;
    }
    .navigation-section {
        gap: 4px; /* Further reduced gap */
    }
    .nav-icon {
        padding: 0; /* CHANGED: Remove padding to let the image fill */
        min-width: 0; /* Ensure no minimum width */
    }
    .nav-icon-symbol {
        font-size: 18px;
        margin-bottom: 4px;
    }
    
    .statistics-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
    .shop-content {
        width: 80%;
        max-width: 80vw;
        max-height: 45vh;
    }

    /* --- ADDED THIS NEW RULE --- */
    .treasures-content {
        width: 80%;
        max-width: 80vw;
        max-height: 45vh;
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        flex-direction: row;
        justify-content: flex-end;
        align-items: flex-start;
        padding: 5px;
    }

    #game-area {
        margin-left: auto;
        margin-right: 5px;
        flex-shrink: 0;
    }

    .grid-container {
        width: auto;
        height: auto;
        max-width: 90vh;
        max-height: 90vw;
        margin-bottom: 0;
    }

    #top-bar {
        position: static;
        width: auto;
        margin-bottom: 5px;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* SLIGHTLY REDUCE SIZE FOR LANDSCAPE MODE BUT KEEP PROPORTIONAL */
    #coin-icon, #pirate-icon {
        width: 80px; /* Slightly smaller for landscape but still proportional */
        height: 35px;
        padding: 0 8px;
    }

    #coin-icon img, #pirate-icon img {
        width: 25px; /* Slightly smaller images for landscape */
        height: 25px;
    }

    #attempts-display {
        font-size: 12px;
        height: 35px; /* Match the icon height */
        padding: 5px 10px;
        margin: 0 5px;
        top: 0;
    }

    .symbol-icons {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: repeat(5, 1fr);
        grid-auto-flow: column;
        gap: 3px;
        justify-content: flex-start;
        align-items: flex-start;
        margin-top: 0;
        margin-right: auto;
        margin-left: 5px;
        max-height: 100vh;
        padding: 0;
        width: 120px;
    }

    .symbol-icon {
        width: 50px;
        padding: 4px 6px;
        margin-bottom: 0;
        flex-basis: auto;
        box-sizing: border-box;
    }

    .symbol-icon img {
        width: 18px;
        height: 18px;
    }

    .symbol-score {
        font-size: 10px;
    }

    #new-game-button {
        left: calc(50% - 60px);
    }

    #message-box {
        top: 5px;
        max-width: 200px;
        font-size: 10px;
        padding: 5px;
    }

    #victory-screen {
        font-size: 16px;
        padding: 10px;
    }
    
    .navigation-section {
        position: relative;
        bottom: auto;
        left: auto;
        transform: none;
        flex-direction: row !important;
        gap: 5px;
        margin-top: 15px;
        width: auto;
        justify-content: center;
    }
    
    .nav-icon {
        /* REMOVED: flex-direction: column; (No longer needed) */
        min-width: 60px;
        padding: 0; /* CHANGED: Remove padding to let the image fill */
    }
    
    .nav-icon-symbol {
        font-size: 16px;
        margin-bottom: 4px;
        margin-right: 0;
    }
    
    }

/* REPLACEMENT: More aggressive rules for short screens */
@media (max-height: 680px) {
    .tab-content {
        /* Reduce main vertical padding */
        padding-top: 45px;
        padding-bottom: 70px;
    }

    #top-bar {
        /* Reduce space below the top bar */
        margin-bottom: 5px;
    }

    /* Make the top bar elements shorter */
    #coin-icon, #pirate-icon, #attempts-display, #chest-countdown-display {
        height: 35px;
    }

    #coin-icon img, #pirate-icon img {
        width: 26px;
        height: 26px;
    }

    .grid-container {
        /* Reduce space below the grid */
        margin-bottom: 8px;
    }

    /* Make the bottom icons smaller */
    .symbol-icon {
        padding: 2px 3px;
    }
    .symbol-icon img {
        width: 15px;
        height: 15px;
    }
    .symbol-score {
        font-size: 7px;
        margin-top: 3px; /* Reduce space inside the icon */
    }

    .symbol-icons {
        margin-top: 0; /* Remove top margin */
        gap: 2px; /* Reduce gap between icons */
    }
}
