/* Arena13 theme for Chess (replaces the original Bootstrap-based screen.css) */
:root {
    --ink: #14171f;
    --ink-2: #1a1e28;
    --ink-3: #262b38;
    --cream: #ebe5ce;
    --dim: rgba(235, 229, 206, .55);
    --line: rgba(235, 229, 206, .16);
    --red: #ff1919;
    --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --pad: 8px;
    --topbar: 40px;
    --player: 24px;
    --controls: 44px;
    --status: 0px;
    /* board edge: fill the width on phones, but leave room for the bars above and below */
    --board: min(calc(100vw - 2 * var(--pad)),
    calc(100vh - var(--topbar) - 2 * var(--player) - var(--controls) - var(--status) - 4 * var(--pad)));
}

@supports (height: 100dvh) {
    :root {
        --board: min(calc(100vw - 2 * var(--pad)),
        calc(100dvh - var(--topbar) - 2 * var(--player) - var(--controls) - var(--status) - 4 * var(--pad)));
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    height: 100%;
    background: var(--ink);
    color: var(--cream);
    font-family: var(--sans);
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

body {
    overflow-x: hidden;
}

button, select {
    font: inherit;
    color: inherit;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.text-muted {
    color: var(--dim);
}

.eyebrow {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--red);
}

/* ---- layout (phone first: one column) ---- */
.app {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--pad);
    padding-top: 0;
}

.topbar {
    width: var(--board);
    min-width: 0;
    height: var(--topbar);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid var(--line);
    margin-bottom: var(--pad);
}

.wordmark {
    font-weight: 800;
    font-size: 18px;
    letter-spacing: .08em;
    line-height: 1;
}

.wordmark::after {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-left: 6px;
    background: var(--red);
    vertical-align: middle;
}

.level {
    display: flex;
    align-items: center;
    gap: 6px;
}

.level select {
    background: var(--ink-3);
    border: 1px solid var(--line);
    border-radius: 0;
    padding: 4px 6px;
    min-width: 54px;
    font-family: var(--mono);
    cursor: pointer;
}

.level select:focus-visible, .btn:focus-visible, .btn-bracket:focus-visible, .choice:focus-visible {
    outline: 2px solid var(--red);
    outline-offset: 1px;
}

#console-container {
    width: var(--board);
}

.chess-console {
    display: flex;
    flex-direction: column;
    gap: var(--pad);
}

.chess-console-board {
    position: relative;
    width: var(--board);
}

.chess-console-board .chessboard {
    width: 100%;
    touch-action: none;
}

.chess-console-board .player {
    height: var(--player);
    line-height: var(--player);
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: .04em;
    color: var(--dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 96px;
}

.chess-console-board .player.to-move {
    color: var(--cream);
}

.chess-console-board .player.to-move::after {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-left: 8px;
    background: var(--red);
    vertical-align: middle;
}

.engine-state {
    position: absolute;
    top: 0;
    right: 0;
    height: var(--player);
    line-height: var(--player);
    font-family: var(--mono);
    font-size: 12px;
    color: var(--dim);
    white-space: nowrap;
}

.engine-state .thinking {
    color: var(--red);
    margin-left: 4px;
}

/* game state (check / game over): sits on the right of the bottom player row, so nothing jumps */
.chess-console-center {
    position: relative;
}

.chess-console-notifications {
    position: absolute;
    right: 0;
    bottom: 0;
    height: var(--player);
    max-width: 60%;
    overflow: hidden;
    pointer-events: none;
}

.gameState {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--red);
    line-height: var(--player);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* "The game is over" is shown in the game-over panel; keep only the reason here */
.gameState b, .gameState br {
    display: none;
}

/* ---- control buttons ---- */
.control-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px;
    height: var(--controls);
    overflow: hidden;
}

.btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: 64px;
    height: var(--controls);
    border: 1px solid var(--line);
    border-radius: 0;
    background: var(--ink-2);
    color: var(--cream);
    cursor: pointer;
    font-size: 15px;
    padding: 0;
    touch-action: manipulation;
}

.btn:hover:not([disabled]) {
    border-color: var(--cream);
}

.btn[disabled] {
    opacity: .35;
    cursor: default;
}

.btn.btn-accent {
    background: var(--red);
    border-color: var(--red);
    color: var(--ink);
}

.btn.btn-active {
    color: var(--red);
}

.btn.autoplay .fa-play, .btn.autoplay .fa-stop {
    color: inherit;
}

/* the board fits on a phone with six buttons: hide jump-to-start/end and autoplay there */
.control-buttons .first, .control-buttons .last, .control-buttons .autoplay {
    display: none;
}

/* ---- captured pieces + move list ---- */
.chess-console-left {
    display: flex;
    flex-direction: column;
    gap: var(--pad);
    padding-bottom: var(--pad);
}

.captured-pieces {
    font-size: 15px;
    min-height: 2.6em;
}

.captured-pieces > div {
    min-height: 1.3em;
}

.fa-figure-white {
    color: var(--cream);
}

.fa-figure-black {
    color: #8b90a0;
}

.history {
    border-top: 1px solid var(--line);
    padding-top: 4px;
    font-family: var(--mono);
    font-size: 13px;
}

.history table {
    width: 100%;
    border-collapse: collapse;
}

.history td {
    padding: 2px 4px;
}

.history .num {
    width: 18%;
    color: var(--dim);
}

.history .ply {
    width: 41%;
}

.history .ply i {
    pointer-events: none;
}

.history .ply.active {
    color: var(--red);
    font-weight: 700;
}

.history.clickable .ply {
    cursor: pointer;
}

