/* Local Font Definitions (100% Offline Support) */
@font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 300;
    font-display: swap;
    src: url('./fonts/outfit-300.ttf') format('truetype');
}
@font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./fonts/outfit-400.ttf') format('truetype');
}
@font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('./fonts/outfit-600.ttf') format('truetype');
}
@font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 800;
    font-display: swap;
    src: url('./fonts/outfit-800.ttf') format('truetype');
}
@font-face {
    font-family: 'Rye';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./fonts/rye-400.ttf') format('truetype');
}

/* General Styles & Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

html {
    background: radial-gradient(circle at center, #2e1d15 0%, #130a06 100%);
    min-height: 100vh;
    overflow-y: auto;
    touch-action: manipulation;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: radial-gradient(circle at center, #2e1d15 0%, #130a06 100%);
    color: #f7e6d4;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: visible;
    touch-action: manipulation;
}

#game-container {
    position: relative;
    width: 100vw;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-image: radial-gradient(rgba(0, 0, 0, 0.4) 1px, transparent 1px);
    background-size: 24px 24px;
}

/* Background Dust Particles */
#dust-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    opacity: 0.3;
}

/* Screen Transitions */
.screen {
    position: relative;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    padding: 0.8rem;
    z-index: 2;
    animation: fadeIn 0.4s ease-out forwards;
    margin: auto; /* Vertically and horizontally center screens, safely handling overflow */
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* Western Typography */
.western-title {
    font-family: 'Rye', 'Impact', 'Trebuchet MS', serif;
    font-size: 3.2rem;
    color: #e5a93b;
    text-shadow: 0 3px 0 #6e4313, 0 6px 10px rgba(0, 0, 0, 0.8), 0 0 30px rgba(229, 169, 59, 0.2);
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: titleFloat 4s ease-in-out infinite;
}

.victory-title {
    font-family: 'Rye', serif;
    font-size: 3.8rem;
    color: #d4af37;
    text-shadow: 0 0 30px rgba(212, 175, 55, 0.4), 0 6px 12px rgba(0, 0, 0, 0.9);
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    text-align: center;
}

.subtitle {
    font-size: 1.0rem;
    color: #c5a880;
    margin-bottom: 1.2rem;
    font-weight: 300;
    letter-spacing: 4px;
    text-transform: uppercase;
}

@keyframes titleFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Buttons */
.btn {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    padding: 0.8rem 1.6rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                box-shadow 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                border-color 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                color 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                background-color 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    will-change: transform;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-large {
    padding: 1.2rem 2.8rem;
    font-size: 1.2rem;
    font-weight: 800;
    border-radius: 12px;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

.btn-primary {
    background: rgba(74, 46, 36, 0.8);
    color: #f7e6d4;
    border: 1px solid #6e4313;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.btn-primary:hover {
    background: #6e4313;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.btn-primary.selected {
    background: #8b521b;
    border-color: #e5a93b;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.3);
}

.btn-gold {
    background: transparent;
    color: #e5a93b;
    font-weight: 800;
    border: 2px solid #d4af37;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

.btn-gold:hover {
    border-color: #e5a93b;
    color: #fff;
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.4);
}

.btn-gold:active {
    transform: translateY(1px) scale(0.98);
}

.btn-danger {
    background: rgba(139, 37, 37, 0.8);
    color: #ffd2d2;
    border: 1px solid #ff4d4d;
}

.btn-danger:hover {
    background: #9d2525;
    box-shadow: 0 0 15px rgba(255, 77, 77, 0.4);
}

.btn-icon {
    font-size: 1.2em;
}

.menu-sections {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.8rem;
    width: 95%;
    max-width: 1200px;
    margin-bottom: 1.0rem;
}

/* Weapon Select Styling */
.weapon-selections-container {
    display: flex;
    gap: 1rem;
    height: 100%;
}

.weapon-select-col {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.weapon-select-col h3 {
    font-size: 0.85rem;
    color: #c5a880;
    margin-bottom: 0.6rem;
    text-align: center;
    border-bottom: 1px dashed rgba(110, 67, 19, 0.2);
    padding-bottom: 0.2rem;
}

.weapon-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.weapon-btn {
    font-size: 0.75rem !important;
    padding: 0.5rem !important;
    width: 100%;
    text-align: center;
    border-radius: 6px;
}

.weapon-btn.p1-wep-active {
    background: #a06e30;
    border-color: #ffffff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
    color: #fff;
}

.weapon-btn.p2-wep-active {
    background: #a06e30;
    border-color: #e5a93b;
    box-shadow: 0 0 10px rgba(229, 169, 59, 0.3);
    color: #fff;
}


.menu-section {
    flex: 1 1 200px;
    max-width: 260px;
    border: 1px solid rgba(110, 67, 19, 0.4);
    border-radius: 12px;
    padding: 0.8rem;
    position: relative;
    z-index: 2;
}

.menu-section::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(30, 18, 12, 0.7);
    border-radius: 12px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: -1;
    pointer-events: none;
}

.menu-section h2 {
    font-family: 'Rye', serif;
    font-size: 1.15rem;
    color: #c5a880;
    margin-bottom: 0.6rem;
    border-bottom: 1px solid rgba(110, 67, 19, 0.3);
    padding-bottom: 0.4rem;
    text-transform: uppercase;
}

.game-modes {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    justify-content: center;
}

.level-grid, .difficulty-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.35rem;
    max-height: 180px;
    overflow-y: auto;
    padding-right: 0.2rem;
}
.level-grid::-webkit-scrollbar, .difficulty-grid::-webkit-scrollbar {
    width: 6px;
}
.level-grid::-webkit-scrollbar-track, .difficulty-grid::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}
.level-grid::-webkit-scrollbar-thumb, .difficulty-grid::-webkit-scrollbar-thumb {
    background: rgba(110, 67, 19, 0.6);
    border-radius: 3px;
}
.level-grid::-webkit-scrollbar-thumb:hover, .difficulty-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(229, 169, 59, 0.6);
}

