* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: #DAC0A1; /* Теплый песочный фон */
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
}

.game-container {
    width: 100%;
    max-width: 500px;
    background: #F5E6D3; /* Светлый кремовый */
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 8px 20px rgba(109, 76, 65, 0.2);
    border: 1px solid #D6B89D;
}

.screen {
    width: 100%;
}

.header {
    text-align: center;
    margin-bottom: 20px;
}

h1 {
    color: #6F4E37; /* Кофейный */
    font-size: clamp(20px, 6vw, 28px);
    margin-bottom: 4px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.subtitle {
    color: #A67B5B; /* Средний кофейный */
    font-size: clamp(12px, 3vw, 14px);
    font-weight: 400;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 10px 14px;
    background: #EAD7C1; /* Светлый песочный */
    border-radius: 16px;
    color: #6F4E37;
    font-size: clamp(12px, 3vw, 14px);
    border: 1px solid #D6B89D;
}

.room-code {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #8B5A2B; /* Темный песочный */
    background: #F5E6D3;
    padding: 6px 12px;
    border-radius: 30px;
    border: 1px solid #D6B89D;
}

.copy-code-btn {
    background: #D6B89D;
    border: none;
    color: #6F4E37;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 14px;
    transition: background 0.2s;
}

.copy-code-btn:hover {
    background: #C4A27A;
}

.player-status {
    color: #A67B5B;
    font-weight: 500;
}

.code-section {
    background: #EAD7C1;
    border-radius: 20px;
    padding: 24px;
    border: 1px solid #D6B89D;
}

.input-group {
    margin-bottom: 16px;
}

.input-label {
    display: block;
    color: #6F4E37;
    margin-bottom: 6px;
    font-size: clamp(12px, 3vw, 14px);
    font-weight: 500;
}

.code-input {
    width: 100%;
    padding: 14px;
    border: 2px solid #C4A27A;
    border-radius: 16px;
    background: #F5E6D3;
    color: #6F4E37;
    font-size: clamp(16px, 5vw, 18px);
    text-align: center;
    letter-spacing: 2px;
    outline: none;
    transition: border-color 0.2s;
}

.code-input::placeholder {
    color: #C4A27A;
}

.code-input:focus {
    border-color: #8B5A2B;
}

.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 40px;
    font-size: clamp(14px, 4vw, 16px);
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 12px;
    transition: transform 0.1s, opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: #8B5A2B; /* Кофейный */
    color: #F5E6D3;
    box-shadow: 0 2px 0 #5A3A1C;
}

.btn-primary:active {
    transform: translateY(2px);
    box-shadow: none;
}

.btn-secondary {
    background: #D6B89D;
    color: #6F4E37;
    box-shadow: 0 2px 0 #B89A7A;
}

.btn-secondary:active {
    transform: translateY(2px);
    box-shadow: none;
}

.waiting-message {
    text-align: center;
    color: #6F4E37;
    padding: 30px 20px;
    background: #EAD7C1;
    border-radius: 20px;
    margin: 20px 0;
    border: 1px solid #D6B89D;
}

.room-code-large {
    font-size: clamp(28px, 8vw, 32px);
    color: #8B5A2B;
    margin: 20px 0;
    font-weight: bold;
    letter-spacing: 4px;
    word-break: break-all;
}

.loader {
    border: 3px solid #D6B89D;
    border-top: 3px solid #8B5A2B;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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

.game-phase {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.game-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #EAD7C1;
    border-radius: 60px;
    padding: 12px 20px;
    border: 1px solid #D6B89D;
}

.player-info {
    font-size: clamp(16px, 4.5vw, 18px);
    color: #6F4E37;
    font-weight: 500;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-pieces {
    font-size: clamp(26px, 6vw, 30px);
    color: #8B5A2B;
}

.turn-indicator {
    font-size: clamp(16px, 4vw, 20px);
    font-weight: 600;
    padding: 8px 24px;
    border-radius: 40px;
    background: #F5E6D3;
    color: #6F4E37;
    white-space: nowrap;
    border: 1px solid #D6B89D;
}

.turn-indicator.your-turn {
    background: #A67B5B;
    color: #F5E6D3;
    border-color: #6F4E37;
}

.turn-indicator.opponent-turn {
    background: #D6B89D;
    color: #6F4E37;
    border-color: #B89A7A;
}

.board-container {
    position: relative;
    background: #EAD7C1;
    border-radius: 20px;
    padding: 12px;
    border: 1px solid #D6B89D;
}

#backgammonBoard {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 12px;
    touch-action: manipulation;
    aspect-ratio: 2/1; /* Фиксируем соотношение сторон */
    background: #D6B89D;
}

.dice-button-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    width: 70%;
    max-width: 250px;
}

.dice-button {
    font-size: clamp(20px, 5.5vw, 24px);
    padding: 16px 24px;
    background: #8B5A2B;
    color: #F5E6D3;
    border: none;
    width: 100%;
    border-radius: 60px;
    box-shadow: 0 4px 0 #5A3A1C;
    -webkit-tap-highlight-color: transparent;
    font-weight: 700;
    letter-spacing: 1px;
}

.dice-button:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* Адаптация для очень маленьких экранов */
@media (max-width: 380px) {
    .game-info-bar {
        flex-direction: column;
        gap: 12px;
        border-radius: 30px;
    }

    .turn-indicator {
        width: 100%;
        text-align: center;
    }

    .dice-button {
        font-size: 18px;
        padding: 14px 20px;
    }
}

/* Адаптация для планшетов */
@media (min-width: 768px) {
    .game-container {
        max-width: 700px;
    }

    #backgammonBoard {
        aspect-ratio: 2/1.1;
    }

    .dice-button {
        font-size: 26px;
        padding: 18px 28px;
    }
}

/* Отключение выделения */
.btn, .copy-code-btn, .dice-button, .turn-indicator, .player-info {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Броски */

.dice-result {
    position: absolute;
    display: flex;
    gap: 8px;
    transform: translate(-50%, -50%);
    z-index: 20;
}

.dice-result.player {
    top: 50%;
    left: 25%;
}

.dice-result.opponent {
    top: 50%;
    left: 75%;
}

.dice-small {
    width: 32px;
    height: 32px;
    background: white;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #333;
    border: 1px solid #8B5A2B;
    box-shadow: 0 2px 0 #5A3A1C;
}

@media (max-width: 480px) {
    .dice-small {
        width: 28px;
        height: 28px;
        font-size: 18px;
    }

    .dice-result {
        gap: 6px;
    }
}
