.chess-trainer-page {
    --trainer-bg: #f6f7f9;
    --trainer-card: #ffffff;
    --trainer-ink: #1f252d;
    --trainer-muted: #687382;
    --trainer-accent: #244b76;
    --trainer-accent-hover: #183957;
    --trainer-border: #dfe3e8;
    --trainer-light-square: #f0d9b5;
    --trainer-dark-square: #b58863;
    --trainer-good: #167645;
    --trainer-bad: #aa2e2e;
}

.chess-trainer-page .trainer-wrap {
    padding: clamp(56px, 7vw, 88px) 16px 68px;
    background: var(--trainer-bg);
}

.chess-trainer-page .trainer-app {
    width: min(1240px, 100%);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 820px) minmax(320px, 390px);
    gap: 30px;
    align-items: start;
}

.chess-trainer-page .chessboard {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(8, minmax(0, 1fr));
    overflow: hidden;
    border-radius: 16px;
    box-shadow: 0 18px 45px rgba(22, 32, 44, 0.14);
    touch-action: pan-y;
    user-select: none;
    isolation: isolate;
}

.chess-trainer-page .square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chess-trainer-page .square.light {
    background: var(--trainer-light-square);
}

.chess-trainer-page .square.dark {
    background: var(--trainer-dark-square);
}

.chess-trainer-page .square.last::after,
.chess-trainer-page .square.selected::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.chess-trainer-page .square.last::after {
    z-index: 1;
    background: rgba(218, 222, 69, 0.48);
}

.chess-trainer-page .square.selected::after {
    z-index: 2;
    inset: 4px;
    border: 3px solid rgba(31, 93, 177, 0.9);
    border-radius: 8px;
    background: rgba(107, 165, 239, 0.22);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32);
}

.chess-trainer-page .square.computer-pulse::after {
    animation: computerMovePulse 0.85s ease-out;
}

.chess-trainer-page .square.target::before {
    content: "";
    position: absolute;
    z-index: 3;
    width: 22%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: rgba(25, 91, 48, 0.65);
    box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.14);
    pointer-events: none;
    animation: targetAppear 0.15s ease-out;
}

.chess-trainer-page .square.capture::before {
    content: "";
    position: absolute;
    inset: 7px;
    z-index: 3;
    border: 5px solid rgba(25, 91, 48, 0.72);
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
    pointer-events: none;
    animation: targetAppear 0.15s ease-out;
}

.chess-trainer-page .piece {
    position: relative;
    z-index: 4;
    width: 88%;
    height: 88%;
    object-fit: contain;
    cursor: grab;
    -webkit-user-drag: none;
    filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.18));
    transition:
        transform 0.12s ease,
        filter 0.12s ease,
        opacity 0.1s ease;
    touch-action: pan-y;
}

.chess-trainer-page .piece:hover {
    transform: translateY(-2px);
    filter: drop-shadow(0 5px 3px rgba(0, 0, 0, 0.22));
}

.chess-trainer-page .piece:active {
    cursor: grabbing;
    transform: scale(1.04);
}

.chess-trainer-page .piece.piece-arriving {
    opacity: 0;
}

.chess-trainer-page .floating-piece {
    position: absolute;
    z-index: 20;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(0 7px 5px rgba(0, 0, 0, 0.28));
    transition: transform 190ms cubic-bezier(0.22, 0.78, 0.25, 1);
    will-change: transform;
}

.chess-trainer-page .coord {
    position: absolute;
    z-index: 5;
    font-size: 0.72rem;
    font-weight: 700;
    pointer-events: none;
}

.chess-trainer-page .coord.file {
    right: 5px;
    bottom: 2px;
}

.chess-trainer-page .coord.rank {
    left: 5px;
    top: 2px;
}

.chess-trainer-page .square.light .coord {
    color: #8a6549;
}

.chess-trainer-page .square.dark .coord {
    color: #f2dcc0;
}

.chess-trainer-page .panel {
    position: sticky;
    top: 18px;
    max-height: calc(100vh - 36px);
    overflow-y: auto;
    padding: 26px;
    color: var(--trainer-ink);
    background: var(--trainer-card);
    border: 1px solid var(--trainer-border);
    border-radius: 16px;
    box-shadow: 0 18px 45px rgba(22, 32, 44, 0.12);
}