.level-card, .difficulty-card {
    background: rgba(50, 31, 23, 0.5);
    border: 1px solid rgba(110, 67, 19, 0.3);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    text-align: left;
    transition: transform 0.2s ease, border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #f7e6d4;
    will-change: transform;
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.level-card:hover, .difficulty-card:hover {
    background: rgba(110, 67, 19, 0.3);
    border-color: rgba(212, 175, 55, 0.5);
    transform: translateX(2px);
}

.level-card.active, .difficulty-card.active {
    background: rgba(139, 82, 27, 0.4);
    border-color: #e5a93b;
    box-shadow: inset 0 0 8px rgba(212, 175, 55, 0.2);
}

.level-num, .difficulty-num {
    font-family: 'Rye', serif;
    font-size: 1.1rem;
    color: #e5a93b;
    min-width: 24px;
    text-align: center;
    border-right: 1px solid rgba(110, 67, 19, 0.3);
    padding-right: 0.4rem;
}

.level-name, .difficulty-name {
    font-weight: 600;
    font-size: 0.82rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.level-desc, .difficulty-desc {
    display: none; /* Hide descriptions to keep layout compact */
}

/* Keyboard Cheat Sheet Compact */
.controls-cheat-sheet-compact {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 900px;
    margin-bottom: 1.2rem;
    font-size: 0.82rem;
    color: #bfa17c;
    border: 1px dashed rgba(110, 67, 19, 0.4);
    border-radius: 8px;
    padding: 0.5rem 1.5rem;
    position: relative;
    z-index: 2;
}

.controls-cheat-sheet-compact::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(30, 18, 12, 0.6);
    border-radius: 8px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: -1;
    pointer-events: none;
}

.controls-cheat-sheet-compact strong {
    color: #fff;
    background: rgba(110, 67, 19, 0.45);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.85rem;
}

.sheet-divider {
    color: rgba(110, 67, 19, 0.5);
    font-weight: bold;
}

/* GAMEPLAY VIEWPORT */
#game-screen {
    justify-content: space-between;
    padding: 1.5rem;
}

#hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1100px;
    border: 2px solid #543310;
    border-radius: 16px;
    padding: 0.8rem 1.5rem;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 10;
}

#hud::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(30, 18, 12, 0.85);
    border-radius: 14px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    z-index: -1;
    pointer-events: none;
}

