* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a1929;
    --bg-secondary: #001e3c;
    --tile-base: #0074D9;
    --tile-highlight: #39a0ff;
    --tile-selected: #7FDBFF;
    --text-primary: #FFFFFF;
    --text-score: #7FDBFF;
    --overlay-bg: rgba(10, 25, 41, 0.95);
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header header"
        "main sidebar"
        "footer footer";
    gap: 20px;
    padding: 20px;
}

#game-header {
    grid-area: header;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: rgba(0, 30, 60, 0.5);
    border-radius: 10px;
    padding: 15px;
    backdrop-filter: blur(10px);
}

.score-container,
.timer-container,
.words-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.label {
    font-size: 14px;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.value {
    font-size: 32px;
    font-weight: bold;
    color: var(--text-score);
    text-shadow: 0 0 20px rgba(127, 219, 255, 0.5);
}

#game-main {
    grid-area: main;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

#game-canvas {
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    background: transparent;
    display: block;
    margin: 0 auto;
}

#game-sidebar {
    grid-area: sidebar;
    width: 200px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.current-word {
    background: rgba(0, 30, 60, 0.5);
    border-radius: 10px;
    padding: 15px;
    backdrop-filter: blur(10px);
    min-height: 60px;
}

.current-word h3 {
    margin-bottom: 10px;
    font-size: 16px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#current-word-text {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-score);
    text-align: center;
    min-height: 32px;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(127, 219, 255, 0.5);
    animation: pulse-subtle 2s ease-in-out infinite;
}

@keyframes pulse-subtle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* Mobile current word display - hidden by default on desktop */
.current-word-mobile {
    display: none;
}

.found-words {
    background: rgba(0, 30, 60, 0.5);
    border-radius: 10px;
    padding: 15px;
    backdrop-filter: blur(10px);
    max-height: 400px;
    overflow-y: auto;
}

