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

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.container {
    text-align: center;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.game-header-main {
    text-align: center;
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.logo {
    width: 320px;
    height: auto;
    margin-bottom: 10px;
}

h1 {
    text-align: center;
    color: #2196F3;
    font-size: 2.5em;
    margin: 10px 0;
    text-transform: uppercase;
    background: linear-gradient(45deg, #1976D2, #2196F3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    letter-spacing: 2px;
    position: relative;
}

h1::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 3px;
    background: linear-gradient(90deg, transparent, #2196F3, transparent);
}

.game-area {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    width: 320px; /* Fixed width based on grid size */
    margin: 0 auto;
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 20px auto;
    max-width: 400px;
    padding: 10px;
}

.grid-cell {
    width: 60px;
    height: 60px;
    background-color: #e9ecef;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: #495057;
    cursor: pointer;
    transition: background-color 0.2s;
}

.grid-cell:hover {
    background-color: #dee2e6;
}

.grid-cell.selected {
    background-color: #ffe5e5;
    color: #c53030;
    border-color: #fc8181;
    box-shadow: 0 0 5px rgba(252, 129, 129, 0.3);
    transform: scale(1.05);
}

.grid-cell.selected:hover {
    background-color: #fed7d7;
    border-color: #fc8181;
}

.grid-cell.frozen {
    background-color: #e8f4ff;
    color: #2c5282;
    cursor: not-allowed;
    position: relative;
    overflow: hidden;
    border-color: #90cdf4;
    box-shadow: inset 0 0 10px rgba(144, 205, 244, 0.5);
}

.grid-cell.frozen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        linear-gradient(45deg, transparent 45%, #fff 46%, transparent 47%) 0 0 / 10px 10px,
        linear-gradient(-45deg, transparent 45%, #fff 46%, transparent 47%) 0 0 / 10px 10px;
    opacity: 0.3;
    pointer-events: none;
}

.grid-cell.frozen::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        linear-gradient(90deg, transparent 48%, #90cdf4 49%, #90cdf4 51%, transparent 52%) 0 0 / 20px 20px,
        linear-gradient(0deg, transparent 48%, #90cdf4 49%, #90cdf4 51%, transparent 52%) 0 0 / 20px 20px;
    opacity: 0.4;
    pointer-events: none;
}

.grid-cell.power-1 {
    background-color: #f5f5f5;
    border-color: #ddd;
}

.grid-cell.power-2 {
    background-color: #fff9c4;
    border-color: #fbc02d;
}

.grid-cell.power-3 {
    background-color: #c8e6c9;
    border-color: #4caf50;
}

.grid-cell.power-4 {
    background-color: #bbdefb;
    border-color: #1976d2;
}

.grid-cell.power-5 {
    background-color: #e1bee7;
    border-color: #7b1fa2;
}

.grid-cell[data-uses]:after {
    content: attr(data-uses);
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 10px;
    opacity: 0.7;
}

.current-word {
    font-size: 24px;
    font-weight: bold;
    margin: 20px 0;
    min-height: 36px;
    color: #495057;
}

.buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 20px;
}

button {
    padding: 10px 20px;
    font-size: 16px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

button:hover {
    background-color: #0056b3;
}

button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.65;
}

#clearButton {
    background-color: #f44336;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
}

#clearButton:hover {
    background-color: #da190b;
}

.message {
    min-height: 24px;
    margin-bottom: 10px;
    font-weight: bold;
}

.message.error {
    color: #dc3545;
}

.message.success {
    color: #28a745;
}

.found-words {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    max-width: 100%;
    padding: 10px;
}

.found-word {
    background-color: #e9ecef;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 14px;
    color: #495057;
    white-space: nowrap;
}

.loading {
    font-size: 18px;
    color: #666;
    margin: 20px 0;
    text-align: center;
}

.score-display, .timer-display {
    font-size: 20px;
    font-weight: bold;
    color: #495057;
    padding: 5px 10px;
    background-color: #e9ecef;
    border-radius: 8px;
    min-width: 120px;
}

.timer-display.warning {
    color: #dc3545;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    overflow-y: auto;
    padding: 20px 0;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 30px;
    border: none;
    border-radius: 12px;
    width: 80%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    color: #1976D2;
    font-size: 2.5em;
    margin-bottom: 10px;
    text-align: center;
    text-transform: uppercase;
    background: linear-gradient(45deg, #1976D2, #2196F3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-content p {
    text-align: center;
    font-size: 2em;
    margin: 20px 0;
    padding: 15px;
    background: linear-gradient(45deg, #f3f3f3, #ffffff);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.modal-content p span {
    color: #1976D2;
    font-weight: bold;
    font-size: 1.2em;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin: 25px 0;
}

.stat-box {
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
    border-radius: 10px;
    padding: 20px 15px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s ease;
}

.stat-box:hover {
    transform: translateY(-2px);
}

.stat-box .stat-label {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-box .stat-value {
    color: #1976D2;
    font-size: 1.5em;
    font-weight: bold;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.stat-box {
    padding: 10px;
    background-color: #f5f5f5;
    border-radius: 5px;
    text-align: center;
}

.stat-box .stat-label {
    font-size: 14px;
    color: #666;
    margin-bottom: 5px;
}

.stat-box .stat-value {
    font-size: 18px;
    font-weight: bold;
    color: #333;
}

.game-modes {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-button {
    padding: 10px 20px;
    font-size: 16px;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: white;
    position: relative;
    opacity: 0.85;
}

.mode-button:hover {
    opacity: 1;
    transform: translateY(-1px);
}

.mode-button.active {
    opacity: 1;
    border: 2px solid white;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    transform: translateY(-1px);
}

.mode-button[data-mode="classic"] {
    background-color: #2196F3;
}

.mode-button[data-mode="classic"].active {
    background-color: #1976D2;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.4);
}

.mode-button[data-mode="freeze"] {
    background-color: #9C27B0;
}

.mode-button[data-mode="freeze"].active {
    background-color: #7B1FA2;
    box-shadow: 0 0 10px rgba(156, 39, 176, 0.4);
}

.mode-button[data-mode="power"] {
    background-color: #FF9800;
}

.mode-button[data-mode="power"].active {
    background-color: #F57C00;
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.4);
}

#playAgainButton {
    display: block;
    margin: 0;
    padding: 12px 25px;
    font-size: 1.1em;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#playAgainButton:hover:not(:disabled) {
    background-color: #45a049;
    transform: translateY(-1px);
}

#playAgainButton:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

.word-length-stats {
    margin: 25px 0;
    text-align: left;
    padding: 0 15px;
}

.word-length-stats h3 {
    text-align: center;
    margin-bottom: 15px;
    color: #495057;
    font-size: 1.2em;
}

.word-length-chart {
    padding: 15px 25px 15px 0;
}

.stat-row {
    display: flex;
    align-items: center;
    margin: 5px 0;
}

.length-label {
    width: 35px;
    font-weight: bold;
    color: #495057;
    text-align: center;
}

.bar-container {
    flex-grow: 1;
    margin-left: 15px;
    height: 24px;
    background-color: #e9ecef;
    border-radius: 4px;
    position: relative;
}

.bar {
    height: 100%;
    background-color: #4CAF50;
    border-radius: 4px;
    transition: width 0.3s ease-in-out;
}

.count-label {
    position: absolute;
    right: -25px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #6c757d;
}

.top-words {
    margin: 15px 0;
    padding: 12px;
    background: linear-gradient(135deg, #FF6B6B, #FF8E53);
    border-radius: 10px;
    color: white;
}

.top-words h3 {
    text-align: center;
    font-size: 1.1em;
    margin-bottom: 10px;
    text-transform: uppercase;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.top-word {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    margin: 5px 0;
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    font-size: 1.1em;
    transition: transform 0.2s ease;
}

.top-word:hover {
    transform: translateX(5px);
}

.top-word.rank-1 {
    background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.1));
    font-size: 1.2em;
}

.top-word.rank-2 {
    background: linear-gradient(135deg, rgba(255,255,255,0.15), rgba(255,255,255,0.05));
    font-size: 1.1em;
}

.top-word.rank-3 {
    background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0));
    font-size: 1em;
}

.top-word .word {
    font-weight: bold;
    text-transform: uppercase;
}

.top-word .score {
    background: rgba(255,255,255,0.2);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: bold;
}

.nav-links {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 1rem;
}

.nav-links a {
    color: #1976D2;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.nav-links a:hover {
    background-color: #e3f2fd;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-top: 20px;
}

.modal-buttons button {
    width: 200px;
}

.secondary-button {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    margin: 0;
}

.secondary-button:hover {
    background-color: #5a6268;
}

@media (max-width: 480px) {
    .modal-content {
        width: 95%;
        padding: 20px;
        margin: 5vh auto;
    }

    .stats-grid {
        gap: 10px;
    }

    .stat-box {
        padding: 10px;
    }

    .word-length-stats {
        padding: 0 5px;
    }

    .word-length-chart {
        padding: 10px 20px 10px 0;
    }
}