.hud-player {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.p1-hud { align-items: flex-start; }
.p2-hud { align-items: flex-end; }

.player-label {
    font-weight: 800;
    font-size: 1.1rem;
    color: #f7e6d4;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.p1-hud .player-label { color: #b5b5b5; }
.p2-hud .player-label { color: #ffffff; text-shadow: 0 0 5px rgba(255,255,255,0.2); }


.hearts {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    max-width: 280px;
}

.hp-count {
    font-family: 'Rye', serif;
    font-size: 1.5rem;
    color: #e5a93b;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    line-height: 1;
}

/* Sheriff star HP indicators */
.sheriff-star {
    width: 24px;
    height: 24px;
    background-color: #d4af37;
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    transition: background-color 0.3s ease, transform 0.3s ease, opacity 0.3s ease;
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.6);
}

.sheriff-star.lost {
    background-color: #3e2e28;
    box-shadow: none;
    transform: scale(0.8) rotate(45deg);
    opacity: 0.4;
}

#level-display {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

#level-display-name {
    font-family: 'Rye', serif;
    font-size: 1.2rem;
    color: #e5a93b;
    letter-spacing: 1px;
}

#wind-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #5ac8fa;
    background: rgba(10, 30, 40, 0.4);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    border: 1px solid rgba(90, 200, 250, 0.3);
}

#wind-arrow {
    display: inline-block;
    font-size: 1.1rem;
    transition: transform 0.5s ease;
}

.hidden {
    display: none !important;
}

/* Canvas styling */
#canvas-wrapper {
    position: relative;
    border: 6px solid #4a2e24;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), inset 0 0 20px rgba(0,0,0,0.6);
    overflow: hidden;
    margin: 0.5rem 0;
    background-color: #d2b48c; /* Fallback sandy brown */
    max-width: 90vw;
    max-height: calc(100vh - 200px); /* Leave room for HUD and control buttons */
    aspect-ratio: 1200 / 800; /* Keep aspect ratio aligned */
}

#canvas-wrapper::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.4);
    pointer-events: none;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#game-controls-bar {
    display: flex;
    gap: 1.5rem;
}

/* Overlays */
#game-over-screen, #pause-screen, #qr-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100;
}

#game-over-screen::before, #pause-screen::before, #qr-modal::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(19, 10, 6, 0.9);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    z-index: -1;
    pointer-events: none;
}

.game-over-buttons, .pause-buttons {
    display: flex;
    gap: 1.5rem;
}

/* Shake Animation for Hit effect */
.shake {
    animation: screenShake 0.15s ease-in-out 2;
}

@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-6px, 4px); }
    75% { transform: translate(6px, -4px); }
}

/* Upgrade Shop Styling */
.upgrade-shop {
    display: flex;
    flex-direction: column;
}

.shop-coins-header {
    font-family: 'Rye', serif;
    font-size: 1.05rem;
    color: #e5a93b;
    text-align: center;
    margin-bottom: 0.5rem;
    background: rgba(0, 0, 0, 0.45);
    padding: 0.3rem;
    border-radius: 8px;
    border: 1px dashed rgba(212, 175, 55, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.shop-coin-symbol {
    font-size: 1.1rem;
}

.shop-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 230px;
    overflow-y: auto;
    padding-right: 0.2rem;
}
.shop-list::-webkit-scrollbar {
    width: 5px;
}
.shop-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}
.shop-list::-webkit-scrollbar-thumb {
    background: rgba(110, 67, 19, 0.6);
    border-radius: 3px;
}
.shop-list::-webkit-scrollbar-thumb:hover {
    background: rgba(229, 169, 59, 0.6);
}

.shop-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(50, 31, 23, 0.5);
    border: 1px solid rgba(110, 67, 19, 0.3);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    gap: 0.4rem;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    will-change: transform;
    transform: translate3d(0, 0, 0);
}

.shop-item:hover {
    background: rgba(110, 67, 19, 0.25);
    border-color: rgba(212, 175, 55, 0.3);
}

.shop-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    text-align: left;
}

.shop-item-title {
    font-weight: 800;
    font-size: 0.85rem;
    color: #fff;
}

.shop-item-desc {
    font-size: 0.68rem;
    color: #bfa17c;
}

.status-inactive {
    color: #ff4d4d;
    font-weight: bold;
}

.status-active {
    color: #4cd964;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(76, 217, 100, 0.4);
}

.btn-shop {
    font-size: 0.75rem !important;
    padding: 0.3rem 0.6rem !important;
    min-width: 65px;
    border-radius: 6px;
}

/* Toast Notification */
.toast-notification {
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translate(-50%, -50px);
    background: rgba(44, 24, 16, 0.95);
    border: 2px solid #d4af37;
    color: #fff;
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    font-family: 'Rye', serif;
    font-size: 1.1rem;
    z-index: 10000;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.8), 0 0 15px rgba(212, 175, 55, 0.4);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}

