/* ===== CSS Variables & Theme ===== */
:root {
    --primary: #00f0ff;
    --primary-dark: #0088cc;
    --secondary: #ff00ff;
    --accent: #ffcc00;
    --danger: #ff3366;
    --success: #00ff88;
    --bg-dark: #0a0a1a;
    --bg-medium: #151530;
    --bg-light: #202050;
    --text-primary: #ffffff;
    --text-secondary: #8888aa;
    --glow-primary: 0 0 20px rgba(0, 240, 255, 0.5);
    --glow-secondary: 0 0 20px rgba(255, 0, 255, 0.5);
    --board-light: #2a3a6a;
    --board-dark: #151535;
    --board-highlight: rgba(0, 240, 255, 0.4);
    --board-selected: rgba(255, 204, 0, 0.5);
    --board-move: rgba(0, 255, 136, 0.4);
    --board-capture: rgba(255, 51, 102, 0.5);
}

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

body {
    font-family: 'Rajdhani', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== Animated Space Background ===== */
.space-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: radial-gradient(ellipse at center, #1a1a3a 0%, #0a0a1a 50%, #050510 100%);
}

.stars,
.stars2 {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(2px 2px at 20px 30px, #fff, transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(1px 1px at 90px 40px, #fff, transparent),
        radial-gradient(2px 2px at 160px 120px, rgba(255, 255, 255, 0.9), transparent),
        radial-gradient(1px 1px at 230px 80px, #fff, transparent),
        radial-gradient(2px 2px at 300px 150px, rgba(255, 255, 255, 0.7), transparent);
    background-size: 350px 350px;
    animation: twinkle 8s ease-in-out infinite;
}

.stars2 {
    background-size: 450px 450px;
    animation-delay: -4s;
    opacity: 0.5;
}

.nebula {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at 20% 80%, rgba(255, 0, 150, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(0, 150, 255, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(100, 0, 255, 0.1) 0%, transparent 60%);
    animation: nebulaPulse 15s ease-in-out infinite;
}

@keyframes twinkle {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

@keyframes nebulaPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(1.05);
    }
}

/* ===== Screens ===== */
.screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.screen.active {
    display: flex;
}

/* ===== Main Menu ===== */
.menu-container {
    text-align: center;
    padding: 40px;
}

.game-logo {
    font-family: 'Orbitron', sans-serif;
    font-size: 4rem;
    font-weight: 900;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.logo-stellar {
    color: var(--primary);
    text-shadow: 0 0 30px rgba(0, 240, 255, 0.8), 0 0 60px rgba(0, 240, 255, 0.4);
    letter-spacing: 0.3em;
}

.logo-chess {
    color: var(--secondary);
    text-shadow: 0 0 30px rgba(255, 0, 255, 0.8), 0 0 60px rgba(255, 0, 255, 0.4);
    letter-spacing: 0.5em;
    font-size: 3rem;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.2rem;
    letter-spacing: 0.2em;
    margin-bottom: 50px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 50px;
}

.menu-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    padding: 20px 60px;
    border: 2px solid;
    background: transparent;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.menu-btn.primary {
    color: var(--primary);
    border-color: var(--primary);
}

.menu-btn.primary:hover {
    background: rgba(0, 240, 255, 0.2);
    box-shadow: var(--glow-primary);
    transform: scale(1.05);
}

.menu-btn.secondary {
    color: var(--secondary);
    border-color: var(--secondary);
}

.menu-btn.secondary:hover {
    background: rgba(255, 0, 255, 0.2);
    box-shadow: var(--glow-secondary);
    transform: scale(1.05);
}

.menu-btn.tertiary {
    color: var(--text-secondary);
    border-color: var(--text-secondary);
}

.menu-btn.tertiary:hover {
    color: var(--text-primary);
    border-color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

.btn-icon {
    font-size: 1.5rem;
}

.stats-preview {
    display: flex;
    justify-content: center;
    gap: 60px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* ===== Screen Container ===== */
.screen-container {
    background: rgba(15, 15, 40, 0.9);
    border: 1px solid rgba(0, 240, 255, 0.3);
    border-radius: 20px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    text-align: center;
    backdrop-filter: blur(10px);
}

.screen-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 30px;
    text-shadow: 0 0 20px rgba(0, 240, 255, 0.5);
}

.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: transparent;
    border: 1px solid var(--text-secondary);
    color: var(--text-secondary);
    padding: 10px 20px;
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    transition: all 0.3s;
}

.back-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* ===== Difficulty Cards ===== */
.difficulty-cards {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    justify-content: center;
}

.difficulty-card {
    background: rgba(20, 20, 60, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 25px 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex: 1;
    max-width: 150px;
}

.difficulty-card:hover,
.difficulty-card.selected {
    transform: translateY(-5px);
}

.difficulty-card[data-difficulty="easy"]:hover,
.difficulty-card[data-difficulty="easy"].selected {
    border-color: var(--success);
    box-shadow: 0 0 30px rgba(0, 255, 136, 0.3);
}

.difficulty-card[data-difficulty="medium"]:hover,
.difficulty-card[data-difficulty="medium"].selected {
    border-color: var(--accent);
    box-shadow: 0 0 30px rgba(255, 204, 0, 0.3);
}

.difficulty-card[data-difficulty="hard"]:hover,
.difficulty-card[data-difficulty="hard"].selected {
    border-color: var(--danger);
    box-shadow: 0 0 30px rgba(255, 51, 102, 0.3);
}

.card-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.difficulty-card h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    margin-bottom: 5px;
}

.difficulty-card p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 10px;
}

.xp-bonus {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    color: var(--accent);
}

/* ===== Color Selection ===== */
.color-selection {
    margin-bottom: 30px;
}

.color-selection h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    margin-bottom: 15px;
    color: var(--text-secondary);
}

.color-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.color-btn {
    background: rgba(20, 20, 60, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 15px 30px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-family: 'Orbitron', sans-serif;
}

.color-btn:hover,
.color-btn.active {
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.3);
}

.fleet-icon {
    font-size: 1.5rem;
}

.start-game-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 15px 50px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    border: none;
    color: var(--bg-dark);
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
}

.start-game-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 40px rgba(0, 240, 255, 0.5);
}

