* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    /* Prevent iOS Safari bounce scrolling */
    overflow: hidden;
    /* Support for safe areas on notched devices */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    user-select: none;
    /* Prevent overscroll behavior */
    overscroll-behavior: none;
    /* Prevent text size adjustment on orientation change */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    /* Smooth scrolling */
    -webkit-overflow-scrolling: touch;
    /* Prevent tap highlight on mobile */
    -webkit-tap-highlight-color: transparent;
    /* Optimize for touch */
    touch-action: manipulation;
}

.game-container {
    display: flex;
    flex-direction: column;
    padding: 12px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
}

.crossword-area {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    min-height: 300px;
    flex: 1;
}

.crossword-grid {
    position: relative;
    display: grid;
    gap: 4px;
    grid-template-columns: repeat(4, 40px);
    grid-template-rows: repeat(6, 40px);
}

.letter-box {
    width: 40px;
    height: 40px;
    border: 2px solid #d3d6da;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.15s ease;
    pointer-events: none;
    opacity: 0;
}

.letter-box.filled {
    background: #6aaa64;
    color: white;
    border-color: #6aaa64;
    opacity: 1;
}

.letter-box.active {
    border-color: #878a8c;
    background: #f3f3f3;
    opacity: 1;
}

.letter-box.current {
    border-color: #565758;
    border-width: 3px;
    opacity: 1;
}

.hint-section {
    text-align: center;
    margin-bottom: 14px;
    padding: 10px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

.hint-section.success {
    background: #6aaa64;
    color: white;
}

.hint-text {
    font-size: 15px;
    font-weight: 400;
    color: #333;
    transition: color 0.3s ease;
}

.hint-section.success .hint-text {
    color: white;
    font-weight: 500;
}

.keyboard {
    width: 100%;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 8px;
}

.key {
    min-width: 36px;
    height: 46px;
    background: #d3d6da;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease;
}

.key:hover {
    background: #c3c6ca;
}

.key:active {
    transform: scale(0.95);
}

.key.wide {
    min-width: 60px;
    font-size: 12px;
}

.key.wide:last-of-type {
    font-size: 16px;
}

.key.used {
    background: #787c7e;
    color: white;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes jump {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(-5px); }
    75% { transform: translateY(5px); }
}

/* Enhanced mobile optimizations */
@media (max-width: 480px) {
    html {
        -webkit-text-size-adjust: 100%;
        height: 100%;
        height: 100dvh;
    }
    
    body {
        min-height: 100vh;
        min-height: 100dvh;
        overflow-x: hidden;
        overscroll-behavior-y: contain;
    }
    
    .keyboard-row {
        gap: 3px;
        margin-bottom: 6px;
    }
    
    .key {
        min-width: 36px;
        height: 47px;
        font-size: 15px;
        min-height: 44px;
    }

    .key.wide {
        min-width: 48px;
        font-size: 11px;
    }
    
    .key.wide:last-of-type {
        font-size: 14px;
    }
}

/* Ultra-small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
    .crossword-grid {
        grid-template-columns: repeat(10, 28px);
        grid-template-rows: repeat(10, 28px);
        gap: 2px;
    }

    .letter-box {
        width: 28px;
        height: 28px;
        font-size: 15px;
    }
    
    .key {
        min-width: 32px;
        height: 40px;
        font-size: 13px;
    }
    
    .key.wide {
        min-width: 45px;
        font-size: 10px;
    }
}

/* Landscape orientation optimizations */
@media (max-width: 896px) and (orientation: landscape) {
    body {
        height: 100vh;
        height: 100dvh;
    }
    
    .game-container {
        padding: 6px;
        flex: 1;
        display: flex;
        flex-direction: column;
    }
    
    .crossword-area {
        margin-bottom: 8px;
        flex: 1;
    }
    
    .crossword-grid {
        grid-template-columns: repeat(10, 26px);
        grid-template-rows: repeat(10, 26px);
        gap: 2px;
    }

    .letter-box {
        width: 26px;
        height: 26px;
        font-size: 14px;
    }
    
    .hint-section {
        margin-bottom: 8px;
        padding: 6px;
    }
    
    .hint-text {
        font-size: 13px;
    }
    
    .keyboard-row {
        margin-bottom: 4px;
        gap: 2px;
    }
    
    .key {
        min-width: 32px;
        height: 42px;
        font-size: 12px;
    }
    
    .key.wide {
        min-width: 42px;
        font-size: 9px;
    }
    
    .key.wide:last-of-type {
        font-size: 12px;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .letter-box {
        border-width: 1px;
    }
    
    .letter-box.current {
        border-width: 2px;
    }
    
    .key {
        border: 1px solid rgba(0, 0, 0, 0.1);
    }
}

/* Coming Soon specific styles */
.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 500px;
    width: 100%;
    padding: 20px;
    text-align: center;
    flex: 1;
}

.container .header {
    background: none;
    border: none;
    margin-bottom: 30px;
}

.container .header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    color: #333;
}

.container .subtitle {
    font-size: 1.1rem;
    opacity: 0.8;
    font-weight: 400;
    color: #666;
}

.footer {
    margin-top: 20px;
}

.footer p {
    font-size: 1rem;
    opacity: 0.8;
    font-weight: 400;
    color: #666;
}
