@font-face {
    font-family: 'Mega Man 2';
    src: url('assets/megaman_2.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --menu-btn-size: clamp(44px, 5vw, 72px);
    --menu-btn-offset-y: max(16px, env(safe-area-inset-top));
    --menu-btn-offset-x: max(16px, env(safe-area-inset-left));
}

body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% -10%, #0a56d6 0%, #0344b9 55%, #022a70 100%);
    font-family: 'Mega Man 2', 'Courier New', Courier, monospace;
    color: #ffffff;
    padding: 24px 16px;
    overflow-x: hidden;
}

.container {
    width: 100%;
    max-width: 780px;
    text-align: center;
    padding: 24px;
}

.hidden {
    display: none;
}

h1 {
    font-size: clamp(3rem, 5vw, 4rem);
    letter-spacing: 2px;
    text-transform: uppercase;
    text-shadow: 3px 3px 0 #00236b;
    overflow-wrap: break-word;
    word-break: break-word;
}

.home-view {
    width: 100%;
    max-width: 780px;
    text-align: center;
    padding: 24px;
    background: rgba(0, 20, 70, 0.35);
    border: 3px solid #ffffff;
    border-radius: 10px;
    box-shadow: inset 0 0 0 3px #b8c4d8;
}

.home-title {
    font-size: clamp(3rem, 5vw, 4rem);
    letter-spacing: 2px;
    text-transform: uppercase;
    text-shadow: 3px 3px 0 #00236b;
    overflow-wrap: break-word;
    word-break: break-word;
}

.flavor-text {
    margin-top: 28px;
    color: #b8c4d8;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
}

.game-covers {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
}

.cover-card {
    width: 220px;
    padding: 0;
    background: rgba(0, 20, 70, 0.35);
    border: 3px solid #ffffff;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    font-family: inherit;
    color: #ffffff;
    box-shadow: inset 0 0 0 3px #b8c4d8, 0 6px 14px rgba(0, 15, 50, 0.5);
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, filter 0.25s ease, opacity 0.25s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.game-covers.dimming .cover-card:not(.preview-active) {
    filter: grayscale(85%);
    opacity: 0.6;
}

.cover-card:hover {
    transform: translateY(-4px);
    border-color: #F0B838;
    box-shadow: inset 0 0 0 3px #b8c4d8, 0 10px 18px rgba(0, 15, 50, 0.55);
}

.cover-card img {
    display: block;
    width: 100%;
    height: 220px;
    object-fit: cover;
}

.cover-card .cover-title {
    display: block;
    padding: 10px 8px;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.25);
}

