body {
    margin: 0;
    padding: 0;
    background-color: #000d1a;
    /* Deep Ocean Black/Blue */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: white;
}

#game-container {
    perspective: 1000px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 800px;
    padding: 10px;
    box-sizing: border-box;
}

#debug-info {
    font-family: monospace;
    font-size: 12px;
    color: #bdc3c7;
    background: rgba(0, 0, 0, 0.5);
    padding: 5px;
    border-radius: 4px;
    max-width: 600px;
    word-wrap: break-word;
    text-align: center;
}

#grid-wrapper {
    position: relative;
    padding: 15px;
    border-radius: 10px;
    background-color: #34495e;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 720px;
    /* Max size for desktop comfort */
    box-sizing: border-box;
    aspect-ratio: 1 / 1;
    /* Keep it square */
}

#grid {
    display: grid;
    /* Responsive Grid: 12 columns, take available space */
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(12, 1fr);
    gap: 0.8%;
    /* Percentage gap for scalability */
    width: 100%;
    height: 100%;
}

.tile {
    width: 100%;
    /* Maintain square aspect ratio */
    aspect-ratio: 1 / 1;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
}

.tile.flipped {
    transform: rotateX(180deg);
    cursor: default;
}

.tile-inner {
    position: absolute;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s;
    transform-style: preserve-3d;
}

.tile-front,
.tile-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 15%;
    /* Responsive radius */
    box-sizing: border-box;
}

.tile-front {
    background-color: #ecf0f1;
    background: linear-gradient(135deg, #ecf0f1 0%, #bdc3c7 100%);
    box-shadow:
        inset 1px 1px 0px rgba(255, 255, 255, 0.5),
        inset -1px -1px 0px rgba(0, 0, 0, 0.1),
        0 4px 6px rgba(0, 0, 0, 0.3);
    border-bottom: 4px solid #95a5a6;
    /* This might need scaling on very small screens */
    transition: transform 0.1s;
}

.tile:active .tile-front {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

.tile-back {
    background-color: #ecf0f1;
    color: #2c3e50;
    transform: rotateX(180deg);
    border-bottom: 4px solid #bdc3c7;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    /* Responsive Font Size */
    font-size: clamp(0.8rem, 2.5vw, 2.5rem);
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Submarine Variant */
.tile.bomb .tile-back {
    background-color: #003366;
    /* Navy Blue */
    color: #fff;
    border-bottom: 4px solid #001f3f;
    /* Responsive Font Size for Bomb */
    font-size: clamp(0.8rem, 2.5vw, 2.5rem);
}

/* Bomb Spin Animation */
@keyframes explodeSpin {
    0% {
        transform: rotateX(180deg) rotateZ(0deg) scale(1);
    }

    50% {
        transform: rotateX(180deg) rotateZ(720deg) scale(1.4);
    }

    100% {
        transform: rotateX(180deg) rotateZ(1440deg) scale(1);
    }
}

.tile.bomb.flipped {
    animation: explodeSpin 0.8s ease-out forwards;
    z-index: 100;
}

/* Glow effect for revealed bomb */
/* Glow effect for revealed submarine */
.tile.bomb.flipped .tile-back {
    box-shadow: 0 0 20px 5px rgba(0, 255, 255, 0.6);
    border: 2px solid #0ff;
}

/* Bomb Glyph Rotation */
.bomb-glyph {
    display: inline-block;
}

/* Hint Overlay Container */
#hint-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    overflow: hidden;
    border-radius: 10px;
}

/* The actual pulse box */
/* Sonar Ripple Pulse Style */
.area-hint-box {
    position: absolute;
    border-radius: 8px;
    /* Square with slight rounding */
    box-sizing: border-box;
    animation: sonar-ripple 1.5s ease-out forwards;
    /* Slightly slower for visibility */
    background-color: rgba(0, 255, 255, 0.4);
    /* Stronger fill */
    border: 3px solid #ffffff;
    /* Stark white for max contrast */
    box-shadow:
        0 0 20px #00ffff,
        0 0 40px #00ffff,
        inset 0 0 40px rgba(0, 255, 255, 0.6);
    /* Intense internal glow */
}

@keyframes sonar-ripple {
    0% {
        opacity: 0;
        transform: scale(0.2);
    }

    10% {
        opacity: 1;
        /* Fade in quickly */
    }

    80% {
        opacity: 1;
        /* Stay visible */
    }

    100% {
        opacity: 0;
        /* Quick fade out at very end */
        transform: scale(1.0);
    }
}

/* Edge Tile Highlight Animation */
/* Edge Tile Highlight Animation */
@keyframes tile-edge-pulse {
    0% {
        box-shadow: inset 0 0 0px #00ffff;
    }

    50% {
        box-shadow: inset 0 0 20px #00ffff;
        /* Only animate shadow */
    }

    100% {
        box-shadow: inset 0 0 0px #00ffff;
    }
}

.tile-pulse-target .tile-back,
.tile-pulse-target .tile-front {
    animation: tile-edge-pulse 0.5s ease-out forwards;
}



/* ... existing code ... */

input[type="text"]:focus {
    border-color: #f1c40f;
    background: rgba(0, 0, 0, 0.4);
    text-transform: lowercase;
    /* Visual cue */
}

/* 2) Stylized Title */
.title-container {
    margin-bottom: 5px;
    background: rgba(0, 20, 40, 0.8);
    border: 1px solid #0ff;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.2);
}

#game-title {
    font-family: 'Orbitron', sans-serif;
    /* Responsive Font Size for Title */
    font-size: clamp(2rem, 8vw, 3.5rem);
    font-weight: 400;
    color: #ccffff;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
    text-shadow:
        0 0 5px #0ff,
        0 0 10px #0ff,
        0 0 20px #00f;
    transform: none;
    -webkit-text-stroke: 0px;
    /* Thinner stroke on small screens implicit */
}

/* HUD Row: Tracker + Score */
#hud-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 720px;
    margin-bottom: 5px;
    padding: 0 10px;
    box-sizing: border-box;
}

