:root {
    --light-square: #f0d9b5;
    --dark-square: #b58863;
    --highlight-move: rgba(72, 187, 120, 0.6);
    --highlight-capture: rgba(245, 101, 101, 0.7);
    --highlight-check: rgba(255, 0, 0, 0.5);
    --highlight-last-move: rgba(255, 215, 0, 0.6);
    --board-size: 640px;
    --cell-size: 80px;
    --piece-size: 60px;
}

body {
    font-family: 'Merriweather', 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-x: hidden;
}

.tlo-strony-gradient {
    background: linear-gradient(135deg, #2c3e50, #4ca1af);
    color: white;
}

a {
    color: inherit;
    text-decoration: none;
}

main {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.game-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 320px;
    max-width: 100%;
}

.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
}

.player-details {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-name {
    font-weight: bold;
    font-size: 1.1rem;
}

.status {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    background-color: #e53e3e;
}

.status.online {
    background-color: #38a169;
}

.timer {
    font-size: 1.5rem;
    font-weight: bold;
    font-family: monospace;
}

.chess-container {
    position: relative;
}

#chess-board {
    display: grid;
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(8, var(--cell-size));
    width: var(--board-size);
    height: var(--board-size);
    border: 5px solid #4a5568;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    background-color: var(--light-square);
    touch-action: none;
}

#chess-board div {
    cursor: pointer;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: var(--cell-size);
    height: var(--cell-size);
    transition: filter 0.2s;
}

#chess-board div:hover {
    filter: brightness(1.2);
}

#chess-board.board-reversed {
    transform: rotate(180deg);
}

#chess-board.board-reversed img {
    transform: rotate(180deg);
}

#chess-board img {
    width: var(--piece-size);
    height: var(--piece-size);
    transition: transform 0.2s;
    cursor: grab;
    z-index: 2;
    touch-action: none;
}

#chess-board img:hover {
    transform: scale(1.05);
}

#chess-board.board-reversed img:hover {
    transform: scale(1.05) rotate(180deg);
}

.move-marker {
    background-color: var(--highlight-move);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    position: absolute;
    z-index: 1;
    cursor: pointer;
}

.roszada-marker {
    background-color: rgba(49, 130, 206, 0.6);
}

.capture-highlight {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    box-shadow: inset 0 0 0 4px var(--highlight-capture);
    z-index: 1;
    cursor: pointer;
}

.king-in-check {
    background-color: var(--highlight-check) !important;
    animation: pulse 2s infinite;
}

.last-move {
    box-shadow: inset 0 0 0 4px var(--highlight-last-move);
}

.dragging {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    width: var(--piece-size);
    height: var(--piece-size);
    filter: drop-shadow(0 0 5px rgba(0, 0, 0, 0.5));
}

.hide-original {
    opacity: 0;
}

.move-history-container {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    padding: 15px;
}

.move-history-container h2 {
    margin-top: 0;
    font-size: 1.2rem;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 5px;
}

#move-history {
    max-height: 300px;
    overflow-y: auto;
}

.move-history-table {
    width: 100%;
    border-collapse: collapse;
}

.move-history-table th, .move-history-table td {
    padding: 4px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.move-number {
    width: 40px;
    color: rgba(255, 255, 255, 0.7);
}

.chat-container {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 5px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    height: 300px;
}

.chat-container h2 {
    margin-top: 0;
    font-size: 1.2rem;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding-bottom: 5px;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 5px;
    margin-bottom: 10px;
}

.chat-message {
    padding: 8px 12px;
    border-radius: 10px;
    max-width: 80%;
    word-wrap: break-word;
}

.chat-message.opponent {
    background-color: rgba(49, 130, 206, 0.7);
    align-self: flex-start;
    border-bottom-left-radius: 0;
}

.chat-message.self {
    background-color: rgba(72, 187, 120, 0.7);
    align-self: flex-end;
    border-bottom-right-radius: 0;
}

.chat-message .sender {
    font-weight: bold;
    font-size: 0.8rem;
    margin-bottom: 2px;
}

.chat-message .time {
    font-size: 0.7rem;
    opacity: 0.7;
    text-align: right;
    margin-top: 2px;
}

.chat-input-container {
    display: flex;
    gap: 5px;
}

#chat-input {
    flex-grow: 1;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background-color: rgba(0, 0, 0, 0.2);
    color: white;
}

#chat-send {
    padding: 8px 16px;
    border-radius: 4px;
    background-color: rgba(72, 187, 120, 0.7);
    color: white;
    border: none;
    cursor: pointer;
    transition: background-color 0.3s;
}

#chat-send:hover {
    background-color: rgba(72, 187, 120, 0.9);
}

.game-over-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.game-over-modal {
    background-color: #2d3748;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.game-over-modal h2 {
    font-size: 24px;
    margin-bottom: 20px;
}

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

.btn {
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    border: none;
    font-weight: bold;
    transition: background-color 0.3s;
}

.btn-primary {
    background-color: #38a169;
    color: white;
}

.btn-primary:hover {
    background-color: #2f855a;
}

.btn-secondary {
    background-color: #4a5568;
    color: white;
}

.btn-secondary:hover {
    background-color: #2d3748;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(255, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 0, 0, 0); }
}

@media (max-width: 1024px) {
    main {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-width: 640px;
    }
}

@media (max-width: 700px) {
    :root {
        --board-size: 320px;
        --cell-size: 40px;
        --piece-size: 30px;
    }

    main {
        padding: 10px;
    }

    .player-info {
        padding: 5px;
    }

    .player-name {
        font-size: 0.9rem;
    }

    .timer {
        font-size: 1.2rem;
    }

    .chat-container, .move-history-container {
        padding: 10px;
    }
}

.move-history-table {
    width: 100%;
    border-collapse: collapse;
}

.move-history-table th, .move-history-table td {
    padding: 4px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.move-number {
    width: 40px;
    color: rgba(255, 255, 255, 0.7);
}

.player-move {
    color: #4299e1;
    font-weight: bold;
}

.last-move-highlight {
    background-color: rgba(66, 153, 225, 0.2);
}

@keyframes newMoveHighlight {
    0% { background-color: rgba(72, 187, 120, 0.4); }
    100% { background-color: transparent; }
}

.new-move {
    animation: newMoveHighlight 2s ease-out;
}

#move-history {
    max-height: 300px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#move-history::-webkit-scrollbar {
    width: 6px;
}

#move-history::-webkit-scrollbar-track {
    background: transparent;
}

#move-history::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.touch-device .dragging {
    display: none !important;
}

.touch-device img {
    cursor: pointer !important;
    touch-action: manipulation !important;
}

.selected-square {
    box-shadow: inset 0 0 0 4px rgba(255, 255, 0, 0.8) !important;
    animation: pulse-highlight 2s infinite !important;
}

@keyframes pulse-highlight {
    0% { box-shadow: inset 0 0 0 4px rgba(255, 255, 0, 0.5); }
    50% { box-shadow: inset 0 0 0 4px rgba(255, 255, 0, 0.8); }
    100% { box-shadow: inset 0 0 0 4px rgba(255, 255, 0, 0.5); }
}

.touch-marker.move-marker {
    width: 40% !important;
    height: 40% !important;
    opacity: 0.85 !important;
}

#chess-board * {
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}
