* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    min-height: 100%;
}

body {
    min-height: 100vh;

    font-family: Arial, sans-serif;

    background:
        radial-gradient(
            circle at top,
            #25304a 0%,
            #111827 45%,
            #070b12 100%
        );

    color: white;

    padding: 12px;
}

.analysis-page {
    width: min(1220px, 100%);

    margin: 0 auto;
}


/* =========================
   TOP
========================= */

.top-bar {
    display: grid;

    grid-template-columns:
        auto 1fr auto;

    align-items: center;

    gap: 12px;

    margin-bottom: 10px;
}

.back-btn {
    padding: 9px 13px;

    border-radius: 9px;

    background: #171d2e;

    border:
        1px solid rgba(255,255,255,0.08);

    color: white;

    text-decoration: none;

    font-size: 13px;
    font-weight: bold;
}

.small-title {
    margin: 0 0 4px;

    color: #8f99b7;

    font-size: 9px;
    font-weight: 800;

    letter-spacing: 1.8px;
}

h1,
h2 {
    margin: 0;
}

h1 {
    font-size:
        clamp(23px, 2.5vw, 32px);
}

.result-badge {
    padding: 9px 14px;

    border-radius: 9px;

    background: #171d2e;

    font-weight: 800;
}

.result-badge.win {
    color: #8df0a4;

    background:
        rgba(55,190,90,0.14);
}

.result-badge.loss {
    color: #ff9c9c;

    background:
        rgba(220,70,70,0.14);
}

.result-badge.draw {
    color: #ffd589;

    background:
        rgba(220,165,60,0.14);
}


/* =========================
   PLAYER INFO
========================= */

.game-info {
    display: grid;

    grid-template-columns:
        1fr auto 1fr;

    align-items: center;

    gap: 12px;

    margin-bottom: 12px;

    padding: 9px 14px;

    background:
        linear-gradient(
            145deg,
            #171d2e,
            #0d1220
        );

    border:
        1px solid rgba(255,255,255,0.08);

    border-radius: 13px;
}

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

.player-info span {
    display: block;

    margin-bottom: 3px;

    color: #8f99b7;

    font-size: 9px;
    font-weight: 800;
}

.player-info strong {
    display: block;

    font-size: 16px;
}

.player-info small {
    display: block;

    margin-top: 3px;

    color: #aab2c7;

    font-size: 11px;
}

.versus {
    color: #747f9e;

    font-size: 11px;
    font-weight: 900;
}


/* =========================
   3 COLUMN LAYOUT
========================= */

.analysis-layout {
    display: grid;

    grid-template-columns:
        190px
        minmax(450px, 560px)
        300px;

    justify-content: center;

    gap: 15px;

    align-items: start;
}


/* =========================
   MOVES - LEFT
========================= */

.moves-section {
    height: 560px;

    padding: 12px;

    background:
        linear-gradient(
            145deg,
            #171d2e,
            #0d1220
        );

    border:
        1px solid rgba(255,255,255,0.08);

    border-radius: 14px;

    display: flex;

    flex-direction: column;

    min-width: 0;
}

.moves-header {
    display: flex;

    align-items: end;
    justify-content: space-between;

    gap: 5px;

    padding-bottom: 10px;

    border-bottom:
        1px solid rgba(255,255,255,0.06);
}

.moves-header h2 {
    font-size: 18px;
}

#totalMoves {
    margin: 0;

    color: #858faa;

    font-size: 10px;
}


/* SCROLL GHIR DAKHEL MOVES */

.moves-list {
    flex: 1;

    min-height: 0;

    overflow-y: auto;
    overscroll-behavior: contain;

    display: flex;

    flex-direction: column;

    gap: 5px;

    margin-top: 10px;

    padding-right: 4px;
}

.moves-list::-webkit-scrollbar {
    width: 6px;
}

.moves-list::-webkit-scrollbar-track {
    background: #0a0f1c;

    border-radius: 10px;
}

.moves-list::-webkit-scrollbar-thumb {
    background: #343d5a;

    border-radius: 10px;
}

.move-item {
    width: 100%;

    min-height: 34px;

    display: flex;

    align-items: center;

    gap: 7px;

    padding: 7px 8px;

    border: none;

    border-radius: 7px;

    background: #0d1322;

    color: #c8cee0;

    cursor: pointer;

    text-align: left;
}

.move-item:hover {
    background: #192137;
}

.move-item.active {
    background:
        linear-gradient(
            135deg,
            #6675ff,
            #8d62ff
        );

    color: white;
}

.move-number {
    min-width: 32px;

    color: #78829d;

    font-size: 9px;

    font-weight: 800;
}

.move-item strong {
    font-size: 12px;
}

.move-item.active .move-number {
    color:
        rgba(255,255,255,0.7);
}


/* =========================
   BOARD - CENTER
========================= */

.board-area {
    min-width: 0;
}

.board-frame {
    width: min(100%, 560px);

    aspect-ratio: 1 / 1;

    padding: 7px;

    background:
        linear-gradient(
            145deg,
            #4a2d1f,
            #26160f
        );

    border:
        1px solid rgba(255,255,255,0.10);

    border-radius: 14px;

    box-shadow:
        0 16px 38px rgba(0,0,0,0.34);
}

