:root {
    --bg-color: #1b1b1b;
    --text-color: #e6edf3;
    --ui-bg-color: #000000;
    --ui-border-color: transparent;
    --button-bg-color: #1b1b1b;
    --button-hover-bg-color: #30363d;
    --button-disabled-bg-color: #30363d;
    --light-square-bg: #818384;
    --dark-square-bg: #494D4F;
    --highlight-selected-bg: #f6f669;
    --highlight-selected-dark-bg: #baca44;
    --highlight-last-move-shadow: rgb(255, 127, 80);
    --highlight-check-bg: red;
    --highlight-hint-bg: rgb(255, 255, 0);
    --highlight-hint-dark-bg: rgb(210, 210, 0);
    --highlight-drop-shadow: rgb(50, 100, 200);
    --attack-indicator-bg: rgb(135, 206, 250);
    --attack-indicator-dark-bg: rgb(100, 170, 210);
    --hanging-piece-type1-bg: rgb(255, 0, 0);
    --hanging-piece-type1-dark-bg: rgb(210, 0, 0);
    --hanging-piece-type2-bg: gold;
    --hanging-piece-type2-dark-bg: rgb(218, 165, 32);
    --threat-lower-value-bg: darkorange;
    --threat-lower-value-dark-bg: rgb(200, 110, 0);
    --modal-bg-color: rgba(0,0,0,0.8);
    --modal-content-bg: #161b22;
    --modal-border-color: #30363d;
    --modal-close-color: #8b949e;
    --modal-close-hover-color: #e6edf3;
    --link-color: #58a6ff;
    --link-hover-color: #80b6ff;
    --advantage-score-color: #e6edf3;
    --history-highlight-bg: #1f6feb;
    --theme-toggle-color: #e6edf3;
    --theme-toggle-hover-color: #ffd700;
}

body.light-theme {
    --bg-color: #f0f0f0;
    --text-color: #333;
    --ui-bg-color: #fff;
    --ui-border-color: #ccc;
    --button-bg-color: #f0f0f0;
    --button-hover-bg-color: #e0e0e0;
    --button-disabled-bg-color: #f0f0f0;
    --light-square-bg: #f0d9b5;
    --dark-square-bg: #b58863;
    --highlight-selected-bg: rgb(255, 255, 0);
    --highlight-selected-dark-bg: rgb(210, 210, 0);
    --advantage-score-color: #333;
    --modal-bg-color: rgba(0,0,0,0.4);
    --modal-content-bg: #fefefe;
    --modal-border-color: #888;
    --modal-close-color: #aaa;
    --modal-close-hover-color: black;
    --link-color: #555;
    --link-hover-color: #000;
    --history-highlight-bg: #d0e0ff;
    --theme-toggle-color: #4f545c;
    --theme-toggle-hover-color: #2c2f33;
}

body.light-theme button:disabled {
    color: #999;
}

body {
    font-family: sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 30px;
    margin: 0;
    overflow-x: hidden;
}

#game-container {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    position: relative;
}

#main-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#board-container {
    position: relative;
    width: 640px;
    height: 640px;
}

#chessboard {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 2px solid var(--ui-border-color);
}

body:not(.light-theme) #chessboard {
    border-color: white;
}

body.light-theme #chessboard {
    border-color: black;
}

#analysis-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

.square {
    width: 80px;
    height: 80px;
    position: relative;
}

.square.light {
    background-color: var(--light-square-bg);
}

.square.dark {
    background-color: var(--dark-square-bg);
}

.piece {
    width: 80px;
    height: 80px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: grab;
    position: relative;
    z-index: 2;
}

.piece.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

#ui-panel {
    width: 250px;
    padding: 20px;
    background-color: var(--ui-bg-color);
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 50px;
}

#ui-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#ui-header-main {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.logo-container {
    position: relative;
    margin-bottom: 20px;
    cursor: pointer;
}

.logo {
    width: 100px;
    height: auto;
    display: none; /* Hide all logos by default */
}

/* Light theme display logic */
body.light-theme #logo-light { display: block; }
body.light-theme .logo-container:hover #logo-light { display: none; }
body.light-theme .logo-container:hover #logo-light-hover { display: block; }

/* Dark theme display logic */
body:not(.light-theme) #logo-dark { display: block; }
body:not(.light-theme) .logo-container:hover #logo-dark { display: none; }
body:not(.light-theme) .logo-container:hover #logo-dark-hover { display: block; }


#game-controls, #difficulty-controls {
    width: 150px;
    margin-bottom: 20px;
}

#new-game-modal-btn {
    width: 150px;
    margin: 10px auto 20px auto;
}

