/* 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;
}

/* Game Actions Menu (meatball menu - top right) - Mobile only */
.game-actions-menu {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    z-index: 1000;
    display: none; /* Hidden by default on desktop */
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.game-actions-menu:hover {
    background: rgba(58, 56, 53, 0.3);
}

.meatball-icon {
    display: flex;
    flex-direction: row;
    gap: 4px;
    align-items: center;
}

.meatball-icon span {
    display: block;
    width: 5px;
    height: 5px;
    background: #d8d8d8;
    border-radius: 50%;
    transition: all 0.3s;
}

.game-actions-menu:hover .meatball-icon span {
    background: #fff;
}

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

/* 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;
}

/* Resign Confirmation Modal */
.resign-confirm-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;
}

.resign-confirm-modal {
    background: #2b2926;
    border: 2px solid #d85000;
    border-radius: 12px;
    padding: 2.5rem 3rem;
    max-width: 450px;
    text-align: center;
    animation: slideUp 0.3s ease-out;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.resign-confirm-title {
    font-size: 1.8rem;
    margin-bottom: 2rem;
    color: #fff;
    font-weight: bold;
}

.resign-confirm-buttons {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
}

.resign-confirm-button {
    padding: 0.9rem 2.5rem;
    font-size: 1.2rem;
    border: 2px solid;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
    min-width: 120px;
}

.resign-confirm-button.yes {
    background: #d85000;
    color: #fff;
    border-color: #d85000;
}

.resign-confirm-button.yes:hover {
    background: #ff6b1a;
    border-color: #ff6b1a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(216, 80, 0, 0.4);
}

.resign-confirm-button.no {
    background: #3a3835;
    color: #d8d8d8;
    border-color: #4a4a4a;
}

.resign-confirm-button.no:hover {
    background: #4a4845;
    border-color: #6a6a6a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.resign-confirm-button:active {
    transform: translateY(0);
}

.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-button.selected {
    border-width: 4px;
    box-shadow: 0 0 20px rgba(122, 186, 90, 0.6);
    background: #4a7a3a;
}

.color-button.orange.selected {
    border-color: #7aba5a;
}

.color-button.gray.selected {
    border-color: #7aba5a;
}

.color-button.random.selected {
    border-color: #7aba5a;
}

.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 - now just top and bottom players with engine indicator in between */
.info-container .player-info {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    justify-content: center;
    align-items: center;
}

.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);
}

/* Engine thinking indicator */
.engine-thinking {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #3a3835 0%, #2b2926 100%);
    border: 2px solid #7aba5a;
    border-radius: 8px;
    color: #7aba5a;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(122, 186, 90, 0.3);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(122, 186, 90, 0.3);
        border-color: #7aba5a;
    }
    50% {
        box-shadow: 0 4px 16px rgba(122, 186, 90, 0.6);
        border-color: #8aca6a;
    }
}

/* Spinning animation for the thinking indicator */
.thinking-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #3a3835;
    border-top: 3px solid #7aba5a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.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;
}

/* Active player highlighting */
.player.active-player {
    border-width: 3px;
}