.cover-card.no-cover {
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cover-card.no-cover .cover-title {
    background: none;
    font-size: 1.3rem;
}

.cover-card:focus-visible {
    outline: 3px solid #F0B838;
    outline-offset: 2px;
}

@media (max-width: 640px) {
    .cover-card {
        width: 45%;
        min-width: 140px;
    }

    .cover-card img,
    .cover-card.no-cover {
        height: 160px;
    }
}

.subtitle {
    margin-top: 8px;
    margin-bottom: 28px;
    color: #dce4ed;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-size: clamp(1.5rem, 5vw, 1.9rem);
}

.boss-grid {
    --cols: 4;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 18px;
}

.boss-card {
    width: calc((100% - (var(--cols) - 1) * 18px) / var(--cols));
    min-width: 160px;
    background: rgba(0, 20, 70, 0.35);
    border: 3px solid #ffffff;
    border-radius: 10px;
    padding: 18px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    cursor: grab;
    box-shadow: inset 0 0 0 3px #b8c4d8, 0 6px 14px rgba(0, 15, 50, 0.5);
    -webkit-tap-highlight-color: transparent;
    /* drag handling is fully custom (see attachDragHandlers), so disable native
       touch scrolling/zooming here rather than letting it race with pickup */
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.boss-card:hover {
    transform: translateY(-4px);
    border-color: #F0B838;
    box-shadow: inset 0 0 0 3px #b8c4d8, 0 10px 18px rgba(0, 15, 50, 0.55);
}

.boss-card.locked {
    border-color: #b8c4d8;
    background: rgba(0, 30, 90, 0.5);
    opacity: 0.8;
    cursor: not-allowed;
}

.boss-card.locked:hover {
    transform: none;
    border-color: #b8c4d8;
    box-shadow: inset 0 0 0 3px #b8c4d8, 0 6px 14px rgba(0, 15, 50, 0.5);
}

.boss-card.drop-target {
    border-color: #F0B838;
    transform: scale(1.05);
    box-shadow: inset 0 0 0 3px #F0B838, 0 0 16px rgba(240, 184, 56, 0.6);
}

.boss-card.dragging {
    opacity: 0.9;
    cursor: grabbing;
    box-shadow: inset 0 0 0 3px #b8c4d8, 0 16px 28px rgba(0, 10, 35, 0.6);
}

.lock-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: 10px auto 0;
    font-size: 1.4rem;
    background: rgba(0, 0, 0, 0);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    filter: grayscale(60%);
    transition: filter 0.15s ease, transform 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.lock-btn:hover {
    filter: none;
    background: rgba(0, 0, 0, 0);
    transform: scale(1.15);
}

.portrait-frame {
    width: 96px;
    height: 96px;
    display: block;
    margin: 0 auto 10px;
    background: #000000;
    border: 4px solid #ffffff;
    border-radius: 6px;
    box-shadow: 0 0 0 3px #b8c4d8;
    position: relative;
}

.portrait-frame img {
    width: 96px;
    height: 96px;
    display: block;
    image-rendering: pixelated;
}

.portrait-frame .quick-man-portrait {
    width: 132px;
    height: 138px;
    position: absolute;
    left: -18px;
    top: -24px;
}

.boss-card .order {
    display: inline-block;
    min-width: 24px;
    padding: 2px 8px;
    margin-bottom: 8px;
    color: #0344b9;
    background: #ffffff;
    border-radius: 12px;
    font-weight: bold;
}

.boss-card .name {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2.4em;
    font-size: 1rem;
    font-weight: bold;
    text-transform: uppercase;
    line-height: 1.2;
}

#shuffle-btn {
    margin-top: 32px;
    padding: 12px 36px;
    max-width: 100%;
    font-family: inherit;
    font-size: clamp(1.4rem, 7vw, 2.2rem);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #0344b9;
    background: #ffffff;
    border: 3px solid #b8c4d8;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 4px 4px 0 #00236b;
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.1s ease;
    overflow-wrap: break-word;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

#shuffle-btn:hover {
    transform: translateY(-4px);
    background: #F0B838;
    box-shadow: inset 0 0 0 3px #b8c4d8, 0 10px 18px rgba(0, 15, 50, 0.55);
}

#shuffle-btn:active {
    transform: translateY(2px);
    box-shadow: 2px 2px 0 #00236b;
}

#shuffle-btn:focus-visible,
.lock-btn:focus-visible,
.boss-card:focus-visible {
    outline: 3px solid #F0B838;
    outline-offset: 2px;
}

#menu-btn {
    position: fixed;
    top: var(--menu-btn-offset-y);
    left: var(--menu-btn-offset-x);
    z-index: 30;
    width: var(--menu-btn-size);
    height: var(--menu-btn-size);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 20, 70, 0.6);
    border: 3px solid #ffffff;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    box-shadow: 0 4px 10px rgba(0, 15, 50, 0.5);
    transition: transform 0.15s ease, border-color 0.15s ease;
}

#menu-btn:hover {
    border-color: #F0B838;
    transform: translateY(-2px);
}

#menu-btn img {
    width: 55%;
    height: 55%;
    image-rendering: pixelated;
}

.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 10, 35, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
}

