/* Replay Modal Styling */
.replay-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    /* Standard dimming overlay */
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.replay-modal.active {
    display: flex;
}

.replay-content {
    background: var(--bg-primary);
    /* Use main theme background */
    width: 90%;
    max-width: 900px;
    height: 80vh;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    position: relative;
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.replay-header {
    padding: 1.2rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.replay-controls-top {
    display: flex;
    gap: 1rem;
    align-items: center;
}

#replay-speed {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
}

#close-replay {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: color 0.2s;
}

#close-replay:hover {
    color: var(--error-color);
}

.replay-display-wrapper {
    flex: 1;
    position: relative;
    padding: 2.5rem;
    overflow-y: auto;
    background: var(--bg-primary);
}

#replay-display {
    font-size: 1.5rem;
    line-height: 1.6;
    color: var(--text-tertiary);
    /* Untyped words color */
    user-select: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

#replay-display .word {
    display: flex;
    opacity: 0.6;
    transition: opacity 0.3s;
}

#replay-display .word.current {
    opacity: 1;
}

#replay-display .word.typed {
    opacity: 0.9;
}

#replay-display .char {
    position: relative;
    transition: color 0.1s;
    color: var(--text-tertiary);
}

#replay-display .char.correct {
    color: var(--text-primary);
    font-weight: 500;
}

#replay-display .char.incorrect {
    color: var(--error-color);
    background: rgba(239, 68, 68, 0.1);
}

#replay-display .char.incorrect.extra {
    color: var(--error-color);
    text-decoration: underline;
}

#replay-display .char.skipped {
    background: rgba(239, 68, 68, 0.1);
}

.replay-modal .caret {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    background: var(--accent-color);
    transition: transform 0.05s ease-out;
    /* Faster for smoother feel */
    pointer-events: none;
    z-index: 10;
}

.replay-footer {
    padding: 1.5rem 2rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.replay-progress-container {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.replay-progress-bar {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.1s linear;
}

.replay-actions {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

.replay-actions button {
    padding: 0.8rem 2rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 140px;
    font-size: 1rem;
}

.replay-actions button.primary {
    background: var(--accent-color);
    color: white;
    border: none;
}

.replay-actions button.primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.replay-actions button.secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.replay-actions button.secondary:hover {
    background: var(--bg-primary);
    border-color: var(--accent-color);
}

.replay-actions button.danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ff4757;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.replay-actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.replay-actions button.danger:hover {
    background: #ff4757;
    color: white;
}

#restart-replay {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

#restart-replay:hover {
    background: var(--bg-secondary);
}

/* Theme compatibility */
.dark-theme #replay-speed {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

#close-replay-footer {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

#close-replay-footer:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ff4757;
    border-color: #ff4757;
}

/* Specific Dark Theme Adjustments */
.dark-theme #replay-display .char.correct {
    color: #ffffff;
}

.dark-theme #replay-display .char.incorrect {
    color: #ff5e5e;
}

.dark-theme .replay-actions button.primary {
    color: #1a1f2e;
}

/* Responsive Adjustments */
@media (max-width: 600px) {
    .replay-content {
        width: 95%;
        height: 85vh;
        margin: 0 auto;
    }

    .replay-header {
        padding: 0.8rem 1.2rem;
    }

    .replay-display-wrapper {
        padding: 1rem;
    }

    #replay-display {
        font-size: 1.25rem;
        gap: 0.35rem;
    }

    .replay-footer {
        padding: 1rem;
    }

    .replay-actions {
        gap: 0.8rem;
    }

    .replay-actions button {
        min-width: auto;
        flex: 1;
        padding: 0.8rem 0.5rem;
        font-size: 0.9rem;
    }
}

/* Custom Select Dropdown Compatibility */
.custom-select-wrapper {
    position: relative;
    width: auto;
    min-width: 140px;
}

.custom-select-wrapper select {
    display: none !important;
}

.select-trigger {
    width: auto;
    min-width: 100%;
    padding: 6px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.select-trigger:after {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-tertiary, #64748b);
    border-bottom: 2px solid var(--text-tertiary, #64748b);
    transform: rotate(45deg);
    margin-top: -4px;
    margin-right: 4px;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.custom-select-wrapper.active {
    z-index: 10001;
}

.custom-select-wrapper.active .select-trigger:after {
    transform: rotate(-135deg);
    margin-top: 2px;
}

.select-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--bg-primary);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s;
    overflow-y: auto;
    max-height: 250px;
    z-index: 10002;
    padding: 5px;
}

.custom-select-wrapper.active .select-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.select-option {
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.select-option:hover {
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-color);
}

.select-option.selected {
    background: var(--accent-color);
    color: #ffffff;
}
