/* WordTres - Main Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    overflow: hidden;
    height: 100vh;
    touch-action: manipulation;
    
    /* Safe area support for modern mobile devices */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    margin: 0 auto;
    padding: 10px;
    position: relative;
    overflow: hidden;
    max-width: none;
    
    /* Adjust for safe areas on mobile */
    min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

/* Responsive container sizing */
@media (max-width: 480px) {
    .game-container {
        max-width: 100vw;
        padding: 5px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .game-container {
        max-width: 600px;
        padding: 15px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .game-container {
        max-width: 800px;
        padding: 20px;
    }
}

@media (min-width: 1025px) {
    .game-container {
        max-width: 1200px;
        padding: 15px;
        flex-direction: column;
        align-items: center;
        gap: 10px;
        min-height: 100vh;
        overflow-y: auto;
    }
    
    .desktop-game-wrapper {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        gap: 20px;
        width: 100%;
        justify-content: center;
        flex: 1;
        min-height: 0;
    }
    
    .game-main {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        flex-shrink: 0;
        gap: 10px;
    }
    
    .game-sidebar {
        width: 250px;
        display: flex;
        flex-direction: column;
        gap: 12px;
        height: fit-content;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }
}

.game-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
    width: 100%;
}

@media (min-width: 1025px) {
    .game-header {
        padding: 0.8rem 1rem;
        max-width: 600px;
        border-radius: 12px;
        border-bottom: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    }
}

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

.title-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

.title-letter {
    width: 35px;
    height: 35px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: bold;
    color: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    text-shadow: none;
}

.score-display {
    text-align: right;
    font-size: 0.9rem;
}

.score-display .level {
    font-size: 0.8rem;
    opacity: 0.9;
    margin-top: 2px;
}

.current-score {
    font-weight: bold;
    font-size: 1.1rem;
}

.high-score {
    opacity: 0.8;
    font-size: 0.8rem;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}

#gameCanvas {
    border: 3px solid #34495e;
    border-radius: 8px;
    background: linear-gradient(135deg, #2c3e50, #34495e);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: block;
    margin: 0 auto 15px auto;
    touch-action: none;
    image-rendering: pixelated;
    image-rendering: -webkit-crisp-edges;
    image-rendering: crisp-edges;
    flex-shrink: 0;
}

/* Responsive canvas sizing */
@media (max-width: 480px) {
    #gameCanvas {
        max-width: calc(100vw - 20px);
        border-width: 2px;
        margin-bottom: 10px;
        max-height: calc(100vh - 260px);
        flex-shrink: 1;
    }
    
    .game-main {
        padding: 5px 0;
        justify-content: flex-start;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    #gameCanvas {
        max-width: calc(100vw - 40px);
        margin-bottom: 15px;
    }
}

@media (min-width: 1025px) {
    #gameCanvas {
        max-width: none;
        margin-bottom: 15px;
        max-height: calc(100vh - 200px);
    }
}

.game-controls {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-top: auto;
    gap: 8px;
    flex-shrink: 0;
}

@media (min-width: 1025px) {
    .game-controls {
        gap: 6px;
        margin-top: 15px;
    }
}

/* Specific adjustments for smaller desktop resolutions like 1366x768 */
@media (min-width: 1025px) and (max-height: 800px) {
    .game-container {
        padding: 10px;
        gap: 8px;
    }
    
    .game-header {
        padding: 0.6rem 1rem;
    }
    
    .falling-cube-preview {
        padding: 8px 0;
    }
    
    .game-info {
        min-height: 50px;
        padding: 8px;
        margin-bottom: 8px;
    }
    
    .primary-btn {
        padding: 10px 12px;
        font-size: 1rem;
        min-height: 40px;
    }
    
    .control-btn {
        padding: 8px 12px;
        font-size: 0.9rem;
        min-height: 35px;
    }
    
    .desktop-game-wrapper {
        gap: 15px;
    }
    
    .game-sidebar {
        gap: 10px;
    }
}

