/* Lichess-inspired styling */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #161512;
    color: #d8d8d8;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.app {
    max-width: 1200px;
    width: 100%;
}

h1 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 1.5rem;
    color: #fff;
}

/* Logo container */
.logo-container {
    text-align: center;
    margin-bottom: 1.5rem;
}

.boop-logo {
    max-width: 300px;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Hamburger Menu Styles */
.hamburger-menu {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 50px;
    height: 50px;
    background: #2b2926;
    border: 2px solid #4a4a4a;
    border-radius: 8px;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.hamburger-menu:hover {
    background: #3a3835;
    border-color: #6a6a6a;
}

.hamburger-icon {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 24px;
}

.hamburger-icon span {
    display: block;
    width: 100%;
    height: 3px;
    background: #d8d8d8;
    border-radius: 2px;
    transition: all 0.3s;
}

.hamburger-menu:hover .hamburger-icon span {
    background: #fff;
}

/* Menu Dropdown */
.menu-dropdown {
    position: fixed;
    top: 80px;
    left: 20px;
    background: #2b2926;
    border: 2px solid #4a4a4a;
    border-radius: 8px;
    padding: 0.5rem 0;
    min-width: 200px;
    z-index: 999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.menu-header {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    font-weight: bold;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #3a3835;
}

.menu-subheader {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    font-weight: bold;
    color: #aaa;
    border-top: 1px solid #3a3835;
    margin-top: 0.5rem;
}

.menu-item {
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    color: #d8d8d8;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.menu-item:hover:not(.disabled) {
    background: #3a3835;
    color: #fff;
}

.menu-item.disabled {
    color: #666;
    cursor: not-allowed;
}

/* Color Selection Overlay */
.color-selection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease-in;
}

.color-selection-modal {
    background: #2b2926;
    border: 2px solid #4a4a4a;
    border-radius: 12px;
    padding: 3rem;
    max-width: 600px;
    text-align: center;
    animation: slideUp 0.3s ease-out;
}

/* Win Popup Overlay */
.win-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    animation: fadeIn 0.4s ease-in;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.win-popup-modal {
    background: linear-gradient(135deg, #2b2926 0%, #3a3835 100%);
    border: 3px solid #ffd700;
    border-radius: 20px;
    padding: 3rem 4rem;
    max-width: 500px;
    text-align: center;
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    box-shadow: 0 20px 60px rgba(255, 215, 0, 0.3);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.win-popup-emoji {
    font-size: 6rem;
    margin-bottom: 1rem;
    animation: bounce 1s ease-in-out infinite;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
}

.win-popup-title {
    font-size: 3rem;
    margin-bottom: 2rem;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    font-weight: bold;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
}

.win-popup-button {
    padding: 1rem 3rem;
    font-size: 1.3rem;
    background: #ffd700;
    color: #161512;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.win-popup-button:hover {
    background: #ffed4e;
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.6);
}

.win-popup-button:active {
    transform: translateY(-1px);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.5) translateY(-50px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

@keyframes graduate {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.3) rotate(10deg);
        opacity: 0.8;
    }
    100% {
        transform: scale(0.5) rotate(20deg);
        opacity: 0;
    }
}

.color-selection-modal h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
    color: #fff;
}

.color-buttons {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.color-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 2rem 1.5rem;
    background: #3a3835;
    color: #d8d8d8;
    border: 3px solid #4a4a4a;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    min-width: 150px;
    font-weight: bold;
}

.color-button:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

.color-button.orange {
    border-color: #ff8c00;
}

.color-button.orange:hover {
    background: #ff8c00;
    color: #fff;
}

.color-button.gray {
    border-color: #808080;
}

.color-button.gray:hover {
    background: #808080;
    color: #fff;
}

.color-button.random {
    border-color: #9370db;
}

.color-button.random:hover {
    background: #9370db;
    color: #fff;
}

.color-icon {
    font-size: 3rem;
}

.color-label {
    font-size: 1.3rem;
    font-weight: bold;
}

.color-sublabel {
    font-size: 0.9rem;
    color: #999;
    min-height: 1.2rem;
}

.back-button {
    padding: 0.75rem 2rem;
    background: #3a3835;
    color: #d8d8d8;
    border: 2px solid #4a4a4a;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1rem;
}

.back-button:hover {
    background: #4a4845;
    border-color: #6a6a6a;
}

.game-container {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    justify-content: center;
}

.board-container {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.info-container {
    display: flex;
    flex-direction: column;
    min-width: 250px;
    height: 672px; /* Match board height */
}

/* The player-info section should be centered relative to the board */
/* with the turn indicator at the board's vertical center (336px) */
.info-container .player-info {
    display: grid;
    grid-template-rows: 1fr auto 1fr;
    gap: 5px; /* 5px gap between turn indicator and hand displays */
    flex: 1;
    align-items: center;
}

/* The turn indicator (game-info) is in the middle row */
.info-container .game-info {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.current-player-box {
    padding: 5.930496rem 2.3rem; /* Increased vertical padding by 20% from 4.94208rem (4.94208 * 1.2 = 5.930496rem), horizontal 15% (2rem -> 2.3rem) */
    border-radius: 12px;
    font-size: 2rem;
    font-weight: bold;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 3px solid;
    width: 305px; /* Match player hand width */
    box-sizing: border-box;
    margin: 0 auto; /* Center horizontally to align with player boxes */
}

.current-player-box.orange-turn {
    background: linear-gradient(135deg, #ff8c00 0%, #ff6600 100%);
    border-color: #ffaa33;
    color: #fff5e6;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.current-player-box.gray-turn {
    background: linear-gradient(135deg, #808080 0%, #606060 100%);
    border-color: #a0a0a0;
    color: #f0f0f0;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.current-player-box.game-over {
    background: linear-gradient(135deg, #2b2926 0%, #3a3835 100%);
    border-color: #4a4a4a;
    color: #d8d8d8;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.player {
    padding: 0.35rem 0.5rem; /* Reduced vertical padding to bring hand displays closer to turn indicator */
    background: #2b2926;
    border-radius: 8px;
    text-align: center;
    width: 305px; /* Fixed width to match turn indicator size */
    margin: 0 auto; /* Center the box */
    box-sizing: border-box;
}

.player.orange {
    border: 2px solid #ff8c00;
}

.player.gray {
    border: 2px solid #808080;
}

.player h3 {
    margin-top: 0;
    margin-bottom: 0.25rem;
    font-size: 1.2rem;
}

/* Hand display rows */
.hand-row {
    display: flex;
    justify-content: flex-start; /* Left-justify pieces */
    align-items: center;
    gap: 0.3rem;
    min-height: 2rem;
    flex-wrap: wrap;
    padding: 0;
}

.hand-piece {
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hand-piece img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Apply color filters to hand pieces */
.hand-piece.orange img {
    filter:
        brightness(0) saturate(100%)
        invert(55%) sepia(93%) saturate(1679%)
        hue-rotate(359deg) brightness(102%) contrast(104%);
}

.hand-piece.gray img {
    filter:
        brightness(0) saturate(100%)
        invert(42%) sepia(0%) saturate(0%)
        hue-rotate(0deg) brightness(95%) contrast(88%);
}

.piece-selector {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 0 3rem;
}

.piece-selector button {
    padding: 1.05rem 1.4rem;
    font-size: 1.1rem;
    background: #2b2926;
    color: #d8d8d8;
    border: 2px solid #4a4a4a;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    max-width: 150px;
}

.piece-selector button:hover {
    background: #3a3835;
    border-color: #6a6a6a;
}

.piece-selector button.selected {
    background: #5a9a3a;
    border-color: #7aba5a;
    color: #fff;
}

.piece-selector button:disabled {
    background: #1a1916;
    border-color: #2a2a2a;
    color: #4a4a4a;
    cursor: not-allowed;
    opacity: 0.5;
}

.board {
    display: inline-block;
    border: 3px solid #3a3835;
    border-radius: 4px;
    width: fit-content;
    position: relative;
    /* Add your board background image here */
    background-image: url('assets/board_background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.board-row {
    display: flex;
}

.cell {
    width: 112px;
    height: 112px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
    /* Make cells transparent to show the board background */
    background: transparent;
}

/* Remove the old checkerboard pattern - cells are now transparent */
/* Uncomment these if you want a subtle hover effect that doesn't obscure the board */
/*
.cell:hover {
    background-color: rgba(255, 255, 255, 0.1);
}
*/

.piece {
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
}

.piece.animating {
    z-index: 10; /* Ensure animating pieces appear above others */
    will-change: transform; /* Hint to browser that transform will change */
    transition: transform 1000ms ease-in-out !important;
}

.piece img {
    width: 90px;
    height: 90px;
    object-fit: contain;
    pointer-events: none;
}

/* Color transformations for pieces */
.piece.orange img {
    /* Transform to orange using CSS filters */
    filter:
        brightness(0) saturate(100%)
        invert(55%) sepia(93%) saturate(1679%)
        hue-rotate(359deg) brightness(102%) contrast(104%)
        drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.piece.gray img {
    /* Transform to gray using CSS filters */
    filter:
        brightness(0) saturate(100%)
        invert(42%) sepia(0%) saturate(0%)
        hue-rotate(0deg) brightness(95%) contrast(88%)
        drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.undo-container {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 250px; /* Match info-container width */
}

.undo-button, .resign-button, .reset-button {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    background: #3a3835;
    color: #d8d8d8;
    border: 2px solid #4a4845;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1; /* Make all buttons equal width */
}

.undo-button:hover:not(:disabled), .resign-button:hover:not(:disabled), .reset-button:hover {
    background: #4a4845;
    border-color: #6a6a6a;
}

.undo-button:disabled, .resign-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.resign-button {
    background: #5a3030;
    border-color: #6a4040;
}

.resign-button:hover:not(:disabled) {
    background: #6a4040;
    border-color: #8a5050;
}

/* P2P Connection Box Styles */
.p2p-connection-box {
    margin-top: 2rem;
    padding: 2rem;
    background: #1a1916;
    border: 2px solid #3a3835;
    border-radius: 12px;
}

.p2p-connection-box h3 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
    color: #fff;
    font-weight: 600;
}

.p2p-connection-box p {
    margin: 1.5rem 0;
    font-size: 1rem;
    color: #d8d8d8;
}

.p2p-connection-box textarea {
    width: 100%;
    min-height: 120px;
    padding: 1rem;
    background: #2b2926;
    color: #d8d8d8;
    border: 2px solid #4a4a4a;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 1rem;
    transition: border-color 0.3s;
}

.p2p-connection-box textarea:focus {
    outline: none;
    border-color: #7aba5a;
}

.p2p-connection-box textarea::placeholder {
    color: #666;
}

.p2p-connection-box textarea[readonly] {
    background: #1a1916;
    cursor: default;
}

.p2p-connection-box button {
    padding: 0.9rem 2rem;
    font-size: 1.1rem;
    background: #5a9a3a;
    color: #fff;
    border: 2px solid #7aba5a;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    margin-bottom: 1.5rem;
    width: 100%;
}

.p2p-connection-box button:hover {
    background: #6aaa4a;
    border-color: #8aca6a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(90, 154, 58, 0.4);
}

.p2p-connection-box button:active {
    transform: translateY(0);
}

/* Make the modal wider for P2P setup */
.color-selection-modal:has(.p2p-connection-box) {
    max-width: 700px;
}

