@import url('https://fonts.googleapis.com/css2?family=VT323&display=swap');

body {
    margin: 0;
    padding: 0;
    background-color: #202020;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    /* dynamic viewport height — accounts for mobile browser chrome */
    font-family: 'VT323', monospace;
    overflow: hidden;
}

#game-container {
    position: relative;
    /* In landscape: height is the constraint. In portrait: width is the constraint. */
    width: min(800px, 100vw, calc(100dvh * 16 / 9));
    aspect-ratio: 16 / 9;
    max-height: 100dvh;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #87CEEB;
    image-rendering: pixelated;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#score {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 32px;
    color: white;
    text-shadow: 2px 2px 0 #000;
}

#select-screen,
#start-screen,
#game-over-screen {
    background: rgba(0, 0, 0, 0.7);
    padding: 40px;
    border: 4px solid white;
    text-align: center;
    color: white;
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

h1 {
    font-size: clamp(28px, 6vw, 64px);
    margin: 0 0 20px 0;
    text-shadow: 4px 4px 0 #000;
    color: #F7E414;
}

p {
    font-size: clamp(16px, 3.5vw, 32px);
    margin-bottom: 20px;
}

button {
    font-family: 'VT323', monospace;
    font-size: clamp(18px, 3.5vw, 32px);
    padding: 10px 30px;
    background-color: #767676;
    color: white;
    border: 4px solid #000;
    cursor: pointer;
    box-shadow: inset -4px -4px 0 rgba(0, 0, 0, 0.5);
}

button:hover {
    background-color: #929292;
}

button:active {
    box-shadow: inset 4px 4px 0 rgba(0, 0, 0, 0.5);
}

/* ═══ Selection Screen ═══ */
#select-screen {
    max-width: 90%;
}

#select-screen h1 {
    color: #FFD700;
    font-size: clamp(24px, 5.5vw, 56px);
    margin-bottom: 8px;
}

#select-screen p {
    font-size: clamp(14px, 3vw, 26px);
    margin-bottom: 16px;
    color: #ccc;
}

#select-cards {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

.select-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 24px;
    border: 4px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    min-width: 160px;
    box-shadow: inset -4px -4px 0 rgba(0, 0, 0, 0.4);
}

.select-card:hover {
    transform: scale(1.06);
}

.select-card:active {
    transform: scale(0.97);
    box-shadow: inset 4px 4px 0 rgba(0, 0, 0, 0.5);
}

.spongebob-card {
    background: linear-gradient(135deg, #1E6FA0 0%, #2196F3 50%, #0D47A1 100%);
    border-color: #F7E414;
}

.cat-card {
    background: linear-gradient(135deg, #7B1FA2 0%, #CE93D8 50%, #4A148C 100%);
    border-color: #F48FB1;
}

.card-icon {
    font-size: clamp(32px, 7vw, 56px);
    line-height: 1;
}

.card-title {
    font-size: clamp(16px, 3vw, 26px);
    color: #FFD700;
    text-shadow: 2px 2px 0 #000;
}

.card-desc {
    font-size: clamp(12px, 2.4vw, 18px);
    color: #ddd;
}

/* Smaller padding on small screens */
@media (max-width: 500px) {

    #select-screen,
    #start-screen,
    #game-over-screen {
        padding: 20px;
    }

    #select-cards {
        flex-direction: column;
        align-items: center;
    }

    .select-card {
        min-width: 140px;
        padding: 12px 18px;
    }
}

.bluey-card {
    background: linear-gradient(135deg, #1565C0 0%, #42A5F5 50%, #E65100 100%);
    border-color: #FFB74D;
}

.scary-card {
    background: linear-gradient(135deg, #B71C1C 0%, #4A0000 50%, #1A1A1A 100%);
    border-color: #FF5252;
}

/* ═══ Settings ═══ */
#settings-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: white;
    font-size: 24px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: none;
    line-height: 1;
}

#settings-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

#menu-btn {
    position: absolute;
    top: 8px;
    right: 56px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: white;
    font-size: 24px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: none;
    line-height: 1;
}

#menu-btn:hover {
    background: rgba(0, 0, 0, 0.7);
}

#settings-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 20;
    gap: 16px;
    color: white;
}

#settings-overlay h2 {
    font-size: clamp(24px, 5vw, 40px);
    margin: 0;
    color: #F7E414;
    text-shadow: 2px 2px 0 #000;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: clamp(16px, 3vw, 24px);
}

.settings-row input[type="range"] {
    width: 160px;
    accent-color: #F7E414;
    cursor: pointer;
}

#speed-value {
    min-width: 50px;
    text-align: center;
    font-size: clamp(16px, 3vw, 24px);
    color: #4FC3F7;
}

#settings-close-btn {
    margin-top: 12px;
}

/* Landscape Mobile Fixes */
@media (max-height: 500px) and (orientation: landscape) {

    body {
        background-color: #000;
    }

    #game-container {
        width: 100vw;
        max-height: 100dvh;
        box-shadow: none;
    }

    #select-screen,
    #start-screen,
    #game-over-screen {
        padding: 10px;
        /* Minimal padding */
        border-width: 2px;
    }

    #select-screen h1 {
        font-size: 28px;
        margin-bottom: 4px;
    }

    #select-screen p {
        font-size: 14px;
        margin-bottom: 8px;
    }

    #select-cards {
        gap: 8px;
    }

    .select-card {
        padding: 6px 10px;
        min-width: 110px;
        border-width: 2px;
        box-shadow: none;
        /* Reduce visual noise */
    }

    .card-icon {
        font-size: 28px;
    }

    .card-title {
        font-size: 12px;
        margin-top: 2px;
        text-shadow: 1px 1px 0 #000;
    }

    .card-desc {
        display: none;
        /* Hide descriptions to fit screen */
    }

    #start-screen h1,
    #game-over-screen h1 {
        font-size: 36px;
        margin-bottom: 10px;
    }

    button {
        font-size: 18px;
        padding: 6px 16px;
        border-width: 2px;
    }

    /* Start Button Scaling */
    #start-btn,
    #restart-btn {
        margin-top: 5px;
    }
}