/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: #1a0810;
    font-family: 'Outfit', sans-serif;
    color: #FBF7EB;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Responsive Game Container */
.game-container {
    position: relative;
    width: 100vw;
    height: calc(100vw * 5 / 3); /* 3:5 aspect ratio */
    max-width: 570px;
    max-height: 950px;
    background-color: #000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9), 0 0 50px rgba(212, 175, 55, 0.25);
    border: 3.5px solid #D4AF37;
    border-radius: 16px;
    overflow: hidden;
}

@media (min-aspect-ratio: 3/5) {
    /* If viewport is wider than 3:5, we scale container by height (leaving 92vh for elegant margins) */
    .game-container {
        height: 92vh;
        width: calc(92vh * 3 / 5);
    }
}

/* Canvas Styles */
#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Overlay Menus Base */
.menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 8, 16, 0.45);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    z-index: 10;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.menu-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Menu Card Structure */
.menu-card {
    width: 100%;
    max-width: 380px;
    background: linear-gradient(135deg, rgba(91, 14, 45, 0.95) 0%, rgba(54, 8, 27, 0.98) 100%);
    border: 2px solid #D4AF37;
    border-radius: 16px;
    padding: 30px 24px;
    text-align: center;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), inset 0 0 20px rgba(212, 175, 55, 0.2);
    position: relative;
}

/* Ornate Corners using pseudo-elements */
.menu-card::before, .menu-card::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid #D4AF37;
    pointer-events: none;
}
.menu-card::before {
    top: 6px; left: 6px;
    border-right: none; border-bottom: none;
}
.menu-card::after {
    bottom: 6px; right: 6px;
    border-left: none; border-top: none;
}

/* Titles and Typography */
.game-title {
    font-family: 'Cinzel', serif;
    font-size: 2.8rem;
    font-weight: 900;
    line-height: 1;
    color: #D4AF37;
    text-shadow: 0 3px 6px rgba(0,0,0,0.5), 0 0 15px rgba(212, 175, 55, 0.4);
    letter-spacing: 2px;
    margin-bottom: 5px;
}

.title-sub {
    font-size: 2.2rem;
    color: #FBF7EB;
    letter-spacing: 4px;
    text-shadow: none;
}

.game-tagline {
    font-size: 0.85rem;
    color: #FBF7EB;
    opacity: 0.85;
    margin-bottom: 25px;
    font-style: italic;
    letter-spacing: 0.5px;
}