/* ===== Settings ===== */
.settings-group {
    background: rgba(20, 20, 60, 0.5);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
}

.settings-group h3 {
    font-family: 'Orbitron', sans-serif;
    color: var(--primary);
    margin-bottom: 15px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-item:last-child {
    border-bottom: none;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 26px;
    transition: 0.3s;
}

.toggle-slider:before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

input:checked+.toggle-slider {
    background: var(--primary);
}

input:checked+.toggle-slider:before {
    transform: translateX(24px);
}

input[type="range"] {
    width: 120px;
    accent-color: var(--primary);
}

.stats-display {
    text-align: left;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    color: var(--text-secondary);
}

.stat-row span:last-child {
    color: var(--text-primary);
    font-weight: 600;
}

.reset-btn {
    margin-top: 15px;
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    transition: all 0.3s;
}

.reset-btn:hover {
    background: rgba(255, 51, 102, 0.2);
}

/* ===== Game Screen ===== */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 15px;
}

.player-panel {
    display: flex;
    align-items: center;
    gap: 20px;
    background: rgba(15, 15, 40, 0.8);
    border: 1px solid rgba(0, 240, 255, 0.2);
    border-radius: 15px;
    padding: 15px 25px;
    min-width: 500px;
    backdrop-filter: blur(5px);
}

.player-panel.active {
    border-color: var(--primary);
    box-shadow: var(--glow-primary);
}

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

.player-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: linear-gradient(135deg, var(--bg-light), var(--bg-medium));
    border: 2px solid var(--primary);
}

.player-details {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-family: 'Orbitron', sans-serif;
    font-weight: 600;
    font-size: 1rem;
}

.player-rank {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.captured-pieces {
    flex: 1;
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    font-size: 1.2rem;
}

.player-timer {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    color: var(--primary);
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 15px;
    border-radius: 8px;
}

/* ===== Chess Board ===== */
.board-container {
    position: relative;
}

.board-frame {
    padding: 15px;
    background: linear-gradient(135deg, rgba(0, 240, 255, 0.1), rgba(255, 0, 255, 0.1));
    border-radius: 10px;
    border: 2px solid rgba(0, 240, 255, 0.3);
    box-shadow: 0 0 50px rgba(0, 240, 255, 0.2), inset 0 0 30px rgba(0, 0, 0, 0.5);
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 70px);
    grid-template-rows: repeat(8, 70px);
    border: 3px solid var(--primary);
    box-shadow: var(--glow-primary);
}