.toast-notification.show {
    transform: translate(-50%, 0);
    opacity: 1;
}

/* Weapon Select Badges */
.weapon-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.8rem !important;
}

.wep-name {
    flex-grow: 1;
    text-align: left;
}

.wep-pts {
    background: rgba(0, 0, 0, 0.45);
    color: #e5a93b;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 800;
    margin-left: 0.5rem;
    border: 1px solid rgba(255, 215, 0, 0.2);
}

/* Coins Reward Banner */
.coins-reward-banner {
    font-family: 'Rye', serif;
    font-size: 1.5rem;
    color: #e5a93b;
    background: rgba(0, 0, 0, 0.55);
    border: 2px solid #d4af37;
    padding: 0.8rem 2rem;
    border-radius: 12px;
    margin: 1rem 0 2rem 0;
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.3);
    animation: rewardPulse 1.5s infinite alternate;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.reward-coin-icon {
    font-size: 1.8rem;
}

@keyframes rewardPulse {
    0% { transform: scale(1); box-shadow: 0 0 15px rgba(212, 175, 55, 0.2); }
    100% { transform: scale(1.05); box-shadow: 0 0 25px rgba(212, 175, 55, 0.5); }
}

/* Weapon select column width override to prevent Bandit-KI button cropping */
.weapon-select {
    flex: 1.5 1 300px !important;
    max-width: 420px !important;
}

/* Locked weapon buttons */
.weapon-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: rgba(40, 20, 15, 0.6) !important;
    border-color: rgba(110, 67, 19, 0.2) !important;
    box-shadow: none !important;
    color: #a58e74 !important;
}

/* Toggle button styles (Green Outline for Active, Red/Gray for Inactive) */
.btn-toggle-active {
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
    color: #2ecc71 !important;
    border: 2px solid #2ecc71 !important;
    box-shadow: none !important;
    text-shadow: none !important;
}
.btn-toggle-active:hover {
    background: rgba(46, 204, 113, 0.1) !important;
    transform: translateY(-2px) !important;
}

.btn-toggle-inactive {
    background: transparent !important;
    background-color: transparent !important;
    background-image: none !important;
    color: #e74c3c !important;
    border: 2px solid #e74c3c !important;
    box-shadow: none !important;
    text-shadow: none !important;
}
.btn-toggle-inactive:hover {
    background: rgba(231, 76, 60, 0.1) !important;
    transform: translateY(-2px) !important;
}

/* Generic Disabled Button Styles */
.btn:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* Prestige Panel Overlay */
.prestige-panel {
    width: 100%;
    max-width: 900px;
    background: linear-gradient(135deg, #2c1a11 0%, #1a0f0a 100%);
    border: 2px solid #d4af37;
    border-radius: 8px;
    padding: 0.35rem 0.8rem;
    margin-bottom: 0.6rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.25);
    animation: borderGlow 2s infinite alternate;
}

