/*
    REVIEW PANEL
    Flat: no boxes, sections split by hairlines and spacing. The same column holds the load form,
    the report, the practice lesson and play mode; #review-container[data-view] picks which.
*/
#review-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#review-panel-main {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#review-panel-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-height: 0;
    overflow-y: auto;
}

/*
    WHICH PANELS SHOW
    #review-container[data-view] is form (load a game), report, practice or play. Everything else is hidden.
*/
#review-container:not([data-view="form"]) .load-section,
#review-container:not([data-view="report"]) #report-cards,
#review-container:not([data-view="report"]) #report-under,
#review-container:not([data-view="report"]) .report-only,
#review-container:not([data-view="report"]) #load-another-button,
#review-container:not([data-view="practice"]) .practice-only,
#review-container:not([data-view="practice"]):not([data-view="play"]) #trainer-lesson,
#review-container:not([data-view="form"]):not([data-view="report"]) .settings,
#review-container:not([data-view="form"]) .profile-card,
#review-container[data-view="form"] #ask-tutor,
#review-container[data-view="play"] .tutor-only,
#review-container[data-view="practice"] .play-only {
    display: none !important;
}

/*
    LOAD A GAME
*/
.load-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    max-width: 420px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

label,
.setting-head label {
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--ink-2);
}

.field select,
.field .fc-select {
    width: 100%;
}

.gameInputContainer {
    display: flex;
    gap: var(--space-2);
}

#chess-site-username {
    flex: 1;
    min-width: 0;
}

.pgn-input-row {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

#pgn {
    width: 100%;
    min-height: 120px;
    resize: vertical;
}

.pgn-upload-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.pgn-file-name {
    min-width: 0;
    overflow: hidden;
    color: var(--ink-2);
    font-size: var(--fs-sm);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.load-actions {
    display: flex;
    gap: var(--space-2);
}

/* Grey while no game is chosen. Still clickable so the error message explains what is missing. */
#review-button.review-button-disabled {
    opacity: 0.45;
}

/*
    ANALYSIS STATUS
    No class: the empty-state prompt. is-info: progress. is-error: failure.
*/
#evaluation-progress-bar {
    display: none;
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border: 0;
    border-radius: 2px;
    background: var(--hair-strong);
    overflow: hidden;
}

#evaluation-progress-bar::-webkit-progress-bar {
    background: var(--hair-strong);
}

#evaluation-progress-bar::-webkit-progress-value {
    background: var(--blue);
}

#evaluation-progress-bar::-moz-progress-bar {
    background: var(--blue);
}

#status-message {
    color: var(--ink-2);
    font-size: var(--fs-sm);
}

#status-message.is-info {
    color: var(--ink);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

#status-message.is-error {
    color: var(--red);
    font-weight: 500;
}

/*
    SETTINGS: depth, arrows, board. A quiet row at the bottom; opens in place.
*/
.settings {
    padding-top: var(--space-3);
    border-top: 1px solid var(--hair);
    max-width: 420px;
}

.settings summary {
    color: var(--ink-2);
    font-size: var(--fs-sm);
    font-weight: 500;
    cursor: pointer;
}

.settings summary:hover {
    color: var(--ink);
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding-top: var(--space-3);
}

.settings .field {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.settings .field select,
.settings .field .fc-select {
    width: 60%;
}

.setting-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

#depth-counter {
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
}

/* Depth slider: thin track, cyan fill up to the value, round thumb */
#depth-slider {
    --fill: 33%;

    appearance: none;
    -webkit-appearance: none;
    display: block;
    width: 100%;
    height: 24px;
    background: transparent;
    cursor: pointer;
}

#depth-slider::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--blue) var(--fill), var(--hair-strong) var(--fill));
}

#depth-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -5px;
    border: 0;
    border-radius: 50%;
    background: var(--ink);
}

#depth-slider::-moz-range-track {
    height: 4px;
    border-radius: 2px;
    background: var(--hair-strong);
}

#depth-slider::-moz-range-progress {
    height: 4px;
    border-radius: 2px;
    background: var(--blue);
}

#depth-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 0;
    border-radius: 50%;
    background: var(--ink);
}

/* Arrows switch: a real checkbox, the track and thumb are drawn */
.switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.toggle {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: 34px;
    height: 20px;
}

.toggle input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.toggle__fill {
    position: absolute;
    inset: 0;
    border: var(--rule);
    border-radius: 999px;
    background: var(--surface-2);
    pointer-events: none;
}

.toggle__fill::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--ink-2);
}

.toggle input:checked ~ .toggle__fill {
    background: var(--blue-soft);
    border-color: var(--blue-line);
}

.toggle input:checked ~ .toggle__fill::after {
    left: 16px;
    background: var(--blue);
}

.toggle input:focus-visible ~ .toggle__fill {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

#load-another-button {
    align-self: flex-start;
    padding-left: 0;
}