button {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    border: 1px solid var(--ui-border-color);
    border-radius: 4px;
    background-color: var(--button-bg-color);
    color: var(--text-color);
    cursor: pointer;
}

button:hover {
    background-color: var(--button-hover-bg-color);
}

button:disabled {
    background-color: var(--button-disabled-bg-color);
    cursor: not-allowed;
}

#game-controls button, #new-game-modal-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
}

#game-controls button i, #new-game-modal-btn i {
    width: 20px;
    text-align: center;
}

#move-history {
    height: 120px;
    width: 100%;
    overflow-y: auto;
    border: 1px solid var(--ui-border-color);
    padding: 10px;
    box-sizing: border-box;
    background-color: var(--bg-color);
}

#history-controls {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-top: 10px;
}

#history-controls button {
    width: 48%;
}

#developer-credit {
    margin-top: auto;
    padding-top: 20px;
    font-size: 12px;
    color: var(--text-color);
}

#developer-credit a {
    color: var(--link-color);
    text-decoration: none;
}

#developer-credit a:hover {
    text-decoration: underline;
    color: var(--link-hover-color);
}

#moves {
    font-family: monospace;
    font-size: 12px;
    text-align: center;
}

.move-pair {
    display: flex;
    justify-content: center;
    margin-bottom: 4px;
}

.move-pair span:first-child {
    margin-right: 15px;
}

.move-pair span {
    padding: 2px 5px;
    border-radius: 3px;
    cursor: pointer;
}

.highlight-history {
    background-color: var(--history-highlight-bg);
}

/* Highlighting styles */
.highlight-legal {
    background-color: rgba(0, 128, 0, 0.3);
}

.square.highlight-selected {
    background-color: var(--highlight-selected-bg);
}

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

.square.highlight-check {
    background-color: var(--threat-lower-value-bg);
}

.highlight-checkmate::before, .highlight-checkmate::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    background-color: var(--highlight-check-bg);
    z-index: 1;
    pointer-events: none;
    transform-origin: center;
}

.highlight-checkmate::before {
    transform: translateX(-50%) rotate(45deg);
}

.highlight-checkmate::after {
    transform: translateX(-50%) rotate(-45deg);
}

.highlight-hint {
    background-color: var(--highlight-hint-bg) !important;
}

.highlight-hint .piece {
    opacity: 0.5;
}

.highlight-drop {
    box-shadow: inset 0 0 0 5px var(--highlight-drop-shadow);
}

.square.attack-indicator {
    background-color: var(--attack-indicator-bg);
}

.square.hanging-piece-type1 {
    background-color: var(--hanging-piece-type1-bg);
}

.square.hanging-piece-type2 {
    background-color: var(--hanging-piece-type2-bg);
}

.square.threat-lower-value {
    background-color: var(--threat-lower-value-bg);
}

.control-black,
.control-white {
    background-image: repeating-linear-gradient(
        45deg,
        rgba(60, 60, 60, 0.7),
        rgba(60, 60, 60, 0.7) 2px,
        transparent 2px,
        transparent 8px
    );
}


/* Dark Square Variants for Highlights */
.square.dark.highlight-selected {
    background-color: var(--highlight-selected-dark-bg);
}

.square.dark.highlight-hint {
    background-color: var(--highlight-hint-dark-bg) !important;
}

.square.dark.attack-indicator {
    background-color: var(--attack-indicator-dark-bg);
}

.square.dark.hanging-piece-type1 {
    background-color: var(--hanging-piece-type1-dark-bg);
}

.square.dark.hanging-piece-type2 {
    background-color: var(--hanging-piece-type2-dark-bg);
}

.square.dark.threat-lower-value {
    background-color: var(--threat-lower-value-dark-bg);
}

.square.dark.highlight-check {
    background-color: var(--threat-lower-value-dark-bg);
}

.threat-indicator {
    position: absolute;
    bottom: 2px;
    font-size: 12px;
    font-weight: bold;
    padding: 1px 3px;
    border-radius: 2px;
    pointer-events: none;
}

.threat-indicator.white {
    left: 2px;
    background-color: white;
    color: black;
}

.threat-indicator.black {
    right: 2px;
    background-color: black;
    color: white;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: var(--modal-bg-color);
}

.modal-content {
    background-color: var(--modal-content-bg);
    color: var(--text-color);
    margin: 10% auto;
    padding: 25px;
    border: 1px solid var(--modal-border-color);
    width: 90%;
    max-width: 550px;
    border-radius: 8px;
    position: relative;
}

.close-btn {
    color: var(--modal-close-color);
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
}

