html {
    height: 100%;
    overflow: hidden;
}

body {
    display: flex;
    margin: 0;
    padding: 0;
    font-family: 'Roboto', sans-serif;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    background-color: #ffffff !important;
    color: #000000;
    min-height: 100vh;
    height: 100%;
    overflow: hidden;
}

.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    gap: 2px;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

.grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.board-title {
    font-size: 24px;
    font-weight: 700;
    margin: 24px 0 16px;
    color: #2c3e50;
    text-align: left;
    font-family: 'Roboto', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    height: auto;
    width: auto;
}

.screen {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding-bottom: 3rem;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

/* Главное меню */
#main-menu, #game-screen, #board-container {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.menu-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-select {
    padding: 8px 12px;
    font-size: 1rem;
    border: 2px solid #2c3e50;
    border-radius: 25px;
    background-color: white;
    color: #2c3e50;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    min-width: 200px;
}

.user-select:hover {
    border-color: #3498db;
}

.user-select:focus {
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.username-display {
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
}

.game-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 4rem;
    margin: 0;
    color: #2c3e50;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.play-button {
    margin-top: 2rem;
    padding: 1rem 3rem;
    font-size: 1.5rem;
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.play-button:hover {
    transform: translateY(-2px);
    background-color: #27ae60;
}

.logout-button {
    position: relative;
    font-size: 1.2rem;
    z-index: 1000;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Игровой экран */
#game-screen {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding-bottom: 3rem;
    box-sizing: border-box;
}

.game-header {
    width: 100%;
    display: flex;
    align-items: center;
    padding: 0.5rem 1.5rem;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    height: 20px;
    flex-shrink: 0;
}

.game-header-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 1rem;
    margin: 0;
    color: #2c3e50;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.leave-button {
    padding: 0.5rem 1.5rem;
    font-size: 1rem;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-left: auto;
    z-index: 1;
    height: 32px;
    line-height: 1;
}

.share-button {
    padding: 0.5rem 1.5rem;
    font-size: 1rem;
    background-color: #4d4dc9;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-right: auto;
    z-index: 1;
    height: 32px;
    line-height: 1;
}

.leave-button:hover {
    background-color: #c0392b;
}

.game-boards {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem 1rem;
    overflow-y: auto;
    min-height: 0;
    position: relative;
    scroll-padding-bottom: 300px; /* space for keyboard on mobile */
}

.board-row {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    max-width: 1200px;
    gap: 2px;
}

.board-divider {
    width: 2px;
    height: 100%;
    background-color: #ccc;
    margin: 0 2px;
}

#board, #opponent_board {
    width: 100%;
    max-width: 400px;
    padding: 10px;
    margin-top: 0;
}

#my-board-title, #opponent-board-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #2c3e50;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    z-index: 1000;
    padding-top: 20px;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 10px;
    text-align: center;
    max-width: 90%;
    width: 400px;
    margin-top: 20px;
}

.modal-content h2 {
    margin: 0 0 1.5rem 0;
    color: #2c3e50;
    font-size: 1.8rem;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.modal-buttons .play-button,
.modal-buttons .leave-button {
    flex: 1;
    max-width: 150px;
}

/* Баннеры */
#banner {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    padding: 8px 16px;
    border-radius: 6px;
    color: white;
    text-align: center;
    z-index: 1000;
    display: none;
    white-space: nowrap;
    min-width: 200px;
}

#banner p {
    margin: 0;
    font-size: 18px;
    font-weight: bold;
}

#banner.show {
    display: block;
}

/* Стили для досок */
.board-row, .opp-board-row {
    display: flex;
    justify-content: center;
    margin-bottom: 5px;
}

.board-column, .opp-board-column {
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    text-transform: uppercase;
    border: 1px solid #000;
    background-color: #fff;
    color: #000;
    transition: all 0.3s ease;
}

.board-column {
    width: 50px;
    height: 50px;
    margin: 1px;
    font-size: 1.2rem;
}

.opp-board-column {
    width: 50px;
    height: 50px;
    margin: 1px;
    font-size: 1.2rem;
}

/* Цвета для букв */
.board-column.grey, .opp-board-column.grey {
    background-color: #787c7e;
    color: #fff;
    border-color: #787c7e;
}

.board-column.yellow, .opp-board-column.yellow {
    background-color: #c9b458;
    color: #fff;
    border-color: #c9b458;
}

.board-column.green, .opp-board-column.green {
    background-color: #6aaa64;
    color: #fff;
    border-color: #6aaa64;
}

/* Input row styles */
.input-row {
    position: sticky;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid #e0e0e0;
    padding: 10px;
    z-index: 10;
    width: 100%;
    /* Ensure it stays above virtual keyboard on mobile */
    /* padding-bottom: calc(10px + env(safe-area-inset-bottom)); */
}