/* 5) Bomb Tracker */
#bomb-tracker {
    display: flex;
    gap: 5px;
    /* Tighter gap */
    padding: 8px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.tracker-icon {
    width: 30px;
    /* Slightly smaller base */
    height: 30px;
    background-color: #001f3f;
    /* Dark Blue */
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    border: 2px solid #bdc3c7;
}

.tracker-icon.found {
    background-color: #2ecc71;
    opacity: 0.8;
}

/* X Overlay when found */
.tracker-icon.found::after {
    content: '❌';
    position: absolute;
    font-size: 1.2rem;
    color: #c0392b;
    text-shadow: 0 0 5px black;
    animation: stamp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes stamp {
    0% {
        transform: scale(3);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Live Score Box */
#live-score-box {
    background: linear-gradient(to bottom, #34495e, #2c3e50);
    padding: 8px 20px;
    border-radius: 12px;
    border: 2px solid #95a5a6;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.hud-label {
    font-size: 0.6rem;
    color: #bdc3c7;
    letter-spacing: 1px;
    font-weight: bold;
}

#live-score {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    color: #00ffff;
    /* Neon Cyan */
    line-height: 1;
    text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
}


/* 7) Game Over & Splash Screens */
#game-over-screen, #splash-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    /* Wider on small screens */
    max-width: 500px;
    height: auto;
    padding: 20px;
    background: rgba(0, 20, 40, 0.9);
    /* Darker Deep Ocean */
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    border: 1px solid rgba(0, 255, 255, 0.3);
    /* Cyan border */
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.2);
    opacity: 0;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#game-over-screen.visible, #splash-screen.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: all;
}

#game-over-screen h2, #splash-screen h2 {
    font-family: 'Orbitron', sans-serif;
    color: #00ffff;
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    margin: 0 0 10px 0;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.6);
    text-align: center;
}

#game-over-screen p, #splash-screen p {
    font-family: 'Inter', sans-serif;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    margin-bottom: 20px;
    color: #b0e0e6;
    /* Powder Blue */
    text-align: center;
}

