/* CSS Variables for theming */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --background-color: #ecf0f1;
    --card-background: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --border-color: #bdc3c7;
    --light-square: #f0d9b5;
    --dark-square: #b58863;
    --highlight-square: rgba(255, 255, 0, 0.5);
    --hint-square: rgba(0, 255, 0, 0.4);
    --selected-square: rgba(52, 152, 219, 0.5);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
    --border-radius: 12px;
    --transition: all 0.3s ease;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--primary-color) 0%, #1a252f 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header styles */
header {
    text-align: center;
    padding: 30px 20px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

header .subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Main content */
main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

/* Controls panel */
.controls-panel {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow-md);
}

.control-group {
    margin-bottom: 25px;
}

.control-group:last-of-type {
    margin-bottom: 30px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.control-group small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 8px;
}

/* Select dropdown */
select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%232c3e50' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
}

select:hover, select:focus {
    border-color: var(--secondary-color);
    outline: none;
}

/* Piece selector */
.piece-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.piece-btn {
    width: 50px;
    height: 50px;
    font-size: 1.8rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.piece-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.piece-btn.active {
    border-color: var(--secondary-color);
    background: rgba(52, 152, 219, 0.1);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

/* Rating slider */
.rating-slider {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
    appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--secondary-color);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.rating-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#rating-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary-color);
}

#rating-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 4px 12px;
    background: var(--background-color);
    border-radius: 20px;
}

/* Color selector */
.color-selector {
    display: flex;
    gap: 15px;
}

.color-btn {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 500;
}

.color-btn:hover {
    border-color: var(--secondary-color);
}

.color-btn.active {
    border-color: var(--secondary-color);
    background: rgba(52, 152, 219, 0.1);
}

.color-icon {
    font-size: 1.5rem;
}

.white-icon {
    color: #333;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.black-icon {
    color: #333;
}

/* Primary button */
.primary-btn {
    width: 100%;
    padding: 15px 30px;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--secondary-color), #2980b9);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: var(--shadow-sm);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.primary-btn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.2rem;
}

/* Board section */
.board-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.board-container {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: var(--shadow-md);
}

.board-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.board-labels {
    display: flex;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
}

.board-labels.top,
.board-labels.bottom {
    justify-content: space-around;
    padding: 0 30px;
    margin: 5px 0;
}

.board-labels.top span,
.board-labels.bottom span {
    width: calc(100% / 8);
    text-align: center;
}

.board-labels.left,
.board-labels.right {
    flex-direction: column;
    justify-content: space-around;
    height: min(400px, 80vw);
}

.board-labels.left span,
.board-labels.right span {
    height: calc(100% / 8);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Chess board */
.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(400px, 80vw);
    height: min(400px, 80vw);
    border: 3px solid var(--primary-color);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(3rem, 8vw);
    cursor: pointer;
    transition: background-color 0.15s ease;
    user-select: none;
    position: relative;
}

.square.light {
    background-color: var(--light-square);
}

.square.dark {
    background-color: var(--dark-square);
}

.square.selected {
    background-color: var(--selected-square) !important;
}

.square.highlight {
    background-color: var(--highlight-square) !important;
}

.square.hint {
    background-color: var(--hint-square) !important;
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

.square.valid-capture::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    box-sizing: border-box;
}

.piece {
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease;
}

.piece:hover {
    transform: scale(1.1);
}

.piece.white {
    color: #fff;
    text-shadow: 0 0 3px #000, 0 0 5px rgba(0, 0, 0, 0.5);
}

.piece.black {
    color: #000;
}

/* Puzzle info cards */
.puzzle-info {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.info-card {
    background: var(--card-background);
    border-radius: 8px;
    padding: 15px 25px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    min-width: 100px;
}

.info-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 5px;
    letter-spacing: 0.5px;
}

.info-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Action buttons */
.action-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.secondary-btn {
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--card-background);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}

.secondary-btn:hover:not(:disabled) {
    border-color: var(--secondary-color);
    background: rgba(52, 152, 219, 0.05);
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Solution panel */
.solution-panel {
    grid-column: 1 / -1;
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow-md);
    display: none;
}

.solution-panel.visible {
    display: block;
}

.solution-panel h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 1.2rem;
}

.solution-moves {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.move-badge {
    background: linear-gradient(135deg, var(--secondary-color), #2980b9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: var(--shadow-sm);
}

.solution-explanation {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.7;
    padding: 15px;
    background: var(--background-color);
    border-radius: 8px;
}

/* Status panel */
.status-panel {
    grid-column: 1 / -1;
}

.status-message {
    background: var(--card-background);
    border-radius: var(--border-radius);
    padding: 20px;
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.status-message.success {
    background: linear-gradient(135deg, rgba(39, 174, 96, 0.1), rgba(39, 174, 96, 0.05));
    border: 2px solid var(--success-color);
    color: var(--success-color);
}

.status-message.error {
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.1), rgba(231, 76, 60, 0.05));
    border: 2px solid var(--accent-color);
    color: var(--accent-color);
}

.status-message.info {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.1), rgba(52, 152, 219, 0.05));
    border: 2px solid var(--secondary-color);
    color: var(--secondary-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: auto;
}

footer p {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
}

footer a {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: white;
    text-decoration: underline;
}

/* Responsive design */
@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        order: 2;
    }

    .board-section {
        order: 1;
    }

    .solution-panel {
        order: 3;
    }

    .status-panel {
        order: 4;
    }
}

@media (max-width: 600px) {
    header h1 {
        font-size: 1.8rem;
    }

    header .subtitle {
        font-size: 0.95rem;
    }

    .app-container {
        padding: 15px;
    }

    .controls-panel,
    .board-container {
        padding: 15px;
    }

    .piece-btn {
        width: 45px;
        height: 45px;
        font-size: 1.5rem;
    }

    .color-selector {
        flex-direction: column;
    }

    .puzzle-info {
        flex-direction: column;
        align-items: center;
    }

    .info-card {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
    }

    .secondary-btn {
        width: 100%;
        justify-content: center;
    }

    .board-labels.left,
    .board-labels.right {
        display: none;
    }

    .square {
        font-size: min(2.5rem, 10vw);
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.solution-panel.visible {
    animation: fadeIn 0.3s ease;
}

.status-message.success,
.status-message.error {
    animation: fadeIn 0.3s ease;
}

/* Checkmate highlight */
.square.checkmate {
    animation: pulse 0.5s ease infinite;
    background-color: rgba(231, 76, 60, 0.5) !important;
}
