/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-panel: #1f2940;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent: #4ecca3;
    --accent-hover: #3db892;
    --light-square: #f0d9b5;
    --dark-square: #b58863;
    --highlight: rgba(255, 255, 0, 0.4);
    --valid-move: rgba(78, 204, 163, 0.5);
    --last-move: rgba(155, 199, 0, 0.4);
    --error: #e74c3c;
    --success: #2ecc71;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header h1 {
    font-size: 1.5rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.back-button {
    background: linear-gradient(45deg, #4ecca3, #3db892);
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.back-button:hover {
    background: linear-gradient(45deg, #3db892, #4ecca3);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(78, 204, 163, 0.4);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Intro Section */
.intro {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.intro h2 {
    color: #fff;
    margin-bottom: 15px;
}

.intro p {
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.6;
}

/* Main Layout */
main {
    display: grid;
    grid-template-columns: auto 350px;
    gap: 30px;
    align-items: start;
}

@media (max-width: 1000px) {
    main {
        grid-template-columns: 1fr;
    }
}

/* Game Area */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Chess Board */
.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.board-wrapper {
    display: flex;
    align-items: center;
}

.chess-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: min(520px, 85vw);
    height: min(520px, 85vw);
    aspect-ratio: 1 / 1;
    border: 4px solid var(--bg-panel);
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(54px, 9vw);
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background-color 0.15s;
    overflow: hidden;
    aspect-ratio: 1 / 1;
}

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

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

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

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

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

.square.valid-move.has-piece::after {
    width: 100%;
    height: 100%;
    background: transparent;
    border: 4px solid var(--valid-move);
    border-radius: 0;
    box-sizing: border-box;
}

.square:hover {
    filter: brightness(1.1);
}

.piece {
    pointer-events: none;
    line-height: 1;
}

.piece.white-piece {
    color: #fff;
    text-shadow: 
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000,
        0 2px 4px rgba(0, 0, 0, 0.4);
}

.piece.black-piece {
    color: #1a1a1a;
    text-shadow: 
        -1px -1px 0 #666,
        1px -1px 0 #666,
        -1px 1px 0 #666,
        1px 1px 0 #666,
        0 2px 4px rgba(0, 0, 0, 0.4);
}

/* Board Labels */
.board-labels {
    display: flex;
    color: rgba(255, 255, 255, 0.6);
    font-size: 14px;
    font-weight: 600;
}

.board-labels.top,
.board-labels.bottom {
    width: min(520px, 85vw);
    justify-content: space-around;
    padding: 4px 0;
}

.board-labels.left,
.board-labels.right {
    flex-direction: column;
    height: min(520px, 85vw);
    justify-content: space-around;
    padding: 0 8px;
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 520px;
}

.mode-selector {
    display: flex;
    gap: 10px;
}

.mode-btn {
    flex: 1;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover {
    background: rgba(78, 204, 163, 0.2);
}

.mode-btn.active {
    background: var(--accent);
    color: #1a1a2e;
}

.nav-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.nav-btn {
    padding: 10px 16px;
    font-size: 0.95rem;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

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

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.panel h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: #fff;
}

/* Opening Selector */
.opening-selector select {
    width: 100%;
    padding: 10px 12px;
    font-size: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 10px;
}

.opening-selector select option {
    background: #2a2a4a;
    color: #fff;
}

.opening-selector select:focus {
    outline: none;
    border-color: var(--accent);
}

.opening-selector select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Opening Info */
.opening-info p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.95rem;
}

.eco-badge {
    display: inline-block;
    margin-top: 10px;
    padding: 4px 10px;
    background: var(--accent);
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
    border-radius: 4px;
}

/* Move List */
.move-list {
    display: table;
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
}

.move-list::-webkit-scrollbar {
    width: 6px;
}

.move-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.move-list::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

.move-row {
    display: table-row;
}

.move-number {
    display: table-cell;
    color: rgba(255, 255, 255, 0.5);
    padding: 4px 8px 4px 0;
    white-space: nowrap;
    width: 30px;
}

.move {
    display: table-cell;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
    width: 50%;
}

.move:hover {
    background: rgba(255, 255, 255, 0.1);
}

.move.current {
    background: var(--accent);
    color: #1a1a2e;
    font-weight: 600;
}

.move.white-move {
    color: #fff;
}

.move.black-move {
    color: rgba(255, 255, 255, 0.7);
}

/* Training Panel */
.training-panel {
    border: 2px solid var(--accent);
}

.training-prompt {
    font-size: 1.1rem;
    margin-bottom: 15px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    text-align: center;
    color: #fff;
}

.training-feedback {
    padding: 10px;
    border-radius: 6px;
    text-align: center;
    margin-bottom: 15px;
    font-weight: 600;
    min-height: 42px;
}

.training-feedback.correct {
    background: rgba(46, 204, 113, 0.2);
    color: var(--success);
}

.training-feedback.incorrect {
    background: rgba(231, 76, 60, 0.2);
    color: var(--error);
}

.training-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 15px;
    font-size: 1.2rem;
    color: #fff;
}

.hint-btn {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.hint-btn:hover {
    background: var(--accent);
    color: #1a1a2e;
}

/* Explanation Panel */
.explanation-panel p {
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

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

.pulse {
    animation: pulse 0.3s ease-in-out;
}