.player.orange.active-player {
    border-color: #7aba5a;
    background: linear-gradient(135deg, #3a3835 0%, #2b2926 100%);
    box-shadow: 0 0 20px rgba(122, 186, 90, 0.7);
    animation: pulse-border-green 2s ease-in-out infinite;
}

.player.gray.active-player {
    border-color: #b794f6;
    background: linear-gradient(135deg, #3a3835 0%, #2b2926 100%);
    box-shadow: 0 0 20px rgba(183, 148, 246, 0.7);
    animation: pulse-border-purple 2s ease-in-out infinite;
}

@keyframes pulse-border-green {
    0%, 100% {
        box-shadow: 0 0 20px rgba(122, 186, 90, 0.7);
    }
    50% {
        box-shadow: 0 0 35px rgba(122, 186, 90, 1);
    }
}

@keyframes pulse-border-purple {
    0%, 100% {
        box-shadow: 0 0 20px rgba(183, 148, 246, 0.7);
    }
    50% {
        box-shadow: 0 0 35px rgba(183, 148, 246, 1);
    }
}

.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;
}

/* Move confirmation buttons */
.move-confirmation {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem 3rem;
    min-height: 4.6rem; /* Reserve space to prevent layout shift */
    animation: slideIn 0.2s ease-out;
}

.move-confirmation.hidden {
    visibility: hidden;
    pointer-events: none;
    min-height: 4.6rem; /* Keep the space reserved */
}

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

.confirm-move-btn,
.cancel-move-btn {
    padding: 0.9rem 1.8rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: 2px solid;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
    max-width: 150px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.confirm-move-btn {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    border-color: #66bb6a;
    color: #fff;
}

.confirm-move-btn:hover {
    background: linear-gradient(135deg, #5bc05f 0%, #4CAF50 100%);
    border-color: #7bc67e;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.confirm-move-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(76, 175, 80, 0.3);
}

.cancel-move-btn {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    border-color: #e57373;
    color: #fff;
}

.cancel-move-btn:hover {
    background: linear-gradient(135deg, #f55a4e 0%, #f44336 100%);
    border-color: #ef9a9a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
}

.cancel-move-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(244, 67, 54, 0.3);
}

/* Board with coordinates wrapper */
.board-with-coords {
    display: inline-flex;
    flex-direction: column;
    gap: 4px;
}

/* Coordinate containers */
.coords {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.coords-top,
.coords-bottom {
    flex-direction: row;
}

.coords-left,
.coords-right {
    flex-direction: column;
}

/* Board middle section (left coords + board + right coords) */
.board-middle {
    display: flex;
    flex-direction: row;
    gap: 4px;
    align-items: center;
}

/* Individual coordinate labels */
.coord {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #8b8680;
    user-select: none;
}

.coord-col {
    width: 112px;
    height: 20px;
}

.coord-row {
    width: 20px;
    height: 112px;
}

/* Spacer for corners */
.coord-spacer {
    width: 20px;
    height: 20px;
}

.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;
    /* Prevent text selection and cursor */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.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;
    /* Prevent text selection and cursor */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-tap-highlight-color: 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;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Pieces don't intercept clicks */
}

.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);
}

.p2p-connection-box button:disabled {
    background: #4a7a2a;
    border-color: #5a8a3a;
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

.p2p-connection-box button:disabled:hover {
    background: #4a7a2a;
    border-color: #5a8a3a;
    transform: none;
    box-shadow: none;
}

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

/* Ensure color buttons in p2p-connection-box display side-by-side */
.p2p-connection-box .color-buttons {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    margin-bottom: 2rem;
    flex-wrap: nowrap;
}

/* Override green button styling for color selection buttons */
.p2p-connection-box .color-button {
    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;
    width: auto;
    margin-bottom: 0;
}

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

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

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

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

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

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

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

/* Room Code Display */
.room-code-display {
    font-size: 2rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    text-align: center;
    padding: 1.5rem;
    background: #2b2926;
    border: 3px solid #7aba5a;
    border-radius: 12px;
    color: #7aba5a;
    letter-spacing: 0.3em;
    margin: 1rem 0;
    user-select: all;
    cursor: pointer;
    transition: all 0.3s;
}

.room-code-display:hover {
    background: #3a3835;
    border-color: #8aca6a;
    box-shadow: 0 4px 12px rgba(122, 186, 90, 0.3);
}

/* Room Code Input */
.p2p-connection-box input[type="text"] {
    width: 100%;
    padding: 1rem;
    font-size: 1.2rem;
    font-family: 'Courier New', monospace;
    text-align: center;
    letter-spacing: 0.2em;
    background: #2b2926;
    color: #d8d8d8;
    border: 2px solid #3a3835;
    border-radius: 8px;
    margin-bottom: 1rem;
    transition: border-color 0.3s;
}

.p2p-connection-box input[type="text"]:focus {
    outline: none;
    border-color: #7aba5a;
}

.p2p-connection-box input[type="text"]::placeholder {
    color: #666;
    letter-spacing: normal;
}

/* ============================================
   MOBILE RESPONSIVE STYLES
   ============================================ */

/* Remove tap delay and improve touch responsiveness */
button, .cell, .hand-piece {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Tablet and smaller (landscape tablets, large phones) */
@media (max-width: 1024px) {
    body {
        padding: 10px;
    }

    .app {
        max-width: 100%;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 1rem;
    }

    .boop-logo {
        max-width: 200px;
    }
}

/* Mobile devices (phones in landscape, small tablets) */
@media (max-width: 768px) {
    body {
        padding: 0;
        align-items: center; /* Keep centered */
        justify-content: flex-start; /* Allow scrolling from top */
        overflow-x: hidden; /* Prevent horizontal scroll */
    }

    .app {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden; /* Prevent horizontal scroll */
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
        text-align: center;
        width: 100%;
        padding: 0 0.5rem;
        box-sizing: border-box;
    }

    .logo-container {
        width: 100%;
        text-align: center;
        margin-bottom: 0.5rem;
        padding: 0;
    }

    .boop-logo {
        max-width: 150px;
        height: auto;
    }

    /* CRITICAL: Stack game container vertically on mobile */
    .game-container {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
        width: 100%;
    }

    /* Show game actions menu on mobile */
    .game-actions-menu {
        display: flex !important;
        top: 10px !important;
    }

    /* Align hamburger menu with meatball menu on mobile */
    .hamburger-menu {
        top: 10px !important;
        background: transparent !important;
        border: none !important;
    }

    .hamburger-menu:hover {
        background: rgba(58, 56, 53, 0.3) !important;
    }

    .menu-dropdown {
        top: 70px !important;
    }

    .game-actions-dropdown {
        top: 70px !important;
    }

    .board-container {
        width: 100%;
        max-width: 100vw;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        margin: 0;
        padding: 0;
        padding-top: 80px; /* Push board below hamburger menu (20px top + 50px height + 10px gap) */
    }

    /* Show coordinates on mobile */
    .board-with-coords {
        display: flex !important;
        flex-direction: column;
        width: 100vw;
        margin: 0;
        padding: 0;
        align-items: center;
        justify-content: center;
    }

    .board-middle {
        display: flex !important;
        flex-direction: row;
        width: auto;
        margin: 0;
        margin-left: -5vw; /* Shift left by coordinate width to center the board */
        padding: 0;
        align-items: center;
    }

    .coords-left {
        display: flex !important;
        flex-direction: column;
        justify-content: space-around;
        width: 5vw;
        font-size: 3vw;
        color: #888;
        gap: 0;
    }

    .coords-right {
        display: none !important; /* Hide right coordinates on mobile */
    }

    .coords-bottom {
        display: flex !important;
        flex-direction: row;
        justify-content: space-around;
        height: 5vw;
        font-size: 3vw;
        color: #888;
        margin-left: 0; /* No offset needed since board-middle handles centering */
        padding-left: 5vw; /* Align with board cells */
        gap: 0;
    }

    .coord-spacer {
        display: none !important; /* Hide spacer on mobile */
    }

    .coord {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Override desktop coordinate sizes to match mobile cells */
    .coord-col {
        width: calc(85vw / 6) !important;
        height: 5vw !important;
    }

    .coord-row {
        width: 5vw !important;
        height: calc(85vw / 6) !important;
    }

    /* Scale down the board - use smaller size to fit everything */
    .board {
        display: block !important; /* Override inline-block */
        width: 85vw !important;
        height: 85vw !important;
        max-width: 85vw;
        max-height: 85vw;
        margin: 0 !important;
        padding: 0 !important;
        border-left: none;
        border-right: none;
        border-radius: 0;
        box-sizing: border-box;
    }

    .board-row {
        gap: 0;
    }

    .cell {
        width: calc(85vw / 6) !important;
        height: calc(85vw / 6) !important;
        border-radius: 0;
        box-sizing: border-box;
    }

    .cell img {
        width: 70%;
        height: 70%;
    }

    /* Hide desktop undo container on mobile - use game actions menu instead */
    .undo-container {
        display: none !important;
    }

    /* Piece selector - make touch-friendly and full width */
    .piece-selector {
        padding: 1vw 1vw;
        width: 100%;
        max-width: 100vw;
        margin: 0;
        gap: 1.5vw;
    }

    .piece-selector button {
        padding: 2vw 2.5vw;
        font-size: 3.5vw;
        min-height: 10vw;
        flex: 1;
    }

    /* Move confirmation buttons */
    .move-confirmation {
        padding: 1vw 1vw;
        width: 100%;
        max-width: 100vw;
        margin: 0;
        gap: 1.5vw;
    }

    .confirm-move-btn,
    .cancel-move-btn {
        padding: 2vw 3vw;
        font-size: 3.5vw;
        min-height: 10vw;
    }

    /* Adjust sidebar and info container */
    .sidebar-container {
        width: 100%;
        max-width: 100vw;
        margin: 0;
        padding: 0 0.5rem;
    }

    .info-container {
        gap: 1vw;
        height: auto !important; /* Remove fixed height */
        min-width: auto;
        width: 100%;
    }

    .info-container .player-info {
        gap: 1vw;
    }

    .current-player-box {
        padding: 2vw 1.5vw;
        font-size: 3.5vw;
        width: 100%;
        max-width: 100%;
    }

    .player {
        width: 100%;
        max-width: 100%;
        padding: 1.5vw;
    }

    .player h3 {
        font-size: 3.8vw;
        margin-bottom: 0.5vw;
    }

    .hand-row {
        gap: 1.2vw;
        min-height: 8vw;
    }

    .hand-piece {
        width: 8vw;
        height: 8vw;
    }

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

    /* Buttons */
    .mode-button, .color-button {
        padding: 0.8rem 1.2rem;
        font-size: 1rem;
        min-height: 48px; /* Touch-friendly */
    }

    .undo-button, .reset-button {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
        min-height: 48px;
    }

    /* Hamburger menu - make it more accessible */
    .hamburger-menu {
        width: 44px;
        height: 44px;
        top: 10px;
        left: 10px;
    }

    /* Settings panel */
    .settings-panel {
        width: 85vw;
        max-width: 400px;
        padding: 1.5rem;
    }

    .settings-panel h2 {
        font-size: 1.5rem;
    }

    /* Engine thinking indicator */
    .engine-thinking {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        gap: 0.5rem;
    }

    .thinking-spinner {
        width: 16px;
        height: 16px;
    }

    /* Win popup */
    .win-popup-content {
        padding: 2rem 1.5rem;
        max-width: 90vw;
    }

    .win-popup-title {
        font-size: 2rem;
    }

    .win-popup-button {
        padding: 0.8rem 2rem;
        font-size: 1rem;
    }
}

/* Small phones in portrait */
@media (max-width: 480px) {
    h1 {
        font-size: 1.2rem;
        margin-bottom: 0.3rem;
    }

    .boop-logo {
        max-width: 100px;
    }

    .game-container {
        gap: 0.5rem;
    }

    .board-container {
        padding-top: 80px; /* Push board below hamburger menu */
    }

    /* Show coordinates on small phones too */
    .coords-left {
        display: flex !important;
        width: 5vw;
        font-size: 2.5vw;
        gap: 0;
    }

    .coords-right {
        display: none !important;
    }

    .coords-bottom {
        display: flex !important;
        height: 5vw;
        font-size: 2.5vw;
        margin-left: 0;
        padding-left: 5vw; /* Align with board cells */
        gap: 0;
    }

    /* Override desktop coordinate sizes to match mobile cells */
    .coord-col {
        width: calc(85vw / 6) !important;
        height: 5vw !important;
    }

    .coord-row {
        width: 5vw !important;
        height: calc(85vw / 6) !important;
    }

    .board-with-coords {
        display: flex !important;
        flex-direction: column;
        width: 100vw;
        margin: 0;
        align-items: center;
        justify-content: center;
    }

    .board-middle {
        display: flex !important;
        flex-direction: row;
        width: auto;
        margin-left: -5vw; /* Shift left by coordinate width to center the board */
        align-items: center;
    }

    .board {
        display: block !important;
        width: 85vw !important;
        height: 85vw !important;
        max-width: 85vw;
        max-height: 85vw;
        margin: 0 !important;
        padding: 0 !important;
        border-left: none;
        border-right: none;
        border-radius: 0;
    }

    .cell {
        width: calc(85vw / 6) !important;
        height: calc(85vw / 6) !important;
        border-radius: 0;
    }

    .piece-selector {
        max-width: 100vw;
        padding: 1vw 1vw;
        gap: 1.5vw;
    }

    .piece-selector button {
        padding: 2vw 2.5vw;
        font-size: 3.5vw;
        min-height: 10vw;
    }

    .move-confirmation {
        max-width: 100vw;
        padding: 1vw 1vw;
        gap: 1.5vw;
    }

    .confirm-move-btn,
    .cancel-move-btn {
        padding: 2vw 3vw;
        font-size: 3.5vw;
        min-height: 10vw;
    }

    .sidebar-container {
        max-width: 100vw;
        padding: 0 1vw;
    }

    .current-player-box {
        padding: 2vw 1.5vw;
        font-size: 3.5vw;
        max-width: 100%;
    }

    .player {
        max-width: 100%;
        padding: 1.5vw;
    }

    .player h3 {
        font-size: 3.8vw;
    }

    .hand-row {
        gap: 1.2vw;
        min-height: 8vw;
    }

    .hand-piece {
        width: 8vw;
        height: 8vw;
    }

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

    .mode-button, .color-button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .undo-button, .reset-button {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }

    .engine-thinking {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }

    .thinking-spinner {
        width: 14px;
        height: 14px;
    }

    /* P2P Connection Box */
    .p2p-connection-box {
        padding: 1rem;
    }

    .room-code-display {
        font-size: 1.2rem;
        padding: 1rem;
    }

    .p2p-connection-box input[type="text"] {
        font-size: 1rem;
        padding: 0.8rem;
    }
}

/* Landscape orientation optimization for phones */
@media (max-height: 600px) and (orientation: landscape) {
    body {
        padding: 5px;
    }

    h1 {
        font-size: 1rem;
        margin-bottom: 0.3rem;
    }

    .logo-container {
        margin-bottom: 0.5rem;
    }

    .boop-logo {
        max-width: 80px;
    }

    .game-container {
        flex-direction: row; /* Side-by-side in landscape */
        gap: 1rem;
    }

    .board {
        width: min(80vh, 400px);
        height: min(80vh, 400px);
    }

    .cell {
        width: calc(80vh / 6 - 5px);
        height: calc(80vh / 6 - 5px);
        max-width: 65px;
        max-height: 65px;
    }

    .sidebar-container {
        max-width: 250px;
    }

    .info-container {
        gap: 0.3rem;
        height: auto !important;
    }

    .current-player-box {
        padding: 0.8rem 0.6rem;
        font-size: 1rem;
        max-width: 250px;
    }

    .player {
        padding: 0.3rem;
        max-width: 250px;
    }

    .player h3 {
        font-size: 0.9rem;
        margin-bottom: 0.3rem;
    }

    .hand-piece {
        width: 30px;
        height: 30px;
    }

    .hand-piece img {
        width: 24px;
        height: 24px;
    }
}

/* Remove hover effects on touch devices */
@media (hover: none) and (pointer: coarse) {
    .cell:hover {
        transform: none;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }

    .mode-button:hover,
    .color-button:hover,
    .undo-button:hover,
    .reset-button:hover {
        transform: none;
    }

    .room-code-display:hover {
        background: #2b2926;
        border-color: #7aba5a;
        box-shadow: none;
    }
}

