/* =========================================================
   CROSSYRAY • RAYFISH
========================================================= */

:root {

    --bg: #070b12;

    --panel: #0f1724;

    --panel-light: #121d2c;

    --border: #263246;

    --border-strong: #34435a;

    --text: #edf4ff;

    --muted: #8ea0b8;

    --human: #52c7ff;

    --bot: #b69cff;

    --current: #ffd66b;

    --legal: #63e69a;

    --danger: #ff6877;

    --cell-size: 36px;

    --cell-gap: 2px;

    --board-padding: 7px;

}


/* =========================================================
   RESET
========================================================= */

* {
    box-sizing: border-box;
}


html,
body {

    margin: 0;

    min-height: 100%;

}


body {

    min-height: 100vh;

    color: var(--text);

    background:

        radial-gradient(
            circle at 50% 25%,
            #13233a 0,
            #080d15 55%,
            #05080d 100%
        );

    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        sans-serif;

}


button,
select {
    font: inherit;
}


.hidden {
    display: none !important;
}


/* =========================================================
   HEADER
========================================================= */

.topbar {

    position: sticky;

    top: 0;

    z-index: 100;

    display: grid;

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

    align-items: center;

    min-height: 64px;

    padding: 0 20px;

    background:
        rgba(
            7,
            11,
            18,
            0.92
        );

    border-bottom:
        1px solid
        var(--border);

    backdrop-filter:
        blur(14px);

}


.back-link {

    justify-self: start;

    color: var(--muted);

    font-weight: 850;

    text-decoration: none;

}


.back-link:hover {
    color: var(--text);
}


.engine-title {

    display: flex;

    flex-direction: column;

    align-items: center;

}


.engine-title span {

    color: var(--muted);

    font-size: 9px;

    font-weight: 950;

    letter-spacing: 0.15em;

}


.engine-title strong {
    font-size: 15px;
}


.engine-status {

    justify-self: end;

    display: flex;

    align-items: center;

    gap: 8px;

    color: var(--muted);

    font-size: 12px;

}


.status-dot {

    width: 8px;

    height: 8px;

    border-radius: 50%;

    background: var(--legal);

    box-shadow:
        0 0 14px
        rgba(
            99,
            230,
            154,
            0.55
        );

}


/* =========================================================
   LAYOUT
========================================================= */

.game-layout {

    display: grid;

    grid-template-columns:
        220px
        minmax(620px, 1fr)
        270px;

    align-items: start;

    gap: 18px;

    width:
        min(
            1420px,
            100%
        );

    margin: 0 auto;

    padding: 22px;

}


.left-column,
.right-column {

    display: flex;

    flex-direction: column;

    gap: 14px;

}


.panel {

    padding: 16px;

    background:
        rgba(
            14,
            23,
            36,
            0.9
        );

    border:
        1px solid
        var(--border);

    border-radius: 16px;

    box-shadow:
        0 18px 45px
        rgba(
            0,
            0,
            0,
            0.25
        );

}


.eyebrow {

    color: var(--muted);

    font-size: 9px;

    font-weight: 950;

    letter-spacing: 0.15em;

}


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

.player-card {

    display: flex;

    flex-direction: column;

    align-items: center;

    text-align: center;

}


.avatar {

    display: grid;

    place-items: center;

    width: 54px;

    height: 54px;

    margin: 12px 0 9px;

    color: #071019;

    border-radius: 16px;

    font-size: 20px;

    font-weight: 1000;

}


.human-avatar {
    background: var(--human);
}


.muted {

    margin-top: 4px;

    color: var(--muted);

    font-size: 11px;

    line-height: 1.45;

}


/* =========================================================
   CONTROLS
========================================================= */

#difficulty {

    width: 100%;

    margin-top: 10px;

    padding: 10px;

    color: var(--text);

    background: #111c2b;

    border:
        1px solid
        var(--border);

    border-radius: 10px;

}


.primary-button {

    width: 100%;

    margin-top: 9px;

    padding: 11px;

    color: #06111b;

    background: var(--human);

    border: 0;

    border-radius: 10px;

    font-weight: 950;

    cursor: pointer;

}


.primary-button:hover {
    filter: brightness(1.08);
}


.secondary-button {

    display: block;

    width: 100%;

    margin-top: 8px;

    padding: 10px;

    color: var(--muted);

    border:
        1px solid
        var(--border);

    border-radius: 10px;

    text-align: center;

    text-decoration: none;

}


.rules-mini {

    margin-top: 14px;

    color: var(--muted);

    font-size: 11px;

    line-height: 1.5;

}


.rules-mini strong {
    color: var(--text);
}


/* =========================================================
   BOARD
========================================================= */

.board-panel {

    min-width: 0;

    text-align: center;

    overflow-x: auto;

    overflow-y: visible;

    scrollbar-width: thin;

    -webkit-overflow-scrolling: touch;

}