.chess-trainer-page .panel h2 {
    margin: 3px 0 22px;
    color: var(--trainer-ink);
}

.chess-trainer-page .label {
    display: block;
    color: var(--trainer-muted);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chess-trainer-page .side-label {
    margin-top: 18px;
}

.chess-trainer-page .panel select {
    width: 100%;
    margin-top: 7px;
    padding: 12px;
    color: var(--trainer-ink);
    background: #ffffff;
    border: 1px solid var(--trainer-border);
    border-radius: 9px;
    font: inherit;
}

.chess-trainer-page .segments,
.chess-trainer-page .buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}

.chess-trainer-page .segments {
    margin-top: 7px;
}

.chess-trainer-page .segments button,
.chess-trainer-page .buttons button {
    padding: 11px;
    color: var(--trainer-ink);
    background: #f4f6f8;
    border: 1px solid var(--trainer-border);
    border-radius: 9px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        transform 0.2s ease;
}

.chess-trainer-page .segments button:hover,
.chess-trainer-page .buttons button:hover {
    background: #e8edf2;
    transform: translateY(-1px);
}

.chess-trainer-page .segments button.active,
.chess-trainer-page .buttons .primary {
    color: #ffffff;
    background: var(--trainer-accent);
    border-color: var(--trainer-accent);
}

.chess-trainer-page .segments button.active:hover,
.chess-trainer-page .buttons .primary:hover {
    background: var(--trainer-accent-hover);
    border-color: var(--trainer-accent-hover);
}

.chess-trainer-page .buttons {
    margin: 22px 0;
}

.chess-trainer-page .buttons .primary,
.chess-trainer-page .buttons .full {
    grid-column: 1 / -1;
}

.chess-trainer-page .stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.chess-trainer-page .stats div {
    padding: 12px 6px;
    text-align: center;
    background: #fafbfc;
    border: 1px solid var(--trainer-border);
    border-radius: 9px;
}

.chess-trainer-page .stats span,
.chess-trainer-page .stats strong {
    display: block;
}

.chess-trainer-page .stats span {
    color: var(--trainer-muted);
    font-size: 0.74rem;
}

.chess-trainer-page .stats strong {
    color: var(--trainer-ink);
    font-size: 1.25rem;
}

.chess-trainer-page .feedback {
    min-height: 72px;
    margin-top: 16px;
    padding: 14px;
    color: var(--trainer-ink);
    background: #f2f5f8;
    border-radius: 9px;
}

.chess-trainer-page .feedback.success {
    color: var(--trainer-good);
    background: #e8f6ee;
}

.chess-trainer-page .feedback.error {
    color: var(--trainer-bad);
    background: #fbeaea;
}

.chess-trainer-page .feedback.hint {
    color: var(--trainer-accent);
    background: #eaf2fb;
}

.chess-trainer-page .mobile-feedback {
    display: none;
}

.chess-trainer-page .reset-link {
    margin-top: 12px;
    padding: 0;
    color: var(--trainer-accent);
    background: transparent;
    border: 0;
    font: inherit;
    cursor: pointer;
}

.chess-trainer-page .reset-link:hover {
    color: var(--trainer-accent-hover);
    text-decoration: underline;
}

.chess-trainer-page .info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    padding-top: 0;
    padding-bottom: 76px;
    background: var(--trainer-bg);
}

.chess-trainer-page .info article {
    padding: 24px;
    background: #ffffff;
    border: 1px solid var(--trainer-border);
    border-radius: 14px;
}

.chess-trainer-page .info h2 {
    margin-top: 0;
    color: var(--trainer-ink);
    line-height: 1.25;
}

.chess-trainer-page .info p {
    margin-bottom: 0;
    color: var(--trainer-muted);
}

.chess-trainer-page .move-history {
    margin-top: 18px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid var(--trainer-border);
    border-radius: 9px;
}

