/* BlunderFree Chess Trainer - Styles */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --success: #4ade80;
    --warning: #fbbf24;
    --error: #ef4444;
    --white-eval: #f0f0f0;
    --black-eval: #2d2d2d;
    --board-size: min(540px, calc(100vh - 100px), 50vw);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 12px;
}

.container {
    max-width: 950px;
    width: 100%;
    text-align: center;
}

header {
    margin-bottom: 6px;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 4px;
    background: linear-gradient(90deg, var(--accent), #ff6b8a);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.main-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.board-column {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.moves-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 200px;
}

.actions-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 220px;
    height: var(--board-size);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Eval Bar */
.eval-bar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.eval-bar {
    width: 20px;
    height: var(--board-size);
    background: var(--black-eval);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.eval-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: var(--white-eval);
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.eval-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 6px;
    min-width: 40px;
    text-align: center;
}

/* Board */
.board-wrapper {
    position: relative;
    width: var(--board-size);
    height: var(--board-size);
}

.board {
    width: 100%;
    height: 100%;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    touch-action: none;
}

.board-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.board-overlay.error {
    animation: flash-error 0.5s ease;
}

.board-overlay.thinking {
    background: rgba(233, 69, 96, 0.1);
}

/* Move History */
.move-history-container {
    width: 100%;
    height: calc(var(--board-size) - 50px);
    background: var(--bg-tertiary);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.move-history-header {
    padding: 10px 12px;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.move-history {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.85rem;
}

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

.move-history::-webkit-scrollbar-track {
    background: transparent;
}

.move-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.move-row {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 2px;
}

.move-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

.move-number {
    color: var(--text-secondary);
    min-width: 28px;
    font-size: 0.8rem;
}

.move-white, .move-black {
    flex: 1;
    padding: 2px 4px;
    border-radius: 3px;
    cursor: default;
}

.move-white {
    color: var(--text-primary);
}

.move-black {
    color: var(--text-secondary);
}

.move-white.last-move, .move-black.last-move {
    background: rgba(233, 69, 96, 0.3);
    color: var(--text-primary);
}

.move-history-empty {
    color: var(--text-secondary);
    font-style: italic;
    padding: 16px;
    text-align: center;
    font-family: inherit;
}

@keyframes flash-error {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(239, 68, 68, 0.3); }
}

/* Highlight squares */
.highlight-move {
    box-shadow: inset 0 0 0 4px rgba(74, 222, 128, 0.6) !important;
}

.highlight-error {
    box-shadow: inset 0 0 0 4px rgba(239, 68, 68, 0.8) !important;
}

.highlight-refutation {
    box-shadow: inset 0 0 0 4px rgba(251, 191, 36, 0.8) !important;
}

/* Shake animation for invalid moves */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.5s ease;
}

/* Opening Display */
.opening-display {
    font-size: 0.85rem;
    color: var(--text-primary);
    padding: 8px 12px;
    background: rgba(233, 69, 96, 0.15);
    border: 1px solid rgba(233, 69, 96, 0.3);
    border-radius: 6px;
    text-align: center;
    transition: all 0.3s ease;
}

.opening-display:empty {
    display: none;
}

.opening-display .eco {
    font-weight: 700;
    color: var(--accent);
    margin-right: 8px;
}

.opening-display .name {
    font-weight: 500;
}

/* Refutation Panel */
.refutation-panel {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 8px;
    width: 100%;
}

.refutation-panel.visible {
    display: flex;
}

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

.refutation-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--error);
}

.refutation-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s ease;
}

.refutation-close:hover {
    color: var(--text-primary);
}

.refutation-line {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.8rem;
    padding: 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    min-height: 28px;
}

.refutation-move {
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.refutation-move.current {
    background: var(--error);
    color: white;
}

.refutation-move.played {
    color: var(--text-secondary);
}

.refutation-move-number {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-right: 2px;
}

.refutation-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
}

.refutation-btn {
    padding: 4px 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.refutation-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.refutation-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.refutation-btn.refutation-play {
    background: var(--error);
    border-color: var(--error);
}

.refutation-btn.refutation-play:hover {
    background: #dc2626;
}

.refutation-btn.refutation-play.playing {
    background: var(--warning);
    border-color: var(--warning);
}

.refutation-position {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 32px;
    text-align: center;
}

/* Status and Actions */
.status {
    font-size: 0.85rem;
    font-weight: 500;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    text-align: center;
    transition: all 0.3s ease;
}

.status.error {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid var(--error);
}

.status.success {
    background: rgba(74, 222, 128, 0.2);
    border: 1px solid var(--success);
}

.status.thinking {
    background: rgba(233, 69, 96, 0.2);
    border: 1px solid var(--accent);
}

.why-btn {
    margin-left: 12px;
    padding: 4px 12px;
    font-size: 0.875rem;
    font-weight: 600;
    color: white;
    background: var(--error);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.why-btn:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.move-quality {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-height: 0;
}

.move-quality:empty {
    display: none;
}

.move-quality.best { color: var(--success); }
.move-quality.good { color: #22d3ee; }
.move-quality.dubious { color: var(--warning); }
.move-quality.blunder { color: var(--error); }

/* Color Selector */
.color-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: auto;
}

.color-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.color-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.color-btn.active {
    background: rgba(233, 69, 96, 0.2);
    border-color: var(--accent);
    color: var(--text-primary);
}

.color-icon {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.white-icon {
    background: #f0f0f0;
}

.black-icon {
    background: #2d2d2d;
}

.btn {
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--accent), #ff6b8a);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(233, 69, 96, 0.4);
}

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

.btn-secondary {
    background: var(--bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

.btn:disabled:hover {
    transform: none;
    box-shadow: none;
}


/* Settings Section */
.settings-section {
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.setting-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.setting-value {
    font-size: 0.75rem;
    color: var(--text-primary);
    min-width: 32px;
    font-weight: 600;
}

.settings-note {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
    margin: 0;
}

/* Slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 5px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease;
}

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

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Thinking dots animation */
.thinking-dots::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Responsive */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }

    .moves-column,
    .actions-column {
        width: 100%;
        max-width: var(--board-size);
    }

    .move-history-container {
        height: auto;
        max-height: 150px;
    }

    .button-group {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .btn {
        width: auto;
        flex: 1;
        min-width: 80px;
    }
}

@media (max-width: 600px) {
    :root {
        --board-size: min(85vw, 400px);
    }

    h1 {
        font-size: 1.5rem;
    }

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

    .eval-bar-container {
        flex-direction: row;
        width: var(--board-size);
    }

    .eval-bar {
        width: 100%;
        height: 20px;
    }

    .eval-fill {
        bottom: auto;
        top: 0;
        left: 0;
        width: 50%;
        height: 100%;
        transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .eval-value {
        margin-top: 0;
        margin-left: 8px;
    }
}
