/* Opening Trainer - Three-theme system */

:root {
    --board-size: 75vh;
    --accent: #5b9bd5;
    --accent-light: #7eb8e8;
    --accent-soft: rgba(91, 155, 213, 0.3);
    --accent-glow: rgba(91, 155, 213, 0.15);
    --success: #5cb85c;
    --success-soft: rgba(92, 184, 92, 0.10);
    --error: #d9534f;
    --error-soft: rgba(217, 83, 79, 0.10);
    --warning: #c9a84c;
    /* Shared easings for consistent, fluid motion across the trainer. */
    --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
}

/* === Pure-black minimalist theme (default) === */
body, body.theme-picture {
    --bg: #000000;
    --text: #ededed;
    --text-secondary: #b4b4b4;
    --text-muted: #808080;
    --text-faint: #555555;
    --surface: rgba(255, 255, 255, 0.03);
    --surface-hover: rgba(255, 255, 255, 0.06);
    --surface-active: rgba(91, 155, 213, 0.14);
    --border: rgba(255, 255, 255, 0.12);
    --border-hover: rgba(91, 155, 213, 0.55);
    --card-bg: rgba(255, 255, 255, 0.02);
    --panel-bg: #0a0a0a;
}

/* === Light theme === */
body.theme-light {
    --bg: #eef2f6;
    --text: #1a2332;
    --text-secondary: #4a5568;
    --text-muted: #7a8a9e;
    --text-faint: #a0aec0;
    --surface: rgba(91, 155, 213, 0.05);
    --surface-hover: rgba(91, 155, 213, 0.08);
    --surface-active: rgba(91, 155, 213, 0.12);
    --border: #dce3eb;
    --border-hover: rgba(91, 155, 213, 0.3);
    --card-bg: #ffffff;
    --panel-bg: rgba(255, 255, 255, 0.95);
}

/* === Dark theme === */
body.theme-dark {
    --bg: #0d1117;
    --text: #e8eef4;
    --text-secondary: #a0b4c8;
    --text-muted: #6b8399;
    --text-faint: #3d5570;
    --surface: rgba(255, 255, 255, 0.05);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --surface-active: rgba(91, 155, 213, 0.12);
    --border: rgba(255, 255, 255, 0.10);
    --border-hover: rgba(91, 155, 213, 0.30);
    --card-bg: rgba(255, 255, 255, 0.06);
    --panel-bg: rgba(255, 255, 255, 0.07);
}

/* Fade overlay for smooth page load */
#fade-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg, #000000);
    opacity: 1;
    z-index: 10000;
    pointer-events: none;
    transition: opacity 0.8s ease-in;
}

/* Trainer-specific body overrides */
body {
    background: var(--bg, #000000);
}

/* Trainer-specific grain opacity */
body::before {
    opacity: 0;
}

/* ===== Background (flat black) ===== */
.background {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: var(--bg, #000000);
}

.background-image {
    display: none;
}

.background-overlay {
    display: none;
}

/* ===== Navigation ===== */
.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s var(--ease-smooth);
}

.nav-btn:hover {
    color: var(--text);
    background: var(--surface);
    transform: scale(1.05);
}

.nav-btn:active {
    transform: scale(0.95);
}

.nav-title {
    margin-left: 12px;
    font-family: var(--font-brand);
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.nav-spacer {
    flex: 1;
}

/* ===== Selection View ===== */
.selection-view {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 80px 20px 40px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.selection-view.view-hidden {
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

.trainer-view.view-hidden {
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

.selection-container {
    max-width: 560px;
    width: 100%;
}

.selection-header {
    text-align: center;
    margin-bottom: 28px;
}

.selection-header h1 {
    font-family: var(--font-brand);
    font-size: 2.3rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text);
    letter-spacing: 0.5px;
    background: linear-gradient(120deg, var(--text) 30%, var(--accent-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.selection-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 300;
    letter-spacing: 1px;
}

/* ===== Stats Summary Bar ===== */
.stats-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 14px 24px;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 24px;
}

.stat-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-value {
    font-family: var(--font-brand);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.66rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.6px;
    font-weight: 500;
}

.stat-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.06);
    margin: 0 8px;
}

/* ===== Search ===== */
.search-container {
    position: relative;
    margin-bottom: 16px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
    transition: color 0.2s;
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 300;
    letter-spacing: 0.5px;
    transition: all 0.3s var(--ease-smooth);
    outline: none;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--border-hover);
    background: var(--surface-hover);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-input:focus + .search-icon,
.search-container:focus-within .search-icon {
    color: var(--accent-light);
}

/* ===== Color Toggle ===== */
.color-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.color-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.8px;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
}

.color-btn:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: var(--surface-hover);
}

.color-btn.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.color-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid currentColor;
    transition: transform 0.2s;
}

.color-icon.white {
    background: #fff;
}

.color-icon.black {
    background: #1a1a1a;
}

/* ===== Add Line Button ===== */
.add-line-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px;
    background: none;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 300;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s var(--ease-smooth);
    margin-bottom: 24px;
}

