/**
 * Chess Pattern Recognition Trainer Styles
 * 
 * Table of Contents:
 * 1. Root & Base Styles
 * 2. Layout Components
 * 3. Header Components
 * 4. Chess Board
 * 5. Puzzle Interface
 * 6. Modal Components
 * 7. Form Elements
 * 8. Button Styles
 * 9. Info & Status Elements
 * 10. Utility Classes
 * 11. Animations
 * 12. Media Queries
 * 13. Accessibility
 */

/* 1. Root & Base Styles
-------------------------------------------------- */
/* Core variables and base element styling */
html,
body {
    min-height: 100vh;
    color-scheme: light dark;
}

body {
    display: flex;
    flex-direction: column;
    background-color: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
}

:root {
    --accessibility-focus: 0 0 0 3px rgba(0, 123, 255, 0.5);
    --min-contrast-ratio: 4.5;
    --bs-body-bg: #fff;
    --bs-body-color: #212529;
    --board-max-width: 600px;
    --puzzle-bg: rgba(255, 255, 255, 0.05);
    --control-bg: rgba(0, 0, 0, 0.2);
    --wrapper-bg: rgba(255, 255, 255, 0.05);
    /* Layout */
    --header-height-mobile: 60px;
    --header-height-desktop: 70px;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;

    /* Colors */
    --color-bg-dark: var(--bs-dark);
    --color-bg-light: var(--bs-light);
    --color-text-primary: #212529;
    --color-text-secondary: #6c757d;
    --color-border: #dee2e6;
    --color-overlay: rgba(0, 0, 0, 0.2);
    --color-shadow: rgba(0, 0, 0, 0.15);

    /* Components */
    --border-radius-sm: 0.25rem;
    --border-radius-md: 0.5rem;
    --border-radius-lg: 1rem;
    --shadow-sm: 0 1px 3px var(--color-shadow);
    --shadow-md: 0 0.5rem 1rem var(--color-shadow);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;

    /* Accessibility */
    --focus-ring: 0 0 0 3px rgba(13, 110, 253, 0.5);

    /* Typography */
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.25rem;
    --font-monospace: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* Add dark mode support */
@media (prefers-color-scheme: dark) {
    /* Copy dark mode styles from engine-trainer.css */
}

/* 2. Layout Components
-------------------------------------------------- */
/* Core structural elements and containers */
.content-wrapper {
    flex: 1 0 auto;
}

/* 3. Header Components
-------------------------------------------------- */
/* Site branding and navigation elements */
.site-header {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    min-height: var(--header-height-mobile);
    background-color: var(--color-bg-dark);
}

.site-header .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

.header-logo {
    height: 32px;
    width: 32px;
    min-width: 32px;
    min-height: 32px;
    object-fit: contain;
    display: block;
}

.header-brand {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-brand:hover {
    opacity: 0.9;
    text-decoration: none;
    color: inherit;
}

.brand-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    margin: 0;
    padding: 0;
    white-space: nowrap;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 500;
    white-space: nowrap;
    color: white;
    margin: 0;
    padding: 0;
}

@media (min-width: 768px) {
    .site-header {
        padding: 0.75rem 0;
        min-height: var(--header-height-desktop);
    }

    .header-logo {
        height: 40px;
        width: 40px;
        min-width: 40px;
        min-height: 40px;
    }
}

@media (max-width: 576px) {
    .header-logo {
        height: 28px;
        width: 28px;
        min-width: 28px;
        min-height: 28px;
    }

    .app-title,
    .brand-name {
        font-size: 0.9rem;
    }
}

/* 4. Chess Board
-------------------------------------------------- */
/* Board container and chess-specific styles */
.board-container {
    position: relative;
    width: 100%;
    max-width: var(--board-max-width);
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto;
}

/* 5. Puzzle Interface
-------------------------------------------------- */
/* Puzzle controls, feedback, and progress indicators */
.puzzle-controls {
    background: #f8f9fa;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    padding: 1.25rem;
    margin: 1.5rem 0;
}

.puzzle-feedback {
    display: none;
    font-size: 1.1rem;
    font-weight: 500;
    color: #000000;
    margin-bottom: 1rem;
}

.controls-row {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
}

.btn-control {
    min-width: 120px;
    padding: 0.5rem 1rem;
    font-weight: 500;
}

/* Puzzle Information & Progress */
.progress-section {
    margin-top: 1rem;
}

.progress {
    position: relative;
}

.progress-compact {
    max-width: var(--board-max-width);
    margin: 1rem auto;
    width: 100%;
    padding: 0;
    /* Remove any padding */
}

.progress-compact .progress {
    height: 1.5rem;
    border-radius: 0.25rem;
    background-color: rgba(0, 0, 0, 0.1);
    overflow: hidden;
    padding: 0;
    /* Remove any padding */
}

.progress-compact .progress-bar {
    height: 100%;
    padding: 0;
    border-radius: 0;
    /* Remove border radius from progress bar */
    color: transparent;
    min-width: 0;
    /* Ensure it can start from 0% */
    transition: width 0.3s ease;
}

/* 6. Modal Components
-------------------------------------------------- */
/* Modal dialogs and their internal layouts */
.modal-header {
    border-bottom: 2px solid #dee2e6;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.puzzle-details label {
    color: #6c757d;
    font-size: 0.875rem;
}

.fen-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #f8f9fa;
    padding: 0.5rem;
    border-radius: 4px;
}

