body {
    background-color: black;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh; /* Take full viewport height */
    flex-direction: column; /* Stack main items (board+names, buttons) vertically */
}

#board-and-players {
    width: 90vh;
    height: 73vh;
    position: relative;
    display: flex;
    /* justify-content: center; */
    justify-content: space-between;
    align-items: center;
}

#player-names {
    font-size: 3.2vh;
    font-family: monospace;
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Distribute names evenly, top and bottom */
    height: 100%; /* Make it take the full height of the container */
    margin-left: 20px; /* Some spacing from the board */
    align-content: left;
    height: 70vh;
}

#eval-bar-container {
    width: 100%;
    height: 1.5vh;
    background: linear-gradient(to right, #ffffff 0%, #888888 50%, #000000 100%);
    border: 1px solid #666;
    margin-top: 0.5vh;
    position: relative;
    border-radius: 0.3vh;
}

#eval-bar {
    position: absolute;
    top: 0;
    left: 50%;
    width: 0.4vh;
    height: 100%;
    background-color: #ff0000;
    transition: left 0.3s ease;
    border-radius: 0.2vh;
}

#buttons-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;  /* Align items to top instead of center */
    /* justify-content: center; */
    width: 90vh;
    margin-top: 30px;
}

#help-container {
    display: flex;
    flex-direction: column;  /* Stack buttons vertically */
    gap: 1vh;
}

#help-container .button-row {
    display: flex;
    flex-direction: row;
    gap: 1vh;
}

    
button {
    width: 9vh;
    height: 4vh;
    font-size: 1.5vh;
    font-family: monospace;
    background-color: white;
    color: black;
    border: none;
    padding: 0.5vh 1vh;
    cursor: pointer;
    transition: background-color 0.3s;
}

/* Action buttons (Undo, Restart) - more prominent */
button.action-btn {
    background-color: #4a5a72;
    color: white;
    font-weight: bold;
}

button.action-btn:hover {
    background-color: #5a6a82;
}

/* Info buttons (Help, Settings) - darker than action buttons */
button.info-btn {
    background-color: #2d3540;
    color: white;
    font-weight: normal;
}

button.info-btn:hover {
    background-color: #3d4550;
}

/* Tooltip icon styling */
.tooltip-icon {
    display: inline-block;
    width: 1.4vh;
    height: 1.4vh;
    line-height: 1.4vh;
    text-align: center;
    border-radius: 50%;
    background-color: #666;
    color: white;
    font-size: 1.2vh;
    font-weight: bold;
    margin-left: 0.3vh;
    cursor: help;
    position: relative;
}

.tooltip-icon:hover {
    background-color: #888;
}

.tooltip-text {
    visibility: hidden;
    width: 25vh;
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    text-align: left;
    border-radius: 0.5vh;
    padding: 1vh;
    position: absolute;
    z-index: 100;
    bottom: 125%;
    left: 50%;
    margin-left: -12.5vh;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 1.4vh;
    font-weight: normal;
    line-height: 1.4;
    pointer-events: none;
}

.tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -0.5vh;
    border-width: 0.5vh;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.9) transparent transparent transparent;
}

.tooltip-icon:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}


table {
    border-collapse: collapse;  /* This ensures that the borders of adjacent cells are merged */
    border: none;  /* Remove table border */
}

td {
    cursor: default;
    width: 10vh;
    height: 10vh;
    text-align: center;
    vertical-align: middle;
    font-size: 5vh;
    border: none;
    transition: background-color 0.3s;  /* Smooth transition for highlighting */
    position: relative;  /* For positioning policy overlay */
}

/* Policy overlay for visualization */
.policy-overlay {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background-color: rgba(0, 0, 0, 0.75);
    color: white;
    font-size: 1.5vh;
    padding: 2px 4px;
    border-radius: 3px;
    pointer-events: none !important;  /* Don't interfere with clicks */
    font-family: monospace;
    font-weight: bold;
    z-index: 10;
    user-select: none;  /* Prevent text selection */
}

