* {
    box-sizing: border-box;
}

@font-face {
  font-family: 'ChessUnicode';
  src: url('fonts/DejaVuSans.ttf') format('truetype');
  font-display: swap;
}

body {
    font-family: 'ChessUnicode', sans-serif;
    color: #3a1402;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;    /* Center items horizontally */
    justify-content: center; /* Center items vertically */
    min-height: 100vh;
    background-color: #3a1402; /* Optional background */
    box-sizing: border-box;
}

h1 {
    color: #3a1402;
}

h2 {
    color: #3a1402;
}

p {
    color: #3a1402;
}

#mode-selector {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 10px;
    background-color: #3a1402;
}

#chess-container {
    display: flex;
    flex-direction: column;
    text-align: center;
    width: 100%;
    max-width: 700px;
    margin: 0 auto;
    background-size: cover;
    background-position: center;
    box-sizing: border-box;
    justify-content: center;
    background-color: #eec89b; /* rgb(255, 255, 255); */
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    margin-top: 10px;
}

.board-slot {
    display: grid;
    justify-content: center;
}

#game-container {
    padding-left: 1rem;
    padding-right: 1rem;
    width: 100%;
    max-width: 100%;
}

.mode-menu,
#game-container {
    display: none;
}

#game-container.hidden {
    display: none;
}

.mode-menu:not(.hidden) {
    display: block;
}

#mode-selector button {
    background-color: #eec89b;
    color: #3a1402;
    border: none;
    padding: 8px 16px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
}
  
#mode-selector button:hover {
    background-color: #d3aa75;
}

#chessboard-container {
    display: grid;
    grid-template-areas:
        "top-left    top-center    top-right"
        "row-labels  chessboard    middle-right"
        "bottom-left column-labels bottom-right";

    grid-template-columns: 3% 1fr 3%;
    grid-template-rows: 3% 1fr 3%;

    width: 90vw;               /* Responsive width */
    max-width: 580px;          /* Limit on large screens */
    aspect-ratio: 1 / 1;       /* Makes it square */
    
    background-color: #8B4513;
    border-radius: 12px;
    margin: 0 auto;
}

#row-labels {
    grid-area: row-labels;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    font-size: clamp(8px, 1.2vw, 14px);
}

#row-labels span {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

#chessboard {
    grid-area: chessboard;
    display: grid;
    width: 100%;
    height: 100%;
    grid-template: repeat(8, 1fr) / repeat(8, 1fr);
    position: relative;

    background-size: cover; 
    background-repeat: no-repeat;
    background-position: center;
}

.edge {
    position: relative;
}

.filler {
    /* background-color: #a3c7aa; */
    /* min-width: 10px;
    min-height: 10px; */
    visibility: hidden;
}

#column-labels {
    grid-area: column-labels;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    font-size: clamp(8px, 1.2vw, 14px);
}

#column-labels span {
    flex: 1;
    text-align: center;
}

#main-menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;  /* Optional: Add space between buttons */
    margin-bottom: 20px;  /* Optional: Add space below the buttons */
}

#levelSelectContainer {
    display: flex;
    flex-direction: column;
}

select {
    padding: 10px;
    margin-bottom: 20px;
    width: 200px;
    font-size: 16px;
    text-align: center;
    border-radius: 10px;
    background-color: #3a1402;
    border: 2px solid #000000;
    color: #eec89b;
}

option {
    color: #eec89b;
    background-color: #3a1402;
}

#SelectLabel {
    font-size: 1.1rem;
    font-weight: bold;
    color: #3a1402;
}

@media (max-width: 500px) {

    #mode-selector {
        display: grid;
        grid-template-columns: 1fr 1fr; /* 2 columns of equal width */
        grid-template-rows: 1fr 1fr;    /* 2 rows of equal height */
        column-gap: 20px;
        row-gap: 0px;  
    }

    select {
        font-size: 12px;
    }

    #main-menu-container {
        gap: 2px;
    }

    h1 {
        font-size: 1.4rem;
    }

    #SelectLabel {
        font-size: 1.0rem;
    }

    select {
        font-size: 1.0rem;
    }

    #chess-container {
        margin: 0 auto;
        padding: 0px;
        max-width: 95vw;
        max-height: 95vh;        
        overflow-x: hidden;
    }

    #game-container {
        max-width: 100%;
    }

}

.piece {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: auto;
    user-select: none;
    z-index: 10;
    touch-action: none;
    cursor: grab;
}

.piece,
.piece:active,
.piece.dragging {
  cursor: grabbing;
}
invisible
.invisible {
    opacity: 0;
}

.square {
    position: absolute;
    width: 12.5%;     /*60px 1/8th of the board */
    height: 12.5%;
    top: 0; left: 0;
    pointer-events: auto
}