.close-btn:hover,
.close-btn:focus {
    color: var(--modal-close-hover-color);
    text-decoration: none;
    cursor: pointer;
}

.modal-title {
    font-weight: bold;
}

.modal-section {
    margin-bottom: 15px;
}

.modal-section > label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.option-label {
    font-weight: normal;
    position: relative;
    top: 1px;
    left: 0px;
}

.modal-section > div:not(.assist-grid) {
    display: flex;
    gap: 15px;
}

#start-new-game-btn, #end-game-new-game-btn {
    width: 100%;
    padding: 12px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

#start-new-game-btn:hover, #end-game-new-game-btn:hover {
    background-color: #45a049;
}

#end-game-modal .modal-content {
    text-align: center;
}

#end-game-new-game-btn {
    width: 50%;
    display: block;
    margin: 20px auto 0;
}

.assist-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 10px;
}

.assist-grid div {
    display: flex;
    align-items: center;
    gap: 8px;
}

.assist-grid input[type="checkbox"] {
    margin: 0;
}

.assist-grid label {
    position: relative;
    top: 0px;
    left: 0;
}

#promotion-modal .modal-content {
    max-width: 400px;
    text-align: center;
}

#promotion-choices {
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-top: 20px;
}

#promotion-choices button {
    background: none;
    border: 2px solid transparent;
    border-radius: 5px;
    padding: 10px;
    cursor: pointer;
    transition: border-color 0.2s;
    width: auto;
    margin: 0;
}

#promotion-choices button:hover {
    border-color: #999;
    background-color: transparent;
}

#promotion-choices img {
    width: 60px;
    height: 60px;
}

/* Move Indicators */
.move-indicator-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    background-color: rgb(255, 165, 0);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
}

.move-indicator-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70px;
    height: 70px;
    border: 5px solid rgb(255, 165, 0);
    border-radius: 50%;
    box-sizing: border-box;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1;
}

/* Captured Pieces Styles */
.captured-pieces-container {
    width: 100%;
    height: 40px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    border-radius: 4px;
    box-sizing: border-box;
}

.captured-pieces {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-grow: 1;
}

.piece-group {
    display: flex;
    align-items: center;
}

.captured-piece {
    width: 32px;
    height: 32px;
    margin-left: -20px;
}

.piece-group .captured-piece:first-child {
    margin-left: 0;
}

.advantage-score {
    font-size: 16px;
    font-weight: bold;
    color: var(--advantage-score-color);
    margin-left: auto;
    padding-right: 5px;
}

/* Responsive Design */
@media (max-width: 1000px) {
    body {
        padding-top: 5px;
    }

    #game-container {
        flex-direction: column;
        align-items: center;
        gap: 5px;
    }

    #main-content {
        order: 1;
        width: 95vw;
        gap: 5px;
    }

    #ui-panel {
        order: 2;
        width: 95vw;
        height: auto;
        margin-top: 0;
        margin-bottom: 20px;
        align-items: center;
    }

    #ui-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 15px;
        margin-bottom: 15px;
    }

    #ui-header-main {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 15px;
        width: 100%;
    }

    .logo-container {
        margin-bottom: 0;
    }

    .logo {
       height: 95px;
       width: auto;
       margin-bottom: 0;
       margin-top: 5px;
    }

    #game-controls {
        display: flex;
        flex-direction: column;
        width: 150px;
        gap: 5px;
    }

    #new-game-modal-btn {
        width: 60%;
        box-sizing: border-box;
        margin-top: 0;
        margin-left: auto;
        margin-right: auto;
    }

    #game-controls button {
        width: 100%;
        padding: 8px 5px;
        font-size: 12px;
        margin-top: 0;
    }

    #history-controls {
        width: 50%;
        margin: 0 auto;
    }

    #history-controls button {
        width: 45%;
    }

    #move-history {
        height: 100px;
        width: 60%;
        margin: 5px auto;
    }

    #board-container {
        width: 100%;
        height: auto;
        padding-bottom: 100%;
        position: relative;
    }

    #chessboard {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }

    .square {
        width: auto;
        height: auto;
    }

    .piece {
        width: 100%;
        height: 100%;
    }

    .captured-pieces-container {
        width: 100%;
    }

    .captured-piece {
        width: 24px;
        height: 24px;
        margin-left: -14px;
    }

    #developer-credit {
        width: 100%;
        text-align: center;
        margin-top: 15px;
    }

    .move-indicator-dot {
        width: 24px;
        height: 24px;
    }

    .move-indicator-ring {
        width: 85%;
        height: 85%;
        border-width: 4px;
    }
}