.position-header {
    min-height: 47px;
}


.position-header strong {

    display: block;

    font-size: 16px;

}


.position-header span {

    display: block;

    margin-top: 4px;

    color: var(--muted);

    font-size: 11px;

}


/* =========================================================
   LEGEND
========================================================= */

.goal-legend {

    display: flex;

    justify-content: center;

    gap: 18px;

    margin-top: 8px;

    color: var(--muted);

    font-size: 10px;

}


.goal-legend span {

    display: flex;

    align-items: center;

    gap: 6px;

}


.goal-dot {

    display: inline-block;

    width: 9px;

    height: 9px;

    border-radius: 3px;

}


.human-dot {

    background: var(--human);

    box-shadow:
        0 0 8px
        rgba(
            82,
            199,
            255,
            0.5
        );

}


.bot-dot {

    background: var(--bot);

    box-shadow:
        0 0 8px
        rgba(
            182,
            156,
            255,
            0.5
        );

}


/* =========================================================
   BOARD STAGE
========================================================= */

.board-stage {

    position: relative;

    width: max-content;

    max-width: none;

    margin:
        12px auto 0;

    /*
     * Gôn nằm thật sự ngoài board.
     * Chừa đủ chỗ đúng một cell ở mỗi cạnh.
     */

    padding:
        calc(
            var(--cell-size)
            + 18px
        );

    overflow: visible;

}


/* =========================================================
   BOARD GRID
========================================================= */

.board {

    display: grid;

    gap: var(--cell-gap);

    width: max-content;

    padding: var(--board-padding);

    background: #05080d;

    border:
        1px solid
        var(--border-strong);

    border-radius: 12px;

    box-shadow:
        0 25px 70px
        rgba(
            0,
            0,
            0,
            0.45
        );

}


/* =========================================================
   CELLS
========================================================= */

.cell {

    position: relative;

    display: grid;

    place-items: center;

    width: var(--cell-size);

    height: var(--cell-size);

    padding: 0;

    color: var(--text);

    background: #141d29;

    border:
        1px solid
        #2b3749;

    border-radius: 5px;

    font-size: 11px;

    font-weight: 900;

    cursor: default;

    transition:
        transform 120ms ease,
        background 120ms ease,
        border-color 120ms ease,
        box-shadow 120ms ease;

}


.cell:disabled {
    opacity: 1;
}


.cell.human-number {
    color: var(--human);
}


.cell.bot-number {
    color: var(--bot);
}


.cell.neutral-number {
    color: var(--current);
}


.cell.current {

    z-index: 3;

    color: #251b00;

    background: var(--current);

    border-color: #e7ae24;

    box-shadow:
        0 0 12px
        rgba(
            255,
            214,
            107,
            0.22
        );

}


.cell.legal {

    color: #dffff0;

    background: #193928;

    border-color: var(--legal);

    cursor: pointer;

    box-shadow:
        inset
        0 0 0 1px
        rgba(
            99,
            230,
            154,
            0.25
        );

}


.cell.legal:hover {

    z-index: 5;

    transform: scale(1.08);

}


/* =========================================================
   MOVE BADGES
========================================================= */

.move-badge {

    position: absolute;

    top: -11px;

    right: -9px;

    z-index: 7;

    display: grid;

    place-items: center;

    min-width: 23px;

    height: 23px;

    padding: 0 4px;

    color: #111;

    background: #f4f7fb;

    border:
        2px solid
        #0a0f17;

    border-radius: 999px;

    font-size: 9px;

    font-weight: 1000;

}


.move-badge.brilliant {
    background: #5ee0d4;
}


.move-badge.great {
    background: #82d7ff;
}


.move-badge.best {
    background: #8ce6a8;
}


.move-badge.good {
    background: #d9e6f5;
}


.move-badge.inaccuracy {
    background: #ffd76a;
}


.move-badge.mistake {
    background: #ff9b62;
}


.move-badge.blunder {

    color: white;

    background: #ff6877;

}


.move-badge.book {
    background: #bca7ff;
}


.move-badge.forced {
    background: white;
}


/* =========================================================
   EXTERNAL GOALS
========================================================= */

.external-goal {

    position: absolute;

    z-index: 8;

    display: flex;

    gap: var(--cell-gap);

    pointer-events: auto;

}


.goal-left,
.goal-right {
    flex-direction: column;
}


.external-goal button {

    width: var(--cell-size);

    height: var(--cell-size);

    flex: 0 0 auto;

    padding: 0;

    border-radius: 5px;

    cursor: default;

    opacity: 1;

    transition:
        transform 120ms ease,
        filter 120ms ease,
        background 120ms ease,
        border-color 120ms ease,
        box-shadow 120ms ease;

}


/*
 * PLAYER A goal
 */

