html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background-color: #ffffff;
    overflow-x: hidden;
}

body.dark {
    background-color: #3a3a3c;
}

.main-container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: center;
    align-items: center;
    height: 100vh;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden;
}

/* Mobile First Responsive Design */
@media (max-width: 768px) {
    .main-container {
        padding: 5px;
        height: 100vh;
        overflow: hidden;
        justify-content: space-between;
    }
    
    html, body {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

.header {
    flex-shrink: 0;
    width: 100%;
    padding: 10px 0;
    position: relative;
}

.header h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: bold;
}

.header .dark-mode-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    cursor: pointer;
    font-size: 1.5rem;
    padding: 5px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.header .dark-mode-toggle:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

body.dark .header {
    color: #d7dadc;
}

body.dark .header .dark-mode-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Mobile header adjustments */
@media (max-width: 768px) {
    .header {
        padding: 5px 0;
    }
    
    .header h1 {
        font-size: 1.3rem;
        margin: 0;
    }
    
    .header .dark-mode-toggle {
        font-size: 1.1rem;
        top: 3px;
        right: 5px;
        padding: 3px;
    }
}

.board {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 400px;
    margin: 15px 0;
}

.board-row {
    display: flex;
    flex-direction: row;
    justify-content: center;
    width: 100%;
    margin-bottom: 5px;
}

.board-row.current {
    background-color: #eee;
    border: 2px solid #ccc;
    border-radius: 8px;
    padding: 2px;
}

body.dark .board-row.current {
    background-color: #888;
    border: 2px solid #555;
}

/* Mobile board adjustments - More space since visual keyboard is hidden */
@media (max-width: 768px) {
    .board {
        margin: 15px 0;
        max-width: 320px;
        flex: 1;
        justify-content: center;
    }
    
    .board-row {
        margin-bottom: 4px;
    }
    
    .board-row.current {
        border-radius: 6px;
        padding: 2px;
    }
}

.tile {
    background-color: #ddd;
    border-radius: 6px;
    width: 60px;
    height: 60px;
    margin: 3px;
    line-height: 60px;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.tile.present {
    background-color: #c9b458;
    color: #fff;
    border-color: #b8a147;
}

.tile.correct {
    background-color: #6aaa64;
    color: #fff;
    border-color: #5d9956;
}

body.dark .tile {
    background-color: #777;
    color: #fff;
}

body.dark .tile.present {
    background-color: #c9b458;
    border-color: #b8a147;
}

body.dark .tile.correct {
    background-color: #6aaa64;
    border-color: #5d9956;
}

/* Mobile tile adjustments - Larger tiles with more space available */
@media (max-width: 768px) {
    .tile {
        width: 50px;
        height: 50px;
        margin: 3px;
        font-size: 1.6rem;
        border-radius: 4px;
        line-height: 50px;
    }
}

@media (max-width: 480px) {
    .tile {
        width: 45px;
        height: 45px;
        margin: 2px;
        font-size: 1.4rem;
        line-height: 45px;
    }
}

.keyboard {
    flex-shrink: 0;
    width: 100%;
    max-width: 500px;
    margin-top: 15px;
    padding: 0 10px;
}

.mobile-hint {
    background-color: rgba(106, 170, 100, 0.1);
    border: 1px solid #6aaa64;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
    font-size: 1rem;
    color: #6aaa64;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    font-weight: 500;
}

.mobile-hint:active {
    background-color: rgba(106, 170, 100, 0.2);
    transform: scale(0.98);
}

body.dark .mobile-hint {
    background-color: rgba(106, 170, 100, 0.15);
    color: #8bc34a;
    border-color: #8bc34a;
}

/* Make mobile hint more prominent on mobile */
@media (max-width: 768px) {
    .mobile-hint {
        padding: 20px;
        font-size: 1.1rem;
        margin: 15px 0;
        box-shadow: 0 2px 8px rgba(106, 170, 100, 0.2);
    }
}

.keyboard > div {
    display: flex;
    justify-content: center;
    margin-bottom: 6px;
    gap: 3px;
}

.btn.key {
    background-color: #ddd;
    border: none;
    border-radius: 6px;
    height: 48px;
    padding: 0 12px;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 32px;
    color: #333;
}

.btn.key:hover {
    background-color: #bbb;
    transform: scale(1.05);
}

.btn.key:active {
    transform: scale(0.95);
}

.btn.key.wrong {
    background-color: #777;
    color: #fff;
}

.btn.key.right {
    background-color: #6aaa64;
    color: #fff;
}

.btn.key.present {
    background-color: #c9b458;
    color: #fff;
}

/* Special keys styling */
.btn.key[data-key="ENTER"],
.btn.key[data-key="⌫"] {
    min-width: 64px;
    font-size: 0.8rem;
}

body.dark .btn.key {
    background-color: #777;
    color: #fff;
}

body.dark .btn.key:hover {
    background-color: #888;
}

body.dark .btn.key.wrong {
    background-color: #444;
}

body.dark .btn.key.right {
    background-color: #6aaa64;
}

body.dark .btn.key.present {
    background-color: #c9b458;
}

/* Mobile keyboard adjustments - Hide visual keyboard on mobile */
@media (max-width: 768px) {
    .keyboard > div {
        display: none !important;
    }
    
    .keyboard {
        margin-top: 10px;
        padding: 0 3px;
    }
    
    /* Keep only the mobile hint visible */
    .mobile-hint {
        display: block !important;
    }
}

.popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 2px solid #ddd;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    text-align: center;
}

body.dark .popup {
    background-color: rgba(70, 70, 70, 0.95);
    color: #d7dadc;
    border-color: #555;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.popup h1 {
    margin-top: 0;
    margin-bottom: 15px;
}

.popup hr {
    margin: 15px 0;
    border: none;
    border-top: 1px solid #ddd;
}

body.dark .popup hr {
    border-top-color: #555;
}

.popup .btn {
    margin-top: 15px;
    padding: 12px 24px;
    font-size: 1rem;
    border-radius: 8px;
}

/* Mobile popup adjustments */
@media (max-width: 768px) {
    .popup {
        padding: 20px;
        border-radius: 10px;
        max-width: 95vw;
    }
    
    .popup h1 {
        font-size: 1.5rem;
    }
    
    .popup .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .popup {
        padding: 15px;
        border-radius: 8px;
    }
    
    .popup h1 {
        font-size: 1.3rem;
    }
}

.shake {
    animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% {
    transform: translate3d(-1px, 0, 0);
  }

  20%, 80% {
    transform: translate3d(2px, 0, 0);
  }

  30%, 50%, 70% {
    transform: translate3d(-4px, 0, 0);
  }

  40%, 60% {
    transform: translate3d(4px, 0, 0);
  }
}

/* Mobile input field for native keyboard */
.mobile-input {
    position: fixed;
    top: -100px;
    left: -100px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    z-index: -1;
    font-size: 16px; /* Prevent zoom on iOS */
}

/* Show mobile input on mobile devices */
@media (max-width: 768px) {
    .mobile-input {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 1px;
        height: 1px;
        opacity: 0;
        pointer-events: auto;
        z-index: 1000;
        border: none;
        outline: none;
        background: transparent;
        color: transparent;
        caret-color: transparent;
    }
}

/* Touch enhancements */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow interaction with buttons */
button, .btn {
    -webkit-tap-highlight-color: rgba(0,0,0,0.2);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* Allow text selection in popups */
.popup {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Focus states for accessibility */
.btn.key:focus {
    outline: 2px solid #6aaa64;
    outline-offset: 2px;
}

body.dark .btn.key:focus {
    outline-color: #c9b458;
}

/* Loading animation for tiles */
@keyframes tileFlip {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(90deg); }
    100% { transform: rotateY(0deg); }
}

.tile.flip {
    animation: tileFlip 0.6s ease-in-out;
}

/* Safe area insets for modern mobile devices */
@supports (padding: max(0px)) {
    .main-container {
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .tile {
        border-width: 3px;
    }
    
    .btn.key {
        border: 2px solid currentColor;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Desktop sidebar ads */
.desktop-only {
    display: none;
}

/* Show ads only on desktop screens (wider than 1200px to ensure enough space) */
@media (min-width: 1200px) {
    .desktop-only {
        display: block;
    }
    
    .left-ad {
        position: fixed;
        top: 50%;
        left: 10px;
        transform: translateY(-50%);
        width: 160px;
        max-height: 600px;
        z-index: 100;
    }
    
    .right-ad {
        position: fixed;
        top: 50%;
        right: 10px;
        transform: translateY(-50%);
        width: 160px;
        max-height: 600px;
        z-index: 100;
    }
    
    /* Ensure main content has enough margin to not overlap with ads */
    body {
        margin-left: 180px;
        margin-right: 180px;
    }
    
    .main-container {
        max-width: calc(100% - 360px);
    }
}

/* For very wide screens, increase ad space */
@media (min-width: 1600px) {
    .left-ad, .right-ad {
        width: 200px;
    }
    
    .left-ad {
        left: 20px;
    }
    
    .right-ad {
        right: 20px;
    }
    
    body {
        margin-left: 240px;
        margin-right: 240px;
    }
}

/* Bottom ad section */
.bottom-ad-section {
    width: 100%;
    min-height: 400px;
    margin-top: 100vh; /* Push below the fold */
    padding: 40px 20px;
    background-color: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.dark .bottom-ad-section {
    background-color: #2a2a2c;
    border-top-color: #555;
}

/* Ensure body can scroll to show bottom ad */
html, body {
    min-height: 200vh; /* Ensure scrollable content */
}

/* Adjust main container to not interfere with bottom ad */
.main-container {
    min-height: 100vh;
}

/* Override desktop margins for body height */
@media (min-width: 1200px) {
    body {
        min-height: 200vh;
    }
}