.square {
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.8rem;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

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

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

.square:hover {
    filter: brightness(1.3);
}

.square.selected {
    background: var(--board-selected) !important;
    box-shadow: inset 0 0 20px rgba(255, 204, 0, 0.5);
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: var(--board-move);
    border-radius: 50%;
    animation: pulse 1s infinite;
}

.square.can-capture {
    background: var(--board-capture) !important;
    animation: captureGlow 1s infinite;
}

.square.check {
    background: rgba(255, 0, 0, 0.5) !important;
    animation: checkPulse 0.5s infinite;
}

.square.last-move {
    background: var(--board-highlight) !important;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

@keyframes captureGlow {

    0%,
    100% {
        box-shadow: inset 0 0 15px rgba(255, 51, 102, 0.5);
    }

    50% {
        box-shadow: inset 0 0 25px rgba(255, 51, 102, 0.8);
    }
}

@keyframes checkPulse {

    0%,
    100% {
        box-shadow: inset 0 0 20px rgba(255, 0, 0, 0.5);
    }

    50% {
        box-shadow: inset 0 0 40px rgba(255, 0, 0, 0.8);
    }
}

/* ===== Piece Styling ===== */
.piece {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    transition: transform 0.15s ease;
    user-select: none;
}

.piece.white {
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6));
}

.piece.black {
    filter: drop-shadow(0 0 8px rgba(100, 100, 255, 0.6));
}

.square:hover .piece {
    transform: scale(1.1);
}

/* ===== Game Status ===== */
.game-status {
    display: flex;
    align-items: center;
    gap: 30px;
    margin-top: 10px;
}

.turn-indicator {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem;
    display: flex;
    gap: 10px;
}

.turn-indicator span:last-child {
    color: var(--primary);
}

#game-message {
    font-family: 'Orbitron', sans-serif;
    color: var(--accent);
    animation: blink 1s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* ===== Game Controls ===== */
.game-controls {
    display: flex;
    gap: 15px;
    margin-top: 15px;
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--text-secondary);
    background: rgba(20, 20, 60, 0.8);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.control-btn:hover {
    border-color: var(--primary);
    box-shadow: var(--glow-primary);
    transform: scale(1.1);
}

/* ===== Score Display ===== */
.score-display {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 20px;
    background: rgba(15, 15, 40, 0.9);
    border: 1px solid rgba(0, 240, 255, 0.3);
    border-radius: 30px;
    padding: 10px 25px;
}

.xp-bar {
    width: 200px;
    height: 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    position: relative;
    overflow: hidden;
}

.xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 10px;
    width: 0%;
    transition: width 0.5s ease;
}

#xp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
}

.current-rank {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    color: var(--accent);
}

/* ===== Modals ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: linear-gradient(135deg, rgba(20, 20, 60, 0.95), rgba(10, 10, 30, 0.95));
    border: 2px solid var(--primary);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 450px;
    box-shadow: 0 0 60px rgba(0, 240, 255, 0.3);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-content h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--primary);
}

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

.result-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 25px 0;
}

.result-stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.result-stat span:first-child {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.result-stat span:last-child {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    color: var(--primary);
}

.modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
}

.modal-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    padding: 12px 30px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
}

.modal-btn.primary {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: var(--bg-dark);
}

.modal-btn.secondary {
    background: transparent;
    border: 2px solid var(--text-secondary);
    color: var(--text-secondary);
}

.modal-btn:hover {
    transform: scale(1.05);
}

/* ===== Promotion Modal ===== */
.promotion-pieces {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 20px;
}

.promotion-piece {
    font-size: 3rem;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 20, 60, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.promotion-piece:hover {
    border-color: var(--primary);
    box-shadow: var(--glow-primary);
    transform: scale(1.1);
}

/* ===== Responsive ===== */
@media (max-width: 700px) {
    .game-logo {
        font-size: 2.5rem;
    }

    .logo-chess {
        font-size: 2rem;
    }

    .chess-board {
        grid-template-columns: repeat(8, 45px);
        grid-template-rows: repeat(8, 45px);
    }

    .square {
        width: 45px;
        height: 45px;
        font-size: 1.8rem;
    }

    .player-panel {
        min-width: auto;
        padding: 10px 15px;
        flex-wrap: wrap;
    }

    .difficulty-cards {
        flex-direction: column;
    }
}