.menu-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.game-menu {
    position: fixed;
    top: 0;
    left: 0;
    /* dvh tracks the real visible viewport (mobile browser chrome shrinks/grows
       100vh), otherwise the bottom of the panel — the donate button — can end
       up sized off-screen with nothing left to actually scroll */
    height: 100vh;
    height: 100dvh;
    width: min(260px, 78vw);
    background: #022a70;
    border-right: 3px solid #ffffff;
    box-shadow: 6px 0 18px rgba(0, 10, 35, 0.6);
    padding: calc(var(--menu-btn-offset-y) + var(--menu-btn-size) + 20px) 20px 20px calc(20px + var(--menu-btn-offset-x));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 25;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.game-menu.open {
    transform: translateX(0);
}

#home-btn {
    flex-shrink: 0;
    margin-bottom: 20px;
}

.game-menu-title {
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #dce4ed;
    margin-bottom: 16px;
    font-size: 1rem;
}

.game-list {
    flex-shrink: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-donate {
    flex-shrink: 0;
    margin-top: auto;
    padding-top: 40px;
    display: flex;
    justify-content: center;
}

.menu-donate form {
    width: 100%;
}

/* extra class beats the per-page inline <style> block's single-class rule */
.menu-donate .pp-8ZA954SJUMY6G {
    display: block;
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 44px;
    padding: 10px 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.95rem;
    color: #F0B838;
    background-color: rgba(255, 255, 255, 0.08);
    border: 2px solid #b8c4d8;
    border-radius: 6px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.menu-donate .pp-8ZA954SJUMY6G:hover {
    border-color: #F0B838;
    transform: translateX(4px);
}

.game-option {
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    min-height: 44px;
    font-family: inherit;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid #b8c4d8;
    border-radius: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, filter 0.25s ease, opacity 0.25s ease;
}

.game-list.dimming .game-option:not(.preview-active) {
    filter: grayscale(85%);
    opacity: 0.6;
}

.game-option:hover {
    border-color: #F0B838;
    transform: translateX(4px);
}

.game-option.active {
    background: #F0B838;
    border-color: #F0B838;
    color: #0344b9;
}

.portrait-frame.no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
}

.portrait-initials {
    font-size: 1.6rem;
    font-weight: bold;
    color: #b8c4d8;
}

/* prevent background scroll while the game menu overlay is open;
   the menu panel itself keeps its own overflow-y: auto */
html.menu-open,
body.menu-open {
    overflow: hidden;
    height: 100%;
}

@media (max-width: 640px) {
    .boss-grid {
        --cols: 2;
        gap: 12px;
    }

    .boss-card {
        min-width: 130px;
        padding: 12px 6px;
    }

    .portrait-frame,
    .portrait-frame img {
        width: 64px;
        height: 64px;
    }

    .portrait-frame .quick-man-portrait {
        width: 88px;
        height: 92px;
        left: -12px;
        top: -16px;
    }

    .boss-card .order {
        margin-bottom: 4px;
    }

    .boss-card .name {
        min-height: 2em;
        font-size: 0.85rem;
    }

    .lock-btn {
        width: 36px;
        height: 36px;
        margin-top: 6px;
        font-size: 1.2rem;
    }

    #shuffle-btn {
        margin-top: 20px;
    }

    .game-menu {
        width: min(240px, 82vw);
    }

    /* grid content often exceeds viewport height on mobile, pinning the
       container to the top, so reserve space below the fixed menu button */
    body {
        padding-top: max(72px, calc(env(safe-area-inset-top) + 60px));
    }

    /* long single words (e.g. "SHUFFLE") in the wide pixel font need real
       headroom below the shared clamp() or they force a mid-word break */
    h1,
    .home-title {
        font-size: clamp(1.7rem, 9vw, 3.2rem);
    }

    .container,
    .home-view {
        padding: 20px 16px;
    }
}

@media (max-width: 360px) {
    .boss-grid {
        --cols: 1;
        max-width: 220px;
        margin: 0 auto;
    }

    :root {
        --menu-btn-offset-y: max(12px, env(safe-area-inset-top));
        --menu-btn-offset-x: max(12px, env(safe-area-inset-left));
    }

    .game-menu {
        width: min(210px, 85vw);
        padding-left: calc(16px + var(--menu-btn-offset-x));
        padding-right: 16px;
    }

    h1,
    .home-title {
        font-size: clamp(1.4rem, 9vw, 2.4rem);
    }
}
