:root {
    --bg: #07111f;
    --bg-deep: #050b14;
    --panel: #13243a;
    --panel-hover: #172b44;
    --border: #26384f;
    --border-soft: rgba(148, 163, 184, 0.18);
    --border-strong: #34506f;
    --text: #f4f7fb;
    --text-soft: #c7d2e1;
    --text-muted: #92a0b4;
    --blue: #2f9cff;
    --blue-dark: #0b5cad;
    --green: #35d07f;
    --red: #ff4d4d;
    --radius-lg: 12px;
    --radius-md: 8px;
    --shadow: 0 14px 34px rgba(0, 0, 0, 0.38);
    --card-bg: linear-gradient(180deg, rgba(17, 31, 49, 0.96), rgba(10, 22, 38, 0.96));
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
    min-height: 100vh;
    overflow: hidden;
    display: grid;
    grid-template: auto 1fr / auto 1fr auto;
    font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 8%, rgba(30, 136, 229, 0.22), transparent 28rem),
        radial-gradient(circle at 85% 18%, rgba(47, 156, 255, 0.11), transparent 24rem),
        linear-gradient(180deg, var(--bg), var(--bg-deep));

    > h1 {
        grid-column: 1 / -1;
        height: 56px;
        margin: 0;
        padding: 0 24px;
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 24px;
        line-height: 1;
        font-weight: 800;
        letter-spacing: 0.02em;
        border-bottom: 1px solid var(--border);
        background: rgba(5, 11, 20, 0.78);
        backdrop-filter: blur(8px);
    }
}

.titleEmphasis {
    color: var(--blue);
    letter-spacing: 0.08em;
}

:is(#teamToken, #inputsContainer, #analysisContainer, #display, .review-header, .turn-controls, .board-panel, .logs-grid, #leaderboard, #p1Logs, #systemLogs, #p2Logs) {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
}

:is(#teamToken, #inputsContainer, #analysisContainer, #display, #leaderboard) {
    box-shadow: var(--shadow);
}

#config {
    grid-column: 1;
    grid-row: 2;
    height: calc(100vh - 56px);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 12px;
    padding: 14px;
}

#display {
    grid-column: 2;
    grid-row: 2;
    overflow: hidden;
    padding: 14px;
    margin: 10px 0;

    display: grid;
    grid-template-rows: auto auto 1fr auto;
    grid-gap: 20px;

    & #analyseNav {
        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
    }

    & #GUI {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    & #logs {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        grid-gap: 20px;

        &>div {
            padding: 10px;
            & h2 {
                text-align: center;
            }
        }
    }
}

:is(#teamToken, #inputsContainer, #analysisContainer) { padding: 16px; }

#analysisContainer {
    min-height: 0;
    display: flex;
    flex-direction: column;
}

h2,
.turn-summary h3,
.leaderboard-title {
    margin: 0 0 14px;
    color: var(--blue);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

#inputsContainer h2 {
    font-size: 17px;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text);

    &::before {
        content: "</> ";
        color: var(--blue);
    }
}

#teamToken h2::before { content: "🔑 "; }
#analysisContainer h2::before { content: "⚔ "; }

p {
    margin: 0 0 12px;
    color: var(--text-soft);
    font-size: 14px;
}

ul {
    margin: 14px 0 0;
    padding-left: 18px;
    color: var(--text-soft);
    font-size: 13px;
    line-height: 1.55;
}

li::marker { color: var(--blue); }

:is(input[type="text"], input[type="file"], button) { font: inherit; }

input[type="text"] {
    width: 100%;
    min-width: 0;
    height: 38px;
    padding: 0 10px;
    color: var(--text);
    background: #0b1626;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;

    &:focus {
        border-color: var(--blue);
        box-shadow: 0 0 0 3px rgba(47, 156, 255, 0.15);
    }
}

input[type="file"] {
    max-width: 100%;
    color: var(--text-muted);
    font-size: 13px;

    &::file-selector-button {
        height: 32px;
        margin-right: 8px;
        padding: 0 12px;
        color: var(--text);
        background: var(--panel);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius-md);
        font-weight: 600;
        cursor: pointer;
    }

    &::file-selector-button:hover {
        background: var(--panel-hover);
        border-color: var(--blue);
    }
}

button {
    height: 36px;
    padding: 0 12px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, transform 80ms ease, opacity 120ms ease;

    &:hover:not(:disabled) {
        background: var(--panel-hover);
        border-color: var(--blue);
    }

    &:active:not(:disabled) { transform: translateY(1px); }

    &:disabled {
        cursor: default;
        color: var(--text-muted);
        background: rgba(19, 36, 58, 0.55);
        border-color: rgba(52, 80, 111, 0.5);
        opacity: 0.9;
    }
}

#inputsContainer, #analysisContainer, #leaderboard, #teamToken>span, #display {
    visibility: hidden;
}

:is(#teamToken, #inputsContainer) p {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: center;

    > button {
        grid-column: 1 / -1;
        width: 100%;
    }
}

