@font-face {
    font-family: 'Rye';
    src: url('../fonts/rye-v17-latin-regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 0;
    background-color: #59331d;
    font-family: Arial, sans-serif;
    color: white;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    isolation: isolate;
}

body::before,
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    z-index: -1;
}

body::before {
    background-image: url('../img/9_intro_outro_screens/start/intro-backdrop.webp');
}

body::after {
    background-image: url('../img/9_intro_outro_screens/end/end-background.webp');
    opacity: 0;
    transition: opacity 1.5s ease;
}

body:has(#restartScreen:not(.d-none) #endCredits:not(.d-none))::after {
    opacity: 1;
}

.game-presentation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.game-presentation h1 {
    font-family: 'Rye', cursive, sans-serif;
    margin: 0;
    font-size: clamp(52px, 5vw, 56px);
    line-height: 1;
    letter-spacing: 4px;
    color: #f2cf83;
    text-shadow: 0 2px 0 #6a3714, 0 5px 14px rgba(26, 12, 4, 0.6);
}

.game-container {
    position: relative;
    width: 720px;
    height: 480px;
    margin: 0 auto;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.7);
}

canvas {
    background-color: black;
    display: block;
    width: 100%;
    height: 100%;
}

.top-nav-bar {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 6px;
    z-index: 25;
    background: rgba(0, 0, 0, 0.4);
    padding: 4px 8px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
}

.nav-icon-btn {
    background: rgba(0, 0, 0, 0.65);
    border: 2px solid #fff;
    color: #fff;
    font-size: 15px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
}

.nav-icon-btn:hover {
    transform: scale(1.1);
    background: #ff9800;
}

.pause-title {
    font-family: 'Rye', cursive, sans-serif;
    font-size: 38px;
    color: #ff9800;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px #000;
}

.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    background: rgba(0, 0, 0, 0.75);
}

.start-screen-layout {
    background: transparent;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0 42px 34px;
    box-sizing: border-box;
}

.start-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    object-fit: cover;
}

.end-result-img {
    max-width: 440px;
    max-height: 180px;
    object-fit: contain;
    margin-bottom: 20px;
}

.end-buttons-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 2;
}

.end-revive-row,
.end-secondary-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

.end-revive-row:has(#retryLevelBtn.d-none) {
    display: none;
}

.end-secondary-row .western-ending-button {
    min-width: 150px;
}

.end-credits {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #21120e;
}

.end-bg {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.credits-copy {
    position: absolute;
    inset: 20% 12% 18%;
    display: grid;
    place-items: center;
    pointer-events: none;
}

.credit-entry {
    position: absolute;
    width: min(100%, 560px);
    margin: 0;
    color: #fff8df;
    font-family: 'Rye', cursive, sans-serif;
    font-size: clamp(18px, 3.2vw, 32px);
    line-height: 1.35;
    text-align: center;
    text-shadow: 0 3px 10px #160700, 0 0 16px rgba(0, 0, 0, 0.9);
    opacity: 0;
    animation: credit-cycle 90s ease-in-out infinite;
    animation-delay: var(--credit-delay, 0s);
}

.credit-role,
.credit-name,
.credit-note {
    display: block;
}

.credit-role {
    margin-bottom: 7px;
    color: #d9ad61;
    font-family: Arial, sans-serif;
    font-size: 0.48em;
    font-weight: 800;
    letter-spacing: 0.16em;
}

.credit-name {
    font-weight: 400;
}

.credit-note {
    margin-top: 9px;
    color: #fff5db;
    font-family: Arial, sans-serif;
    font-size: 0.53em;
    font-style: normal;
    line-height: 1.45;
}

@keyframes credit-cycle {
    0%, 0.72% { opacity: 0; transform: translateY(14px); }
    1.35%, 4.05% { opacity: 1; transform: translateY(0); }
    5%, 100% { opacity: 0; transform: translateY(-14px); }
}

#restartScreen:has(.end-credits:not(.d-none)) {
    justify-content: flex-end;
    align-items: center;
    padding: 0 24px 18px;
    box-sizing: border-box;
}

#restartScreen:has(.end-credits:not(.d-none)) .end-buttons-group {
    align-self: center;
}

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

