* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #202124;
    color: #e8eaed;
    font-family: Arial, sans-serif;
}

main {
    max-width: 680px;
    margin: 30px auto;
    padding: 0 15px;
}

h1 {
    font-size: 26px;
}

h2 {
    font-size: 19px;
}

#board {
    width: 100%;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 4px solid #111;
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
}

.light {
    background: #eeeed2;
}

.dark {
    background: #769656;
}

.piece {
    width: 84%;
    height: 84%;
    pointer-events: none;
    user-select: none;
}

.square {
    cursor: pointer;
}

.square.selected {
    box-shadow: inset 0 0 0 5px #ffd700;
}

@keyframes square-blink {
    0%, 100% { opacity: 1; }
    25%, 75% { opacity: 0.25; }
    50% { opacity: 1; }
}

.square.blink .piece {
    animation: square-blink 0.7s ease-in-out;
}

.result-indicator {
    display: inline-flex;
    width: 32px;
    height: 32px;
    margin-left: 14px;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: white;
    font-weight: bold;
}

.result-indicator.success {
    background: #348a46;
}

.result-indicator.failure {
    background: #b93c3c;
}


/* Learning progress indicators */
#exercise-progress {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 5px;
    margin: 18px 0;
}

.progress-square {
    min-width: 0;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 4px;
    background: #62656b;
    color: white;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
}

.progress-square.success {
    background: #348a46;
}

.progress-square.failure {
    background: #b93c3c;
}

.progress-square.active {
    border-color: #f2ca57;
    box-shadow: 0 0 0 1px #f2ca57;
}

.progress-square:hover {
    filter: brightness(1.2);
}

@media (max-width: 480px) {
    #exercise-progress {
        gap: 3px;
    }

    .progress-square {
        font-size: 11px;
    }
}

/* Chess King-style lesson progress: one row of thin rectangles */
#exercise-progress {
    display: grid;
    grid-template-columns: repeat(36, minmax(0, 1fr));
    gap: 3px;
    width: 100%;
    margin: 14px 0;
}

.progress-square {
    width: 100%;
    height: 12px;
    min-width: 0;
    aspect-ratio: auto;
    padding: 0;
    border: none;
    border-radius: 0;
    font-size: 0;
}

.progress-square.active {
    outline: 2px solid #f2ca57;
    outline-offset: 2px;
    box-shadow: none;
}

@media (max-width: 480px) {
    #exercise-progress {
        grid-template-columns: repeat(36, minmax(0, 1fr));
        gap: 2px;
    }
}


/* Fit all lesson exercises into a single horizontal row */
#exercise-progress {
    display: grid;
    width: 100%;
    gap: 2px;
    overflow: visible;
}

.progress-square {
    width: 100%;
    min-width: 0;
    height: 12px;
    padding: 0;
    border-radius: 0;
}

/* Unified WebChessTraining controls */

#lesson-select {
    background: #303338;
    color: #e8eaed;
    border: 1px solid #555b62;
    border-radius: 5px;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 14px;
    max-width: 100%;
    cursor: pointer;
}

#lesson-select:hover {
    border-color: #769656;
}

#lesson-select:focus-visible {
    outline: 2px solid #8caf71;
    outline-offset: 2px;
}

label[for="lesson-select"] {
    color: #bfc3c9;
    font-size: 14px;
    margin-right: 8px;
}

#exercise-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 16px;
}

#exercise-navigation button {
    background: #34383d;
    color: #e8eaed;
    border: 1px solid #555b62;
    border-radius: 5px;
    padding: 9px 18px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

#exercise-navigation button:hover:not(:disabled) {
    background: #43533d;
    border-color: #769656;
}

#exercise-navigation button:disabled {
    opacity: 0.35;
    cursor: default;
}

#exercise-number {
    color: #bfc3c9;
    font-size: 14px;
    white-space: nowrap;
}

#status {
    margin: 14px 0 8px;
}



/* Collapsible course and lesson navigation */

#lesson-panel {
    margin: 18px 0;
    border: 1px solid #555b62;
    border-radius: 6px;
    background: #303338;
}

#lesson-toggle {
    padding: 13px 15px;
    cursor: pointer;
    font-size: 14px;
    color: #e8eaed;
    line-height: 1.5;
}

#lesson-toggle:hover {
    background: #383d42;
}

#lesson-toggle:focus-visible {
    outline: 2px solid #8caf71;
    outline-offset: 2px;
}

#lesson-panel[open] > #lesson-toggle {
    border-bottom: 1px solid #555b62;
}

