/* ── Chessboard ── */
.chess {
    margin: 56px auto 0;
    width: 100%;
    max-width: 980px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.chess-head {
    width: 100%;
    max-width: 480px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    font-size: 10px;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: rgba(0,0,0,.55);
    gap: 10px;
}
.chess-nav {
    display: inline-flex;
    gap: 2px;
    border: 1px solid rgba(0,0,0,.18);
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}
.chess-nav-btn {
    background: transparent;
    border: 0;
    width: 26px;
    height: 26px;
    color: rgba(0,0,0,.65);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    transition: background-color .15s, color .15s;
    padding: 0;
}
.chess-nav-btn + .chess-nav-btn { border-left: 1px solid rgba(0,0,0,.08); }
.chess-nav-btn:hover { background: #000; color: #fff; }
.chess-nav-btn:disabled { opacity: .3; cursor: not-allowed; }
.chess-nav-btn:disabled:hover { background: transparent; color: rgba(0,0,0,.65); }
.chess-stage {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 18px;
    width: 100%;
}
.chess-side {
    flex: 0 0 224px;
    width: 224px;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,.14);
    border-radius: 4px;
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    max-height: 480px;
    min-height: 240px;
    overflow: hidden;
    box-shadow: 0 6px 18px rgba(0,0,0,.07);
}
.chess-side-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 13px 16px 11px;
    background: linear-gradient(180deg, #fafafa 0%, #f4f4f4 100%);
    border-bottom: 1px solid rgba(0,0,0,.1);
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 2.2px;
    text-transform: uppercase;
    color: rgba(0,0,0,.62);
    flex: 0 0 auto;
}
.chess-side-head::before {
    content: "";
    width: 5px;
    height: 5px;
    background: #000;
    border-radius: 50%;
    display: inline-block;
}
.chess-side-count {
    margin-left: auto;
    font-size: 9px;
    letter-spacing: 1.2px;
    color: rgba(0,0,0,.4);
    font-weight: 500;
}
.chess-side-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,.18) transparent;
}
.chess-side-body::-webkit-scrollbar { width: 6px; }
.chess-side-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 3px; }
.chess-side-empty {
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
    font-size: 12px;
    line-height: 1.5;
    color: rgba(0,0,0,.38);
    text-align: center;
    padding: 28px 8px;
}
.chess-side-empty::before {
    content: "♟";
    display: block;
    font-size: 24px;
    font-style: normal;
    color: rgba(0,0,0,.18);
    margin-bottom: 10px;
}

/* Opening panel */
.chess-opening-eco {
    display: inline-block;
    padding: 4px 9px;
    background: #000;
    color: #fff;
    border-radius: 2px;
    font: 700 10px/1 'Montserrat', system-ui, sans-serif;
    letter-spacing: 1.8px;
    margin-bottom: 14px;
}
.chess-opening-name {
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.3;
    color: #000;
    letter-spacing: -0.2px;
    margin-bottom: 14px;
}
.chess-opening-line {
    font: 11px/1.7 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    color: rgba(0,0,0,.6);
    word-break: break-word;
    padding-top: 12px;
    border-top: 1px solid rgba(0,0,0,.08);
}