.fen-field code {
    flex: 1;
    font-size: 0.8rem;
    word-break: break-all;
}

/* Session Completion Modal Styles */
.modal#sessionCompletionModal .modal-header {
    border-bottom: none;
    padding-bottom: 0;
}

.modal#sessionCompletionModal .modal-body {
    padding: 1.5rem;
}

.modal#sessionCompletionModal .stats-summary {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 0.5rem;
}

.modal#sessionCompletionModal .stats-summary .border {
    border-color: #dee2e6;
    background: #fff;
}

/* Welcome Modal Styles */
#welcomeModal .modal-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.5rem 1rem 0.5rem;
}

#welcomeModal .header-brand {
    margin-bottom: 0.75rem;
}

#welcomeModal .modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
    padding: 0;
    color: #212529;
}

#welcomeModal .brand-name {
    font-size: 1.1rem;
}

#welcomeModal .modal-body {
    padding: 1.5rem;
}

#welcomeModal .quick-start-section {
    max-width: 450px;
    margin: 0 auto 2rem;
}

#welcomeModal .quick-start {
    padding: 1rem;
    font-weight: 500;
    transition: all 0.2s;
}

#welcomeModal .quick-start:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#welcomeModal .helpful-tips {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 0.5rem;
}

#welcomeModal .helpful-tips i {
    font-size: 0.9rem;
}

@media (max-width: 576px) {
    #welcomeModal .modal-header {
        padding: 1rem 0.75rem 0.25rem;
    }

    #welcomeModal .modal-title {
        font-size: 1.25rem;
    }

    #welcomeModal .brand-name {
        font-size: 1rem;
    }

    #welcomeModal .modal-body {
        padding: 1rem;
    }

    #welcomeModal .quick-start {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* 7. Form Elements
-------------------------------------------------- */
/* Input fields, selectors, and form-related components */
.form-check {
    text-align: left;
    font-size: 0.9rem;
}

.form-select {
    background-color: #fff;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

.form-select:focus {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, .25);
}

/* 8. Button Styles
-------------------------------------------------- */
/* Button variations, states, and interactions */
.btn {
    transition: all 0.2s ease-in-out;
}

.btn:active {
    transform: scale(0.98);
}

.btn-group .btn {
    margin: 0 2px;
}

/* 9. Info & Status Elements
-------------------------------------------------- */
/* Information displays, timers, and status indicators */
.puzzle-info-bar {
    position: sticky;
    z-index: 999;
    top: 48px;
}

.puzzle-info-bar .container {
    max-width: var(--board-max-width);
    width: 100%;
    margin: 0 auto;
    padding: 0;
}

.puzzle-quick-info {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    min-width: 0;
    /* Allow text truncation */
}

.puzzle-id {
    color: #000000;
    font-family: monospace;
}

.puzzle-pattern {
    color: #000000;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    /* Adjust based on your needs */
}

.puzzle-timer .puzzle-completion {
    font-family: monospace;
    font-weight: 600;
    color: #000000;
}

/* Update Puzzle Info Bar styles */
.info-label {
    font-size: 0.75rem;
    color: #000000;
}

.btn-link {
    color: #000000;
    text-decoration: none;
}