@keyframes borderGlow {
    0% { border-color: #8b6e2f; box-shadow: 0 0 8px rgba(212, 175, 55, 0.15); }
    100% { border-color: #e5a93b; box-shadow: 0 0 18px rgba(212, 175, 55, 0.3); }
}

.prestige-info {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
    text-align: left;
}

.prestige-title {
    font-family: 'Rye', serif;
    font-size: 0.92rem;
    color: #e5a93b;
    letter-spacing: 0.5px;
}

.prestige-desc {
    font-size: 0.72rem;
    color: #c5a880;
}

.prestige-timer {
    font-family: monospace;
    font-size: 1.05rem;
    color: #ff9500;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.4);
    padding: 0.12rem 0.4rem;
    border-radius: 4px;
    border: 1px solid rgba(255, 149, 0, 0.3);
}

.prestige-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-prestige-keep {
    background: linear-gradient(135deg, #ffee00 0%, #ffc107 100%) !important;
    color: #1a0f0a !important;
    font-weight: 800 !important;
    border: 2px solid #fff350 !important;
    box-shadow: 0 4px 14px rgba(255, 215, 0, 0.6) !important;
    text-shadow: none !important;
}
.btn-prestige-keep:hover {
    background: linear-gradient(135deg, #fff200 0%, #ffa000 100%) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 18px rgba(255, 215, 0, 0.8) !important;
}

.btn-prestige-reset {
    background: linear-gradient(135deg, #ff1744 0%, #d50000 100%) !important;
    color: #ffffff !important;
    font-weight: 800 !important;
    border: 2px solid #ff616f !important;
    box-shadow: 0 4px 14px rgba(255, 23, 68, 0.6) !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6) !important;
}
.btn-prestige-reset:hover {
    background: linear-gradient(135deg, #ff4569 0%, #b71c1c 100%) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 18px rgba(255, 23, 68, 0.8) !important;
}

#prestige-keep-btn:disabled {
    background: linear-gradient(135deg, #d4b800 0%, #b88a00 100%) !important;
    color: #2a1f0a !important;
    border-color: #aa9000 !important;
    opacity: 0.7 !important;
    cursor: not-allowed !important;
}

#prestige-reset-btn:disabled {
    background: linear-gradient(135deg, #b81030 0%, #800000 100%) !important;
    color: #ffcccc !important;
    border-color: #991020 !important;
    opacity: 0.7 !important;
    cursor: not-allowed !important;
}

/* Spieler-Namen Styling */
.player-names {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}
.name-inputs {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.input-group label {
    font-size: 0.8rem;
    color: #c5a880;
    font-weight: 600;
}
.input-group input {
    background: rgba(30, 18, 12, 0.8);
    border: 1px solid #6e4313;
    border-radius: 6px;
    padding: 0.5rem;
    color: #f7e6d4;
    font-family: 'Outfit', sans-serif;
    font-size: 1rem; /* Prevent iOS Safari focus auto-zoom */
    width: 100%;
}
.input-group input:focus {
    outline: none;
    border-color: #e5a93b;
    box-shadow: 0 0 8px rgba(229, 169, 59, 0.4);
}

/* Language Selector Styles */
#language-selector {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    gap: 0.5rem;
    z-index: 1000;
}

#language-selector .btn {
    font-size: 0.75rem !important;
    padding: 0.4rem 0.8rem !important;
    letter-spacing: 0.5px;
    height: auto !important;
    width: auto !important;
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

#language-selector .btn.selected {
    background: transparent !important;
    color: #ffd700 !important;
    border: 2px solid #d4af37 !important;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.4) !important;
    font-weight: 800 !important;
}

@media (max-width: 768px) {
    #language-selector {
        top: 0.5rem;
        right: 0.5rem;
    }
}

/* touch-action: none to prevent iPad scroll & zoom gestures during play */
#game-screen, #game-canvas, #mobile-controls {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Lock body scroll on touch devices ONLY during active gameplay to prevent screen dragging */
html.touch-device.game-playing, body.touch-device.game-playing {
    overflow: hidden !important;
    height: 100% !important;
}

/* Hide mobile controls by default on non-touch devices */
#mobile-controls {
    display: none !important;
}

/* Show mobile controls on touch-capable devices */
body.touch-device #mobile-controls {
    display: block !important;
}

/* Mobile Joystick Controls */
#mobile-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 99;
}

.joystick-container {
    position: absolute;
    width: 120px;
    height: 120px;
    max-width: 120px;
    max-height: 120px;
    box-sizing: border-box;
    margin-left: -60px; /* Center-align on touch coordinate */
    margin-top: -60px;
    pointer-events: none;
    display: none; /* Shown dynamically on touchstart */
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 100;
}

.joystick-container.active {
    opacity: 1;
}

.joystick-base {
    width: 120px;
    height: 120px;
    max-width: 120px;
    max-height: 120px;
    box-sizing: border-box;
    border-radius: 50%;
    background: rgba(19, 10, 6, 0.35);
    border: 3px solid rgba(247, 230, 212, 0.4);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    position: relative;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
}

.joystick-knob {
    width: 52px;
    height: 52px;
    max-width: 52px;
    max-height: 52px;
    box-sizing: border-box;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.25);
}