/*
    PRACTICE and PLAY MODE
    Heading and mode switch, progress, the instruction, one action row, the moves, other lines, stats.
*/
.trainer-lesson {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-height: 0;
}

.lesson-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.lesson-titles {
    min-width: 0;
}

.tutor-opening {
    font-size: var(--fs-lg);
    line-height: 1.25;
}

.tutor-line-name {
    margin-top: 2px;
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
}

.tutor-switch {
    flex-shrink: 0;
}

.tutor-switch .chip {
    min-height: 26px;
    white-space: nowrap;
    padding: 3px 10px;
    font-size: var(--fs-xs);
}

.tutor-progress {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--ink-2);
    font-size: var(--fs-xs);
    white-space: nowrap;
}

.tutor-bar {
    flex: 1;
    height: 3px;
    border-radius: 2px;
    background: var(--hair-strong);
    overflow: hidden;
}

.tutor-bar i {
    display: block;
    width: 0;
    height: 100%;
    border-radius: 2px;
    background: var(--blue);
    transition: width 0.25s ease;
}

/* The instruction, "The idea:" and "Why it is good:" run on as plain lines */
.lesson-text {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--hair);
    border-bottom: 1px solid var(--hair);
    font-size: var(--fs-sm);
    line-height: 1.5;
}

.lesson-text:not(:has(p:not(:empty))) {
    display: none;
}

#secondary-message {
    color: var(--ink-2);
    font-size: var(--fs-sm);
}

#secondary-message:empty,
.tutor-why:empty,
.tutor-idea:empty {
    display: none;
}

#secondary-message.trainer-error {
    color: var(--red);
}

.tutor-why {
    color: var(--ink-2);
}

/* A researched lesson note: the point of the Learn step, so it stands out from the plain lines around it */
.tutor-why.is-lesson {
    padding: var(--space-3);
    border-left: 3px solid var(--blue);
    border-radius: 0 var(--radius-card) var(--radius-card) 0;
    background: var(--surface-2);
    color: var(--ink);
    font-size: var(--fs-md);
    line-height: 1.55;
}

.tutor-why.is-lesson b {
    display: block;
    margin-bottom: var(--space-1);
    color: var(--blue);
    font-size: var(--fs-sm);
}

.why-sources {
    display: block;
    margin-top: var(--space-2);
    color: var(--ink-3);
    font-size: var(--fs-xs);
    line-height: 1.5;
}

.why-sources a {
    color: var(--ink-2);
}

/* Lessons choose the mode themselves, so the Learn / Drill switch goes and "About this opening" takes its place */
#trainer-lesson[data-lesson] .tutor-switch {
    display: none;
}

.lesson-about {
    align-self: flex-start;
    white-space: nowrap;
}

/* Overview and end-of-lesson cards, inside the same box as the all-lines summary */
.card-text {
    margin: 0;
    color: var(--ink-2);
    font-size: var(--fs-sm);
    line-height: 1.5;
}

.card-heading {
    margin: var(--space-2) 0 0;
    font-size: var(--fs-sm);
    font-weight: 600;
}

.card-list {
    margin: 0;
    padding-left: var(--space-4);
    color: var(--ink-2);
    font-size: var(--fs-sm);
    line-height: 1.5;
}

.card-sources {
    margin: 0;
    color: var(--ink-3);
    font-size: var(--fs-xs);
    line-height: 1.6;
}

.card-sources a {
    color: var(--ink-2);
}

#tree-summary {
    min-height: 0;
    overflow-y: auto;
}

/* The overview is long: it gets the whole panel, with the move list and stats out of the way */
#trainer-lesson[data-card="overview"] .lesson-moves,
#trainer-lesson[data-card="overview"] #lines-panel,
#trainer-lesson[data-card="overview"] #opening-stats {
    display: none;
}

/* All-lines session: the lines played, known or missed, once the last one is done */
.tree-summary {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--hair);
    border-bottom: 1px solid var(--hair);
}

#trainer-lesson:not([data-tree-summary]) .tree-summary {
    display: none;
}

#trainer-lesson[data-tree-summary] > .tutor-actions,
#trainer-lesson[data-tree-summary] .lesson-text,
#trainer-lesson[data-tree-summary] .tutor-progress {
    display: none;
}

.reply-list {
    max-height: 320px;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;
}

.reply-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
    align-items: baseline;
    column-gap: var(--space-2);
    padding: var(--space-1) 0;
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    color: var(--ink-2);
}

.reply-row.is-line {
    grid-template-columns: minmax(0, 1fr) auto;
}

.reply-row .reply-user {
    color: var(--ink);
    font-weight: 600;
}

.reply-row .reply-status {
    color: var(--ink-3);
}

.reply-row.is-missed .reply-status {
    color: var(--red);
}

.tutor-idea {
    color: var(--ink-2);
}

.lesson-text b {
    color: var(--ink);
    font-weight: 600;
}

