:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --primary-color: #38bdf8;
    --primary-hover: #0ea5e9;
    --secondary-color: #64748b;
    --accent-color: #f59e0b;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --success-color: #22c55e;
    --error-color: #ef4444;
    --info-color: #3b82f6;
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-border: #451a03;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    overflow-x: hidden;
}

#app {
    width: 100%;
    max-width: 1400px;
    background: radial-gradient(circle at top right, rgba(56, 189, 248, 0.1), transparent);
    padding: 2rem;
    border-radius: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
}

.btn-icon {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--secondary-color);
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--primary-color);
    transform: translateY(-50%) rotate(45deg);
}

.btn-icon svg {
    width: 1.5rem;
    height: 1.5rem;
}

header h1 {
    font-size: 3.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #38bdf8, #818cf8, #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

#game-status {
    font-size: 1.1rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 2px;
}

main {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 3rem;
    align-items: start;
}

#board-container {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    padding: 1.5rem;
    border-radius: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.chessboard {
    width: 100%;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    border: 8px solid var(--board-border);
    border-radius: 4px;
    transition: all 0.3s ease;
}

.square {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
}

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

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

.square img,
.piece {
    width: 100%;
    height: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    object-fit: contain;
    user-select: none;
}

/* Highlight square when piece is selected */
.square.selected {
    box-shadow: inset 0 0 0 5px rgba(255, 255, 0, 0.5);
}

/* Highlight square for hint */
.square.hint {
    background-color: rgba(255, 255, 0, 0.5) !important;
}

/* Valid move indicator */
.square.valid-move::after {
    content: '';
    position: absolute;
    width: 20%;
    height: 20%;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    pointer-events: none;
}

.square.dark.valid-move::after {
    background-color: rgba(0, 0, 0, 0.25);
    /* Slightly darker on dark squares */
}

#controls {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    padding: 2rem;
    border-radius: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.panel h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

#instruction {
    font-size: 1.1rem;
    color: #cbd5e1;
    margin-bottom: 2rem;
}

.difficulty-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.btn-difficulty {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 0.75rem;
    border-radius: 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-difficulty:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-difficulty.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #0f172a;
    font-weight: 600;
}

.action-buttons {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.btn-primary {
    flex: 2;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    border: 2px solid transparent;
    color: #0f172a;
    padding: calc(1rem - 2px);
    border-radius: 0.75rem;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    border-color: #ffffff;
}

.btn-secondary {
    flex: 1;
    background: transparent;
    border: 2px solid var(--secondary-color);
    color: var(--text-color);
    padding: 1rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-color);
}

.settings-actions {
    text-align: right;
}

.btn-text {
    background: none;
    border: none;
    color: var(--secondary-color);
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.btn-text:hover {
    opacity: 1;
}

.btn-text.danger {
    color: var(--error-color);
    text-decoration: none;
    font-weight: 600;
}

.btn-text.danger:hover {
    text-decoration: underline;
}

.score-board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    background: rgba(15, 23, 42, 0.5);
    padding: 1.5rem;
    border-radius: 1rem;
}

.score-item {
    text-align: center;
}

.score-item .label {
    display: block;
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

.score-item .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
}

#feedback-container {
    min-height: 2.5rem;
}

#feedback-msg {
    padding: 1rem;
    border-radius: 0.75rem;
    text-align: center;
    font-weight: 500;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#feedback-msg.show {
    opacity: 1;
    transform: translateY(0);
}

#feedback-msg.success {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

#feedback-msg.error {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

#feedback-msg.info {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Custom Confirmation Modal */
#modal-overlay,
#settings-overlay,
#promotion-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

#modal-overlay.hidden,
#settings-overlay.hidden,
#promotion-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background: var(--panel-bg);
    padding: 2.5rem;
    border-radius: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    width: 90%;
    text-align: center;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#modal-overlay.hidden .modal,
#settings-overlay.hidden .modal,
#promotion-overlay.hidden .modal {
    transform: translateY(20px);
}

.modal h3 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.modal p {
    color: #94a3b8;
    margin-bottom: 2rem;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 1rem;
}

.modal-actions button {
    flex: 1;
}

/* Settings Modal Specifics */
.settings-modal {
    max-width: 500px;
    text-align: left;
}