/* Notation panel — inline PGN flow */
.chess-moves {
    font: 12px/1.75 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    color: rgba(0,0,0,.85);
    word-spacing: 1px;
}
.chess-moves-num {
    color: rgba(0,0,0,.4);
    font-weight: 500;
    font-size: 10px;
    margin: 0 2px 0 4px;
    user-select: none;
}
.chess-moves > .chess-moves-num:first-child { margin-left: 0; }
.chess-moves-ply {
    cursor: pointer;
    background: transparent;
    border: 0;
    font: inherit;
    color: inherit;
    padding: 2px 5px;
    margin: 0 1px;
    border-radius: 3px;
    transition: background-color .12s ease, color .12s ease;
    outline: none;
    vertical-align: baseline;
    position: relative;
}
.chess-moves-ply:hover { background: #ffd54f; color: #000; }
.chess-moves-ply:focus-visible { box-shadow: inset 0 0 0 1px rgba(0,0,0,.5); }
.chess-moves-ply.is-current {
    background: #000;
    color: #fff;
    font-weight: 600;
}
.chess-moves-ply.is-current:hover { background: #000; color: #fff; }

/* Per-ply review quality badge (small dot to the right of the move) */
.chess-moves-ply[data-quality]::after {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: middle;
}
.chess-moves-ply[data-quality="best"]::after      { background: #1abc4b; }
.chess-moves-ply[data-quality="good"]::after      { background: #6cba36; }
.chess-moves-ply[data-quality="inaccuracy"]::after{ background: #f0a52a; }
.chess-moves-ply[data-quality="mistake"]::after   { background: #e67e22; }
.chess-moves-ply[data-quality="blunder"]::after   { background: #c82d2d; }
.chess-moves-ply[data-quality="brilliant"]::after { background: #1abc9c; box-shadow: 0 0 0 2px rgba(26,188,156,.3); }

/* Variation block — indented rail */
.chess-moves-var {
    display: block;
    margin: 6px 0 6px 4px;
    padding: 5px 8px 5px 10px;
    border-left: 2px solid #ffd54f;
    background: rgba(0,0,0,.028);
    border-radius: 0 4px 4px 0;
    color: rgba(0,0,0,.72);
    font-size: 11px;
    line-height: 1.75;
}
.chess-moves-var .chess-moves-var {
    margin-left: 4px;
    border-left-color: rgba(0,0,0,.32);
    background: rgba(0,0,0,.05);
    font-size: 10.5px;
}
.chess-moves-var .chess-moves-var .chess-moves-var {
    border-left-color: rgba(0,0,0,.2);
    background: rgba(0,0,0,.075);
}
.chess-moves-var .chess-moves-ply { padding: 1px 4px; }
.chess-moves-var-paren { display: none; }
.chess-turn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
.chess-turn-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    border: 1.5px solid #000;
    transition: background-color .25s ease;
}
.chess-turn.black .chess-turn-dot { background: #000; }
.chess-reset {
    background: transparent;
    border: 1px solid rgba(0,0,0,.4);
    border-radius: 6px;
    padding: 6px 12px;
    font: 500 10px/1 'Montserrat', system-ui, sans-serif;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    color: rgba(0,0,0,.7);
    cursor: pointer;
    transition: all .2s ease;
}
.chess-reset:hover { background: #000; color: #fff; border-color: #000; }

/* Board + arrow overlay container */
.chess-board-wrap {
    position: relative;
    width: min(480px, calc(100vw - 36px));
    aspect-ratio: 1 / 1;
}
.chess-board {
    position: relative;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 2px solid #000;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 10px 24px rgba(0,0,0,.12);
    user-select: none;
    touch-action: manipulation;
}
.chess-arrows {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 30;
    overflow: visible;
}
.chess-arrows .arrow-best       { fill: #1aa64a; stroke: #1aa64a; opacity: .82; }
.chess-arrows .arrow-pv2        { fill: #5a8dff; stroke: #5a8dff; opacity: .55; }
.chess-arrows .arrow-pv3        { fill: #b46be0; stroke: #b46be0; opacity: .42; }

/* Promotion picker */
.chess-promo-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 40;
    cursor: pointer;
}
.chess-promo-picker {
    position: absolute;
    z-index: 50;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, .25);
    border-radius: 3px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chess-promo-picker button {
    background: #ffffff;
    border: 0;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color .12s ease;
}
.chess-promo-picker button + button { border-top: 1px solid rgba(0, 0, 0, .08); }
.chess-promo-picker button:hover { background: rgba(255, 213, 79, .5); }
.chess-promo-picker img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    pointer-events: none;
    -webkit-user-drag: none;
}
.chess-promo-cancel {
    font: 700 14px/1 'Montserrat', system-ui, sans-serif;
    color: rgba(0,0,0,.55);
    height: 24%;
    background: #f4f4f4 !important;
}
.chess-promo-cancel:hover { background: rgba(200, 45, 45, .15) !important; color: #c82d2d; }
.chess-sq {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: filter .12s ease;
}
.chess-sq.light { background: #f0d9b5; }
.chess-sq.dark  { background: #b58863; }
.chess-sq.last-move::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(255, 213, 79, .28);
    pointer-events: none;
}
.chess-sq.selected { box-shadow: inset 0 0 0 4px rgba(255, 213, 79, .92); }
.chess-sq.move-dot::after {
    content: "";
    position: absolute;
    width: 24%;
    height: 24%;
    border-radius: 50%;
    background: rgba(0,0,0,.28);
    pointer-events: none;
}
.chess-sq.move-capture::after {
    content: "";
    position: absolute;
    inset: 6%;
    border: 3.5px solid rgba(0,0,0,.32);
    border-radius: 50%;
    box-sizing: border-box;
    pointer-events: none;
}
.chess-sq img {
    width: 86%;
    height: 86%;
    object-fit: contain;
    pointer-events: none;
    -webkit-user-drag: none;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,.15));
}
.chess-sq:hover:not(.move-dot):not(.move-capture) { filter: brightness(1.04); }
.chess-status {
    margin-top: 12px;
    min-height: 14px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: rgba(0,0,0,.55);
}
.chess-result {
    display: inline-block;
    padding: 6px 14px;
    background: #000;
    color: #fff;
    border-radius: 3px;
    font: 700 11px/1 'Montserrat', sans-serif;
    letter-spacing: 2px;
}
.chess-result.draw { background: #555; }
.chess-viewing {
    font: italic 12px/1 Georgia, serif;
    color: rgba(0,0,0,.5);
    text-transform: none;
    letter-spacing: 0;
}
.chess-sq.in-check {
    box-shadow: inset 0 0 0 3px rgba(200, 45, 45, .65),
                inset 0 0 18px rgba(200, 45, 45, .45);
}
.chess-sq.in-check::after { display: none; }

/* Opening continuations */
.chess-conts-label {
    font: 700 9px/1 'Montserrat', system-ui, sans-serif;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    color: rgba(0,0,0,.5);
    margin: 14px 0 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(0,0,0,.08);
}
.chess-conts {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.chess-cont {
    display: grid;
    grid-template-columns: 46px 1fr;
    gap: 8px;
    align-items: baseline;
    padding: 5px 6px;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color .12s ease;
    text-align: left;
    border: 0;
    background: transparent;
    width: 100%;
    font-family: inherit;
}
.chess-cont:hover { background: rgba(0,0,0,.05); }
.chess-cont-move {
    font: 600 11px/1.3 'SFMono-Regular', Consolas, monospace;
    color: #000;
}
.chess-cont-name {
    font: italic 11px/1.35 Georgia, 'Times New Roman', serif;
    color: rgba(0,0,0,.62);
    word-break: break-word;
}

/* ── Eval bar (Tier 1) ── */
.chess-evalbar {
    width: 18px;
    flex: 0 0 18px;
    border-radius: 3px;
    overflow: hidden;
    background: #000;
    position: relative;
    box-shadow: 0 6px 18px rgba(0,0,0,.07);
    align-self: stretch;
    display: flex;
    flex-direction: column;
}
.chess-evalbar-white {
    background: #f5f5f5;
    width: 100%;
    height: 50%;
    transition: height .35s cubic-bezier(.4,0,.2,1);
}
.chess-evalbar-num {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font: 600 9px/1 'Montserrat', sans-serif;
    letter-spacing: .3px;
    pointer-events: none;
    user-select: none;
}
.chess-evalbar-num.top    { top: 4px;    color: #fff; }
.chess-evalbar-num.bottom { bottom: 4px; color: #000; }

/* ── Engine controls panel (Tier 1) ── */
.chess-engine {
    margin: 16px auto 0;
    width: 100%;
    max-width: 720px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding: 10px 14px;
    border: 1px solid rgba(0,0,0,.14);
    border-radius: 6px;
    background: #fff;
    font-family: 'Montserrat', sans-serif;
    font-size: 11px;
    letter-spacing: .3px;
}
.chess-engine-toggle {
    background: transparent;
    border: 1px solid rgba(0,0,0,.4);
    border-radius: 6px;
    padding: 7px 14px;
    font: 600 10px/1 'Montserrat', sans-serif;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: rgba(0,0,0,.78);
    cursor: pointer;
    transition: all .18s ease;
}
.chess-engine-toggle:hover { background: #000; color: #fff; border-color: #000; }
.chess-engine-toggle.is-on { background: #1aa64a; color: #fff; border-color: #1aa64a; }
.chess-engine-toggle.is-on:hover { background: #168c3e; border-color: #168c3e; }
.chess-engine-status {
    font: italic 11px/1.2 Georgia, serif;
    color: rgba(0,0,0,.55);
    flex: 1 1 200px;
    min-width: 0;
    word-break: break-word;
}
.chess-engine-status code { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 10px; }
.chess-engine-ctrl {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: rgba(0,0,0,.7);
}
.chess-engine-ctrl label { font-size: 10px; letter-spacing: .8px; text-transform: uppercase; }
.chess-engine-ctrl input[type=range] { width: 90px; }
.chess-engine-ctrl input[type=number] {
    width: 48px;
    padding: 3px 5px;
    border: 1px solid rgba(0,0,0,.2);
    border-radius: 4px;
    font: 500 11px 'SFMono-Regular', Consolas, monospace;
}
.chess-engine-review {
    background: #000;
    color: #fff;
    border: 1px solid #000;
    border-radius: 6px;
    padding: 7px 14px;
    font: 600 10px/1 'Montserrat', sans-serif;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all .18s ease;
}
.chess-engine-review:hover { opacity: .85; }
.chess-engine-review:disabled { opacity: .35; cursor: not-allowed; }

/* PV (principal variation) line under the board */
.chess-pv-list {
    margin: 10px auto 0;
    width: 100%;
    max-width: 720px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.chess-pv {
    display: grid;
    grid-template-columns: 56px 1fr;
    gap: 10px;
    align-items: baseline;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(0,0,0,.025);
    font: 11px/1.5 'SFMono-Regular', Consolas, monospace;
    color: rgba(0,0,0,.82);
}
.chess-pv-eval {
    font-weight: 700;
    color: #000;
}
.chess-pv-eval.bad  { color: #c82d2d; }
.chess-pv-eval.good { color: #1aa64a; }
.chess-pv-moves { word-break: break-word; }

/* Review summary */
.chess-review-summary {
    margin: 12px auto 0;
    width: 100%;
    max-width: 720px;
    padding: 12px 16px;
    border: 1px solid rgba(0,0,0,.14);
    border-radius: 6px;
    background: #fff;
    display: none;
    font: 11px/1.5 'Montserrat', sans-serif;
    color: rgba(0,0,0,.7);
}
.chess-review-summary.show { display: block; }
.chess-review-row {
    display: grid;
    grid-template-columns: 60px repeat(6, 1fr) 72px;
    gap: 8px;
    align-items: center;
    padding: 4px 0;
}
.chess-review-row + .chess-review-row { border-top: 1px dotted rgba(0,0,0,.08); }
.chess-review-row-head {
    font: 700 9px/1 'Montserrat', sans-serif;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(0,0,0,.45);
}
.chess-review-side { font-weight: 600; }
.chess-review-cell { text-align: center; }
.chess-review-cell.brilliant { color: #1abc9c; }
.chess-review-cell.best      { color: #1abc4b; }
.chess-review-cell.good      { color: #6cba36; }
.chess-review-cell.inacc     { color: #f0a52a; }
.chess-review-cell.mistake   { color: #e67e22; }
.chess-review-cell.blunder   { color: #c82d2d; }
.chess-review-acc {
    font-weight: 700;
    font-size: 14px;
    color: #000;
    text-align: right;
}
.chess-review-progress {
    height: 4px;
    margin-top: 8px;
    border-radius: 2px;
    background: rgba(0,0,0,.08);
    overflow: hidden;
}
.chess-review-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #1aa64a, #6cba36);
    width: 0;
    transition: width .25s ease;
}

@media (max-width: 980px) {
    .chess-side { flex: 0 0 188px; width: 188px; }
}
@media (max-width: 860px) {
    .chess-side { flex: 0 0 172px; width: 172px; }
    .chess-stage { gap: 12px; }
}
@media (max-width: 768px) {
    .chess-stage { flex-direction: column; align-items: center; gap: 16px; }
    .chess-side {
        flex: 1 1 auto;
        width: min(480px, calc(100vw - 36px));
        max-height: 220px;
        min-height: 0;
    }
    .chess-board-wrap { order: 1; }
    .chess-evalbar { order: 0; width: 100%; height: 14px; flex-direction: row; max-width: min(480px, calc(100vw - 36px)); }
    .chess-evalbar-white { width: 50%; height: 100%; transition: width .35s cubic-bezier(.4,0,.2,1); }
    .chess-evalbar-num { left: auto; transform: none; }
    .chess-evalbar-num.top    { top: 50%; right: 6px; transform: translateY(-50%); }
    .chess-evalbar-num.bottom { bottom: 50%; left: 6px; transform: translateY(50%); }
    .chess-opening { order: 2; }
    .chess-notation { order: 3; }
}
@media (max-width: 480px) {
    .chess { margin-top: 36px; }
    .chess-board-wrap { width: calc(100vw - 36px); }
}