.add-line-btn:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: var(--accent-glow);
}

/* ===== Openings Grid ===== */
.openings-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.opening-category {
    margin-bottom: 12px;
}

.opening-category h3 {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
    padding-left: 4px;
}

.opening-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ===== Opening Card (Rich) ===== */
.opening-btn {
    display: flex;
    align-items: center;
    padding: 0;
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.25s var(--ease-smooth);
    text-align: left;
    overflow: hidden;
    position: relative;
}

.opening-btn:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 22px rgba(91, 155, 213, 0.14);
}

.opening-btn:active {
    transform: translateY(0) scale(0.98);
}

/* Left color stripe */
.opening-color-stripe {
    width: 4px;
    align-self: stretch;
    flex-shrink: 0;
    border-radius: 3px 0 0 3px;
}

/* Card content area */
.opening-card-content {
    flex: 1;
    padding: 12px 14px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.opening-card-top {
    display: flex;
    align-items: center;
    gap: 8px;
}

.opening-btn .opening-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.88rem;
    letter-spacing: 0.2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.opening-btn .opening-eco {
    font-size: 0.65rem;
    color: var(--accent-light);
    font-weight: 600;
    padding: 2px 6px;
    background: var(--accent-glow);
    border-radius: 4px;
    flex-shrink: 0;
}

.opening-card-bottom {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.7rem;
    color: var(--text-faint);
}

.opening-card-bottom .card-moves-count {
    display: flex;
    align-items: center;
    gap: 3px;
}

.opening-card-bottom .card-last-practiced {
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Mastery bar */
.mastery-bar-container {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.mastery-bar {
    width: 56px;
    height: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.mastery-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
    background: linear-gradient(90deg, var(--accent), var(--success));
    box-shadow: 0 0 6px var(--accent-glow);
}

.mastery-percentage {
    font-size: 0.65rem;
    color: var(--text-faint);
    font-weight: 600;
    min-width: 28px;
    text-align: right;
}

/* Card action buttons */
.opening-card-actions {
    display: flex;
    align-items: center;
    padding-right: 8px;
    gap: 2px;
}

.opening-btn .edit-line-btn,
.opening-btn .delete-line-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    transition: all 0.2s var(--ease-smooth);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    opacity: 0;
}

.opening-btn:hover .edit-line-btn,
.opening-btn:hover .delete-line-btn {
    opacity: 0.7;
}

.opening-btn .edit-line-btn:hover {
    opacity: 1;
    color: var(--accent-light);
    background: var(--accent-glow);
}

.opening-btn .delete-line-btn:hover {
    opacity: 1;
    color: var(--error);
    background: var(--error-soft);
}

.no-lines-msg {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 300;
    text-align: center;
    padding: 32px 16px;
    letter-spacing: 0.5px;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px dashed var(--border);
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s var(--ease-smooth);
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 32px;
    max-width: 420px;
    width: 100%;
    /* Keep Save/Cancel reachable when the Add/Edit-line body is tall (board
       editor, tree preview) on short or landscape phones. */
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    transform: scale(0.95) translateY(10px);
    transition: transform 0.25s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal-overlay.open .modal {
    transform: scale(1) translateY(0);
}

.modal h3 {
    font-family: var(--font-brand);
    font-size: 1.4rem;
    font-weight: 400;
    letter-spacing: 1px;
    margin-bottom: 24px;
}

.modal-field {
    margin-bottom: 16px;
}

.modal-field label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}

.modal-field label .hint {
    opacity: 0.6;
}

.modal-field input,
.modal-field textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.875rem;
    font-family: inherit;
    transition: all 0.2s var(--ease-smooth);
}

.modal-field input:focus,
.modal-field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.modal-field textarea {
    min-height: 80px;
    resize: vertical;
}

.modal-color-btns {
    display: flex;
    gap: 8px;
}

.modal-color-btn {
    flex: 1;
    padding: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
}

.modal-color-btn.active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text);
}

/* Import confirmation modal */
.import-confirm-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 4px 0 20px;
}

.import-confirm-text strong {
    color: var(--text);
}

.import-confirm-color-btns {
    display: flex;
    gap: 10px;
}

.import-color-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
}

.import-color-btn:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.import-color-btn.detected {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.import-color-btn .color-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.35);
}

.import-color-btn[data-color="white"] .color-dot {
    background: #f5f5f0;
}

.import-color-btn[data-color="black"] .color-dot {
    background: #1c1c1e;
    border-color: rgba(255, 255, 255, 0.45);
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 24px;
}

.btn-secondary,
.btn-primary {
    flex: 1;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 300;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
}

.btn-secondary {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-hover);
}

.btn-primary {
    background: var(--accent);
    border: none;
    color: #ffffff;
    box-shadow: 0 2px 12px rgba(91, 155, 213, 0.25);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(91, 155, 213, 0.3);
}

/* ===== Trainer View ===== */
.trainer-view {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px 20px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.trainer-layout {
    display: flex;
    align-items: flex-start;
    gap: 24px;
    max-width: 100%;
}

/* ===== Board Wrapper with Coordinates ===== */
.board-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 0;
}

