:root {
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --primary-glow: rgba(56, 189, 248, 0.5);
    --white-square: #f1f5f9;
    --black-square: #64748b;
    --highlight-color: rgba(56, 189, 248, 0.4);
    --last-move-color: rgba(250, 204, 21, 0.3);
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --accent: #38bdf8;
    --white-piece-color: #ffffff;
    --black-piece-color: #1e293b;
    --board-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 2rem;
}

.background-glow {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80vw;
    height: 80vh;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
    z-index: -1;
    opacity: 0.3;
}

.app-container {
    width: 100%;
    max-width: 1200px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    z-index: 1;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title {
    font-family: 'Outfit', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -1px;
}

.title span {
    color: var(--accent);
    font-weight: 300;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.difficulty-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 99px;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.select-premium {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    padding-right: 0.5rem;
}

.select-premium option {
    background-color: #1e293b;
    color: var(--text-main);
}

.turn-indicator {
    padding: 0.75rem 1.5rem;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 99px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.3s ease;
}

.indicator-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #fff;
    box-shadow: 0 0 10px #fff;
}

.black-turn .indicator-dot {
    background-color: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

.game-layout {
    display: grid;
    grid-template-columns: 250px 1fr 250px;
    gap: 2rem;
    align-items: center;
}

.sidebar {
    display: flex;
    flex-direction: column;
    height: 600px;
}

.sidebar.left {
    justify-content: space-between;
}

.sidebar.right {
    justify-content: space-between;
}

.captured-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    min-height: 80px;
    max-width: 250px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.captured-piece {
    width: 24px;
    height: 24px;
    opacity: 0.8;
    transition: transform 0.2s ease;
}

.captured-piece:hover {
    transform: scale(1.2);
    opacity: 1;
}

.captured-piece img {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.player-card {
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.player-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.2);
    transform: scale(1.05);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
}

.black-player .avatar {
    background: #334155;
}

.player-info {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.player-sub {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.board-container {
    display: flex;
    justify-content: center;
    perspective: 1000px;
}

.chess-board {
    width: 600px;
    height: 600px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    background: #1e293b;
    border: 12px solid #1e293b;
    border-radius: 8px;
    box-shadow: var(--board-shadow);
    position: relative;
}

.square {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.square.light {
    background-color: var(--white-square);
}

.square.dark {
    background-color: var(--black-square);
}

.square.selected {
    background-color: var(--highlight-color) !important;
}

.square.last-move {
    background-color: var(--last-move-color) !important;
}

.square.in-check {
    background: radial-gradient(circle, rgba(239, 68, 68, 0.8) 0%, transparent 70%) !important;
    box-shadow: inset 0 0 20px 5px rgba(239, 68, 68, 0.6) !important;
    border: 3px solid rgba(239, 68, 68, 0.8) !important;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}

.thinking-dots span {
    animation: blink 1.4s infinite both;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0% {
        opacity: 0.2;
    }
    20% {
        opacity: 1;
    }
    100% {
        opacity: 0.2;
    }
}

.legal-dot {
    width: 20px;
    height: 20px;
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    pointer-events: none;
}

.square:hover .legal-dot {
    background-color: rgba(0, 0, 0, 0.2);
}

.piece {
    width: 80%;
    height: 80%;
    z-index: 10;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.piece img {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

.game-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

@media (max-width: 1100px) {
    .game-header {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .title {
        font-size: 1.5rem;
    }

    .header-controls {
        flex-direction: row;
        justify-content: center;
        gap: 0.5rem;
        width: 100%;
        align-items: center;
    }

    .difficulty-control, .turn-indicator {
        width: fit-content;
        padding: 0.35rem 0.75rem;
        font-size: 0.8rem;
    }

    .difficulty-control label {
        display: none; /* Hide label to save horizontal space */
    }

    .select-premium {
        font-size: 0.8rem;
    }

    .game-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .sidebar.left {
        order: 3;
        flex-direction: column-reverse;
    }

    .sidebar.right {
        order: 1;
        flex-direction: column-reverse;
    }

    .board-container {
        order: 2;
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .sidebar {
        height: auto;
        justify-content: center;
        align-items: center;
        gap: 0.5rem;
    }

    .player-card {
        padding: 0.5rem 0.75rem;
        width: fit-content;
        min-width: 120px;
    }

    .avatar {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }

    .player-name {
        font-size: 0.9rem;
    }

    .player-sub {
        display: none; /* Hide sub-info on mobile to save space */
    }

    .app-container {
        padding: 0.5rem;
        gap: 0.75rem;
        padding-bottom: 1rem;
    }

    .game-footer {
        flex-direction: row;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .status-bar p {
        font-size: 0.85rem;
    }

    .controls {
        width: auto;
    }

    .btn {
        width: auto;
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .captured-container {
        height: auto;
        min-height: 40px;
        padding: 0.4rem;
        gap: 0.25rem;
    }

    .captured-piece {
        width: 18px;
        height: 18px;
    }

    .chess-board {
        width: 98vw;
        height: 98vw;
        max-width: none;
        max-height: 80vh; /* Safely limit height to avoid pushing footer off-screen too far */
        aspect-ratio: 1/1;
        border-width: 4px;
    }
}