/* Hide game-only buttons on the start screen */
.game-container:has(#startScreen:not(.d-none)) #pauseBtn,
.game-container:has(#startScreen:not(.d-none)) #menuBtn {
    display: none;
}

.game-menu {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 60;
    font-family: 'Rye', cursive;
}


/* How to Play dialog: fit inside the game screen */
#infoDialog .dialog-card {
    box-sizing: border-box;
    width: min(90%, 520px);
    max-height: min(92%, 540px);
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#infoDialog .dialog-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 6px 4px;
    text-align: center;
}

/* Slim western-style scrollbars for readable dialog content. */
#infoDialog .dialog-content,
.legal-content {
    scrollbar-width: thin;
    scrollbar-color: #c58a3a rgba(48, 28, 13, 0.9);
    scroll-behavior: smooth;
}

#infoDialog .dialog-content::-webkit-scrollbar,
.legal-content::-webkit-scrollbar {
    width: 8px;
}

#infoDialog .dialog-content::-webkit-scrollbar-track,
.legal-content::-webkit-scrollbar-track {
    background: rgba(48, 28, 13, 0.9);
    border-radius: 8px;
}

#infoDialog .dialog-content::-webkit-scrollbar-thumb,
.legal-content::-webkit-scrollbar-thumb {
    background: linear-gradient(#e0ad55, #8a4d20);
    border: 1px solid #f6d47b;
    border-radius: 8px;
}

#infoDialog .dialog-content::-webkit-scrollbar-thumb:hover,
.legal-content::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(#f2c46e, #a96028);
}

#infoDialog .dialog-content:focus-visible,
.legal-content:focus-visible {
    outline: 2px solid #f6d47b;
    outline-offset: 3px;
}

#infoDialog .dialog-content h3 {
    margin: 10px 0 4px;
    font-size: 18px;
}

#infoDialog .dialog-content p {
    margin: 4px 0;
    font-size: 15px;
    line-height: 1.3;
}

#infoDialog .dialog-card h2 {
    margin: 0 0 12px;
    font-size: 24px;
}

#infoDialog .guide-section-heading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

#infoDialog .guide-icon,
#infoDialog .guide-icon-pair {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
}

#infoDialog .guide-icon {
    object-fit: contain;
}

#infoDialog .guide-icon-pair {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#infoDialog .guide-icon-pair .guide-icon {
    width: 22px;
    height: 22px;
}

#infoDialog .guide-copy-with-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

#infoDialog .guide-copy-with-icon .guide-icon {
    width: 26px;
    height: 26px;
    flex-basis: 26px;
}

/* Pepe loading animation */
#loadingScreen {
    position: absolute;
    inset: 0;
    z-index: 40;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: black;
}

#loadingPepe {
    width: auto;
    height: 180px;
    object-fit: contain;
}

/* Hide touch controls on the result screen. Controls live beside game-container. */
body:has(#restartScreen:not(.d-none)) .mobile-controls-container {
    display: none !important;
}

/* Legal Notice dialog */
.legal-card {
    width: 90%;
    max-width: 520px;
    max-height: 85%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.legal-card h2 {
    flex-shrink: 0;
}

.legal-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 10px;
    text-align: left;
    line-height: 1.5;
    font-size: 14px;
    overscroll-behavior: contain;
}

.legal-content h3 {
    color: #ff9800;
    font-size: 15px;
    margin: 16px 0 8px;
}

.legal-content a {
    color: #ff9800;
}

/* Start screen music player */
.bgm-menu {
    position: absolute;
    top: 8px;
    left: 12px;
    z-index: 25;
    font-family: 'Rye', cursive;
}

.bgm-menu.d-none {
    display: none !important;
}

/* Main Menu and BGM buttons */
.game-menu summary,
.bgm-menu summary {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 106px;
    min-width: 106px;
    height: 48px;
    padding: 0 14px;
    background: #422512;
    color: white;
    border: 3px solid white;
    border-radius: 16px;
    font-family: 'Rye', cursive;
    font-size: 20px;
    cursor: pointer;
    list-style: none;
    transition: transform 0.15s ease, background-color 0.15s ease;
}