#score-display {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.5rem, 5vw, 1.8rem);
    font-weight: bold;
    margin-bottom: 20px;
    color: #00ffff;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 50px;
    border: 1px solid #00ffff;
    box-shadow: inset 0 0 10px rgba(0, 255, 255, 0.2);
}

/* Inputs & Buttons */
input[type="text"] {
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid rgba(0, 255, 255, 0.3);
    background: rgba(0, 10, 20, 0.6);
    color: #00ffff;
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    outline: none;
    text-align: center;
    transition: all 0.2s;
    width: 100%;
    /* Full width in container */
    max-width: 200px;
    margin-bottom: 15px;
    box-sizing: border-box;
}

input[type="text"]::placeholder {
    color: rgba(0, 255, 255, 0.5);
    font-family: 'Inter', sans-serif;
}

input[type="text"]:focus {
    border-color: #00ffff;
    background: rgba(0, 20, 40, 0.8);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.4);
}

button {
    padding: 12px 30px;
    background: linear-gradient(to bottom, #00ffff, #00cccc);
    /* Cyan Gradient */
    color: #002233;
    /* Dark text for contrast */
    border: none;
    border-radius: 50px;
    font-size: 1rem;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    text-transform: uppercase;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.4);
    transition: transform 0.1s, filter 0.2s, box-shadow 0.2s;
    letter-spacing: 1px;
}

button:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(0, 255, 255, 0.6);
}

button:active {
    transform: translateY(1px);
}

/* Leaderboard */
#leaderboard-section {
    width: 100%;
    margin-top: 20px;
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border-radius: 12px;
    text-align: left;
    box-sizing: border-box;
}

#leaderboard-section h3 {
    margin: 0 0 10px 0;
    text-align: center;
    color: #bdc3c7;
    font-size: 1.1rem;
}

#scoreboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 120px;
    overflow-y: auto;
    font-size: 0.9rem;
}

#scoreboard-list li {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#scoreboard-list li:nth-child(1) {
    color: #f1c40f;
    font-weight: bold;
}

/* Gold */
#scoreboard-list li:nth-child(2) {
    color: #bdc3c7;
}

/* Silver */
#scoreboard-list li:nth-child(3) {
    color: #e67e22;
}

/* Bronze */

.leaderboard-date {
    font-size: 0.7rem;
    color: #7f8c8d;
    text-align: right;
    margin-top: 5px;
}

.hidden {
    display: none !important;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 600px) {
    #game-container {
        padding: 5px;
        gap: 10px;
    }

    /* Title scales with clamp(), but reduce margin */
    .title-container {
        padding: 8px 20px;
        margin-bottom: 0;
    }

    #hud-row {
        padding: 0 5px;
    }

    #bomb-tracker {
        padding: 5px 10px;
        gap: 3px;
    }

    .tracker-icon {
        width: 25px;
        height: 25px;
        font-size: 0.8rem;
    }

    #grid-wrapper {
        padding: 8px;
        /* Less padding around grid */
        border-radius: 6px;
    }

    .tile-front {
        border-bottom-width: 2px;
        /* Thinner 3D effect */
    }

    /* Reduce spacing in Game Over screen */
    #game-over-screen {
        width: 95%;
    }
}
}

/* Victory Pulse Animation for Bombs */
@keyframes victory-pulse {
    0% {
        transform: rotateX(180deg) scale(1);
        box-shadow: 0 0 20px 5px rgba(231, 76, 60, 0.8);
        border-color: #ff7979;
    }

    50% {
        transform: rotateX(180deg) scale(1.3);
        /* Pop out */
        box-shadow: 0 0 50px 20px rgba(241, 196, 15, 0.9);
        /* Gold Glow */
        border-color: #f1c40f;
    }

    100% {
        transform: rotateX(180deg) scale(1);
        box-shadow: 0 0 20px 5px rgba(231, 76, 60, 0.8);
        border-color: #ff7979;
    }
}

.tile.bomb.victory-pulse .tile-back {
    animation: victory-pulse 2s infinite ease-in-out;
    z-index: 200;
    /* Ensure on top */
}