#lesson-tree {
    padding: 8px;
    max-height: 360px;
    overflow-y: auto;
}

.lesson-branch {
    margin: 3px 0;
}

.lesson-branch > summary {
    padding: 9px 10px;
    cursor: pointer;
    color: #d5d9dd;
    font-size: 14px;
    border-radius: 4px;
}

.lesson-branch > summary:hover {
    background: #3b4045;
}

.lesson-children {
    padding-left: 16px;
    margin-left: 7px;
    border-left: 1px solid #494e53;
}

.lesson-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 9px 12px;
    margin: 2px 0;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: #d5d9dd;
    font-family: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.lesson-option:hover {
    background: #3e4740;
}

.lesson-option.active {
    background: #354b37;
    color: #e3efdf;
    font-weight: bold;
}

.lesson-option:focus-visible {
    outline: 2px solid #8caf71;
}

.lesson-count {
    color: #aeb5bc;
    font-size: 12px;
    flex-shrink: 0;
}

/* Pointer-based chess piece dragging */
#board {
    touch-action: none;
}

.piece {
    -webkit-user-drag: none;
    user-select: none;
}

.dragged-piece {
    position: fixed;
    width: 65px;
    height: 65px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 1000;
    user-select: none;
}


/* Highlight the starting square while dragging */
.square.drag-origin {
    box-shadow: inset 0 0 0 5px #ffd700;
}

.square.drag-origin .piece {
    visibility: hidden;
}


/* Chessboard coordinates */
.square {
    position: relative;
}

.coordinate {
    position: absolute;
    z-index: 2;
    font-size: clamp(10px, 1.4vw, 14px);
    font-weight: bold;
    pointer-events: none;
    user-select: none;
}

.rank-coordinate {
    top: 3px;
    left: 4px;
}

.file-coordinate {
    bottom: 2px;
    right: 4px;
}

/* Contrast against the square background */
.square.light .coordinate {
    color: #769656;
}

.square.dark .coordinate {
    color: #eeeed2;
}


/* Active player and dashboard navigation */
#training-header {
    position: relative;
}

#training-header h1 {
    margin-bottom: 10px;
}

#player-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 0 14px;
}

#active-player {
    color: #bfc3c9;
    font-size: 13px;
}

#dashboard-link {
    display: inline-block;
    padding: 7px 12px;
    color: #e8eaed;
    background: #303338;
    border: 1px solid #555b62;
    border-radius: 5px;
    font-size: 13px;
    text-decoration: none;
}

#dashboard-link:hover {
    background: #3e4740;
    border-color: #769656;
}

/* Group player information and Dashboard navigation */
#player-controls {
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 14px;
}

#active-player {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 12px;
    background: #303338;
    border: 1px solid #555b62;
    border-radius: 5px;
    color: #e8eaed;
}

#dashboard-link {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
}

/* Group player information and Dashboard navigation */
#player-controls {
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 14px;
}

#active-player {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 12px;
    background: #303338;
    border: 1px solid #555b62;
    border-radius: 5px;
    color: #e8eaed;
}

#dashboard-link {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
}


/* Annotations and Variations panel */
#training-stage {
    position: relative;
    width: 100%;
}

#annotation-panel {
    position: absolute;
    top: 0;
    left: calc(100% + 18px);
    width: 235px;
    padding: 16px;
    border: 1px solid #555b62;
    border-radius: 6px;
    background: #303338;
    color: #d5d9dd;
    font-size: 14px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

#annotation-panel h3 {
    margin: 0 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #555b62;
    font-size: 15px;
    color: #e8eaed;
}

#annotation-content p {
    margin: 0 0 12px;
    white-space: pre-line;
}

.annotation-secondary {
    margin-top: 18px !important;
    padding-top: 12px;
    border-top: 1px solid #494e53;
    color: #aeb5bc;
    font-size: 12px;
}

@media (max-width: 1150px) {
    #annotation-panel {
        position: static;
        width: 100%;
        margin-top: 16px;
    }
}


/* Learning / Testing mode selector */

#training-modes {
    display: flex;
    gap: 10px;
    margin: 14px 0 18px;
}

#training-modes button {
    padding: 10px 24px;
    border: 1px solid #555b62;
    border-radius: 6px;
    background: #303338;
    color: #e8eaed;
    cursor: pointer;
    font-size: 14px;
}

#training-modes button.mode-active {
    background: #39513a;
    border-color: #769656;
}

#testing-setup[hidden] {
    display: none !important;
}