.settings-modal h3 {
    text-align: center;
    margin-bottom: 2rem;
}

.settings-group {
    margin-bottom: 2rem;
}

.settings-group label {
    display: block;
    font-size: 0.9rem;
    color: #94a3b8;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.theme-selector {
    display: flex;
    gap: 1rem;
}

.btn-theme {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.75rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-theme:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-theme.active {
    border-color: var(--primary-color);
    background: rgba(56, 189, 248, 0.1);
}

.theme-preview {
    width: 100%;
    height: 40px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.theme-preview.classic {
    background: linear-gradient(135deg, #f0d9b5 50%, #b58863 50%);
}

.theme-preview.stone {
    background: linear-gradient(135deg, #e4e2e0 50%, #769656 50%);
}

.theme-preview.bw {
    background: linear-gradient(135deg, #ffffff 50%, #555555 50%);
}

.btn-theme span {
    font-size: 0.8rem;
    color: var(--text-color);
}

.input-action {
    display: flex;
    gap: 0.5rem;
}

.input-action input {
    flex: 1;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.75rem;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
}

.input-action input:focus {
    outline: none;
    border-color: var(--primary-color);
}


/* Toggle Switch */
.option-row {
    margin-bottom: 1rem;
}

.settings-group .toggle-switch {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    gap: 0.75rem;
    /* Reset label defaults if needed */
    width: fit-content;
}

.toggle-switch input {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 3rem;
    height: 1.5rem;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 1.5rem;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: calc(1.5rem - 6px);
    height: calc(1.5rem - 6px);
    background-color: var(--secondary-color);
    border-radius: 50%;
    transition: all 0.2s;
}

.toggle-switch input:checked+.toggle-slider {
    background-color: rgba(56, 189, 248, 0.2);
    border-color: var(--primary-color);
}

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(1.5rem);
    background-color: var(--primary-color);
}

.toggle-label {
    font-size: 1rem;
    color: var(--text-color);
}

.settings-modal hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

/* Theme variables */
body[data-theme="classic"] {
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-border: #451a03;
}

body[data-theme="stone"] {
    --board-light: #e4e2e0;
    --board-dark: #769656;
    --board-border: #2c3e50;
}

body[data-theme="bw"] {
    --board-light: #ffffff;
    --board-dark: #555555;
    --board-border: #000000;
}

@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 2.5rem;
    }

    .btn-icon {
        width: 2.5rem;
        height: 2.5rem;
    }
}

/* Promotion Modal Specifics */
.promotion-modal {
    max-width: 600px;
    width: auto;
}

.promotion-modal h3 {
    text-align: center;
    margin-bottom: 2rem;
}

.promotion-options {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-promotion {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s;
    min-width: 100px;
}

.btn-promotion:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
    transform: translateY(-5px);
}

.piece-preview {
    width: 50px;
    height: 50px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.piece-preview.queen {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/1/15/Chess_qlt45.svg');
}

.piece-preview.rook {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/7/72/Chess_rlt45.svg');
}

.piece-preview.bishop {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/b/b1/Chess_blt45.svg');
}

.piece-preview.knight {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/7/70/Chess_nlt45.svg');
}

.body-turn-black .piece-preview.queen {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/4/47/Chess_qdt45.svg');
}

.body-turn-black .piece-preview.rook {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/f/ff/Chess_rdt45.svg');
}

.body-turn-black .piece-preview.bishop {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/9/98/Chess_bdt45.svg');
}

.body-turn-black .piece-preview.knight {
    background-image: url('https://upload.wikimedia.org/wikipedia/commons/e/ef/Chess_ndt45.svg');
}

.btn-promotion span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);
}
/* Coordinates */
.coordinate-rank {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    pointer-events: none;
    user-select: none;
    opacity: 0.7;
}

.coordinate-file {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    pointer-events: none;
    user-select: none;
    opacity: 0.7;
}

/* Ensure text color contrasts with square color */
.square.light .coordinate-rank,
.square.light .coordinate-file {
    color: var(--board-dark); /* Use dark color on light square */
}

.square.dark .coordinate-rank,
.square.dark .coordinate-file {
    color: var(--board-light); /* Use light color on dark square */
}