.human-goal {
    color: var(--human);
}


.human-goal button {

    color: var(--human);

    background:
        rgba(
            82,
            199,
            255,
            0.22
        );

    border:
        2px solid
        rgba(
            82,
            199,
            255,
            0.95
        );

    box-shadow:
        inset
        0 0 12px
        rgba(
            82,
            199,
            255,
            0.11
        );

}


/*
 * RAYFISH goal
 */

.bot-goal {
    color: var(--bot);
}


.bot-goal button {

    color: var(--bot);

    background:
        rgba(
            182,
            156,
            255,
            0.22
        );

    border:
        2px solid
        rgba(
            182,
            156,
            255,
            0.95
        );

    box-shadow:
        inset
        0 0 12px
        rgba(
            182,
            156,
            255,
            0.12
        );

}


.external-goal button:disabled {
    opacity: 1;
}


/*
 * reachable goal:
 * vẫn giữ màu gôn nhưng thêm viền xanh.
 */

.external-goal button.legal {

    background:
        rgba(
            99,
            230,
            154,
            0.25
        );

    border-color: var(--legal);

    box-shadow:
        0 0 16px
        rgba(
            99,
            230,
            154,
            0.52
        );

    cursor: pointer;

}


.external-goal button.legal:hover {

    transform: scale(1.09);

    filter: brightness(1.12);

}


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

.game-info {

    display: grid;

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

    gap: 8px;

    margin-top: 12px;

}


.game-info div {

    padding: 8px;

    background:
        rgba(
            255,
            255,
            255,
            0.025
        );

    border:
        1px solid
        var(--border);

    border-radius: 9px;

}


.game-info span {

    display: block;

    color: var(--muted);

    font-size: 9px;

}


/* =========================================================
   ENGINE
========================================================= */

.analysis-row {

    display: flex;

    justify-content: space-between;

    gap: 10px;

    padding: 7px 0;

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

}


.analysis-row span {
    color: var(--muted);
}


.pv-title {

    margin-top: 12px;

    color: var(--muted);

    font-size: 9px;

    letter-spacing: 0.1em;

}


#principalVariation {

    display: block;

    margin-top: 7px;

    color: #c7d3e4;

    font-size: 11px;

    line-height: 1.5;

    white-space: normal;

}


/* =========================================================
   REVIEWS
========================================================= */

.move-review {

    max-height: 310px;

    margin-top: 7px;

    overflow: auto;

}


.review-item {

    display: grid;

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

    gap: 7px;

    padding: 8px 0;

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

    font-size: 11px;

}


.review-item small {
    color: var(--muted);
}


.review-grid {

    display: grid;

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

    gap: 7px;

    margin-top: 10px;

}


.review-grid div {

    padding: 8px;

    border:
        1px solid
        var(--border);

    border-radius: 8px;

    text-align: center;

}


/* =========================================================
   RESULT
========================================================= */

.result-overlay {

    position: fixed;

    inset: 0;

    z-index: 200;

    display: grid;

    place-items: center;

    padding: 20px;

    background:
        rgba(
            2,
            5,
            9,
            0.87
        );

    backdrop-filter:
        blur(12px);

}


.result-modal {

    width:
        min(
            420px,
            100%
        );

    padding: 30px;

    background: #101a28;

    border:
        1px solid
        var(--border-strong);

    border-radius: 20px;

    text-align: center;

}


.result-icon {
    font-size: 40px;
}


.result-modal h1 {
    margin: 8px 0;
}


.result-modal p {
    color: var(--muted);
}



/* =========================================================
   MOBILE GOAL ALIGNMENT FIX
========================================================= */

@media (max-width: 760px) {

    .board-panel {

        width: 100%;

        overflow-x: auto;

        overflow-y: visible;

        overscroll-behavior-x: contain;

        -webkit-overflow-scrolling: touch;

    }


    .board-stage {

        min-width: max-content;

    }


    .external-goal {

        flex-shrink: 0;

    }

}


/* =========================================================
   RESPONSIVE
========================================================= */

@media (max-width: 1080px) {

    .game-layout {
        grid-template-columns: 1fr;
    }

    .left-column {
        display: none;
    }

    .right-column {

        display: grid;

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

    }

}


@media (max-width: 760px) {

    :root {
        --cell-size: 30px;
    }

    .game-layout {
        padding: 10px;
    }

    .right-column {
        grid-template-columns: 1fr;
    }

    .board-stage {

        width: max-content;

        max-width: none;

        padding:
            calc(
                var(--cell-size)
                + 14px
            );

        overflow: visible;

    }

}


@media (max-width: 470px) {

    :root {

        --cell-size: 27px;

        --cell-gap: 1px;

    }

    .topbar {
        padding: 0 10px;
    }

    .engine-title span {
        display: none;
    }

}