.chess-board {
    width: 100%;
    height: 100%;

    display: grid;

    grid-template-columns:
        repeat(8, 1fr);

    grid-template-rows:
        repeat(8, 1fr);

    overflow: hidden;

    border-radius: 6px;
}

.square {
    position: relative;

    display: flex;

    align-items: center;
    justify-content: center;

    min-width: 0;
    min-height: 0;

    user-select: none;
}

.square.light {
    background: #e7d4ad;
}

.square.dark {
    background: #8d6245;
}

.square.current-move {
    box-shadow:
        inset 0 0 0 999px
        rgba(255,226,77,0.28);
}

.piece {
    width: 80%;
    height: 80%;

    object-fit: contain;

    display: block;

    user-select: none;
    pointer-events: none;

    filter:
        drop-shadow(
            0 2px 2px rgba(0,0,0,0.22)
        );
}


/* =========================
   NAVIGATION
========================= */

.navigation-controls {
    display: grid;

    grid-template-columns:
        auto auto 1fr auto auto;

    gap: 6px;

    align-items: center;

    width: 100%;

    margin-top: 9px;
}

.navigation-controls button {
    min-height: 36px;

    padding: 6px 8px;

    border:
        1px solid rgba(255,255,255,0.08);

    border-radius: 8px;

    background: #171d2e;

    color: white;

    font-size: 11px;
    font-weight: 700;

    cursor: pointer;
}

.navigation-controls button:hover {
    background: #20283e;
}

.navigation-controls button:disabled {
    opacity: 0.35;

    cursor: not-allowed;
}

#moveCounter {
    text-align: center;

    color: #adb5cb;

    font-size: 12px;
    font-weight: bold;
}


/* =========================
   ANALYSIS - RIGHT
========================= */

.analysis-panel {
    display: grid;

    gap: 9px;

    position: sticky;

    top: 10px;
}

.analysis-card {
    padding: 14px;

    background:
        linear-gradient(
            145deg,
            #171d2e,
            #0d1220
        );

    border:
        1px solid rgba(255,255,255,0.08);

    border-radius: 13px;

    box-shadow:
        0 8px 20px rgba(0,0,0,0.15);
}

.panel-label {
    margin: 0 0 6px;

    color: #7f89a6;

    font-size: 8px;
    font-weight: 800;

    letter-spacing: 1.5px;
}

#moveQuality {
    font-size: 22px;
}

#movePlayed,
#engineMessage {
    margin: 6px 0 0;

    color: #aeb6ca;

    font-size: 12px;

    line-height: 1.4;
}

.evaluation-value {
    font-size: 34px;

    font-weight: 900;
}

#bestMove {
    font-size: 20px;

    font-weight: 800;

    color: #b9c2ff;
}


/* =========================
   QUALITY
========================= */

.quality-best {
    color: #66e6d0;
}

.quality-great {
    color: #7ee0ff;
}

.quality-good {
    color: #8df0a4;
}

.quality-inaccuracy {
    color: #ffd266;
}

.quality-mistake {
    color: #ff9a5f;
}

.quality-blunder {
    color: #ff6f7f;
}


/* =========================
   SMALL LAPTOP
========================= */

@media (max-width: 1100px) {

    .analysis-layout {
        grid-template-columns:
            170px
            minmax(420px, 520px)
            270px;

        gap: 10px;
    }

    .moves-section {
        height: 520px;
    }
}


/* =========================
   TABLET
========================= */

@media (max-width: 900px) {

    .analysis-layout {
        grid-template-columns:
            170px
            minmax(0, 1fr);

        max-width: 720px;

        margin: 0 auto;
    }

    .moves-section {
        height: 520px;
    }

    .board-frame {
        width: min(100%, 520px);
    }

    .analysis-panel {
        grid-column: 1 / -1;

        position: static;

        grid-template-columns:
            repeat(2, 1fr);
    }
}


/* =========================
   MOBILE
========================= */

@media (max-width: 620px) {

    body {
        padding: 7px;
    }

    .top-bar {
        grid-template-columns:
            auto 1fr;

        gap: 7px;
    }

    .result-badge {
        grid-column: 1 / -1;

        text-align: center;
    }

    h1 {
        font-size: 22px;
    }

    .game-info {
        padding: 8px 5px;
    }

    .player-info strong {
        font-size: 12px;
    }

    .player-info small {
        font-size: 9px;
    }

    .analysis-layout {
        display: flex;

        flex-direction: column;

        width: 100%;
    }

    .board-area {
        order: 1;

        width: 100%;
    }

    .board-frame {
        width: 100%;

        padding: 4px;

        border-radius: 9px;
    }

    .moves-section {
        order: 2;

        width: 100%;
        height: 200px;
    }

    .moves-list {
        display: grid;

        grid-template-columns:
            repeat(2, 1fr);

        align-content: start;
    }

    .analysis-panel {
        order: 3;

        width: 100%;

        grid-template-columns: 1fr;
    }

    .navigation-controls {
        grid-template-columns:
            repeat(4, 1fr);
    }

    #moveCounter {
        grid-column: 1 / -1;

        grid-row: 1;
    }

    .navigation-controls button {
        padding: 5px 2px;

        font-size: 10px;
    }
}