.found-words h3 {
    margin-bottom: 10px;
    font-size: 16px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#found-words-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#found-words-list li {
    padding: 5px 10px;
    background: rgba(127, 219, 255, 0.1);
    border-radius: 5px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.combo-display {
    background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    animation: pulse 0.5s ease-in-out infinite;
}

.combo-display.hidden {
    display: none;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.combo-text {
    display: block;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 2px;
}

.combo-multiplier {
    display: block;
    font-size: 28px;
    font-weight: bold;
    margin-top: 5px;
}

#game-footer {
    grid-area: footer;
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 10px;
}

.icon-button {
    width: 50px;
    height: 50px;
    border: none;
    background: rgba(0, 30, 60, 0.5);
    color: var(--text-primary);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.icon-button:hover {
    background: rgba(0, 116, 217, 0.5);
    transform: scale(1.1);
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
    z-index: 10;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 30px;
    background: rgba(0, 30, 60, 0.8);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.overlay-content h2 {
    font-size: 48px;
    margin-bottom: 20px;
    background: linear-gradient(135deg, var(--tile-highlight) 0%, var(--tile-selected) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.overlay-content p {
    font-size: 18px;
    margin-bottom: 30px;
    opacity: 0.9;
}

.game-button {
    padding: 15px 40px;
    font-size: 20px;
    font-weight: bold;
    background: linear-gradient(135deg, var(--tile-base) 0%, var(--tile-highlight) 100%);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.game-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(57, 160, 255, 0.5);
}

/* Grid size selector */
.grid-size-selector {
    margin: 20px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.grid-size-selector label {
    font-size: 16px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.grid-size-select {
    padding: 8px 16px;
    font-size: 16px;
    font-weight: 500;
    border: 2px solid rgba(127, 219, 255, 0.3);
    border-radius: 8px;
    background: rgba(0, 30, 60, 0.5);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.grid-size-select:hover {
    border-color: var(--tile-highlight);
    background: rgba(0, 30, 60, 0.7);
}

.grid-size-select:focus {
    outline: none;
    border-color: var(--tile-selected);
    box-shadow: 0 0 0 3px rgba(127, 219, 255, 0.2);
}

.grid-size-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Start modal button layout */
.start-modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin: 30px 0;
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stat-label {
    font-size: 14px;
    opacity: 0.8;
    text-transform: uppercase;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: var(--text-score);
}

.panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(10, 25, 41, 0.98);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    z-index: 100;
    backdrop-filter: blur(20px);
}

.panel.hidden {
    display: none;
}

.panel-content h3 {
    margin-bottom: 20px;
    font-size: 24px;
}

.setting-group {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-group label {
    font-size: 14px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.setting-group select,
.setting-group input {
    padding: 10px;
    background: rgba(0, 30, 60, 0.5);
    border: 1px solid rgba(127, 219, 255, 0.3);
    border-radius: 5px;
    color: white;
    font-size: 16px;
}

.setting-group select option {
    background: var(--bg-primary);
}

.range-value {
    color: var(--text-score);
    font-size: 14px;
    margin-left: 10px;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-wrapper input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--tile-selected);
}

.checkbox-label {
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
}

/* Stats Panel Styles */
.stats-tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid rgba(127, 219, 255, 0.2);
}

.stats-tab {
    flex: 1;
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

.stats-tab:hover {
    background: rgba(127, 219, 255, 0.1);
}

.stats-tab.active {
    color: var(--tile-selected);
    border-bottom-color: var(--tile-selected);
}

.stats-content.hidden {
    display: none;
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.summary-stat {
    background: rgba(0, 30, 60, 0.3);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.summary-label {
    display: block;
    font-size: 14px;
    opacity: 0.8;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.summary-value {
    display: block;
    font-size: 32px;
    font-weight: bold;
    color: var(--text-score);
}

.recent-games-list {
    max-height: 300px;
    overflow-y: auto;
}

.recent-header {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1.5fr;
    gap: 10px;
    padding: 10px;
    font-weight: bold;
    border-bottom: 1px solid rgba(127, 219, 255, 0.3);
    margin-bottom: 10px;
}

.recent-game {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1.5fr;
    gap: 10px;
    padding: 10px;
    background: rgba(0, 30, 60, 0.2);
    border-radius: 5px;
    margin-bottom: 5px;
    font-size: 14px;
}

.recent-game:nth-child(odd) {
    background: rgba(0, 30, 60, 0.1);
}

.stats-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.game-button.secondary {
    background: rgba(127, 219, 255, 0.2);
    color: var(--text-primary);
}

.game-button.secondary:hover {
    background: rgba(127, 219, 255, 0.3);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 30, 60, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--tile-highlight);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--tile-selected);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    body {
        overflow: hidden;
        height: 100vh;
        position: fixed;
        width: 100%;
    }

    #game-container {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main"
            "footer";
        padding: 10px;
        gap: 10px;
        height: 100vh;
    }
    
    #game-main {
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    #game-header {
        padding: 10px 8px;
    }

    #game-sidebar {
        display: none;
    }
    
    /* Show mobile current word display above the game grid */
    .current-word-mobile {
        display: flex !important;
        background: rgba(0, 30, 60, 0.5);
        padding: 8px 15px;
        margin: 8px auto;
        width: 85%;
        max-width: 300px;
        border-radius: 10px;
        backdrop-filter: blur(10px);
        height: 42px;
        align-items: center;
        justify-content: center;
    }
    
    #current-word-text-mobile {
        font-size: 22px;
        font-weight: bold;
        color: var(--text-score);
        text-align: center;
        letter-spacing: 3px;
        text-transform: uppercase;
        text-shadow: 0 0 20px rgba(127, 219, 255, 0.5);
        animation: pulse-subtle 2s ease-in-out infinite;
    }
    
    /* Mobile button layout */
    .start-modal-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .start-modal-buttons .game-button {
        width: 200px;
    }

    .value {
        font-size: 18px;
    }

    .overlay-content {
        padding: 20px;
        margin: 10px;
    }

    .overlay-content h2 {
        font-size: 32px;
        margin-bottom: 15px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin: 20px 0;
    }

    .stat-value {
        font-size: 18px;
    }

    #game-canvas {
        max-width: 98vw;
        max-height: calc(100vh - 200px);
        width: auto !important;
        height: auto !important;
        object-fit: contain;
        display: block !important;
        margin: 0 auto !important;
        flex-shrink: 0;
        position: relative;
    }

    .icon-button {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .panel-content {
        max-width: 90vw;
        max-height: 80vh;
        overflow-y: auto;
    }

    .game-button {
        padding: 12px 30px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    #game-container {
        padding: 5px;
    }

    .value {
        font-size: 18px;
    }

    .overlay-content h2 {
        font-size: 28px;
    }

    .icon-button {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    #game-canvas {
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 200px);
    }
    
    #game-main {
        padding: 5px;
    }
}

/* Touch optimizations */
@media (hover: none) and (pointer: coarse) {
    .icon-button:hover {
        transform: none;
    }

    .game-button:hover {
        transform: none;
        box-shadow: none;
    }

    .stats-tab:hover {
        background: none;
    }

    /* Larger touch targets */
    .icon-button {
        min-width: 44px;
        min-height: 44px;
    }

    .game-button {
        min-height: 44px;
        padding: 15px 35px;
    }
}