/* Force controls on all small mobile screens */
@media (max-width: 480px) {
    .game-controls {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 12px !important;
        background: rgba(102, 126, 234, 0.2) !important;
        backdrop-filter: blur(10px) !important;
        border-top: 2px solid rgba(255, 255, 255, 0.3) !important;
        border-radius: 12px 12px 0 0 !important;
        z-index: 1000 !important;
        box-sizing: border-box !important;
    }
    
    .all-controls {
        display: flex !important;
        width: 100% !important;
        justify-content: space-between !important;
        gap: 8px !important;
    }
    
    .control-btn {
        display: flex !important;
        flex: 1 !important;
        justify-content: center !important;
        align-items: center !important;
        min-height: 50px !important;
        font-size: 0.9rem !important;
        font-weight: bold !important;
        padding: 12px 8px !important;
        color: white !important;
        background: rgba(255, 255, 255, 0.25) !important;
        border: 2px solid rgba(255, 255, 255, 0.4) !important;
        border-radius: 8px !important;
        transition: all 0.2s ease !important;
        touch-action: manipulation !important;
        user-select: none !important;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .game-controls {
        display: flex !important;
        max-width: 500px;
        margin: 0 auto;
        margin-top: auto;
        background: rgba(102, 126, 234, 0.15);
        backdrop-filter: blur(10px);
        border-top: 2px solid rgba(255, 255, 255, 0.3);
        border-radius: 12px 12px 0 0;
        padding: 15px;
        position: sticky;
        bottom: 0;
        z-index: 100;
    }
    
    .all-controls {
        display: flex !important;
        width: 100%;
        justify-content: space-between;
        gap: 12px;
    }
    
    .control-btn {
        display: flex !important;
        flex: 1;
        justify-content: center;
        align-items: center;
        min-height: 55px;
        font-size: 1rem;
        padding: 15px 12px;
        color: white;
        background: rgba(255, 255, 255, 0.25);
        border: 2px solid rgba(255, 255, 255, 0.4);
        border-radius: 8px;
        font-weight: bold;
    }
}

/* iPad and larger tablets - centered layout */
@media (min-width: 769px) and (max-width: 1024px) {
    .game-controls {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        width: auto !important;
        max-width: 600px !important;
        min-width: 500px !important;
        margin: 0 !important;
        padding: 20px !important;
        background: rgba(102, 126, 234, 0.2) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border-top: 2px solid rgba(255, 255, 255, 0.3) !important;
        border-radius: 15px 15px 0 0 !important;
        z-index: 1000 !important;
        box-sizing: border-box !important;
    }
    
    .all-controls {
        display: flex !important;
        width: 100% !important;
        justify-content: space-between !important;
        gap: 20px !important;
    }
    
    .control-btn {
        display: flex !important;
        flex: 1 !important;
        justify-content: center !important;
        align-items: center !important;
        min-height: 60px !important;
        font-size: 1.1rem !important;
        padding: 18px 15px !important;
        color: white !important;
        background: rgba(255, 255, 255, 0.25) !important;
        border: 2px solid rgba(255, 255, 255, 0.4) !important;
        border-radius: 10px !important;
        font-weight: bold !important;
        transition: all 0.2s ease !important;
        touch-action: manipulation !important;
        user-select: none !important;
    }
    
    .control-btn:hover,
    .control-btn:active {
        background: rgba(255, 255, 255, 0.35) !important;
        border-color: rgba(255, 255, 255, 0.6) !important;
        transform: translateY(-1px) !important;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .game-controls {
        max-width: 500px;
        margin: 0 auto;
        margin-top: 20px;
    }
}

/* FORCE mobile controls on ALL touch devices */
@media (hover: none) and (pointer: coarse) {
    .game-controls {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 600px !important;
        margin: 0 auto !important;
        background: rgba(102, 126, 234, 0.2) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border-top: 2px solid rgba(255, 255, 255, 0.3) !important;
        border-radius: 12px 12px 0 0 !important;
        padding: 12px !important;
        z-index: 1000 !important;
        box-sizing: border-box !important;
    }
    
    .all-controls {
        display: flex !important;
        width: 100% !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }
    
    .control-btn {
        display: flex !important;
        flex: 1 !important;
        justify-content: center !important;
        align-items: center !important;
        min-height: 50px !important;
        font-size: 0.9rem !important;
        font-weight: bold !important;
        padding: 12px 8px !important;
        color: white !important;
        background: rgba(255, 255, 255, 0.25) !important;
        border: 2px solid rgba(255, 255, 255, 0.4) !important;
        border-radius: 8px !important;
        transition: all 0.2s ease !important;
        touch-action: manipulation !important;
        user-select: none !important;
    }
    
    .control-btn:hover,
    .control-btn:active {
        background: rgba(255, 255, 255, 0.35) !important;
        border-color: rgba(255, 255, 255, 0.6) !important;
        transform: translateY(-1px) !important;
    }
    
    .control-btn:active {
        transform: scale(0.98) !important;
        background: rgba(76, 175, 80, 0.8) !important;
    }
}

/* Ultimate fallback - show controls on ANY screen smaller than desktop */
@media screen and (max-width: 1024px) {
    .game-controls {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        z-index: 1000 !important;
        background: rgba(102, 126, 234, 0.2) !important;
        backdrop-filter: blur(10px) !important;
        border-top: 2px solid rgba(255, 255, 255, 0.3) !important;
        border-radius: 12px 12px 0 0 !important;
        padding: 12px !important;
        box-sizing: border-box !important;
    }
    
    .all-controls {
        display: flex !important;
        width: 100% !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }
    
    .control-btn {
        display: flex !important;
        flex: 1 !important;
        justify-content: center !important;
        align-items: center !important;
        min-height: 50px !important;
        font-size: 0.9rem !important;
        font-weight: bold !important;
        padding: 12px 8px !important;
        color: white !important;
        background: rgba(255, 255, 255, 0.25) !important;
        border: 2px solid rgba(255, 255, 255, 0.4) !important;
        border-radius: 8px !important;
    }
}

/* Tablet-specific centering for landscape and portrait */
@media screen and (min-width: 768px) and (max-width: 1024px) {
    .game-controls {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        width: auto !important;
        max-width: 600px !important;
        min-width: 500px !important;
    }
}

/* General mobile fallback - force on all mobile screens */
@media screen and (max-width: 768px) {
    .game-controls {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 12px !important;
        background: rgba(102, 126, 234, 0.2) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border-top: 2px solid rgba(255, 255, 255, 0.3) !important;
        border-radius: 12px 12px 0 0 !important;
        z-index: 1000 !important;
        box-sizing: border-box !important;
    }
    
    .all-controls {
        display: flex !important;
        width: 100% !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }
    
    .control-btn {
        display: flex !important;
        flex: 1 !important;
        justify-content: center !important;
        align-items: center !important;
        min-height: 50px !important;
        font-size: 0.9rem !important;
        font-weight: bold !important;
        padding: 12px 8px !important;
        color: white !important;
        background: rgba(255, 255, 255, 0.25) !important;
        border: 2px solid rgba(255, 255, 255, 0.4) !important;
        border-radius: 8px !important;
        transition: all 0.2s ease !important;
        touch-action: manipulation !important;
        user-select: none !important;
    }
}

@media (min-width: 1025px) {
    .game-controls {
        max-width: none;
        margin-top: 15px;
    }
}

.all-controls {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 10px;
}

@media (max-width: 480px) {
    .all-controls {
        gap: 8px;
    }
}

/* Remove primary-btn styles as we're now using control-btn for all buttons */

.control-btn {
    flex: 1;
    padding: 12px 8px;
    font-size: 0.9rem;
    font-weight: bold;
    color: white;
    background: rgba(255, 255, 255, 0.25);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    user-select: none;
    min-height: 45px;
    text-align: center;
}

/* Responsive control buttons */
@media (max-width: 480px) {
    .control-btn {
        padding: 10px 6px;
        font-size: 0.8rem;
        min-height: 40px;
    }
}

@media (min-width: 769px) {
    .control-btn {
        padding: 14px 12px;
        font-size: 1rem;
        min-height: 50px;
    }
}

@media (min-width: 1025px) {
    .control-btn {
        padding: 12px 16px;
        font-size: 0.95rem;
        min-height: 45px;
    }
}

.control-btn:hover,
.control-btn:active {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.6);
    transform: translateY(-2px);
}

.control-btn:active {
    transform: scale(0.95);
    background: #4caf50;
}

.game-info {
    min-height: 60px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

@media (min-width: 1025px) {
    .game-info {
        margin-bottom: 10px;
    }
}

.word-preview {
    text-align: center;
    font-weight: bold;
}

.detected-word {
    display: inline-block;
    margin: 2px 5px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    animation: wordGlow 0.5s ease-in-out;
}

.detected-word.horizontal {
    background: rgba(76, 175, 80, 0.3);
    border-color: rgba(76, 175, 80, 0.5);
}

.detected-word.vertical {
    background: rgba(255, 152, 0, 0.3);
    border-color: rgba(255, 152, 0, 0.5);
}

.detected-word.vertical::after {
    content: " (2x)";
    font-size: 0.7rem;
    opacity: 0.8;
}

.header-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: bold;
}

.falling-cube-preview {
    background: rgba(255, 255, 255, 0.1);
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    padding: 10px 0;
    text-align: center;
    width: 100%;
}

@media (min-width: 1025px) {
    .falling-cube-preview {
        max-width: 600px;
        border-radius: 8px;
        border-bottom: 2px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
}

.cube-letters {
    display: flex;
    justify-content: center;
    gap: 8px;
    align-items: center;
}

.cube-letter {
    width: 35px;
    height: 35px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Loading and Game States */
.game-paused {
    opacity: 0.7;
}

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.game-over-content {
    background: white;
    color: #333;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 300px;
}

.game-over h2 {
    margin-bottom: 15px;
    color: #764ba2;
}

.restart-btn {
    margin-top: 15px;
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

.restart-btn:hover {
    background: #764ba2;
}

/* Bonus message animation */
@keyframes bonusAnimation {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1) translateY(-20px);
    }
}

@keyframes slideDown {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    20% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    80% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
}

.bonus-message {
    pointer-events: none;
    font-size: 1.2rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1100;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Show modal when display is set to flex */
.modal[style*="flex"] {
    display: flex !important;
}

.modal-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 15px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    pointer-events: auto; /* Ensure modal content can receive clicks */
    position: relative;
    z-index: 1;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Leaderboard Tabs */
.leaderboard-tabs {
    display: flex;
    background: rgba(255, 255, 255, 0.1);
}

.tab-btn {
    flex: 1;
    padding: 15px;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.tab-btn.active {
    background: rgba(255, 255, 255, 0.2);
    border-bottom: 3px solid white;
}

/* Leaderboard Content */
.leaderboard-content {
    max-height: 400px;
    overflow-y: auto;
    padding: 20px;
}

.no-scores {
    text-align: center;
    padding: 40px 20px;
    opacity: 0.7;
    font-style: italic;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.score-item:hover {
    background: rgba(255, 255, 255, 0.15);
}

.score-item.rank-1 {
    background: rgba(255, 215, 0, 0.3);
    border: 2px solid rgba(255, 215, 0, 0.6);
}

.score-item.rank-2 {
    background: rgba(192, 192, 192, 0.3);
    border: 2px solid rgba(192, 192, 192, 0.6);
}

.score-item.rank-3 {
    background: rgba(205, 127, 50, 0.3);
    border: 2px solid rgba(205, 127, 50, 0.6);
}

.rank {
    font-weight: bold;
    font-size: 1.2rem;
    min-width: 40px;
    text-align: center;
}

.player-info {
    flex: 1;
}

.player-name {
    font-weight: bold;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.country-flag {
    width: 24px;
    height: 18px;
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.player-details {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 2px;
}

.score-value {
    font-weight: bold;
    font-size: 1.1rem;
    color: #FFD700;
}

/* Leaderboard Stats */
.leaderboard-stats {
    padding: 20px;
    border-top: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    text-align: center;
}

.stat-item {
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.stat-number {
    font-size: 1.2rem;
    font-weight: bold;
    color: #FFD700;
}

.stat-label {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 2px;
}

/* Tutorial System Styles */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

/* Show game over screen specifically */
.tutorial-overlay.game-over {
    display: flex !important;
}

/* Hide game controls when game over screen is visible */
.tutorial-overlay.game-over ~ * .game-controls,
body:has(.tutorial-overlay.game-over) .game-controls {
    display: none !important;
}

.tutorial-modal {
    background: linear-gradient(135deg, #2c3e50, #34495e);
    color: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    text-align: center;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.welcome-screen {
    animation: welcomeSlideIn 0.5s ease-out;
}

@keyframes welcomeSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.tutorial-header h2 {
    margin: 0 0 20px 0;
    font-size: 2.2em;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-weight: bold;
}

.welcome-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 20px 0;
}

.welcome-title .welcome-text {
    font-size: 2.2em;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-weight: bold;
    margin: 0;
    background: none;
    padding: 0;
    border: none;
}

.welcome-text {
    font-size: 1.1em;
    line-height: 1.6;
    margin: 20px 0 30px 0;
    color: #ecf0f1;
    text-align: left;
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 10px;
    border-left: 4px solid #27ae60;
}

.tutorial-controls {
    margin-top: 20px;
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.start-btn, .leaderboard-btn {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.1em;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(39, 174, 96, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
    flex: 1;
    min-width: 140px;
}

.leaderboard-btn {
    background: linear-gradient(135deg, #3498db, #2980b9);
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}

.start-btn:hover {
    background: linear-gradient(135deg, #229954, #27ae60);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(39, 174, 96, 0.4);
}

.leaderboard-btn:hover {
    background: linear-gradient(135deg, #2980b9, #1f618d);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
}

.start-btn:active, .leaderboard-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(39, 174, 96, 0.3);
}

/* Enhanced Game Effects */
#currentScore, #personalBest, #currentLevel {
    transition: all 0.3s ease;
}

.score-popup {
    animation: scoreFloat 1.5s ease-out forwards;
}

@keyframes scoreFloat {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-50px) scale(1.2);
    }
}

@keyframes wordGlow {
    0% {
        background: transparent;
    }
    50% {
        background: rgba(255, 215, 0, 0.3);
    }
    100% {
        background: transparent;
    }
}

/* Desktop wrapper - hidden on mobile */
.desktop-game-wrapper {
    display: contents;
}

/* Hide mobile controls on desktop */
@media (min-width: 1025px) {
    .mobile-controls {
        display: none !important;
    }
}

/* Tutorial overlay base styles */
.tutorial-overlay {
    display: none;
}

/* Show tutorial overlay when it's active (either welcome or game-over) */
.tutorial-overlay.active,
.tutorial-overlay.game-over {
    display: flex !important;
}

/* Hide non-essential popup elements */
[class*="popup"]:not(.tutorial-overlay) {
    display: none !important;
}

/* Hide other modals but allow leaderboard */
.modal:not(#leaderboardModal) {
    display: none !important;
}

/* Ensure leaderboard modal can override hiding rules and appears above game over */
#leaderboardModal.modal {
    display: none; /* Default hidden */
    z-index: 1200; /* Higher than game over screen */
}

#leaderboardModal.modal[style*="flex"] {
    display: flex !important; /* Override when shown via JS */
    z-index: 1200; /* Ensure it stays above game over */
}

/* Ensure leaderboard modal can be shown */
#leaderboardModal {
    display: none; /* Hidden by default, can be shown via JavaScript */
}

#leaderboardModal.modal {
    display: none; /* Override any conflicting rules */
}

/* Ensure mobile controls are hidden on desktop */
@media (min-width: 1025px) {
    .mobile-controls {
        display: none !important;
    }
}

/* Desktop Sidebar Styles - HIDDEN */
.game-sidebar {
    display: none !important;
}

@media (min-width: 1025px) {
    .game-sidebar {
        display: none !important;
    }
    
    .sidebar-section {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        padding: 12px;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .sidebar-section h3 {
        margin: 0 0 10px 0;
        color: #fff;
        font-size: 1rem;
        font-weight: bold;
        border-bottom: 2px solid rgba(255, 255, 255, 0.2);
        padding-bottom: 6px;
    }
    
    .control-hints {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .hint-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .hint-item:last-child {
        border-bottom: none;
    }
    
    .hint-item .key {
        background: rgba(255, 255, 255, 0.2);
        color: #fff;
        padding: 4px 8px;
        border-radius: 4px;
        font-family: monospace;
        font-size: 0.85rem;
        font-weight: bold;
        border: 1px solid rgba(255, 255, 255, 0.3);
        min-width: 60px;
        text-align: center;
    }
    
    .hint-item .desc {
        color: rgba(255, 255, 255, 0.9);
        font-size: 0.9rem;
        flex: 1;
        text-align: right;
    }
    
    .info-stats {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .stat-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .stat-item:last-child {
        border-bottom: none;
    }
    
    .stat-item .label {
        color: rgba(255, 255, 255, 0.8);
        font-size: 0.9rem;
    }
    
    .stat-item .value {
        color: #fff;
        font-weight: bold;
        font-size: 0.9rem;
        background: rgba(255, 255, 255, 0.1);
        padding: 2px 8px;
        border-radius: 4px;
    }
}