main.testing-mode #lesson-panel,
main.testing-mode #lesson,
main.testing-mode #instruction,
main.testing-mode #training-stage,
main.testing-mode #status,
main.testing-mode #exercise-progress,
main.testing-mode #exercise-navigation {
    display: none !important;
}

/* Testing setup */

#testing-setup {
    box-sizing: border-box;
    max-width: 720px;
    padding: 24px;
    background: #303338;
    border: 1px solid #555b62;
    border-radius: 7px;
    color: #e8eaed;
}

#testing-setup h2 {
    margin: 0 0 22px;
}

.test-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.test-options fieldset {
    min-width: 0;
    border: 1px solid #555b62;
    border-radius: 6px;
    padding: 16px;
}

.test-options legend {
    padding: 0 8px;
    font-weight: 600;
}

.test-options label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
    cursor: pointer;
}

.test-options input,
#test-count {
    accent-color: #769656;
}

.test-disabled {
    opacity: 0.45;
    cursor: not-allowed !important;
}

.test-task-count {
    margin-top: 26px;
}

.test-task-count label {
    display: block;
    margin-bottom: 14px;
}

#test-count {
    width: 100%;
}

.test-range-labels {
    display: flex;
    justify-content: space-between;
    color: #bfc3c9;
    font-size: 12px;
}

.test-actions {
    margin-top: 24px;
}

#start-test {
    padding: 10px 24px;
    border-radius: 5px;
    border: 1px solid #555b62;
    background: #39513a;
    color: white;
}

#start-test:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.test-actions p {
    font-size: 13px;
    color: #bfc3c9;
}

@media (max-width: 600px) {
    .test-options {
        grid-template-columns: 1fr;
    }
}


/* Canonical Lessons sidebar layout */

#exercise-area {
    position: relative;
}

#exercise-area > #lesson {
    margin-top: 0;
}

#lesson-panel {
    position: absolute;
    top: 0;
    right: calc(100% + 18px);
    width: 280px;
    height: auto;
    margin: 0;
    box-sizing: border-box;
    z-index: 20;
}

#lesson-toggle {
    position: static;
    display: block;
    width: 100%;
    padding: 12px 15px;
    min-height: 0;
    font-size: 14px;
    font-weight: 600;
    list-style: none;
}

#lesson-toggle::-webkit-details-marker {
    display: none;
}

#lesson-toggle::after {
    content: none;
}

#lesson-tree {
    position: static;
    width: auto;
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    padding: 8px;
    border: none;
    box-shadow: none;
}

/* On smaller displays, place Lessons above the exercise. */
@media (max-width: 1279px) {
    #lesson-panel {
        position: relative;
        right: auto;
        width: 100%;
        margin-bottom: 14px;
    }
}

main.testing-mode #exercise-area {
    display: none !important;
}




/* Compact training application header */

#training-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

#training-header h1 {
    margin: 0;
    font-size: 25px;
    line-height: 1.3;
}

#player-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin: 0;
}

#active-player,
#dashboard-link {
    min-height: 34px;
    box-sizing: border-box;
    white-space: nowrap;
}

#training-modes {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px;
    padding-top: 12px;
    border-top: 1px solid #45494e;
}

#training-modes button {
    padding: 8px 18px;
}

#current-course-label {
    margin-left: auto;
    font-size: 13px;
    color: #aeb5bc;
    white-space: nowrap;
}

#exercise-area > #lesson {
    margin: 0 0 8px;
    font-size: 19px;
}

#exercise-area > #instruction {
    margin: 0 0 12px;
    color: #bfc3c9;
    font-size: 15px;
    line-height: 1.4;
}

@media (max-width: 650px) {
    #training-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    #player-controls {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    #training-modes {
        flex-wrap: wrap;
    }

    #current-course-label {
        margin-left: 0;
        width: 100%;
    }
}

/* Raise side panels to use the empty header space */
@media (min-width: 1280px) {
    #training-stage > #lesson-panel {
        top: -116px;
    }

    #annotation-panel {
        top: -116px;
    }
}

/* Extend the header to align with the left sidebar */
@media (min-width: 1280px) {
    #training-header {
        width: calc(100% + 298px);
        margin-left: -298px;
        box-sizing: border-box;
    }
}


/* WebChessTraining canonical grid layout */

/* Full-width application header and content */
main {
    width: min(1080px, calc(100% - 32px));
    max-width: 1080px;
    margin: 16px auto;
    padding: 0;
}

