/* Main CSS for Chess Bot Web App */

:root {
    /* Telegram theme variables */
    --tg-theme-bg-color: var(--tg-theme-bg-color, #1a1a2e);
    --tg-theme-text-color: var(--tg-theme-text-color, #ffffff);
    --tg-theme-hint-color: var(--tg-theme-hint-color, #7c7c7c);
    --tg-theme-link-color: var(--tg-theme-link-color, #3390ec);
    --tg-theme-button-color: var(--tg-theme-button-color, #3390ec);
    --tg-theme-button-text-color: var(--tg-theme-button-text-color, #ffffff);
    --tg-theme-secondary-bg-color: var(--tg-theme-secondary-bg-color, #232333);
    
    /* Board colors */
    --board-light: #f0d9b5;
    --board-dark: #b58863;
    --board-highlight: rgba(255, 255, 0, 0.5);
    --board-move-hint: rgba(0, 128, 0, 0.3);
    --board-last-move: rgba(155, 199, 0, 0.41);
    --board-check: rgba(255, 0, 0, 0.5);
    
    /* Sizing */
    --board-size: min(100vw - 20px, 400px);
    --square-size: calc(var(--board-size) / 8);
}

/* Board themes */
.theme-classic {
    --board-light: #f0d9b5;
    --board-dark: #b58863;
}

.theme-wood {
    --board-light: #e6d5ac;
    --board-dark: #8b6914;
}

.theme-blue {
    --board-light: #dee3e6;
    --board-dark: #8ca2ad;
}

.theme-dark {
    --board-light: #4a4a4a;
    --board-dark: #2d2d2d;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    padding: 10px;
}

.screen.active {
    display: flex;
}

/* Loading Screen */
#loading-screen {
    justify-content: center;
    align-items: center;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--tg-theme-secondary-bg-color);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Player Bar */
.player-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 10px;
    margin: 5px 0;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--tg-theme-hint-color);
}

.player-color.white {
    background: #fff;
}

.player-color.black {
    background: #000;
}

.player-name {
    font-weight: 600;
    font-size: 16px;
}

.player-rating {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

.timer {
    font-size: 24px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    padding: 5px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.timer.low-time {
    color: #ff4444;
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.timer.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

/* Captured pieces */
.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    min-height: 24px;
    padding: 5px;
    font-size: 18px;
}

/* Board Container */
#board-container,
#puzzle-board-container {
    position: relative;
    width: var(--board-size);
    height: var(--board-size);
    margin: 10px auto;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

#chess-board,
#puzzle-board {
    width: 100%;
    height: 100%;
    display: block;
}

/* Promotion overlay */
#promotion-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#promotion-overlay.hidden {
    display: none;
}

.promotion-choices {
    display: flex;
    gap: 10px;
    background: var(--tg-theme-secondary-bg-color);
    padding: 15px;
    border-radius: 10px;
}

.promotion-choices button {
    width: 60px;
    height: 60px;
    font-size: 40px;
    border: none;
    background: var(--tg-theme-bg-color);
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.promotion-choices button:hover {
    transform: scale(1.1);
}

/* Moves Panel */
.moves-panel {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 10px;
    padding: 10px;
    margin: 10px 0;
    max-height: 100px;
    overflow-y: auto;
}

#moves-list {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Game Actions */
.game-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 10px 0;
}

.action-btn {
    width: 50px;
    height: 50px;
    border: none;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.action-btn:hover {
    transform: scale(1.1);
    background: var(--tg-theme-button-color);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

.btn:hover {
    transform: scale(1.02);
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

.btn-secondary {
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

/* Result Screen */
#result-screen {
    justify-content: center;
    align-items: center;
}

.result-content {
    text-align: center;
    background: var(--tg-theme-secondary-bg-color);
    padding: 30px;
    border-radius: 20px;
    max-width: 350px;
    width: 100%;
}

.result-icon {
    font-size: 60px;
    margin-bottom: 15px;
}

.result-title {
    font-size: 28px;
    margin-bottom: 10px;
}

.result-reason {
    color: var(--tg-theme-hint-color);
    margin-bottom: 20px;
}

.rating-change {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    margin-bottom: 25px;
}

.rating-change .change {
    padding: 5px 10px;
    border-radius: 5px;
}

.rating-change .change.positive {
    background: rgba(40, 167, 69, 0.2);
    color: #28a745;
}

.rating-change .change.negative {
    background: rgba(220, 53, 69, 0.2);
    color: #dc3545;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Puzzle Screen */
.puzzle-header {
    text-align: center;
    margin-bottom: 10px;
}

.puzzle-info {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

.puzzle-status {
    text-align: center;
    padding: 10px;
    font-size: 18px;
    font-weight: 600;
}

.puzzle-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

/* Modals */
#modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
}

#modal-backdrop.hidden {
    display: none;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--tg-theme-secondary-bg-color);
    padding: 25px;
    border-radius: 15px;
    text-align: center;
    min-width: 280px;
}

.modal-content h3 {
    margin-bottom: 10px;
    font-size: 20px;
}

.modal-content p {
    color: var(--tg-theme-hint-color);
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Utility classes */
.hidden {
    display: none !important;
}

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

/* Responsive */
@media (max-width: 400px) {
    :root {
        --board-size: calc(100vw - 20px);
    }
    
    .timer {
        font-size: 20px;
        padding: 5px 10px;
    }
    
    .player-name {
        font-size: 14px;
    }
}