/* Hover effect for BGM and Menu */
.game-menu summary:hover,
.bgm-menu summary:hover {
    transform: scale(1.05);
    background-color: #60371e;
}

/* Bright effect when pressed */
.game-menu summary:active,
.bgm-menu summary:active {
    transform: scale(0.98);
    background-color: #85502a;
}

.game-menu summary::-webkit-details-marker,
.bgm-menu summary::-webkit-details-marker {
    display: none;
}

/* Dropdown panels fit their respective menu content without excess side space. */
.game-menu .top-nav-bar,
.bgm-panel {
    max-height: 70dvh;
    box-sizing: border-box;
    padding: 10px;
    color: #ffe3a3;
    background: rgba(32, 20, 13, 0.96);
    border: 2px solid #a76d33;
    border-radius: 10px;
    overflow-y: auto;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    backdrop-filter: none;
}

.game-menu .top-nav-bar {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: min(176px, calc(100vw - 24px));
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.bgm-panel {
    margin-top: 6px;
    width: min(200px, calc(100vw - 24px));
}

.bgm-panel h3 {
    margin: 0 0 8px;
    font-size: 16px;
    text-align: center;
}

/* Both dropdowns share the same item style. */
.game-menu .nav-icon-btn,
.playlist-track {
    display: block;
    width: 100%;
    height: auto;
    box-sizing: border-box;
    min-height: 38px;
    padding: 8px 7px;
    color: #f2dfc4;
    background: transparent;
    border: none;
    border-radius: 5px;
    font-family: 'Rye', cursive;
    font-size: 14px;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
    transform: none;
}

.game-menu .nav-icon-btn:hover,
.playlist-track:hover,
.playlist-track.is-playing {
    color: #ffd166;
    background: rgba(255, 209, 102, 0.15);
    transform: none;
}

.bgm-player-controls,
.bgm-player-options {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}

.bgm-player-controls button,
.bgm-player-options button {
    min-height: 34px;
    padding: 6px 8px;
    color: #ffe3a3;
    background: #70401d;
    border: 1px solid #a76d33;
    border-radius: 5px;
    font-family: inherit;
    cursor: pointer;
}

.bgm-player-options button {
    flex: 1;
    min-width: 0;
    font-size: 11px;
    white-space: nowrap;
}


/* Western wooden Menu and BGM buttons */
.game-menu > summary,
.bgm-menu > summary {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;

    min-width: 115px;
    padding: 10px 18px;

    background:
        repeating-linear-gradient(
            0deg,
            transparent 0 11px,
            rgba(70, 30, 10, 0.18) 12px 14px,
            transparent 15px 24px
        ),
        linear-gradient(
            180deg,
            #df943f 0%,
            #b96729 48%,
            #854019 100%
        );

    color: #fff1cf;
    font-size: 21px;
    font-weight: 800;
    text-shadow: 2px 2px 0 #4b220d;

    border: 4px solid #54270f;
    border-radius: 14px;

    box-shadow:
        inset 0 3px 0 #f4b760,
        inset 0 -4px 0 #622d13,
        0 5px 0 #351808;

    cursor: pointer;
    list-style: none;
    transition: filter 0.2s ease;
}

.game-menu > summary::-webkit-details-marker,
.bgm-menu > summary::-webkit-details-marker {
    display: none;
}

.game-menu > summary:hover,
.bgm-menu > summary:hover {
    filter: brightness(1.12);
}

.game-menu[open] > summary,
.bgm-menu[open] > summary {
    filter: brightness(0.9);
}

/* Keep BGM and Menu buttons exactly the same size */
.game-menu > summary,
.bgm-menu > summary {
    box-sizing: border-box;
    width: 108px;
    height: 50px;
    min-width: 108px;
    min-height: 50px;
    padding: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    white-space: nowrap;
    flex-wrap: nowrap;
    gap: 5px;
    line-height: 1;
}

/* Align BGM vertically with Menu */
.bgm-menu {
    transform: translateY(4px);
}

/* Keep compact top controls limited to the start screen and active game UI. */
.game-container:has(#startScreen:not(.d-none)) .game-menu > summary,
.game-container:has(#startScreen:not(.d-none)) .bgm-menu > summary,
.game-container:has(#startScreen.d-none) .game-menu > summary {
    width: 76px;
    min-width: 76px;
    min-height: 35px;
    height: 35px;
    padding: 0 9px;
    border-width: 2px;
    border-radius: 9px;
    box-shadow:
        inset 0 2px 0 #e4a858,
        inset 0 -2px 0 #5a2c12,
        0 3px 0 #351808;
    font-size: 15px;
}

/* The playlist belongs to the start screen. Game music is still controlled in Menu. */
.game-container:has(#startScreen.d-none) .bgm-menu {
    display: none;
}

/* The Menu credits view reuses the ending screen but exposes only its Back action. */
#restartScreen.menu-credits-mode #retryLevelBtn,
#restartScreen.menu-credits-mode #restartBtn,
#restartScreen.menu-credits-mode #homeBtn {
    display: none;
}

.game-container:has(#startScreen:not(.d-none)) .game-menu > summary:focus-visible,
.game-container:has(#startScreen:not(.d-none)) .bgm-menu > summary:focus-visible,
.game-container:has(#startScreen.d-none) .game-menu > summary:focus-visible,
#startBtn.is-keyboard-selected {
    outline: 3px solid #f2cf83;
    outline-offset: 3px;
}


/* Earned sombreros use the original one-icon-per-reward display. */
#sombreroCounter {
    position: absolute;
    top: 64px;
    right: 20px;
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    max-width: 180px;
    pointer-events: none;
}

/* The run-wide coin statistic remains visible even before a sombrero is earned. */
#coinCollectedCounter {
    position: absolute;
    top: 112px;
    right: 20px;
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 5px;
    color: #ffe3a3;
    font-family: 'Rye', cursive;
    font-size: 16px;
    line-height: 26px;
    text-shadow: 1px 1px 0 #351808;
    pointer-events: none;
}

#coinCollectedCounter img {
    width: 26px;
    height: 26px;
    object-fit: contain;
}

.sombrero-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    display: block;
}