#training-header {
    width: 100%;
    margin: 0;
    padding: 0 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-sizing: border-box;
}

#training-header h1 {
    margin: 0;
    font-size: 26px;
}

#player-controls {
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

#training-modes {
    margin: 0 0 18px;
    padding: 12px 0 0;
    border-top: 1px solid #45494e;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Three real columns, not absolute offsets */
#exercise-area {
    display: grid;
    grid-template-columns: 254px minmax(0, 1fr) 254px;
    grid-template-areas:
        "lessons heading annotations"
        "lessons instruction annotations"
        "lessons board annotations"
        "lessons status annotations"
        "lessons progress annotations"
        "lessons navigation annotations";
    column-gap: 12px;
    row-gap: 0;
    position: relative;
    align-items: start;
}

/* Left column */
#exercise-area > #lesson-panel {
    grid-area: lessons;
    position: static;
    display: block;
    width: 100%;
    height: auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: #303338;
    box-sizing: border-box;
    border-radius: 8px;
    overflow: hidden;
}

#exercise-area > #lesson-panel > #lesson-toggle {
    position: static;
    display: block;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 15px 12px;
    border: 0;
    border-bottom: 1px solid #555b62;
    background: #303338;
    border-radius: 0;
    font-size: 15px;
    font-weight: 600;
    box-sizing: border-box;
    list-style: none;
}

#lesson-toggle::after {
    content: none !important;
}

#exercise-area > #lesson-panel > #lesson-tree {
    position: static;
    width: 100%;
    max-height: 650px;
    margin: 0;
    padding: 10px;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    box-sizing: border-box;
    overflow-y: auto;
}

/* Centre column */
#exercise-area > #lesson {
    grid-area: heading;
    margin: 4px 0 8px;
    font-size: 19px;
}

#exercise-area > #instruction {
    grid-area: instruction;
    margin: 0 0 12px;
    color: #bfc3c9;
    font-size: 14px;
}

#exercise-area > #training-stage {
    grid-area: board;
    position: static;
    width: 100%;
    min-width: 0;
}

#training-stage > #board {
    width: 100%;
    box-sizing: border-box;
}

#exercise-area > #status {
    grid-area: status;
}

#exercise-area > #exercise-progress {
    grid-area: progress;
}

#exercise-area > #exercise-navigation {
    grid-area: navigation;
}

/* Right column */
#exercise-area > #annotation-panel {
    grid-area: annotations;
    position: static;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    margin: 0;
    padding: 16px 12px;
    box-sizing: border-box;
    border-radius: 8px;
}

/* Testing configuration replaces Learning content */
main.testing-mode #exercise-area {
    display: none !important;
}

/* Responsive layout */
@media (max-width: 1100px) {
    #exercise-area {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "lessons"
            "heading"
            "instruction"
            "board"
            "status"
            "progress"
            "navigation"
            "annotations";
        row-gap: 12px;
    }

    #exercise-area > #lesson-panel {
        position: static;
        width: 100%;
    }

    #exercise-area > #annotation-panel {
        position: static;
        width: 100%;
    }
}

@media (max-width: 650px) {
    #training-header {
        flex-wrap: wrap;
    }

    #player-controls {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}


/* Functional Testing session layout */
main.testing-mode.testing-running #exercise-area {
    display: grid !important;
    grid-template-columns: minmax(0, 680px);
    grid-template-areas:
        "heading"
        "instruction"
        "board"
        "status";
    justify-content: center;
    row-gap: 0;
}

main.testing-mode.testing-running #exercise-area > #lesson,
main.testing-mode.testing-running #exercise-area > #instruction,
main.testing-mode.testing-running #exercise-area > #training-stage,
main.testing-mode.testing-running #exercise-area > #status {
    display: block !important;
}

main.testing-mode #exercise-area > #lesson-panel,
main.testing-mode #exercise-area > #annotation-panel,
main.testing-mode #exercise-area > #exercise-progress,
main.testing-mode #exercise-area > #exercise-navigation {
    display: none !important;
}

#testing-summary[hidden] {
    display: none !important;
}

#testing-summary {
    max-width: 680px;
    margin: 16px auto;
    padding: 24px;
    border: 1px solid #555b62;
    border-radius: 8px;
    background: #303338;
}

#testing-results {
    margin: 20px 0;
    font-size: 17px;
}

#new-test {
    padding: 10px 20px;
    border: 1px solid #769656;
    border-radius: 5px;
    background: #39513a;
    color: white;
    cursor: pointer;
}

#testing-feedback {
    color: #e3bd77;
}