/* Today lines stage: between two lines */
.line-done {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--hair);
    border-bottom: 1px solid var(--hair);
}

#trainer-lesson:not([data-line-done]) .line-done {
    display: none !important;
}

#trainer-lesson[data-line-done] .tutor-actions,
#trainer-lesson[data-line-done] .lesson-text {
    display: none;
}

.line-done-title {
    font-size: var(--fs-md);
    font-weight: 600;
}

.line-done-next {
    color: var(--ink-2);
    font-size: var(--fs-sm);
}

/* One compact action row; buttons carry their key like the drills */
.tutor-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.tutor-actions .btn {
    white-space: nowrap;
}

/* One button size in every action row */
.tutor-actions .btn,
.load-actions .btn,
.line-done .btn,
#load-another-button {
    gap: 6px;
    min-height: 32px;
    padding: 4px 12px;
    font-size: var(--fs-sm);
}

.kbd-btn::after {
    content: attr(data-key);
    min-width: 18px;
    padding: 0 5px;
    border: 1px solid var(--hair-strong);
    border-radius: 4px;
    background: var(--surface);
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    line-height: 16px;
    text-align: center;
}

.kbd-btn.primary::after {
    border-color: rgba(6, 20, 22, 0.35);
    background: transparent;
    color: var(--on-accent);
}

/* Touch screens have no keyboard: drop the key chips, as the puzzle screen does */
@media (pointer: coarse) {
    .kbd-btn::after { content: none; }
}

.more {
    position: relative;
    margin-left: auto;
}

.more-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 20;
    min-width: 150px;
    padding: var(--space-1);
    border: var(--rule);
    border-radius: var(--radius-card);
    background: var(--surface-2);
}

.more-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--fs-sm);
    text-align: left;
    cursor: pointer;
}

.more-item:hover:not(:disabled) {
    background: var(--hair);
}

.more-item:disabled {
    color: var(--ink-3);
    cursor: not-allowed;
}

.trainer-lesson[data-mode="drill"] .learn-only {
    display: none;
}

.lesson-moves {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#practice-move-list {
    flex: 1;
    min-height: 96px;
}

/*
    MOVE LISTS: the same component in review and practice. Number, white move, black move.
*/
.move-list {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    font-variant-numeric: tabular-nums;
}

.move-pair {
    display: grid;
    grid-template-columns: 32px 1fr 1fr;
    align-items: center;
    flex-shrink: 0;
    min-height: 27px;
    border-radius: 4px;
}

.move-pair:has(.move-current) {
    background: var(--surface-2);
}

.move-num {
    padding-left: var(--space-2);
    color: var(--ink-3);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
}

.move-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-self: start;
    min-height: 27px;
    padding: 0 6px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    font-weight: 400;
    cursor: pointer;
}

.move-chip:hover {
    background: var(--hair);
}

.move-chip.move-future {
    color: var(--ink-3);
}

.move-chip.move-current {
    background: none;
    color: var(--blue);
    font-weight: 500;
}

.move-icon {
    width: 14px;
    height: 14px;
}

.panel-empty {
    color: var(--ink-2);
    font-size: var(--fs-xs);
}

/* Other lines from here: one row per alternative next move */
.other-line {
    display: grid;
    grid-template-columns: 56px 1fr auto auto;
    align-items: center;
    column-gap: var(--space-2);
    width: 100%;
    min-height: 28px;
    padding: 0 var(--space-1);
    border: 0;
    border-top: 1px solid var(--hair);
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    text-align: left;
    cursor: pointer;
}

.other-line:hover {
    background: var(--surface-2);
}

.other-line.is-current {
    cursor: default;
}

.other-line.is-current .other-line-move {
    color: var(--blue);
}

.other-line-move {
    font-family: var(--font-mono);
    font-weight: 500;
}

.other-line-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.other-line-count {
    color: var(--ink-3);
    font-size: var(--fs-xs);
}

.other-line-current {
    color: var(--blue);
    font-size: var(--fs-xs);
}

.stat-line {
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
}

.stat-line + .stat-line {
    margin-top: var(--space-1);
}

/*
    PROFILE AND STATS (signed in)
*/
.profile-card {
    padding-top: var(--space-3);
    border-top: 1px solid var(--hair);
    max-width: 420px;
}

.profile-card summary {
    display: flex;
    align-items: center;
    min-height: 36px;
    font-weight: 500;
    cursor: pointer;
}

.profile-card details[open] summary {
    margin-bottom: var(--space-2);
}

.profile-card details > div + div {
    margin-top: var(--space-3);
}

.profile-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

.profile-row h3,
.profile-card details > div > h3 {
    color: var(--ink-2);
    font-size: var(--fs-sm);
    font-weight: 400;
    letter-spacing: 0;
}

.profile-row p {
    font-weight: 600;
}

.sessions-list {
    list-style: none;
}

.sessions-list li {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--hair);
    font-size: var(--fs-sm);
}