/* ---- wide / landscape: board left, panel right ---- */
@media (min-width: 600px) and (min-aspect-ratio: 5/4) {
    :root {
        --side: clamp(200px, 30vw, 300px);
        --board: min(calc(100vw - var(--side) - 3 * var(--pad)),
        calc(100vh - var(--topbar) - 2 * var(--player) - var(--status) - 3 * var(--pad)));
    }

    @supports (height: 100dvh) {
        :root {
            --board: min(calc(100vw - var(--side) - 3 * var(--pad)),
            calc(100dvh - var(--topbar) - 2 * var(--player) - var(--status) - 3 * var(--pad)));
        }
    }

    .topbar {
        width: calc(var(--board) + var(--side) + var(--pad));
    }

    #console-container {
        width: calc(var(--board) + var(--side) + var(--pad));
    }

    .chess-console {
        display: grid;
        grid-template-columns: var(--board) var(--side);
        grid-template-rows: auto 1fr;
        column-gap: var(--pad);
        row-gap: var(--pad);
    }

    .chess-console-center {
        grid-column: 1;
        grid-row: 1 / span 2;
    }

    .chess-console-right {
        grid-column: 2;
        grid-row: 1;
        padding-top: var(--player);
    }

    .chess-console-left {
        grid-column: 2;
        grid-row: 2;
        min-height: 0;
        max-height: calc(var(--board) - var(--controls) - 2 * var(--pad));
        overflow: hidden;
    }

    .chess-console-history {
        min-height: 0;
        flex: 1;
        overflow-y: auto;
    }

    /* row 1: new, undo, resign, flip; row 2: start, back, forward, end, autoplay */
    .control-buttons {
        display: grid;
        grid-template-columns: repeat(20, 1fr);
        height: auto;
        overflow: visible;
    }

    .control-buttons .btn {
        grid-column: span 4;
        max-width: none;
        height: 40px;
        order: 2;
    }

    .control-buttons .startNewGame, .control-buttons .undoMove, .control-buttons .resign {
        grid-column: span 5;
        order: 0;
    }

    .control-buttons .orientation {
        grid-column: span 5;
        order: 1;
    }

    .control-buttons .first, .control-buttons .last, .control-buttons .autoplay {
        display: inline-block;
    }
}

/* ---- the board itself (muted ink / cream squares) ---- */
.cm-chessboard.arena13 .board .square.white {
    fill: #e2dbc2;
}

.cm-chessboard.arena13 .board .square.black {
    fill: #7b8091;
}

.cm-chessboard.arena13.border-type-thin .board .border,
.cm-chessboard.arena13.border-type-none .board .border {
    stroke: #7b8091;
    stroke-width: 0;
    fill: #7b8091;
}

.cm-chessboard.arena13.border-type-frame .board .border {
    fill: var(--ink-2);
    stroke: none;
}

.cm-chessboard.arena13.border-type-frame .board .border-inner {
    fill: #7b8091;
    stroke: var(--line);
}

.cm-chessboard.arena13 .coordinates {
    pointer-events: none;
    user-select: none;
}

.cm-chessboard.arena13 .coordinates .coordinate {
    fill: var(--dim);
    font-size: 7px;
    font-family: var(--mono);
}

.cm-chessboard.arena13 .coordinates .coordinate.black {
    fill: #e2dbc2;
}

.cm-chessboard.arena13 .coordinates .coordinate.white {
    fill: #5a5f6e;
}

.cm-chessboard .markers .marker.marker-frame {
    stroke: var(--red);
    stroke-width: 2px;
    opacity: .75;
}

.cm-chessboard .markers .marker.marker-frame-danger,
.cm-chessboard .markers .marker.marker-circle-danger {
    stroke: var(--red);
    opacity: .9;
}

.cm-chessboard .markers .marker.marker-frame-primary {
    stroke: #19c8ff;
    opacity: .8;
}

.cm-chessboard .markers .marker.marker-dot,
.cm-chessboard .markers .marker.marker-bevel {
    fill: var(--ink);
    opacity: .35;
}

svg.cm-chessboard .promotion-dialog-group .promotion-dialog {
    fill: var(--cream);
    fill-opacity: .92;
    stroke: var(--ink);
}

/* ---- overlay panels (new game / resign / game over) ---- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(20, 23, 31, .78);
}

.overlay[hidden] {
    display: none;
}

.panel {
    position: relative;
    width: min(100%, 340px);
    padding: 20px 18px 18px;
    background: var(--ink-2);
    border: 1px solid var(--line);
    text-align: center;
}

/* corner brackets (HUD frame) */
.hud::before, .hud::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border: 2px solid var(--cream);
    pointer-events: none;
}

.hud::before {
    top: -4px;
    left: -4px;
    border-right: 0;
    border-bottom: 0;
}

.hud::after {
    right: -4px;
    bottom: -4px;
    border-left: 0;
    border-top: 0;
}

.panel h2 {
    margin: 6px 0 4px;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: .02em;
}

.panel p {
    margin: 4px 0 0;
    color: var(--dim);
    font-size: 13px;
}

.panel-choices {
    display: flex;
    gap: 6px;
    margin-top: 14px;
}

.choice {
    flex: 1;
    height: 40px;
    background: var(--ink-3);
    border: 1px solid var(--line);
    cursor: pointer;
    font-family: var(--mono);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.choice.selected {
    border-color: var(--red);
    color: var(--red);
}

.panel-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
}

.btn-bracket {
    flex: 1;
    height: 42px;
    background: transparent;
    border: 1px solid var(--line);
    cursor: pointer;
    font-family: var(--mono);
    font-size: 13px;
    letter-spacing: .08em;
}

.btn-bracket.primary {
    background: var(--red);
    border-color: var(--red);
    color: var(--ink);
    font-weight: 700;
}