#gameContainer:not(:has(#sombreroCounter .sombrero-icon)) #coinCollectedCounter {
    top: 64px;
}

/* Sombrero retry button */
#retryLevelBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    padding: 12px 20px;
    background: #70401d;
    color: white;
    border: 3px solid white;
    border-radius: 30px;

    font-family: 'Rye', cursive;
    font-size: 18px;
    white-space: nowrap;
    cursor: pointer;
}

#retryLevelBtn img {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

#retryLevelBtn:hover {
    background: #85502a;
    transform: scale(1.03);
}

#retryLevelBtn.d-none {
    display: none !important;
}

#sombreroRewardImage + p {
    margin-top: 4px;
}

.ending-reward-screen {
    z-index: 35;
    padding: 8px;
    background: rgba(13, 9, 6, 0.9);
}

.ending-reward-screen .level-rules-card {
    padding: 8px;
    gap: 8px;
}

.ending-reward-media {
    display: block;
    width: min(700px, 100%);
    max-height: 72%;
    object-fit: contain;
    margin: 0 auto 8px;
    background: #000;
    filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

.credits-paused .credit-entry {
    animation-play-state: paused;
}

.revive-message {
    position: absolute;
    left: 50%;
    top: 24%;
    z-index: 30;
    padding: 10px 16px;
    color: #ffe3a3;
    background: rgba(53, 24, 8, 0.9);
    border: 2px solid #f2cf83;
    border-radius: 8px;
    font-family: 'Rye', cursive;
    font-size: clamp(16px, 3vw, 26px);
    text-shadow: 2px 2px 0 #351808;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.revive-message.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Global sound toggle and start screen keyboard guide */

.sound-toggle-btn {
    position: absolute;
    top: 12px;
    right: 96px;
    z-index: 60;
    width: 35px;
    height: 35px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

body:has(#loadingScreen) .sound-toggle-btn {
    display: none;
}

body:has(#loadingScreen) .game-menu {
    display: none;
}

.sound-toggle-btn img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.start-controls {
    position: absolute;
    left: 12px;
    bottom: 10px;
    z-index: 10;
}

.start-controls-guide {
    display: block;
    height: 96px; /* 기존 48px → 96px */
    width: auto;
    max-width: calc(100% - 24px);
    opacity: 0.7;
    object-fit: contain;
}