.western-action-button {
    font-family: 'Rye', cursive, sans-serif;
    min-height: 44px;
    padding: 9px 19px;
    color: #f7e7bf;
    background:
        linear-gradient(90deg, rgba(255, 225, 161, 0.08), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.2)),
        linear-gradient(180deg, #65432b 0%, #422719 55%, #2b180f 100%);
    border: 1px solid #d1a55e;
    border-radius: 8px;
    cursor: pointer;
    box-shadow:
        inset 0 1px 0 rgba(255, 235, 190, 0.25),
        inset 0 -1px 0 rgba(0, 0, 0, 0.45),
        0 4px 9px rgba(0, 0, 0, 0.45);
    text-shadow: 1px 1px 0 #26130b;
    transition: background 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.western-start-button {
    min-width: 156px;
    font-size: 18px;
    letter-spacing: 1.1px;
}

/* Make the initial keyboard target easy to recognize without affecting other actions. */
#startBtn {
    position: relative;
    overflow: hidden;
}

#startBtn::after {
    content: '';
    position: absolute;
    inset: -35% auto -35% -45%;
    width: 28%;
    background: linear-gradient(90deg, transparent, rgba(255, 236, 167, 0.75), transparent);
    transform: skewX(-22deg);
    animation: start-button-sweep 2.8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes start-button-sweep {
    0%, 38% { left: -45%; }
    68%, 100% { left: 120%; }
}

@media (prefers-reduced-motion: reduce) {
    #startBtn::after { animation: none; }
}

.western-ending-button {
    min-height: 40px;
    min-width: 0;
    padding: 7px 12px;
    font-size: 14px;
    letter-spacing: 0.55px;
}

.western-action-button:hover {
    background:
        linear-gradient(90deg, rgba(255, 225, 161, 0.14), transparent 22%, transparent 78%, rgba(0, 0, 0, 0.16)),
        linear-gradient(180deg, #765037 0%, #50311f 55%, #301b10 100%);
    box-shadow:
        inset 0 1px 0 rgba(255, 240, 200, 0.32),
        inset 0 -1px 0 rgba(0, 0, 0, 0.4),
        0 5px 11px rgba(0, 0, 0, 0.52);
    transform: translateY(-1px);
}

.western-action-button:focus-visible {
    outline: 3px solid #f2cf83;
    outline-offset: 3px;
}

.western-action-button:active {
    transform: translateY(1px);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
}

.story-video-screen {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: #000;
}

.story-video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.story-video-skip {
    position: absolute;
    right: 16px;
    bottom: 16px;
    padding: 8px 14px;
    color: #fff;
    background: rgba(0, 0, 0, 0.65);
    border: 2px solid #fff;
    border-radius: 20px;
    font-family: 'Rye', cursive;
    font-size: 14px;
    cursor: pointer;
}

.volume-control-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin: 15px 0;
    font-size: 15px;
    width: 100%;
}

.volume-control-row label {
    margin-bottom: 8px;
    color: #ff9800;
    font-weight: bold;
}

.volume-control-row input[type="range"] {
    width: 100%;
    accent-color: #ff9800;
    cursor: pointer;
}

.dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 30;
}

.dialog-card {
    position: relative;
    background: #232323;
    border: 3px solid #ff9800;
    border-radius: 12px;
    padding: 20px 26px;
    width: 360px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.dialog-card h2 {
    font-family: 'Rye', cursive, sans-serif;
    color: #ff9800;
    font-size: 20px;
    margin-top: 5px;
    margin-bottom: 15px;
    padding-inline: 32px;
}

.dialog-close-btn {
    position: absolute;
    top: 10px;
    left: 12px;
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    width: 28px;
    height: 28px;
    padding: 0;
    line-height: 1;
    display: grid;
    place-items: center;
    cursor: pointer;
}

/* Keep every existing keyboard control visibly focused in the Western UI. */
.game-container button:focus-visible,
.game-container summary:focus-visible,
.game-container input[type='range']:focus-visible {
    outline: 3px solid #f2cf83;
    outline-offset: 3px;
}

/* Keep the selected top Menu and BGM buttons visible after closing a dialog. */
.game-container summary:focus {
    outline: 3px solid #f2cf83;
    outline-offset: 3px;
}

.key-badge {
    background: #444;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid #777;
    font-weight: bold;
    color: #ff9800;
}

.mobile-controls-container {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
    z-index: 20;
}

.touch-group-left, .touch-group-right {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 12px;
    pointer-events: auto;
}

.touch-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.45);
    border: 2px solid rgba(255, 255, 255, 0.8);
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    cursor: pointer;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
}

.touch-btn:active {
    background: rgba(255, 152, 0, 0.7);
    transform: scale(0.95);
}

.turn-device-overlay {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: #111;
    z-index: 999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
}

.turn-device-overlay h2 {
    font-family: 'Rye', cursive, sans-serif;
    color: #ff9800;
}

.turn-icon {
    font-size: 55px;
    margin-bottom: 15px;
    animation: rotateDevice 2s infinite ease-in-out;
}

@keyframes rotateDevice {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}