#inputsContainer p > button {
    background: linear-gradient(180deg, var(--blue), var(--blue-dark));
    border-color: var(--blue);

    &:hover { filter: brightness(1.07); }
}

:is(#fightList, .log-content) {
    scrollbar-color: #4a5d74 transparent;
    scrollbar-width: thin;
}

#fightList {
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
    display: flex;
    flex-direction: column;
    gap: 7px;

    &::-webkit-scrollbar { width: 8px; }
    &::-webkit-scrollbar-track { background: transparent; }
    &::-webkit-scrollbar-thumb {
        background: #4a5d74;
        border-radius: 999px;
    }
}

.review-layout {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(320px, 1fr) 220px;
    gap: 12px;
}

.review-header {
    padding: 16px 18px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: center;
}

.match-title {
    margin: 0;
    font-size: 25px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.match-meta {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    color: var(--text-muted);
    font-size: 13px;
}

.match-score {
    min-width: 82px;
    height: 52px;
    display: grid;
    place-items: center;
    color: var(--red);
    font-size: 30px;
    font-weight: 800;
    border: 1px solid rgba(255, 77, 77, 0.5);
    border-radius: var(--radius-md);
    background: rgba(255, 77, 77, 0.08);
}

.turn-controls {
    padding: 12px 14px;
    display: grid;
    grid-template-columns: auto auto 120px 1fr auto auto auto auto;
    gap: 10px;
    align-items: center;
}

.turn-label {
    text-align: center;
    font-weight: 800;
    color: var(--text);
}

.turn-slider { accent-color: var(--blue); }

.board-panel {
    position: relative;
    min-height: 0;
    padding: 16px;
    display: grid;
    grid-template-columns: minmax(360px, 620px) 280px;
    gap: 16px;
    align-items: stretch;
}

.board-10x10 {
    aspect-ratio: 1 / 1;
    width: min(100%, 620px);
    align-self: center;
    justify-self: center;
    display: grid;
    grid-template: repeat(10, 1fr) / repeat(10, 1fr);
    overflow: hidden;
    background: #101820;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: 0 0 0 1px rgba(47, 156, 255, 0.15), 0 18px 38px rgba(0, 0, 0, 0.42);
}

.board-cell {
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(255, 255, 255, 0.035);

    &:nth-child(odd) { background: rgba(255, 255, 255, 0.065); }
}

.turn-summary {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(5, 11, 20, 0.35);

    & h3 { margin-bottom: 14px; }

    & p {
        margin: 8px 0;
        font-size: 13px;
    }
}

.logs-grid {
    min-height: 0;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.log-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(5, 11, 20, 0.32);

    & h3 {
        margin: 0;
        padding: 10px 12px;
        border-bottom: 1px solid var(--border-soft);
        font-size: 13px;
        font-weight: 800;
    }

    &.team-a h3 { color: var(--red); }
    &.server h3 { color: var(--text-soft); }
    &.team-b h3 { color: var(--blue); }
}

.log-content {
    min-height: 0;
    overflow: auto;
    padding: 10px 12px;
    color: var(--text-soft);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
}

#leaderboard {
    overflow-y: auto;
    padding-bottom: 8px;
    margin: 0 14px;
    max-height: calc(100vh - 100px);
    align-self: center;

    scrollbar-color: #4a5d74 transparent;
    scrollbar-width: thin;
}

#leaderboard::-webkit-scrollbar {
    width: 8px;
}

#leaderboard::-webkit-scrollbar-track {
    background: transparent;
}

#leaderboard::-webkit-scrollbar-thumb {
    background: #4a5d74;
    border-radius: 999px;
}

.leaderboard-title {
    margin: 0;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.leaderboard-header {
    font-weight: 800;
    color: var(--text-muted);
}

.leaderboard-row {
    display: grid;
    grid-template-columns: auto auto auto;
    gap: 15px;
    align-items: center;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-soft);
    font-size: 13px;


    &.current-team {
        background: rgba(47, 156, 255, 0.12);
        color: var(--blue);
    }

    &:hover {
        background: var(--panel-hover);
    }

    &>div:nth-child(1) {
        text-align: left;
    }

    &>div:nth-child(2) {
        text-align: center;
    }

    &>div:nth-child(3) {
        text-align: right;
    }
}

.elo-up,
.elo-down { font-weight: 800; }
.elo-up { color: var(--green); }
.elo-down { color: var(--red); }

@media (max-width: 1100px) {
    body {
        overflow: auto;
        grid-template: 56px auto auto / 1fr;

        > h1 { grid-column: 1; }
    }

    #config {
        grid-column: 1;
        grid-row: 2;
        height: auto;
        max-height: none;
        grid-template: auto 420px / 1fr 1fr;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    #analysisContainer { grid-column: 1 / -1; }

    #display {
        grid-column: 1;
        grid-row: 3;
        height: 720px;
    }

    .board-panel,
    .logs-grid { grid-template-columns: 1fr; }
}