.board-and-files {
    display: flex;
    flex-direction: column;
}

/* Board Coordinates - Ranks (left side) */
.board-coords-ranks {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding-right: 6px;
    height: var(--board-size);
    max-height: 90vw;
}

.board-coords-ranks span {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-faint);
    width: 14px;
    text-align: center;
    user-select: none;
    line-height: 1;
}

/* Board Coordinates - Files (below board) */
.board-coords-files {
    display: flex;
    justify-content: space-around;
    padding-top: 4px;
    width: 100%;
}

.board-coords-files span {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-faint);
    width: 14px;
    text-align: center;
    user-select: none;
    line-height: 1;
}

/* ===== Board Container ===== */
.board-container {
    position: relative;
}

/* ===== Chessboard ===== */
.chessboard {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: var(--board-size);
    height: var(--board-size);
    max-width: 90vw;
    max-height: 90vw;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    contain: layout style;
    /* The checkerboard is painted ONCE on the board itself (squares are
       transparent): an 8x8 grid of fractional-width cells leaves sub-pixel
       seams between tiles, a single repeating pattern cannot. */
    background: repeating-conic-gradient(
        var(--sq-dark, #94a7b8) 0% 25%,
        var(--sq-light, #eae6df) 0% 50%
    );
    background-size: 25% 25%;
}

.chess-square {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    contain: layout style;
}

.chessboard .chess-square.light,
.chessboard .chess-square.dark {
    background: transparent;
}

.chessboard .chess-square:hover {
    box-shadow: inset 0 0 0 999px rgba(255, 255, 255, 0.06);
}

.chess-square.selected {
    background: rgba(20, 85, 30, 0.5) !important;
}

.chess-square.possible-move::after {
    content: '';
    position: absolute;
    width: 28%;
    height: 28%;
    background: rgba(0, 0, 0, 0.12);
    border-radius: 50%;
}

.chess-square.possible-capture::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 5px solid rgba(0, 0, 0, 0.12);
    border-radius: 50%;
}

.chess-square.last-move {
    background: rgba(155, 199, 0, 0.41) !important;
}

.chess-square.last-move.light {
    background: rgba(205, 210, 106, 0.8) !important;
}

.chess-square.last-move.dark {
    background: rgba(170, 162, 58, 0.8) !important;
}

.chess-square.premove {
    background: rgba(20, 30, 85, 0.5) !important;
}

.chess-square.premove.light {
    background: rgba(82, 115, 173, 0.7) !important;
}

.chess-square.premove.dark {
    background: rgba(82, 95, 153, 0.7) !important;
}

.chess-square.wrong-move {
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(3px); }
}

.chess-square.drag-hover {
    filter: brightness(1.2);
}

/* ===== Board Feedback Overlay ===== */
.board-feedback-overlay {
    position: absolute;
    inset: 0;
    border-radius: 6px;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.board-feedback-overlay.correct-flash {
    background: rgba(92, 184, 92, 0.2);
    opacity: 1;
    animation: flashFade 0.5s ease forwards;
}

.board-feedback-overlay.wrong-flash {
    background: rgba(217, 83, 79, 0.25);
    opacity: 1;
    animation: flashFade 0.5s ease forwards;
}

@keyframes flashFade {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* ===== Board Checkmark ===== */
.board-checkmark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 60px;
    height: 60px;
    pointer-events: none;
    z-index: 6;
    opacity: 0;
}

.board-checkmark.show {
    animation: checkmarkPop 0.6s ease forwards;
}

@keyframes checkmarkPop {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

.board-checkmark svg circle {
    stroke-dasharray: 157;
    stroke-dashoffset: 157;
}

.board-checkmark.show svg circle {
    animation: checkCircle 0.4s ease 0.1s forwards;
}

@keyframes checkCircle {
    100% { stroke-dashoffset: 0; }
}

.board-checkmark svg path {
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
}

.board-checkmark.show svg path {
    animation: checkMark 0.3s ease 0.3s forwards;
}

@keyframes checkMark {
    100% { stroke-dashoffset: 0; }
}

/* ===== Celebration Particles ===== */
.celebration-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 7;
    overflow: hidden;
    border-radius: 6px;
}

.confetti-particle {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    opacity: 1;
    will-change: transform, opacity;
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(120px) rotate(720deg) scale(0.3);
        opacity: 0;
    }
}

/* ===== Chess Pieces ===== */
.chess-piece {
    width: 90%;
    height: 90%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: grab;
    user-select: none;
    transition: transform 0.1s ease;
}

.chess-piece:active {
    cursor: grabbing;
}

/* Piece sprites provided by base.css */

/* Drag Ghost */
#drag-ghost {
    position: fixed;
    width: 80px;
    height: 80px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.9;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
}

/* ===== Premove Indicator ===== */
.premove-indicator {
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 12px;
    background: rgba(82, 95, 153, 0.9);
    border-radius: 6px;
    font-size: 0.7rem;
    color: #ffffff;
    font-weight: 500;
}