.joystick-knob.blue {
    background: radial-gradient(circle at 35% 35%, #5ac8fa 0%, #007aff 70%, #0056b3 100%);
    box-shadow: 0 0 15px rgba(0, 122, 255, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.joystick-knob.red {
    background: radial-gradient(circle at 35% 35%, #ff5e5e 0%, #ff3b30 70%, #c21a0f 100%);
    box-shadow: 0 0 15px rgba(255, 59, 48, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.joystick-knob.green {
    background: radial-gradient(circle at 35% 35%, #34c759 0%, #28a745 70%, #1e7e34 100%);
    box-shadow: 0 0 15px rgba(52, 199, 89, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.joystick-knob.orange {
    background: radial-gradient(circle at 35% 35%, #ff9500 0%, #ff8c00 70%, #d97706 100%);
    box-shadow: 0 0 15px rgba(255, 149, 0, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

/* Hide keyboard cheat sheet on mobile devices */
body.mobile-device .controls-cheat-sheet-compact {
    display: none !important;
}

/* Hide controls cheat sheet on mobile devices during gameplay */
body.mobile-device .gameplay-cheat-sheet {
    display: none !important;
}

/* Hide P2 cheat sheet instructions in 1-Player (PvE) mode */
body.mode-pve .controls-cheat-sheet-compact .sheet-divider,
body.mode-pve .controls-cheat-sheet-compact [data-i18n="cheat-sheet-p2"] {
    display: none !important;
}

/* Gameplay cheat sheet layout styling */
.gameplay-cheat-sheet {
    margin-top: 0.8rem;
    margin-bottom: 0;
    z-index: 10;
}

/* Smartphone specific viewport optimizations to enlarge playfield and resolve layout overlaps */
body.smartphone .western-title {
    font-size: 1.8rem !important;
    margin-top: 2.2rem !important;
    margin-bottom: 0.1rem !important;
}

body.smartphone .subtitle {
    font-size: 0.75rem !important;
    margin-bottom: 0.4rem !important;
    letter-spacing: 2px !important;
}

body.smartphone #language-selector {
    top: 0.4rem !important;
    right: 0.4rem !important;
    gap: 0.3rem !important;
}

body.smartphone #language-selector .btn {
    font-size: 0.65rem !important;
    padding: 0.25rem 0.5rem !important;
}

body.smartphone #game-screen {
    position: relative !important;
    padding: 0 !important;
    justify-content: center !important;
    align-items: center !important;
    height: 100vh !important;
    overflow: hidden !important;
}

body.smartphone #canvas-wrapper {
    max-width: 98vw !important;
    max-height: 96vh !important;
    height: auto !important;
    aspect-ratio: 1200 / 800 !important;
    border-width: 3px !important;
    margin: auto !important;
}

body.smartphone #hud {
    position: absolute !important;
    top: 5px !important;
    left: 5px !important;
    right: 5px !important;
    display: flex !important;
    justify-content: space-between !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    pointer-events: none !important;
    z-index: 10 !important;
}

body.smartphone .hud-player,
body.smartphone #level-display {
    background: rgba(30, 18, 12, 0.8) !important;
    border: 1px solid rgba(110, 67, 19, 0.4) !important;
    border-radius: 8px !important;
    padding: 0.25rem 0.5rem !important;
    pointer-events: auto !important;
}

body.smartphone .player-label {
    font-size: 0.85rem;
}

body.smartphone .sheriff-star {
    width: 16px;
    height: 16px;
}

body.smartphone #level-display-name {
    font-size: 0.95rem;
}

body.smartphone #wind-indicator {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
}

body.smartphone #game-controls-bar {
    position: absolute !important;
    bottom: 5px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    display: flex !important;
    flex-direction: row !important;
    gap: 0.3rem !important;
    background: rgba(30, 18, 12, 0.8) !important;
    border: 1px solid rgba(110, 67, 19, 0.4) !important;
    border-radius: 8px !important;
    padding: 0.2rem 0.4rem !important;
    z-index: 10 !important;
}

body.smartphone #game-controls-bar .btn {
    font-size: 0.65rem !important;
    padding: 0.2rem 0.4rem !important;
    height: auto !important;
    width: auto !important;
}

/* Landscape Mode Notice (shown only on iPad and Smartphone) */
.mobile-only-notice {
    display: none;
}

@media (orientation: portrait) {
    body.mobile-device .mobile-only-notice {
        display: block;
        margin-top: 1rem;
        font-size: 0.95rem;
        font-weight: 800;
        color: #ff9500;
        text-shadow: 0 0 8px rgba(255, 149, 0, 0.4);
        text-align: center;
        letter-spacing: 1px;
        animation: pulseNotice 2.5s infinite alternate;
    }
}

@media (orientation: landscape) {
    body.mobile-device .mobile-only-notice {
        display: none;
    }
}

@keyframes pulseNotice {
    0% { opacity: 0.8; transform: scale(1); }
    100% { opacity: 1; transform: scale(1.03); }
}

/* QR Code Selector Styles */
#qr-container {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    display: flex;
    gap: 0.5rem;
    z-index: 1000;
}

#qr-container .btn {
    font-size: 0.75rem !important;
    padding: 0.4rem 0.8rem !important;
    letter-spacing: 0.5px;
    height: auto !important;
    width: auto !important;
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

#qr-container .btn:hover {
    background: #8b521b;
    border-color: #e5a93b;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.3);
}