/* Hover effects - only on devices with true hover capability (not touch screens) */
@media (hover: hover) {
    /* For the attacker (only when not AI turn) */
    #board.attacker:not(.ai-turn) td.⚫:hover {
        cursor: pointer;
        background-color: rgba(50, 50, 50, 0.1);
    }

    /* For the defender (only when not AI turn) */
    #board.defender:not(.ai-turn) td.⚪:hover, 
    #board.defender:not(.ai-turn) td.⬜:hover {
        cursor: pointer;
        background-color: rgba(50, 50, 50, 0.1);
    }
}

/* Disable pointer cursor on pieces during AI turn */
#board.ai-turn td.⚫,
#board.ai-turn td.⚪,
#board.ai-turn td.⬜ {
    cursor: default;
}

/* Prevent mobile tap highlight and active states */
td {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Light squares */
tr:nth-child(odd) td:nth-child(odd),
tr:nth-child(even) td:nth-child(even) {
    background-color: #b58863;
    /* background-color: #62a6d6; */
}

/* Dark squares */
tr:nth-child(odd) td:nth-child(even),
tr:nth-child(even) td:nth-child(odd) {
    background-color: #e9c387;
    /* background-color: #4c98cf; */
}

/* Corner squares */
tr:first-child td:first-child,
tr:first-child td:last-child,
tr:last-child td:first-child,
tr:last-child td:last-child {
    background-color: #7b7b7b; /* Example color; adjust as you like */
}


#board td.selected {
    background-color: rgba(120, 120, 120, 0.7);  /* Example color; feel free to adjust */
}

/* Highlighting for legal squares */
td.legal-move {
    position: relative;
}

td.legal-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2vh;
    height: 2vh;
    border-radius: 50%;
    background-color: var(--move-indicator-color, rgba(255, 255, 255, 0.6));
    pointer-events: none;
}

/* Darken legal move squares on hover */
td.legal-move:hover {
    filter: brightness(0.7);
}

/* Black pieces get black indicators */
.attacker td.legal-move::after {
    background-color: rgba(0, 0, 0, 0.5);
}

/* White pieces get white indicators */
.defender td.legal-move::after {
    background-color: rgba(255, 255, 255, 0.6);
}

/* The overlay styles */
#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
    font-size: 50px;
    font-family: monospace;
    color: white;
    z-index: 10; /* Make sure it's on top of other elements */
}

/* The class that hides elements */
#overlay.hidden {
    display: none;
}
#helpText,
#settingsText {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.9);
    font-size: 50px;
    font-family: monospace;
    color: white;
    z-index: 20;
}

.panel-content {
    position: relative;
}

.close-btn {
    position: absolute;
    top: -3vh;
    right: -3vh;
    background: none;
    border: none;
    color: white;
    font-size: 4vh;
    cursor: pointer;
    width: auto;
    height: auto;
    padding: 0;
    font-weight: normal;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #ff6666;
}

/* The class that hides elements */
#helpText.hidden,
#settingsText.hidden {
    display: none;
}

input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #999; /* Adjust as desired */
    vertical-align: middle;
    cursor: pointer;
}

input[type="radio"]:checked {
    background-color: #969696; /* Adjust color as desired */
    border-color: #333; /* Adjust color as desired */
}

input[type="radio"]:focus {
    outline: none;
}

#ai-difficulty-container label {
    font-size: 1.8vh;
    font-family: monospace;
}

#ai-difficulty-container {
    width: 18vh;
}

#player-config-container {
    width: 18vh;
    margin-right: 2vh;
    display: flex;
    flex-direction: column;
    align-items: stretch;  /* Ensure children stretch to full width */
}

#player-config-container > div:first-child {
    /* Label div - fixed height to prevent layout shift */
    height: 3.6vh;  /* Accommodate two lines of text */
    line-height: 1.8vh;
    margin-bottom: 5px;
}