/* ===== Side Panel ===== */
.side-panel {
    width: 260px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    max-height: var(--board-size);
    overflow-y: auto;
}

.side-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.opening-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.opening-name {
    font-family: var(--font-brand);
    font-weight: 400;
    font-size: 1rem;
    letter-spacing: 0.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.opening-eco-badge {
    font-size: 0.65rem;
    color: var(--accent-light);
    font-weight: 600;
    padding: 1px 6px;
    background: var(--accent-glow);
    border-radius: 4px;
    align-self: flex-start;
    display: none;
}

.opening-eco-badge.visible {
    display: inline-block;
}

.opening-meta-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* Color badge (training view) */
.opening-color-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
    text-transform: uppercase;
}

.opening-color-badge .color-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.35);
}

.opening-color-badge.white {
    color: #1a1a1a;
    background: rgba(245, 245, 240, 0.92);
}

.opening-color-badge.white .color-dot {
    background: #f5f5f0;
}

.opening-color-badge.black {
    color: #e8e8e8;
    background: rgba(28, 28, 30, 0.85);
    border-color: rgba(255, 255, 255, 0.2);
}

.opening-color-badge.black .color-dot {
    background: #1c1c1e;
    border-color: rgba(255, 255, 255, 0.45);
}

/* Color badge (selection cards) */
.card-color-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 1px 6px;
    border-radius: 4px;
    flex-shrink: 0;
    text-transform: uppercase;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
}

.card-color-badge .color-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.35);
}

.card-color-badge.white {
    color: #1a1a1a;
    background: rgba(245, 245, 240, 0.9);
}

.card-color-badge.white .color-dot {
    background: #f5f5f0;
}

.card-color-badge.black {
    color: #e8e8e8;
    background: rgba(28, 28, 30, 0.8);
    border-color: rgba(255, 255, 255, 0.2);
}

.card-color-badge.black .color-dot {
    background: #1c1c1e;
    border-color: rgba(255, 255, 255, 0.45);
}

/* ===== Progress Ring ===== */
.progress-ring-container {
    position: relative;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.progress-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.progress-ring-bg {
    stroke: var(--surface);
}

.progress-ring-fill {
    stroke: var(--accent);
    transition: stroke-dashoffset 0.4s ease, stroke 0.3s ease;
    stroke-linecap: round;
}

.progress-ring-fill.complete {
    stroke: var(--success);
}

.progress-ring-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ===== Streak Display ===== */
.streak-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.3s var(--ease-smooth);
}

.streak-display.on-fire {
    background: var(--surface);
    border-color: var(--border-hover);
}

.streak-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: all 0.3s var(--ease-smooth);
    flex-shrink: 0;
}

.streak-display.on-fire .streak-dot {
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.streak-count {
    font-family: var(--font-brand);
    font-size: 1.3rem;
    font-weight: 400;
    color: var(--text);
    transition: all 0.3s var(--ease-smooth);
}

.streak-display.on-fire .streak-count {
    color: #f59e0b;
}

.streak-label {
    font-size: 0.7rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* ===== Feedback Container ===== */
.feedback-container {
    text-align: center;
    padding: 4px 0;
}

.feedback {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 300;
    letter-spacing: 0.5px;
    transition: all 0.25s var(--ease-smooth);
}

.feedback.correct {
    color: var(--success);
}

.feedback.incorrect {
    color: var(--error);
    animation: feedbackPulse 0.3s ease;
}

.feedback.complete {
    color: var(--success);
    font-weight: 600;
    font-size: 0.95rem;
}

@keyframes feedbackPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ===== Move History Panel ===== */
.move-history-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.move-history-header {
    padding: 8px 12px;
    font-size: 0.65rem;
    font-weight: 300;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.move-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px;
    min-height: 80px;
    max-height: 200px;
    font-size: 0.8rem;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-hover) transparent;
}

.move-history-list::-webkit-scrollbar {
    width: 4px;
}

.move-history-list::-webkit-scrollbar-track {
    background: transparent;
}

.move-history-list::-webkit-scrollbar-thumb {
    background: var(--surface-hover);
    border-radius: 2px;
}

.move-history-empty {
    color: var(--text-faint);
    font-size: 0.75rem;
    text-align: center;
    padding: 16px 8px;
    font-style: italic;
}

.move-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 4px;
    border-radius: 4px;
    transition: background 0.15s;
}

.move-row:hover {
    background: var(--surface);
}

.move-number {
    font-size: 0.7rem;
    color: var(--text-faint);
    min-width: 22px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.move-san {
    font-size: 0.8rem;
    font-weight: 500;
    padding: 1px 5px;
    border-radius: 3px;
    min-width: 40px;
    font-family: 'Inter', monospace;
}

.move-san.white-move {
    color: var(--text);
}

.move-san.black-move {
    color: var(--text-secondary);
}

.move-san.correct-move {
    color: var(--success);
    background: var(--success-soft);
}

.move-san.wrong-attempt {
    color: var(--error);
    text-decoration: line-through;
    opacity: 0.7;
    font-size: 0.7rem;
}

.move-wrong-x {
    color: var(--error);
    font-weight: 700;
    font-size: 0.7rem;
    margin-left: -2px;
}

/* ===== Side Panel Action Buttons ===== */
.side-panel-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 300;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
}