.chess-trainer-page .move-history-header {
    padding: 10px 13px;
    color: var(--trainer-muted);
    background: #f4f6f8;
    border-bottom: 1px solid var(--trainer-border);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chess-trainer-page .move-history-list {
    max-height: 180px;
    overflow-y: auto;
    padding: 8px 0;
}

.chess-trainer-page .move-history-empty {
    margin: 0;
    padding: 10px 13px;
    color: var(--trainer-muted);
    font-size: 0.9rem;
}

.chess-trainer-page .move-row {
    display: grid;
    grid-template-columns: 36px 1fr 1fr;
    gap: 12px;
    align-items: center;
    padding: 7px 13px;
    font-size: 0.95rem;
}

.chess-trainer-page .move-row:nth-child(even) {
    background: #f8f9fb;
}

.chess-trainer-page .move-number {
    color: var(--trainer-muted);
    font-weight: 700;
}

.chess-trainer-page .move-white,
.chess-trainer-page .move-black {
    min-width: 0;
    font-family: "Courier New", Courier, monospace;
    font-weight: 700;
    white-space: nowrap;
}


@keyframes computerMovePulse {
    0% {
        box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0);
    }

    35% {
        box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.65);
    }

    100% {
        box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0);
    }
}

.chess-trainer-page .feedback.completion-message {
    position: relative;
    overflow: hidden;
    padding: 18px 48px 18px 18px;
    border: 1px solid rgba(22, 118, 69, 0.25);
    box-shadow: 0 8px 24px rgba(22, 118, 69, 0.12);
    font-weight: 700;
    animation: completionMessageIn 0.35s ease-out;
}

.chess-trainer-page .feedback.completion-message::after {
    content: "♛";
    position: absolute;
    right: 16px;
    top: 50%;
    color: var(--trainer-good);
    font-size: 1.8rem;
    transform: translateY(-50%);
}

.chess-trainer-page .chessboard.is-complete {
    box-shadow:
        0 18px 45px rgba(22, 32, 44, 0.14),
        0 0 0 5px rgba(22, 118, 69, 0.2);
    animation: completedBoardGlow 0.8s ease-out;
}

@keyframes completionMessageIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes completedBoardGlow {
    0% {
        box-shadow:
            0 18px 45px rgba(22, 32, 44, 0.14),
            0 0 0 0 rgba(22, 118, 69, 0);
    }

    45% {
        box-shadow:
            0 18px 45px rgba(22, 32, 44, 0.14),
            0 0 0 9px rgba(22, 118, 69, 0.3);
    }

    100% {
        box-shadow:
            0 18px 45px rgba(22, 32, 44, 0.14),
            0 0 0 5px rgba(22, 118, 69, 0.2);
    }
}

