:root {
    --square-size: clamp(45px, 9vmin, 90px);
    --board-bg-light: #ebecd0;
    --board-bg-dark: #739552;
}

* { 
    box-sizing: border-box; 
}

body, html {
    height: 100%; 
    margin: 0; 
    display: flex; 
    justify-content: center; 
    align-items: center;
    background: #302e2b;
    font-family: sans-serif;
}

.game-layout { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    padding: 20px; 
}

.board-container {
    position: relative;
    width: calc(var(--square-size) * 8);
    height: calc(var(--square-size) * 8);
}

.chessboard { 
    display: grid; 
    grid-template-columns: repeat(8, var(--square-size)); 
    grid-template-rows: repeat(8, var(--square-size)); 
}

.coordinates { 
    font-size: calc(var(--square-size) * 0.2); 
    color: rgba(255,255,255,0.4); 
    position: absolute; 
    user-select: none;
    display: none;
}

.files { 
    display: flex; 
    justify-content: space-around; 
    width: 100%; 
    bottom: calc(var(--square-size) * -0.4); 
}

.ranks { 
    display: flex; 
    flex-direction: column; 
    justify-content: space-around; 
    height: 100%; 
    left: calc(var(--square-size) * -0.4); 
    text-align: right; 
}

.ranks span, .files span { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    width: var(--square-size); 
    height: var(--square-size); 
}

.progress-container {
    width: calc(var(--square-size) * 8);
    height: 6px;
    background-color: #333;
    border-radius: 3px;
    margin-top: 15px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.progress-container.active {
    opacity: 1;
}

.progress-bar {
    height: 100%;
    background-color: #4CAF50;
    border-radius: 3px;
    transition: width 0.1s linear;
    width: 0%;
}

.square { 
    width: var(--square-size); 
    height: var(--square-size); 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    position: relative; 
}

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

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

.square.selected { 
    background-color: #f6d56a; 
}

/* Corner squares border radius */
.square[data-index="0"] { 
    border-top-left-radius: 8px; 
}

.square[data-index="7"] { 
    border-top-right-radius: 8px; 
}

.square[data-index="56"] { 
    border-bottom-left-radius: 8px; 
}

.square[data-index="63"] { 
    border-bottom-right-radius: 8px; 
}

.piece {
    width: calc(var(--square-size) * 0.8);
    height: calc(var(--square-size) * 0.8);
    cursor: pointer;
    position: relative;
    z-index: 2;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    user-select: none;
    transition: transform 0.3s ease-out;
}

.piece.moving {
    z-index: 10;
    transition: transform 0.3s ease-out;
}

/* White pieces */
.piece.wp { background-image: url('assets/wp.png'); }
.piece.wr { background-image: url('assets/wr.png'); }
.piece.wn { background-image: url('assets/wn.png'); }
.piece.wb { background-image: url('assets/wb.png'); }
.piece.wq { background-image: url('assets/wq.png'); }
.piece.wk { background-image: url('assets/wk.png'); }

/* Black pieces */
.piece.bp { background-image: url('assets/bp.png'); }
.piece.br { background-image: url('assets/br.png'); }
.piece.bn { background-image: url('assets/bn.png'); }
.piece.bb { background-image: url('assets/bb.png'); }
.piece.bq { background-image: url('assets/bq.png'); }
.piece.bk { background-image: url('assets/bk.png'); }

.square.highlight::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background-color: rgba(0, 0, 0, 0.25);
    border-radius: 50%;
    z-index: 5;
}

#promotion-modal { 
    display: none; 
    position: absolute; 
    z-index: 1000; 
    backdrop-filter: blur(5px); 
    background: rgba(0,0,0,0.5); 
    padding: 15px; 
    border-radius: 10px; 
    gap: 10px; 
}

.promotion-choice { 
    font-size: var(--square-size); 
    cursor: pointer; 
}

#chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    height: 300px;
    background-color: #1a1d21;
    border: 1px solid #444;
    border-radius: 25px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    padding: 15px;
    color: #e1e1e1;
    font-size: 14px;
}

#chat-header {
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    color: white;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #444;
}

#chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #444 #1a1d21;
}

#chat-messages p {
    position: relative;
    background: #36393f;
    padding: 8px 12px;
    border-radius: 12px;
    line-height: 1.4;
    margin: 0 0 10px 10px;
    max-width: 90%;
    width: fit-content;
}

#game-analysis-container {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 350px;
    height: 400px;
    background-color: #1a1d21;
    border: 1px solid #444;
    border-radius: 15px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    padding: 15px;
    color: #e1e1e1;
    font-size: 14px;
}

#analysis-header {
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    color: white;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid #444;
}

#position-rating {
    margin-bottom: 15px;
}

.rating-bar-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rating-bar {
    flex: 1;
    height: 20px;
    background-color: #333;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.rating-fill {
    height: 100%;
    background-color: #4CAF50;
    border-radius: 10px;
    transition: all 0.3s ease;
    width: 50%;
}

.rating-text {
    font-weight: bold;
    font-size: 12px;
    min-width: 60px;
    text-align: center;
}

#captures-section {
    margin-bottom: 15px;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
}

.captures-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.player-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.captured-pieces {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    min-height: 20px;
    align-items: center;
}

.capture-count {
    font-weight: bold;
    font-size: 16px;
    margin-right: 8px;
    color: #FFC107;
}

.captured-piece {
    width: 16px;
    height: 16px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.8;
}

#moves-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#moves-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid #444;
}

.moves-controls {
    display: flex;
    gap: 5px;
}

.moves-controls button {
    background: #36393f;
    border: 1px solid #555;
    color: #e1e1e1;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.moves-controls button:hover {
    background: #4a4d52;
}

#moves-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #444 #1a1d21;
    font-family: monospace;
    font-size: 13px;
    line-height: 1.4;
    max-height: 200px;
    padding-right: 5px;
}

.move-pair {
    margin-bottom: 2px;
}

.move-number {
    color: #888;
    margin-right: 8px;
}

.white-move, .black-move {
    margin-right: 8px;
}

.white-move {
    color: #f8f8f8;
}

.black-move {
    color: #ccc;
}

.empty-moves-message {
    text-align: center;
    color: #888;
    font-style: italic;
    padding: 20px 10px;
    font-size: 13px;
}