#player-config-container select {
    width: 100%;
    padding: 5px;
    font-size: 1.6vh;
    font-family: monospace;
    background-color: #1a2332;
    color: white;
    border: 2px solid #3a4a62;
    cursor: pointer;
}

#player-config-container select:hover {
    background-color: #2a3542;
    border-color: #4a5a72;
}

#player-config-container select option {
    background-color: #1a2332;
    color: white;
}

.hidden {
    display: none;
}

/* Animation keyframes */
@keyframes flash {
    0%, 100% { background-color: inherit; }
    50% { background-color: rgba(255, 255, 153, 0.4); }
}

@keyframes fadeOut {
    from { 
        opacity: 1; 
        transform: scale(1); 
        color: inherit;
    }
    to { 
        opacity: 0; 
        transform: scale(0.5); 
        color: transparent;
    }
}

/* Animation classes */
.flash-animation {
    animation: flash 0.3s ease-in-out;
}

.fade-out-animation {
    color: inherit;
}

.fade-out-animation::first-line {
    animation: fadeOut 0.3s ease-out forwards;
}


#attacker-label, #defender-label {
    color: #868686;
}

.active-player {
    font-weight: bold;
    color: #ffffff !important; /* or any other color you prefer */
}



/* Responsive layout for screens smaller than 768 pixels */
@media only screen and (max-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        padding: 10px 0;
    }

    td {
        cursor: default;
        width: 50px;
        height: 50px;
        text-align: center;
        vertical-align: middle;
        font-size: 32px;
        border: none;
        transition: background-color 0.3s;
    }

    #board-and-players {
        flex-direction: column;
        align-items: center;
        width: 98%;
        height: auto;
        margin-bottom: 15px;
    }
    
    #player-names {
        font-size: 16px;  /* Much smaller text for mobile */
        flex-direction: row;
        width: 100%;
        margin-bottom: 15px;
        height: auto;
        padding: 5px 0;
    }
    
    #attacker-label, #defender-label {
        flex: 1;
        text-align: center;
        line-height: 1.3;
    }

    #buttons-container {
        display: grid;
        grid-template-columns: 1fr 1fr;  /* 2 columns */
        gap: 10px;
        width: 95%;
        max-width: 400px;
        margin-top: 10px;
    }

    #player-config-container {
        width: 100%;
        margin-right: 0;
    }

    #player-config-container > div:first-child {
        font-size: 12px;  /* Much smaller label text */
        height: auto;
        line-height: 1.2;
        margin-bottom: 3px;
        min-height: 30px;  /* Ensure space for two lines */
    }

    #player-config-container select {
        font-size: 14px;
        padding: 8px 4px;
        width: 100%;
    }

    .tooltip-icon {
        width: 14px;
        height: 14px;
        line-height: 14px;
        font-size: 10px;
        margin-left: 3px;
    }

    .tooltip-text {
        width: 200px;
        font-size: 11px;
        padding: 8px;
        margin-left: -100px;
    }

    #help-container {
        grid-column: 1 / -1;  /* Span both columns */
        width: 100%;
    }

    #help-container .button-row {
        width: 100%;
        justify-content: space-between;
    }

    button {
        width: 100%;
        min-width: 70px;
        height: 45px;
        font-size: 14px;
        font-family: monospace;
        margin: 0;
        padding: 8px 12px;
        cursor: pointer;
    }

    button.action-btn,
    button.info-btn {
        font-size: 14px;
    }

    td.legal-move::after {
        width: 15px;  /* Smaller indicator for mobile */
        height: 15px;
    }

    .policy-overlay {
        font-size: 9px;  /* Smaller but still readable on mobile */
        padding: 1px 3px;
        bottom: 1px;
        right: 1px;
    }

    #eval-bar {
        width: 3px;  /* Thin red line, not 50px */
        font-size: 14px;
    }
    
    #eval-bar-container {
        width: 100%;
        height: 12px;  /* Fixed height instead of vh */
        border-radius: 3px;
        margin-top: 5px;
    }
}