@keyframes targetAppear {
    from {
        opacity: 0;
        transform: scale(0.55);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes completionFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes completionCardIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.92);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes confettiBurst {
    from {
        opacity: 1;
        transform:
            translate(-50%, -50%)
            rotate(var(--angle))
            translateY(-25px)
            scale(1);
    }

    to {
        opacity: 0;
        transform:
            translate(-50%, -50%)
            rotate(var(--angle))
            translateY(calc(var(--distance) * -1))
            rotate(280deg)
            scale(0.7);
    }
}

@media (prefers-reduced-motion: reduce) {
    .chess-trainer-page .piece,
    .chess-trainer-page .floating-piece,
    .chess-trainer-page .square.target::before,
    .chess-trainer-page .square.capture::before,
    .chess-trainer-page .square.computer-pulse::after,
}

.chess-trainer-page .mobile-move-history {
    display: none;
    margin-top: 16px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid var(--trainer-border);
    border-radius: 9px;
}

.chess-trainer-page .strategy-explanation {
    margin-top: 18px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid var(--trainer-border);
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(22, 32, 44, 0.08);
    animation: strategyExplanationIn 0.35s ease-out;
}

.chess-trainer-page .strategy-explanation[hidden] {
    display: none;
}

.chess-trainer-page .strategy-explanation-header {
    padding: 10px 13px;
    color: #ffffff;
    background: var(--trainer-accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chess-trainer-page .strategy-explanation-body {
    padding: 16px;
}

.chess-trainer-page .strategy-explanation h3 {
    margin: 0 0 8px;
    color: var(--trainer-ink);
    font-size: 1.15rem;
}

.chess-trainer-page .strategy-explanation p {
    margin: 0 0 12px;
    color: var(--trainer-muted);
    line-height: 1.55;
}

.chess-trainer-page .strategy-explanation ul {
    margin: 0;
    padding-left: 20px;
}

.chess-trainer-page .strategy-explanation li + li {
    margin-top: 6px;
}

@keyframes strategyExplanationIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chess-trainer-page .trainer-app > div > .strategy-explanation {
    display: none;
}

.chess-trainer-page .mobile-board-actions {
    display: none;
}

.chess-trainer-page .chess-seo-section {
    padding: 20px 0 90px;
    background: var(--trainer-bg);
}

.chess-trainer-page .chess-seo-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 38px;
    background: #ffffff;
    border: 1px solid var(--trainer-border);
    border-radius: 16px;
    box-shadow: 0 14px 35px rgba(22, 32, 44, 0.08);
}

.chess-trainer-page .chess-seo-content h2 {
    margin: 0 0 18px;
    color: var(--trainer-ink);
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    line-height: 1.2;
}

.chess-trainer-page .chess-seo-content h3 {
    margin: 30px 0 12px;
    color: var(--trainer-ink);
    font-size: 1.3rem;
}

.chess-trainer-page .chess-seo-content p {
    color: var(--trainer-muted);
    line-height: 1.75;
}

.chess-trainer-page .chess-opening-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 28px;
    margin: 18px 0 0;
    padding-left: 22px;
    color: var(--trainer-ink);
}

.chess-trainer-page .chess-seo-links {
    display: flex;
    align-items: center;
    gap: 22px;
    margin-top: 32px;
    flex-wrap: wrap;
}

.chess-trainer-page .chess-resource-link {
    color: var(--trainer-accent);
    font-weight: 600;
    text-decoration: none;
}

.chess-trainer-page .chess-resource-link:hover {
    color: var(--trainer-accent-hover);
    text-decoration: underline;
}

@media (max-width: 640px) {
    .chess-trainer-page .chess-seo-section {
        padding: 10px 8px 60px;
    }

    .chess-trainer-page .chess-seo-content {
        padding: 24px 20px;
    }

    .chess-trainer-page .chess-opening-list {
        grid-template-columns: 1fr;
    }

    .chess-trainer-page .chess-seo-links {
        align-items: flex-start;
        flex-direction: column;
    }
}


@media (max-width: 1100px) {
    .chess-trainer-page .trainer-app {
        grid-template-columns: minmax(0, 1fr) minmax(300px, 350px);
    }
}

@media (max-width: 980px) {
	.chess-trainer-page .mobile-board-actions {
	    display: grid;
	    grid-template-columns: 1fr 1fr;
	    gap: 10px;
	    margin-top: 14px;
	}

	.chess-trainer-page .mobile-board-actions button {
	    width: 100%;
	    padding: 12px;
	    color: var(--trainer-ink);
	    background: #f4f6f8;
	    border: 1px solid var(--trainer-border);
	    border-radius: 9px;
	    font: inherit;
	    font-weight: 700;
	    cursor: pointer;
	}

	.chess-trainer-page .mobile-board-actions button:active {
	    background: #e8edf2;
	    transform: translateY(1px);
	}

	.chess-trainer-page #hintButton,
	.chess-trainer-page #undoButton {
	    display: none;
	}
	.chess-trainer-page .trainer-app > div > .strategy-explanation {
        display: block;
    }

    .chess-trainer-page .trainer-app > div > .strategy-explanation[hidden] {
        display: none;
    }
	.chess-trainer-page .mobile-move-history {
    display: block;
	}

	.chess-trainer-page .panel .move-history {
	    display: none;
	}
    .chess-trainer-page .trainer-app {
        grid-template-columns: 1fr;
        max-width: 820px;
    }

    .chess-trainer-page .panel {
        position: static;
        max-height: none;
        overflow-y: visible;
    }

    .chess-trainer-page .mobile-feedback {
        display: block;
    }

    .chess-trainer-page .panel .feedback {
        display: none;
    }

    .chess-trainer-page .info {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .chess-trainer-page .trainer-wrap {
        padding: 44px 8px 50px;
    }

    .chess-trainer-page .panel {
        padding: 20px;
    }

    .chess-trainer-page .stats {
        grid-template-columns: 1fr;
    }
}