.highlight-square {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 0, 0.6); /* transparent yellow */
    outline: 2px solid rgba(255, 255, 0, 0.6);
    outline-offset: -1px;
    pointer-events: none;
    z-index: 1; /* make sure it appears above piece images */
}

#chessboard .valid-dot {
    height: 10px;
    width: 10px;
    background-color: rgb(139, 70, 19, 0.9); /*rgb(0, 250, 0, 0.2); */
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none; /* so it doesn’t block clicks/drags */
    z-index: 11;
}

button {
    padding: 10px 20px;
    margin: 10px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 10px;
    background-color: #3a1402;
    border-color: #000000;
    color: #eec89b;
}

#startGameBtn {
    margin-top: 40px;
}

button:hover {
    background-color: #eec89b;
    color: #3a1402;
    border-color: #3a1402;
}


#endgame-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;       /* on top of everything */
}

#endgame-overlay.hidden {
    display: none;
}

.endgame-box {
    background: rgba(238, 200, 150, 0.9);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    color: #3a1402;
}

.endgame-box h2 {
    margin-bottom: 20px;
}

/* Buttons inside the overlay */
#overlay-restart,
#overlay-mainmenu {
  margin: 0 10px;
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
}

.player-name {
    display: flex;
    flex-direction: row;
    align-items: center;   /* vertically center text and pieces */
    justify-content: center;
    gap: 8px;
    text-align: center;
    font-weight: bold;
    margin: 10px 0;
    font-size: 1.2rem;
}

@media (max-width: 400px) {

    .player-name {
        flex-direction: column;
    }

    #whiteCaptured {
        height: 15px;
    }

    #blackCaptured {
        height: 15px;
    }

}

.captured-pieces {
    display: flex;
    gap: 4px;
    /* you can also add justify-content or flex-wrap if you expect many captures */
}

/* Promotion Modal Styles */
#promotion-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#promotion-choices {
    display: flex;
    gap: 10px;
    background: #fff;
    padding: 15px;
    border-radius: 8px;
}
  
#promotion-choices img {
    width: 60px;
    height: 60px;
    cursor: pointer;
    border-radius: 6px;
    transition: transform 0.2s ease;
}
  
#promotion-choices img:hover {
    transform: scale(1.1);
}

#game-menu-container {
    display: flex;
    justify-content: center;
    align-items: center; 
}

#title {
    color: #3a1402;
    padding: 16px;
    margin-bottom: 10px;
    margin-left: 40px;
    margin-right: 40px;
}

/* Puzzle */
#title-puzzle {
    color: #3a1402;
    padding: 16px;
    margin-bottom: 10px;
    margin-left: 40px;
    margin-right: 40px;
}

#puzzle-top-text {
    color: #3a1402;
    padding: 16px;
    font-size: 20px;
    font-weight: bold;
}

#puzzle-info{
    color: #3a1402;
    margin: 10px;
}

#puzzle-initial-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

#startPuzzleBtn {
    margin-top: 60px;
    margin-bottom: 40px;
}

/* Evaluate menu */
#evaluate-menu {
    flex-direction: column;
    align-items: center;
}

#analyze-position-text p {
    margin-bottom: 0px;
}

#evaluate-menu.hidden {
    display: none;
}

input[type="text"] {
    padding: 8px;
    margin: 8px;
    color: #3a1402;
    font-size: 16px;
    border: 2px solid #3a1402;
    background-color: #eec89b;
    border-radius: 4px;
    width: 500px;
}

@media (max-width: 400px) {

    input[type="text"] {
        width: 300px;
        font-size: 10px;
    }

    #eval-result p{
        font-size: 12px;
    }

}

#fenInput {
    width: 500px;  /* Adjust the width as needed */
    padding: 5px;
    font-size: 16px;
    color: #3a1402;
}


/* About menu */
#about-menu {
    color: #3a1402;              /* dark text for contrast */
    max-width: 600px;            /* keeps it readable on large screens */
    width: 90vw;                 /* scales down on small devices */
    margin: 20px auto;           /* centered with some breathing room */
    padding: 20px;               /* internal white-space */
    border-radius: 10px;         /* rounded corners to match theme */
    box-sizing: border-box;
    text-align: center;
}

/* Heading inside About */
#about-menu h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5em;
    text-align: center;
    color: #3a1402;
  }
  
/* Paragraph text inside About */
#about-menu {
    margin-bottom: 1em;
}

.mode-menu p {
  margin-bottom: 1rem;
  line-height: 1.6;
  font-size: 1rem;
}

.mode-menu .call-to-action {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
}

.mode-menu .king {
    font-size: 1.4rem;
    margin-left: 0.3rem;
}

.hidden {
    display: none !important;; 
}
  