.action-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

.action-btn:active {
    transform: translateY(0) scale(0.97);
}

/* Legacy info-bar (hidden in new layout but kept for JS compat) */
.info-bar {
    display: none;
}

.progress-badge {
    display: none;
}

/* ===== Settings Toggle ===== */
.settings-toggle {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: calc(20px + env(safe-area-inset-right));
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    background: var(--panel-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 300;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.25s var(--ease-smooth);
    z-index: 50;
}

.settings-toggle-icon {
    transition: transform 0.3s ease;
}

.settings-toggle:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--border-hover);
}

.settings-toggle:hover .settings-toggle-icon {
    transform: rotate(45deg);
}

.settings-toggle:active {
    transform: scale(0.97);
}

/* ===== Settings Panel (slide-out drawer) ===== */
.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    padding: 60px 20px 20px;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border);
    opacity: 0;
    visibility: hidden;
    transform: translateX(100%);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 150;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
}

.settings-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.settings-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.15);
    z-index: 140;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s var(--ease-smooth);
}

.settings-backdrop.open {
    opacity: 1;
    visibility: visible;
}

.settings-panel-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 0.85rem;
    font-weight: 300;
    color: var(--text-muted);
}

.setting-row:not(:last-child) {
    border-bottom: 1px solid var(--border);
}

.setting-row input[type="range"] {
    width: 80px;
    accent-color: var(--accent);
}

/* ===== Toggle Switch ===== */
.toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--surface);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.25s ease;
}

.toggle-track::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle input:checked + .toggle-track {
    background: var(--accent);
}

.toggle input:checked + .toggle-track::after {
    transform: translateX(16px);
}