.input-container {
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

.input-columns {
    display: flex;
    gap: 4px;
    justify-content: center;
}

.input-column {
    width: 60px;
    height: 60px;
    border: 2px solid #d3d6da;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    text-transform: uppercase;
    background-color: white;
    color: #1a1a1b;
    transition: all 0.2s ease;
}

.input-column.filled {
    border-color: #878a8c;
    background-color: #f8f9fa;
}

.input-column:focus {
    border-color: #1a1a1b;
    outline: none;
}

.input-row:hover {
    background: rgba(255, 255, 255, 0.98);
}

.input-column:hover {
    border-color: #1a1a1b;
    background-color: #f8f9fa;
}

/* Медиа-запросы */
@media (max-width: 768px) {
    .game-boards {
        padding: 1rem 2px 2px;
    }

    .board-row {
        gap: 2px;
    }

    .board-divider {
        width: 2px;
        margin: 0 2px;
    }

    #my-board-title, #opponent-board-title {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    .board-column, .opp-board-column {
        width: 35px;
        height: 35px;
        margin: 1px;
        font-size: 1rem;
    }
    
    /* Input row mobile adjustments */
    .input-column {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .input-container {
        max-width: 300px;
    }
}

@media (max-width: 480px) {
    .game-boards {
        padding: 1rem 2px 2px;
    }

    .board-row {
        gap: 2px;
    }

    .board-divider {
        width: 2px;
        margin: 0 2px;
    }

    .board-column, .opp-board-column {
        width: 25px;
        height: 25px;
        margin: 1px;
        
    /* Input row small mobile adjustments */
    .input-column {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    .input-container {
        max-width: 280px;
    }
        font-size: 0.8rem;
    }
}

/* Анимации */
@keyframes flipIn {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.8);
    }
}

.board-column.animate, .opp-board-column.animate {
    animation: flipIn 0.3s ease;
}

header {
    height: 40px;
    background-color: black;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 15px;
    padding-left: 20px;
    width: calc(100% - 20px);
}

header div {
    margin: 10px;
}

#sub-header {
    font-size: 12px;
}

footer {
    height: 60px;
    background-color: #000;
    width: 100%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    flex-direction: column;
    font-size: 13px;
}

footer a {
    color: #fff100;
}

section#canvas {
    width: 100%;
    background-color: #1b1b1b;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    height: calc(100vh - 100px);
}

#messages {
    border-radius: 5px;
    display: flex;
    opacity: 0;
    position: fixed;
    background-color: #000000;
    height: 30px;
    width: auto;
    padding: 5px;
    color: #fff;
    top: 50px;
    z-index: 99;
    align-items: center;
    justify-content: center;
    transition: all 1s;
}

#messages.shown {
    opacity: 1;
}

#hidden-input {
    position: fixed;
    opacity: 0;
    height: 0;
    width: 0;
    padding: 0;
    border: none;
    margin: 0;
    z-index: -1;
    bottom: 0;
    left: 0;
    right: 0;
}

.board-column-front, .board-column-back,
.opp-board-column-front, .opp-board-column-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
    border: 1px solid #000;
}

.opp-board-column-front, .opp-board-column-back {
    font-size: 0.8rem;
}

.board-column-front, .opp-board-column-front {
    background-color: #fff;
    color: #000;
}

.board-column-back, .opp-board-column-back {
    background-color: #787c7e;
    color: #fff;
    transform: rotateX(180deg);
}

.board-column-back.yellow, .opp-board-column-back.yellow {
    background-color: #c9b458;
}

.board-column-back.green, .opp-board-column-back.green {
    background-color: #6aaa64;
}

.board-column-front::after, .board-column-back::after,
.opp-board-column-front::after, .opp-board-column-back::after {
    content: attr(data-letter);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.board-column-back::after, .opp-board-column-back::after {
    transform: translate(-50%, -50%) rotateX(180deg);
}

.opp-board-column.flipped {
    transform: rotateY(180deg);
}

.opp-board-column-front, .opp-board-column-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    padding-left: 1px;
}

.opp-board-column-back {
    /* background-color: blue; */
    transform: rotateY(180deg);
}

.grey {
    background-color: #6f6f6f;
}

.yellow {
    background-color: #e8cc37;
}

.green {
    background-color: #27a22c;
}

.keypad-special-key {
    height: 2rem;
    width: 3rem;
    background: #e7e3e3;
    color: #000;
    border-radius: 5px;
    padding: 5px;
    margin: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
}

.disabled-button {
    background-color: #a9a9a9;
    opacity: 0.6;
    pointer-events: none;
}

@media (prefers-color-scheme: dark) {
    #main-menu, #game-screen, #board-container {
        background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%) !important;
    }
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    margin: 20px auto;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#waiting-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#waiting-screen .game-title {
    margin-bottom: 30px;
}

.powered-by-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.45rem 0;
    font-size: 0.85rem;
    text-align: center;
    background: rgba(255, 255, 255, 0.92);
    color: #2c3e50;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 2500;
}

.powered-by-footer a {
    color: #1a73e8;
    text-decoration: none;
    font-weight: 600;
}

.powered-by-footer a:hover {
    text-decoration: underline;
}