.menu-title {
    font-family: 'Reem Kufi', sans-serif;
    font-size: 1.8rem;
    color: #D4AF37;
    letter-spacing: 2px;
    margin-bottom: 20px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

/* Character Showcase Panel */
.character-preview-box {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.character-preview-box canvas {
    background: transparent;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

.character-name {
    font-family: 'Reem Kufi', sans-serif;
    font-size: 1.1rem;
    font-weight: bold;
    color: #FBF7EB;
    margin-top: 8px;
    letter-spacing: 1px;
}

/* Button Styling System */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.button-row {
    display: flex;
    gap: 12px;
    width: 100%;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Reem Kufi', sans-serif;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 1.05rem;
    letter-spacing: 1px;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(to bottom, #FFAA00, #D4AF37);
    color: #1a0810;
    font-weight: 900;
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
    animation: btn-glow 2s infinite ease-in-out;
}

.btn-primary:hover {
    transform: scale(1.04);
    box-shadow: 0 6px 16px rgba(212, 175, 55, 0.6);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: #0F5257;
    color: #FBF7EB;
    border: 1px solid rgba(212, 175, 55, 0.5);
    box-shadow: 0 4px 10px rgba(15, 82, 87, 0.3);
}

.btn-secondary:hover {
    background: #157279;
    transform: scale(1.02);
}

.btn-tertiary {
    flex: 1;
    background: rgba(255, 255, 255, 0.08);
    color: #FBF7EB;
    font-size: 0.9rem;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-tertiary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.btn-lg {
    font-size: 1.3rem;
    padding: 16px;
    letter-spacing: 2px;
}

.btn-icon {
    margin-right: 6px;
}

/* In-game HUD Layout */
.hud {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    pointer-events: none;
    z-index: 5;
    transition: opacity 0.3s ease;
}

.hud.hidden {
    opacity: 0;
}

.hud-left {
    display: flex;
    gap: 12px;
}

.hud-item {
    background: rgba(26, 8, 16, 0.8);
    border: 1px solid #D4AF37;
    border-radius: 20px;
    padding: 6px 14px;
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.coins-container {
    color: #FFAA00;
}

.coin-icon {
    width: 16px;
    height: 16px;
    animation: coin-spin 3s infinite linear;
}

.icon-btn {
    background: rgba(26, 8, 16, 0.8);
    border: 1px solid #D4AF37;
    color: #FBF7EB;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
}

.icon-btn:hover {
    transform: scale(1.1);
    color: #D4AF37;
}

/* Grand Bazaar / Shop Layout */
.shop-card {
    max-height: 90%;
    display: flex;
    flex-direction: column;
}

.shop-coins {
    background: rgba(0,0,0,0.4);
    border-radius: 30px;
    padding: 8px 18px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 auto 20px;
    font-size: 0.95rem;
    font-weight: bold;
    border: 1px solid rgba(212, 175, 55, 0.3);
}

.shop-coins img {
    width: 18px;
    height: 18px;
}

.gold-text {
    color: #FFAA00;
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: 900;
}

.skins-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    overflow-y: auto;
    max-height: 380px;
    padding: 4px;
    margin-bottom: 20px;
}

/* Scrollbar styles for modern custom cards */
.skins-grid::-webkit-scrollbar {
    width: 6px;
}
.skins-grid::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}
.skins-grid::-webkit-scrollbar-thumb {
    background: #D4AF37;
    border-radius: 4px;
}

.skin-item {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.skin-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(212, 175, 55, 0.6);
    transform: translateY(-2px);
}

.skin-item.selected {
    border-color: #D4AF37;
    background: rgba(212, 175, 55, 0.08);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

.skin-preview-canvas {
    width: 60px;
    height: 60px;
    background: transparent;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.skin-title {
    font-family: 'Reem Kufi', sans-serif;
    font-size: 0.85rem;
    font-weight: bold;
    margin-top: 6px;
    color: #FBF7EB;
}

.skin-price {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
    font-size: 0.85rem;
    color: #FFAA00;
    font-weight: bold;
}

.skin-status {
    margin-top: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #A0A0A0;
}

.selected .skin-status {
    color: #FFAA00;
}

.skin-item.locked {
    opacity: 0.85;
}

.skin-item.locked .skin-preview-canvas {
    filter: grayscale(80%) brightness(0.6);
}

/* Leaderboard Overlay */
.leaderboard-list {
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: 12px;
    padding: 10px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leader-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    border-left: 3px solid transparent;
}

.leader-item.rank-1 {
    border-left-color: #D4AF37;
    background: rgba(212, 175, 55, 0.08);
}

.leader-item.rank-2 {
    border-left-color: #C0C0C0;
    background: rgba(192, 192, 192, 0.05);
}

.leader-item.rank-3 {
    border-left-color: #CD7F32;
    background: rgba(205, 127, 50, 0.05);
}

.leader-rank-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.leader-rank {
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    font-weight: bold;
    color: #A0A0A0;
    width: 20px;
}

.rank-1 .leader-rank { color: #D4AF37; }
.rank-2 .leader-rank { color: #C0C0C0; }
.rank-3 .leader-rank { color: #CD7F32; }

.leader-name {
    font-weight: 600;
}

.leader-score {
    font-family: 'Cinzel', serif;
    font-weight: 900;
    font-size: 1.1rem;
}

.rank-1 .leader-score { color: #D4AF37; }

/* Settings Layout */
.settings-list {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-label {
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
}

/* Custom Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.15);
    transition: .3s;
    border: 1px solid rgba(212, 175, 55, 0.3);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #FBF7EB;
    transition: .3s;
}

input:checked + .slider {
    background-color: #0F5257;
}

input:checked + .slider:before {
    transform: translateX(24px);
    background-color: #D4AF37;
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Language selector */
.lang-selector {
    display: flex;
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 6px;
    overflow: hidden;
}

.lang-btn {
    background: transparent;
    border: none;
    color: #FBF7EB;
    font-weight: bold;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.lang-btn.active {
    background: #D4AF37;
    color: #1a0810;
}

/* Game Over / Eyvah Screen */
.game-over-title {
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    color: #E63946;
    text-shadow: 0 4px 10px rgba(230, 57, 70, 0.4);
    margin-bottom: 2px;
}

.game-over-tagline {
    font-size: 0.9rem;
    margin-bottom: 20px;
    color: rgba(251, 247, 235, 0.85);
}

.results-box {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: 600;
}

.result-val {
    font-family: 'Cinzel', serif;
    font-size: 1.25rem;
    font-weight: 800;
}

.result-val.highlight {
    color: #D4AF37;
}

.result-val.coin-gain {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #FFAA00;
}

/* Back Button Alignment */
.back-btn {
    width: 100%;
    margin-top: 10px;
}

/* Animations */
@keyframes btn-glow {
    0% {
        box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(212, 175, 55, 0.7), 0 0 10px rgba(212, 175, 55, 0.3);
    }
    100% {
        box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
    }
}

@keyframes coin-spin {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

.animate-fade-in {
    animation: fadeIn 0.25s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Shake screen effect for collision */
.shake {
    animation: shakeEffect 0.35s ease-in-out;
}

@keyframes shakeEffect {
    0%, 100% { transform: translate(0, 0); }
    10%, 30%, 50%, 70%, 90% { transform: translate(-3px, 2px); }
    20%, 40%, 60%, 80% { transform: translate(3px, -2px); }
}

/* Coin shine flash effect */
.coin-shine {
    animation: flashShine 0.15s ease-out;
}

@keyframes flashShine {
    0% { box-shadow: inset 0 0 0px rgba(255, 170, 0, 0); }
    50% { box-shadow: inset 0 0 30px rgba(255, 170, 0, 0.6); }
    100% { box-shadow: inset 0 0 0px rgba(255, 170, 0, 0); }
}