@media (max-width: 768px) {
    #qr-container {
        top: 0.5rem;
        left: 0.5rem;
    }
}

/* QR Modal Styles */
.qr-modal-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2c1a11 0%, #1a0f0a 100%);
    border: 3px solid #d4af37;
    border-radius: 16px;
    padding: 2rem;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8), 0 0 30px rgba(212, 175, 55, 0.15);
    text-align: center;
    animation: qrZoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes qrZoomIn {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.qr-modal-content h2 {
    font-family: 'Rye', serif;
    font-size: 1.8rem;
    color: #e5a93b;
    margin-bottom: 0.6rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.6);
    text-transform: uppercase;
}

.qr-desc {
    font-size: 0.85rem;
    color: #c5a880;
    margin-bottom: 1.2rem;
    line-height: 1.4;
}

.qr-canvas-container {
    background: transparent;
    padding: 0;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.2rem;
    box-shadow: none;
    transition: transform 0.2s ease;
}

.qr-canvas-container:hover {
    transform: scale(1.02);
}

#qr-image {
    display: block;
    width: 180px !important;
    height: 180px !important;
    object-fit: contain;
}

.qr-link-container {
    display: flex;
    width: 100%;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

#qr-link-input {
    flex-grow: 1;
    background: rgba(30, 18, 12, 0.8);
    border: 1px solid #6e4313;
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    color: #f7e6d4;
    font-family: monospace;
    font-size: 0.8rem;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#qr-link-input:focus {
    outline: none;
    border-color: #e5a93b;
}

.qr-modal-buttons {
    display: flex;
    gap: 1rem;
    width: 100%;
    justify-content: center;
}

.qr-modal-buttons .btn {
    width: 100%;
    max-width: 200px;
}

/* Menu QR Code Section Styles */
.qr-code-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.menu-qr-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    height: calc(100% - 2.5rem);
    padding-top: 0.4rem;
}

.menu-qr-image {
    width: 120px;
    height: 120px;
    border-radius: 8px;
    border: 2px solid #d4af37;
    background: #ffd700;
    padding: 4px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.menu-qr-image:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 15px rgba(212, 175, 55, 0.4);
}

.menu-qr-desc {
    font-size: 0.7rem;
    color: #c5a880;
    text-align: center;
    margin: 0;
    line-height: 1.3;
}

/* Responsive landscape and scroll rules for QR Code Modal */
#qr-modal {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#qr-modal.active {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important; /* critical for scrollbar behavior */
    padding: 2rem 0 !important;
    box-sizing: border-box !important;
}

@media (min-height: 600px) and (min-width: 600px) {
    #qr-modal.active {
        justify-content: center !important;
        padding: 0 !important;
    }
}

.qr-text-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

@media (max-height: 520px) {
    #qr-modal.active {
        align-items: flex-start; /* prevent clipping at the top */
        padding: 1.5rem 0;
    }

    .qr-modal-content {
        flex-direction: row !important;
        max-width: 620px;
        gap: 1.5rem;
        padding: 1.2rem !important;
        align-items: center;
        text-align: left;
    }

    .qr-text-col {
        align-items: flex-start;
        flex-grow: 1;
    }

    .qr-modal-content h2 {
        font-size: 1.35rem;
        margin-bottom: 0.2rem;
        text-align: left;
    }

    .qr-desc {
        font-size: 0.75rem;
        margin-bottom: 0.6rem;
        text-align: left;
    }

    .qr-canvas-container {
        margin-bottom: 0 !important;
    }

    #qr-image {
        width: 130px !important;
        height: 130px !important;
    }

    .qr-link-container {
        margin-bottom: 0.6rem !important;
    }

    .qr-modal-buttons {
        justify-content: flex-start !important;
    }
    
    .qr-modal-buttons .btn {
        max-width: 150px !important;
        height: 35px !important;
        font-size: 0.75rem !important;
        padding: 0.3rem 0.6rem !important;
    }
}