/* ===== Arrow Assist SVG ===== */
#arrow-assist {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* ===== Opening Family Colors ===== */
.family-sicilian { background: #5b9bd5; }
.family-french { background: #5cb85c; }
.family-carokann { background: #7eb8e8; }
.family-italian { background: #6daed5; }
.family-spanish { background: #d9534f; }
.family-queens-gambit { background: #7eb8e8; }
.family-kings-indian { background: #5cb85c; }
.family-nimzo { background: #d9534f; }
.family-english { background: #93c5e8; }
.family-dutch { background: #6daed5; }
.family-scandinavian { background: #5cb85c; }
.family-pirc { background: #5b9bd5; }
.family-alekhine { background: #7eb8e8; }
.family-benoni { background: #7eb8e8; }
.family-grunfeld { background: #93c5e8; }
.family-slav { background: #5cb85c; }
.family-catalan { background: #6daed5; }
.family-london { background: #5cb85c; }
.family-vienna { background: #7eb8e8; }
.family-scotch { background: #d9534f; }
.family-petroff { background: #7eb8e8; }
.family-default { background: var(--accent); }

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .trainer-layout {
        flex-direction: column;
        align-items: center;
    }

    .side-panel {
        width: 100%;
        max-width: 500px;
        max-height: none;
    }

    .move-history-list {
        max-height: 120px;
    }

    .board-coords-ranks {
        display: none;
    }
}

@media (max-width: 600px) {
    .selection-container {
        max-width: 100%;
    }

    .selection-header h1 {
        font-size: 1.6rem;
    }

    .stats-summary {
        padding: 10px 16px;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .chessboard {
        width: 90vw;
        height: 90vw;
    }

    .board-coords-ranks {
        display: none;
    }

    .side-panel {
        width: 90vw;
        padding: 12px;
    }

    .opening-btn {
        border-radius: 8px;
    }
}

/* ========== WIDE MODAL ========== */

.modal.modal-wide {
    max-width: 700px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-header h3 {
    margin-bottom: 0;
}

.modal-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    transition: all 0.2s;
    line-height: 1;
}

.modal-close-btn:hover {
    color: var(--text);
    background: var(--surface);
}

.modal-top-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-field-name {
    flex: 1;
}

.modal-field-color {
    flex-shrink: 0;
}

/* ========== TABS ========== */

.modal-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--surface);
    padding: 4px;
    border-radius: 8px;
}

.modal-tab {
    flex: 1;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-tab:hover {
    color: var(--text);
}

.modal-tab.active {
    background: var(--accent-soft);
    color: var(--text);
}

.modal-tab-content {
    display: none;
}

.modal-tab-content.active {
    display: block;
}

/* ========== PARSE BUTTON ========== */

.btn-parse {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 8px 14px;
}

/* ========== EDITOR LAYOUT ========== */

.editor-layout {
    display: flex;
    gap: 16px;
    min-height: 300px;
}

.editor-board-container {
    width: 280px;
    flex-shrink: 0;
}

.editor-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 280px;
    height: 280px;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.editor-board {
    background: repeating-conic-gradient(
        var(--sq-dark, #94a7b8) 0% 25%,
        var(--sq-light, #eae6df) 0% 50%
    );
    background-size: 25% 25%;
}

.editor-board .chess-square {
    width: 35px;
    height: 35px;
}

.editor-board .chess-piece {
    width: 35px;
    height: 35px;
    background-size: cover;
}

.editor-tree-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.editor-tree {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    background: rgba(91, 155, 213, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    line-height: 1.9;
    font-size: 0.85rem;
    max-height: 260px;
}

.editor-tree-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.btn-small {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-small:hover {
    background: rgba(91, 155, 213, 0.08);
    color: var(--text);
}

/* Board editor on phones: the dedicated stacking rules live in the
   max-width:600px block further down (full-width board via padding-bottom:100%).
   Here we just lighten the modal chrome and make the pieces scale with their
   (now fluid) squares — the base 35px piece size would overflow shrunk cells. */
@media (max-width: 600px) {
    .modal-overlay { padding: 12px; }
    .modal { padding: 20px; }
    .editor-board .chess-piece { width: 100%; height: 100%; }
}

/* ========== TREE DISPLAY ========== */

.tree-preview {
    margin-top: 14px;
    background: rgba(91, 155, 213, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.tree-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    background: rgba(91, 155, 213, 0.03);
}

.tree-stats {
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text-muted);
}

.tree-preview-content {
    padding: 10px 12px;
    max-height: 180px;
    overflow-y: auto;
    line-height: 1.9;
    font-size: 0.85rem;
}

.tree-movenum {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-right: 2px;
}

.tree-move {
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--text);
    font-weight: 500;
    transition: all 0.15s;
    display: inline;
}

.tree-move:hover {
    background: rgba(91, 155, 213, 0.08);
    color: var(--accent-light, #7eb8e8);
}

.tree-move.active {
    background: var(--accent-soft);
    color: var(--accent-light, #7eb8e8);
    outline: 1px solid rgba(91, 155, 213, 0.4);
}

.tree-move.variation {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.tree-variation {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.tree-comment {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.75rem;
}

.tree-empty {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    padding: 30px 20px;
    font-style: italic;
}

/* ========== CONTEXT MENU ========== */

.tree-context-menu {
    position: fixed;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 0;
    min-width: 170px;
    z-index: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.ctx-item {
    padding: 8px 14px;
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}

.ctx-item:hover {
    background: rgba(91, 155, 213, 0.06);
}

.ctx-item.ctx-danger {
    color: #f87171;
}

.ctx-item.ctx-danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

/* ========== SETTINGS ADDITIONS ========== */

.setting-divider {
    height: 1px;
    background: var(--border);
    margin: 10px 0;
}

.setting-select {
    padding: 5px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
}

.setting-select:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-number {
    width: 50px;
    padding: 5px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.8rem;
    text-align: center;
}

.setting-number:focus {
    outline: none;
    border-color: var(--accent);
}

.depth-control {
    display: flex;
    align-items: center;
    gap: 6px;
}

.depth-control .hint {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ========== VARIATION TOGGLE & PICKER ========== */

.setting-row-full {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.variation-toggle-group {
    display: flex;
    gap: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    width: 100%;
}

.var-toggle-btn {
    flex: 1;
    padding: 6px 10px;
    background: var(--surface);
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
}

.var-toggle-btn:not(:last-child) {
    border-right: 1px solid var(--border);
}

.var-toggle-btn.active {
    background: var(--accent);
    color: #fff;
}

.var-toggle-btn:hover:not(.active) {
    background: var(--surface-hover);
    color: var(--text);
}

.var-toggle-btn:active {
    transform: scale(0.96);
}

/* Variation Picker Modal */
.variation-picker {
    max-width: 480px;
    width: 90vw;
}

.var-picker-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.var-picker-actions-top {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.var-picker-list {
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0;
}

.var-picker-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s var(--ease-smooth);
}

.var-picker-item:hover {
    background: var(--surface-hover);
    border-color: var(--border-hover);
}

.var-picker-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.var-picker-item-label {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.4;
}

.var-picker-item-label .branch-name {
    font-weight: 500;
    display: block;
    margin-bottom: 2px;
}

.var-picker-item-label .branch-moves {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
}

/* ========== DRAG GHOST ========== */

.drag-ghost {
    pointer-events: none;
    z-index: 1000;
    opacity: 0.85;
}

/* ========== RESPONSIVE EDITOR ========== */

@media (max-width: 600px) {
    .modal.modal-wide {
        max-width: 100%;
        padding: 20px;
    }

    .modal-top-row {
        flex-direction: column;
        gap: 8px;
    }

    .editor-layout {
        flex-direction: column;
    }

    .editor-board-container {
        width: 100%;
    }

    .editor-board {
        width: 100%;
        height: 0;
        padding-bottom: 100%;
    }

    .editor-board .chess-square {
        width: auto;
        height: auto;
    }

    .editor-tree {
        max-height: 150px;
    }

    /* Comfortable thumb target for the in-lesson action buttons. */
    .learn-btn { min-height: 38px; }
}

/* ========== PERFORMANCE HINTS ========== */

#arrow-assist {
    will-change: contents;
}

.board-feedback-overlay {
    will-change: opacity;
}

.board-checkmark {
    will-change: transform, opacity;
}

/* ========== MICRO-INTERACTIONS ========== */

/* Button press scale for all interactive buttons */
.btn-primary:active,
.btn-secondary:active,
.btn-small:active,
.btn-parse:active,
.color-btn:active,
.modal-color-btn:active,
.add-line-btn:active,
.opening-btn:active,
.modal-tab:active,
.modal-close-btn:active {
    transform: scale(0.97);
}

/* Feedback message slide transition */
.feedback {
    transition: all 0.3s var(--ease-smooth);
    transform: translateY(0);
}

.feedback.slide-in {
    animation: feedbackSlideIn 0.3s ease forwards;
}

@keyframes feedbackSlideIn {
    0% { opacity: 0; transform: translateY(4px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Streak counter pulse on increment */
.streak-count.pulse {
    animation: streakPulse 0.35s ease;
}

@keyframes streakPulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Move history entry slide-in animation */
.move-row {
    animation: moveSlideIn 0.25s ease;
}

@keyframes moveSlideIn {
    0% { opacity: 0; transform: translateX(12px); }
    100% { opacity: 1; transform: translateX(0); }
}

/* Progress ring gradient stroke */
.progress-ring-fill {
    stroke-width: 2.5;
}

.progress-ring-bg {
    stroke-width: 2.5;
}

/* Settings section labels */
.settings-section-label {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 12px 0 4px;
}

.settings-section-label:first-child {
    padding-top: 0;
}

/* ========== THEME TOGGLE ========== */

/* Theme toggle provided by base.css */

/* === Theme-specific overrides === */

/* Light theme */
body.theme-light {
    background: #f0f4f8;
}
body.theme-light .background-image {
    display: none;
}
body.theme-light .background-overlay {
    display: none;
}

/* Dark theme */
body.theme-dark {
    background: #050508;
}
body.theme-dark .background-image {
    opacity: 0.15;
    filter: brightness(0.4) saturate(0.5);
}
body.theme-dark .background-overlay {
    background: rgba(0, 0, 0, 0.5);
}
body.theme-dark .modal {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
body.theme-dark .settings-panel {
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
}
body.theme-dark .chessboard {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ========== REDUCED MOTION ========== */
/* Respect the OS "reduce motion" setting: keep essential feedback (color/
   opacity) but disable large transforms, confetti, and looping pulses. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.08s !important;
        scroll-behavior: auto !important;
    }
    .confetti-particle {
        display: none !important;
    }
    .nav-btn:hover,
    .action-btn:hover,
    .opening-btn:active,
    .modal-tab:active,
    .modal-close-btn:active {
        transform: none !important;
    }
}

/* ========== Learn mode (lesson experience) ========== */

/* Learn / Quiz segmented toggle in the side panel */
.mode-toggle-group {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 10px);
    overflow: hidden;
    margin-bottom: 4px;
}
.mode-toggle-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 10px;
    background: var(--surface);
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s var(--ease-smooth), color 0.15s var(--ease-smooth);
}
.mode-toggle-btn svg { flex-shrink: 0; opacity: 0.9; }
.mode-toggle-btn:not(:last-child) { border-right: 1px solid var(--border); }
.mode-toggle-btn.active { background: var(--accent); color: #fff; }
.mode-toggle-btn:hover:not(.active) { background: var(--surface-hover); color: var(--text); }
.mode-toggle-btn:active { transform: scale(0.985); }

/* Learn-mode status + controls */
.learn-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 10px);
    background: var(--surface);
    padding: 10px 12px;
    animation: learnSlideIn 0.25s var(--ease-smooth, ease) both;
}
@keyframes learnSlideIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.learn-status {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-light);
    letter-spacing: 0.02em;
    font-variant-numeric: tabular-nums;
}
.learn-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.learn-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    font-size: 12px;
}
.learn-quiz-cta {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.learn-quiz-cta:hover { background: var(--accent-light); }

/* Lesson text (AI explanation of the current move) */
.learn-lesson {
    font-size: 0.8rem;
    line-height: 1.55;
    color: var(--text-secondary);
    border-top: 1px dashed var(--border);
    padding-top: 8px;
    max-height: 150px;
    overflow-y: auto;
    animation: learnSlideIn 0.2s var(--ease-smooth, ease) both;
}
.learn-lesson .lesson-move {
    color: var(--text);
    font-weight: 600;
}
.learn-lesson .lesson-loading {
    color: var(--text-faint);
    font-style: italic;
}

/* ========== Highlight styles (global pref: html[data-hl]) ========== */
/* 'classic' (or no attribute) keeps the default rules above. */

html[data-hl="glow"] .chessboard .chess-square.last-move,
html[data-hl="glow"] .chessboard .chess-square.last-move.light,
html[data-hl="glow"] .chessboard .chess-square.last-move.dark {
    background: rgba(255, 200, 87, 0.16) !important;
    box-shadow: inset 0 0 16px rgba(255, 200, 87, 0.55);
}

html[data-hl="frame"] .chessboard .chess-square.last-move,
html[data-hl="frame"] .chessboard .chess-square.last-move.light,
html[data-hl="frame"] .chessboard .chess-square.last-move.dark {
    background: transparent !important;
    box-shadow: inset 0 0 0 3px rgba(255, 200, 87, 0.85);
}

html[data-hl="minimal"] .chessboard .chess-square.last-move,
html[data-hl="minimal"] .chessboard .chess-square.last-move.light,
html[data-hl="minimal"] .chessboard .chess-square.last-move.dark {
    background: rgba(255, 213, 79, 0.18) !important;
    box-shadow: none;
}

/* Learn-mode line picker */
.learn-line-select {
    width: 100%;
    min-width: 0;
    text-overflow: ellipsis;
}

/* Explore mode (pause + evaluate inside a lesson) */
.explore-controls { animation: learnSlideIn 0.2s var(--ease-smooth, ease) both; }
.explore-eval {
    font-size: 0.82rem;
    color: var(--text-secondary);
    border-top: 1px dashed var(--border);
    padding-top: 8px;
    font-variant-numeric: tabular-nums;
    animation: learnSlideIn 0.2s var(--ease-smooth, ease) both;
}
.explore-eval .ev-score {
    font-weight: 700;
    color: var(--accent-light);
    font-size: 0.92rem;
}
.explore-eval .ev-dim { color: var(--text-faint); }
.explore-eval strong { color: var(--text); }

/* ===== Floating home (header removed) ===== */
.trainer-float-home {
    position: fixed;
    top: calc(14px + env(safe-area-inset-top));
    left: calc(14px + env(safe-area-inset-left));
    z-index: 200;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel-bg);
    color: var(--text-muted);
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.15s var(--ease-smooth);
}
.trainer-float-home:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ===== Browse mode (free stepping through the line) ===== */
.browse-controls { animation: learnSlideIn 0.2s var(--ease-smooth, ease) both; }
.browse-step { font-weight: 600; }

/* ===== Mistakes drill ===== */
.mistakes-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--error);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

/* ===========================================================================
   Selection landing — aesthetic pass (DNA glyphs + refined cards)
   =========================================================================== */

/* DNA glyph slot: invisible until computed, then fades in */
.opening-dna {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 12px;
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 0.45s var(--ease-smooth), transform 0.45s var(--ease-smooth);
}
.opening-dna.filled { opacity: 1; transform: scale(1); }

/* Cards: airier, sharper typography, staggered entrance */
.opening-list .opening-btn {
    animation: trainerCardIn 0.38s var(--ease-smooth) both;
}
.opening-list .opening-btn:nth-child(1) { animation-delay: 0.02s; }
.opening-list .opening-btn:nth-child(2) { animation-delay: 0.06s; }
.opening-list .opening-btn:nth-child(3) { animation-delay: 0.10s; }
.opening-list .opening-btn:nth-child(4) { animation-delay: 0.14s; }
.opening-list .opening-btn:nth-child(5) { animation-delay: 0.18s; }
.opening-list .opening-btn:nth-child(6) { animation-delay: 0.22s; }
.opening-list .opening-btn:nth-child(n+7) { animation-delay: 0.26s; }
@keyframes trainerCardIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.opening-card-content { padding: 14px 16px; gap: 6px; }

.opening-name {
    font-family: var(--font-brand);
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
}

.opening-eco {
    font-size: 0.64rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
}

/* stripe keeps its family/custom color but fades at the ends (mask) */
.opening-color-stripe {
    width: 3px;
    -webkit-mask-image: linear-gradient(180deg, transparent 0%, #000 18%, #000 82%, transparent 100%);
    mask-image: linear-gradient(180deg, transparent 0%, #000 18%, #000 82%, transparent 100%);
}

/* mastery bar: luminous fill */
.mastery-bar-fill {
    background: linear-gradient(90deg, var(--accent) 0%, var(--accent-light) 100%) !important;
    box-shadow: 0 0 6px var(--accent-glow, rgba(91, 155, 213, 0.4));
}

/* actions reveal on hover only — quieter resting state */
.opening-card-actions { opacity: 0; transition: opacity 0.2s var(--ease-smooth); }
.opening-btn:hover .opening-card-actions { opacity: 1; }

/* category headers as fine dividers */
.opening-category h3 {
    display: flex;
    align-items: center;
    gap: 12px;
}
.opening-category h3::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--border), transparent);
}

/* hero header: a touch more presence */
.selection-header h1 { font-size: 2.5rem; font-weight: 600; }
.selection-header p {
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 0.72rem;
    color: var(--text-faint);
}

/* stats bar: quiet glass, gently alive */
.stats-summary {
    border-radius: 999px;
    padding: 12px 28px;
    transition: border-color 0.3s var(--ease-smooth);
}
.stats-summary:hover { border-color: var(--border-hover); }
.stat-value {
    font-family: var(--font-brand);
    font-variant-numeric: tabular-nums;
}

/* search: focus glow consistent with the site */
.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow, rgba(91, 155, 213, 0.18));
}