.btn-link:hover {
    color: #212529;
}

/* Timer & Statistics */
.timer-container {
    font-family: monospace;
    font-size: 1.1rem;
}

#puzzleTimer {
    font-weight: bold;
}

#puzzleTimer.warning {
    color: var(--bs-danger);
    animation: pulse 1s infinite;
}

#resetStats {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* 10. Utility Classes
-------------------------------------------------- */
/* Helper classes and common utilities */
.copy-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.copy-btn:active {
    transform: scale(0.98);
}

/* FEN Display */
.fen-display {
    background: #f8f9fa;
    border-radius: 4px;
    padding: 0.75rem;
    font-family: monospace;
    margin-top: 1rem;
    font-size: 0.8rem;
}

.fen-display code {
    background: #fff;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    border: 1px solid #dee2e6;
    word-break: break-all;
    color: #212529;
}

/* Add styles for the stats modal */
.stats-grid {
    padding: 0.5rem;
}

.stats-grid i {
    font-size: 1.1rem;
    opacity: 0.7;
}

.modal-body .btn-outline-danger {
    padding: 0.5rem 1.5rem;
}

/* Controls Bar - consolidate duplicate selectors */
.controls-bar {
    background: #fff;
    padding: 0.5rem;
    border-radius: 0.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.controls-bar .btn {
    width: 38px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.controls-bar .btn i {
    font-size: 1.1rem;
}

.controls-bar .btn-outline-warning:hover {
    color: #000;
    background-color: #ffc107;
    border-color: #ffc107;
}

/* Update control icon sizes */
.nav-bar {
    max-width: 600px;
    /* Match board container width */
    margin: 0 auto;
}

.nav-bar .btn i {
    font-size: 1.25rem;
    /* Increase from default size */
}

.puzzle-info-bar .btn i {
    font-size: 1.25rem;
    /* Match the size for consistency */
}

/* 11. Animations
-------------------------------------------------- */
/* Keyframe definitions and animation utilities */
@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* 12. Media Queries
-------------------------------------------------- */
/* Responsive design breakpoints and adjustments */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }

    .card {
        margin-bottom: 1rem;
    }

    .board-container,
    .puzzle-info-bar .container,
    .progress-compact,
    .nav-bar {
        max-width: 100%;
        padding: 0;
        /* Remove padding on mobile */
    }

    .progress-compact {
        margin: 1rem 15px;
        /* Add margin instead of padding */
    }
}

@media (max-width: 576px) {
    .puzzle-pattern {
        max-width: 120px;
        /* Reduced to accommodate labels */
    }

    .puzzle-quick-info {
        gap: 0.5rem;
    }

    .puzzle-info-bar .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .board-container,
    .puzzle-info-bar .container,
    .progress-compact,
    .nav-bar {
        padding: 0;
    }
}

/* Update Feedback Message styles */
.feedback-message {
    margin: 0;
    text-align: center;
    font-size: 1rem;
    font-weight: 500;
    flex: 1;
    padding: 0 1rem;
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .feedback-message {
        font-size: 0.9rem;
        padding: 0 0.5rem;
    }

    .puzzle-info-bar .container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

@media (max-width: 576px) {
    .puzzle-pattern {
        max-width: 100px;
    }

    .feedback-message {
        font-size: 0.85rem;
        padding: 0 0.25rem;
    }

    .puzzle-info-bar .gap-3 {
        gap: 0.5rem;
    }
}

/* 13. Accessibility
-------------------------------------------------- */
/* Focus states and screen reader enhancements */
/* Add focus styles for accessibility */
button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: var(--accessibility-focus);
    outline-offset: 2px;
}

/* Error States */
.alert {
    margin: 1rem 0;
    display: flex;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

.alert.d-none {
    opacity: 0;
}

.alert-danger {
    background-color: #f8d7da;
    border-color: #f5c2c7;
    color: #842029;
}

/* Improve focus visibility */
:focus-visible {
    outline: var(--accessibility-focus);
    outline-offset: 2px;
}

[role="button"]:focus:not(:focus-visible) {
    outline: none;
}

/* Container size consistency */
.board-container,
.puzzle-info-bar .container,
.progress-compact,
.av-bar,
.controls-wrapper {
    max-width: var(--board-max-width);
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.modal-content {
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-md);
}